diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-04-20 07:33:54 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-20 12:33:54 +0200 |
| commit | 4770cfa920b606b1496ca9348c3dd69b476dbbbf (patch) | |
| tree | 864a33b60a4bf30239e26f720026f4988e72d220 /Ryujinx.Graphics.Shader | |
| parent | 89791ba68dba70999643c5d876e9329b385c6e8a (diff) | |
Only enable clip distance if written to on shader (#2217)
* Only enable clip distance if written to on shader
* Signal InstanceId use through FeatureFlags
* Shader cache version bump
Diffstat (limited to 'Ryujinx.Graphics.Shader')
8 files changed, 44 insertions, 10 deletions
diff --git a/Ryujinx.Graphics.Shader/Instructions/InstEmitMemory.cs b/Ryujinx.Graphics.Shader/Instructions/InstEmitMemory.cs index 81d5c7af..7afdbf4e 100644 --- a/Ryujinx.Graphics.Shader/Instructions/InstEmitMemory.cs +++ b/Ryujinx.Graphics.Shader/Instructions/InstEmitMemory.cs @@ -53,6 +53,8 @@ namespace Ryujinx.Graphics.Shader.Instructions Operand dest = Attribute(op.AttributeOffset + index * 4); + context.FlagAttributeWritten(dest.Value); + context.Copy(dest, Register(rd)); } } diff --git a/Ryujinx.Graphics.Shader/ShaderProgramInfo.cs b/Ryujinx.Graphics.Shader/ShaderProgramInfo.cs index 2324fac2..9329442f 100644 --- a/Ryujinx.Graphics.Shader/ShaderProgramInfo.cs +++ b/Ryujinx.Graphics.Shader/ShaderProgramInfo.cs @@ -11,13 +11,15 @@ namespace Ryujinx.Graphics.Shader public ReadOnlyCollection<TextureDescriptor> Images { get; } public bool UsesInstanceId { get; } + public byte ClipDistancesWritten { get; } public ShaderProgramInfo( BufferDescriptor[] cBuffers, BufferDescriptor[] sBuffers, TextureDescriptor[] textures, TextureDescriptor[] images, - bool usesInstanceId) + bool usesInstanceId, + byte clipDistancesWritten) { CBuffers = Array.AsReadOnly(cBuffers); SBuffers = Array.AsReadOnly(sBuffers); @@ -25,6 +27,7 @@ namespace Ryujinx.Graphics.Shader Images = Array.AsReadOnly(images); UsesInstanceId = usesInstanceId; + ClipDistancesWritten = clipDistancesWritten; } } }
\ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs index 2667be1d..c4d8b85f 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramContext.cs @@ -291,10 +291,6 @@ namespace Ryujinx.Graphics.Shader.StructuredIr { Info.IAttributes.Add(attrIndex); } - else if (operand.Type == OperandType.Attribute && operand.Value == AttributeConsts.InstanceId) - { - Info.UsesInstanceId = true; - } else if (operand.Type == OperandType.ConstantBuffer) { Info.CBuffers.Add(operand.GetCbufSlot()); diff --git a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramInfo.cs b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramInfo.cs index 16a27f51..d1619bfa 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramInfo.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgramInfo.cs @@ -12,7 +12,6 @@ namespace Ryujinx.Graphics.Shader.StructuredIr public HashSet<int> IAttributes { get; } public HashSet<int> OAttributes { get; } - public bool UsesInstanceId { get; set; } public bool UsesCbIndexing { get; set; } public HelperFunctionsMask HelperFunctionsMask { get; set; } diff --git a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs index a4c21c1d..9b220177 100644 --- a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs +++ b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs @@ -55,7 +55,11 @@ namespace Ryujinx.Graphics.Shader.Translation public void FlagAttributeRead(int attribute) { - if (Config.Stage == ShaderStage.Fragment) + if (Config.Stage == ShaderStage.Vertex && attribute == AttributeConsts.InstanceId) + { + Config.SetUsedFeature(FeatureFlags.InstanceId); + } + else if (Config.Stage == ShaderStage.Fragment) { switch (attribute) { @@ -67,6 +71,26 @@ namespace Ryujinx.Graphics.Shader.Translation } } + public void FlagAttributeWritten(int attribute) + { + if (Config.Stage == ShaderStage.Vertex) + { + switch (attribute) + { + case AttributeConsts.ClipDistance0: + case AttributeConsts.ClipDistance1: + case AttributeConsts.ClipDistance2: + case AttributeConsts.ClipDistance3: + case AttributeConsts.ClipDistance4: + case AttributeConsts.ClipDistance5: + case AttributeConsts.ClipDistance6: + case AttributeConsts.ClipDistance7: + Config.SetClipDistanceWritten((attribute - AttributeConsts.ClipDistance0) / 4); + break; + } + } + } + public void MarkLabel(Operand label) { Add(Instruction.MarkLabel, label); diff --git a/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs b/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs index d2b53f84..1b712896 100644 --- a/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs +++ b/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs @@ -12,9 +12,11 @@ namespace Ryujinx.Graphics.Shader.Translation None = 0, // Affected by resolution scaling. - FragCoordXY = 1 << 1, IntegerSampling = 1 << 0, + FragCoordXY = 1 << 1, + + Bindless = 1 << 2, - Bindless = 1 << 2, + InstanceId = 1 << 3 } } diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs index b1fd6470..c71a8398 100644 --- a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs +++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs @@ -28,6 +28,8 @@ namespace Ryujinx.Graphics.Shader.Translation public int Size { get; private set; } + public byte ClipDistancesWritten { get; private set; } + public FeatureFlags UsedFeatures { get; private set; } public HashSet<int> TextureHandlesForCache { get; } @@ -115,6 +117,11 @@ namespace Ryujinx.Graphics.Shader.Translation Size += size; } + public void SetClipDistanceWritten(int index) + { + ClipDistancesWritten |= (byte)(1 << index); + } + public void SetUsedFeature(FeatureFlags flags) { UsedFeatures |= flags; diff --git a/Ryujinx.Graphics.Shader/Translation/Translator.cs b/Ryujinx.Graphics.Shader/Translation/Translator.cs index 9f0f9010..1c15ccf2 100644 --- a/Ryujinx.Graphics.Shader/Translation/Translator.cs +++ b/Ryujinx.Graphics.Shader/Translation/Translator.cs @@ -94,7 +94,8 @@ namespace Ryujinx.Graphics.Shader.Translation program.SBufferDescriptors, program.TextureDescriptors, program.ImageDescriptors, - sInfo.UsesInstanceId); + config.UsedFeatures.HasFlag(FeatureFlags.InstanceId), + config.ClipDistancesWritten); string glslCode = program.Code; |
