diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-08-11 16:33:43 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-11 21:33:43 +0200 |
| commit | 0f6ec446ea3be41b1c22aa5c3870bd7a6c595d1f (patch) | |
| tree | e441560dbdd560e9a020bb4b7606d3cd0698da02 /Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs | |
| parent | b5b7e23fc41e7045f9e803d6926e98ec7d049f0c (diff) | |
Replace BGRA and scale uniforms with a uniform block (#2496)
* Replace BGRA and scale uniforms with a uniform block
* Setting the data again on program change is no longer needed
* Optimize and resolve some warnings
* Avoid redundant support buffer updates
* Some optimizations to BindBuffers (now inlined)
* Unify render scale arrays
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs')
| -rw-r--r-- | Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index e1f49065..478ae497 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -1,9 +1,7 @@ using Ryujinx.Common; -using Ryujinx.Graphics.Shader.IntermediateRepresentation; using Ryujinx.Graphics.Shader.StructuredIr; using Ryujinx.Graphics.Shader.Translation; using System; -using System.Collections.Generic; using System.Linq; namespace Ryujinx.Graphics.Shader.CodeGen.Glsl @@ -159,23 +157,38 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl context.AppendLine(); } - if (context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) + bool isFragment = context.Config.Stage == ShaderStage.Fragment; + + if (isFragment || context.Config.Stage == ShaderStage.Compute) { - if (context.Config.Stage == ShaderStage.Fragment) + if (isFragment && context.Config.GpuAccessor.QueryEarlyZForce()) + { + context.AppendLine("layout(early_fragment_tests) in;"); + context.AppendLine(); + } + + if ((context.Config.UsedFeatures & (FeatureFlags.FragCoordXY | FeatureFlags.IntegerSampling)) != 0) { - if (context.Config.GpuAccessor.QueryEarlyZForce()) + string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage); + + int scaleElements = context.Config.GetTextureDescriptors().Length + context.Config.GetImageDescriptors().Length; + + if (isFragment) { - context.AppendLine("layout(early_fragment_tests) in;"); - context.AppendLine(); + scaleElements++; // Also includes render target scale, for gl_FragCoord. } - context.AppendLine($"uniform bool {DefaultNames.IsBgraName}[8];"); - context.AppendLine(); - } + DeclareSupportUniformBlock(context, isFragment, scaleElements); - if (DeclareRenderScale(context)) + if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IntegerSampling)) + { + AppendHelperFunction(context, $"Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_{stage}.glsl"); + context.AppendLine(); + } + } + else if (isFragment) { - context.AppendLine(); + DeclareSupportUniformBlock(context, true, 0); } } @@ -498,31 +511,33 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } } - private static bool DeclareRenderScale(CodeGenContext context) + private static void DeclareSupportUniformBlock(CodeGenContext context, bool isFragment, int scaleElements) { - if ((context.Config.UsedFeatures & (FeatureFlags.FragCoordXY | FeatureFlags.IntegerSampling)) != 0) + if (!isFragment && scaleElements == 0) { - string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage); - - int scaleElements = context.Config.GetTextureDescriptors().Length + context.Config.GetImageDescriptors().Length; - - if (context.Config.Stage == ShaderStage.Fragment) - { - scaleElements++; // Also includes render target scale, for gl_FragCoord. - } + return; + } - context.AppendLine($"uniform float {stage}_renderScale[{scaleElements}];"); + context.AppendLine($"layout (binding = 0, std140) uniform {DefaultNames.SupportBlockName}"); + context.EnterScope(); - if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IntegerSampling)) - { - context.AppendLine(); - AppendHelperFunction(context, $"Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_{stage}.glsl"); - } + if (isFragment) + { + context.AppendLine($"uint {DefaultNames.SupportBlockAlphaTestName};"); + context.AppendLine($"bool {DefaultNames.SupportBlockIsBgraName}[{SupportBuffer.FragmentIsBgraCount}];"); + } + else + { + context.AppendLine($"uint s_reserved[{SupportBuffer.ComputeRenderScaleOffset / SupportBuffer.FieldSize}];"); + } - return true; + if (scaleElements != 0) + { + context.AppendLine($"float {DefaultNames.SupportBlockRenderScaleName}[{scaleElements}];"); } - return false; + context.LeaveScope(";"); + context.AppendLine(); } private static void AppendHelperFunction(CodeGenContext context, string filename) |
