From c7f3b337f00db3daaf64120befce603bb2119c1c Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 28 Mar 2020 19:14:05 -0300 Subject: [PATCH] Support constant attributes (with a value of zero) --- Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs | 5 ++++- Ryujinx.Graphics.Gpu/Engine/Methods.cs | 1 + Ryujinx.Graphics.Gpu/State/VertexAttribState.cs | 9 +++++++++ Ryujinx.Graphics.OpenGL/VertexArray.cs | 14 ++++++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs index 34daff57b6..1547658e47 100644 --- a/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs +++ b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs @@ -5,12 +5,15 @@ namespace Ryujinx.Graphics.GAL public int BufferIndex { get; } public int Offset { get; } + public bool IsZero { get; } + public Format Format { get; } - public VertexAttribDescriptor(int bufferIndex, int offset, Format format) + public VertexAttribDescriptor(int bufferIndex, int offset, bool isZero, Format format) { BufferIndex = bufferIndex; Offset = offset; + IsZero = isZero; Format = format; } } diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index a2c9876e42..2835288794 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -506,6 +506,7 @@ namespace Ryujinx.Graphics.Gpu.Engine vertexAttribs[index] = new VertexAttribDescriptor( vertexAttrib.UnpackBufferIndex(), vertexAttrib.UnpackOffset(), + vertexAttrib.UnpackIsConstant(), format); } diff --git a/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs b/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs index 897da79753..c22b1ca93a 100644 --- a/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs +++ b/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs @@ -16,6 +16,15 @@ namespace Ryujinx.Graphics.Gpu.State return (int)(Attribute & 0x1f); } + /// + /// Unpacks the attribute constant flag. + /// + /// True if the attribute is constant, false otherwise + public bool UnpackIsConstant() + { + return (Attribute & 0x40) != 0; + } + /// /// Unpacks the offset, in bytes, of the attribute on the vertex buffer. /// diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs index 721a90f0c7..f4ce1aa49b 100644 --- a/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -58,7 +58,17 @@ namespace Ryujinx.Graphics.OpenGL { FormatInfo fmtInfo = FormatTable.GetFormatInfo(attrib.Format); - GL.EnableVertexAttribArray(attribIndex); + if (attrib.IsZero) + { + // Disabling the attribute causes the shader to read a constant value. + // The value is configurable, but by default is a vector of (0, 0, 0, 1). + GL.DisableVertexAttribArray(attribIndex); + } + else + { + GL.EnableVertexAttribArray(attribIndex); + } + int offset = attrib.Offset; int size = fmtInfo.Components; @@ -117,7 +127,7 @@ namespace Ryujinx.Graphics.OpenGL continue; } - if (_needsAttribsUpdate) + if (_needsAttribsUpdate && !attrib.IsZero) { GL.EnableVertexAttribArray(attribIndex); }