aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-10-12 21:40:50 -0300
committerGitHub <noreply@github.com>2020-10-12 21:40:50 -0300
commitb066cfc1a3e31bf7197ddbd0f4d774b886cd9d65 (patch)
tree95a1d0bb640948c184857fd1bccb56cad90839fb /Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
parent14fd9aa640936d2455c9f0929fc904a5bdb2fada (diff)
Add support for shader constant buffer slot indexing (#1608)
* Add support for shader constant buffer slot indexing * Fix typo
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs87
1 files changed, 60 insertions, 27 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index a7b67a60..cd82aa02 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -213,51 +213,57 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
private static void DeclareUniforms(CodeGenContext context, StructuredProgramInfo info)
{
- foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
+ string ubSize = "[" + NumberFormatter.FormatInt(Constants.ConstantBufferSize / 16) + "]";
+
+ if (info.UsesCbIndexing)
{
string ubName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
- ubName += "_" + DefaultNames.UniformNamePrefix + cbufSlot;
+ ubName += "_" + DefaultNames.UniformNamePrefix;
+
+ string blockName = $"{ubName}_{DefaultNames.BlockSuffix}";
+
+ int maxSlot = 0;
+
+ foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
+ {
+ context.CBufferDescriptors.Add(new BufferDescriptor($"{blockName}[{cbufSlot}]", cbufSlot));
- context.CBufferDescriptors.Add(new BufferDescriptor(ubName, cbufSlot));
+ if (maxSlot < cbufSlot)
+ {
+ maxSlot = cbufSlot;
+ }
+ }
- context.AppendLine("layout (std140) uniform " + ubName);
+ context.AppendLine("layout (std140) uniform " + blockName);
context.EnterScope();
- string ubSize = "[" + NumberFormatter.FormatInt(Constants.ConstantBufferSize / 16) + "]";
+ context.AppendLine("vec4 " + DefaultNames.DataName + ubSize + ";");
- context.AppendLine("vec4 " + OperandManager.GetUbName(context.Config.Stage, cbufSlot) + ubSize + ";");
+ string arraySize = NumberFormatter.FormatInt(maxSlot + 1);
- context.LeaveScope(";");
+ context.LeaveScope($" {ubName}[{arraySize}];");
}
- }
-
- private static bool DeclareRenderScale(CodeGenContext context)
- {
- if ((context.Config.UsedFeatures & (FeatureFlags.FragCoordXY | FeatureFlags.IntegerSampling)) != 0)
+ else
{
- string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage);
+ foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
+ {
+ string ubName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
- int scaleElements = context.TextureDescriptors.Count;
+ ubName += "_" + DefaultNames.UniformNamePrefix + cbufSlot;
- if (context.Config.Stage == ShaderStage.Fragment)
- {
- scaleElements++; // Also includes render target scale, for gl_FragCoord.
- }
+ context.CBufferDescriptors.Add(new BufferDescriptor(ubName, cbufSlot));
- context.AppendLine($"uniform float {stage}_renderScale[{scaleElements}];");
+ context.AppendLine("layout (std140) uniform " + ubName);
- if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IntegerSampling))
- {
- context.AppendLine();
- AppendHelperFunction(context, $"Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_{stage}.glsl");
- }
+ context.EnterScope();
- return true;
- }
+ context.AppendLine("vec4 " + OperandManager.GetUbName(context.Config.Stage, cbufSlot, false) + ubSize + ";");
- return false;
+ context.LeaveScope(";");
+ }
+ }
}
private static void DeclareStorages(CodeGenContext context, StructuredProgramInfo info)
@@ -500,6 +506,33 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
}
+ private static bool DeclareRenderScale(CodeGenContext context)
+ {
+ if ((context.Config.UsedFeatures & (FeatureFlags.FragCoordXY | FeatureFlags.IntegerSampling)) != 0)
+ {
+ string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage);
+
+ int scaleElements = context.TextureDescriptors.Count;
+
+ if (context.Config.Stage == ShaderStage.Fragment)
+ {
+ scaleElements++; // Also includes render target scale, for gl_FragCoord.
+ }
+
+ context.AppendLine($"uniform float {stage}_renderScale[{scaleElements}];");
+
+ if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IntegerSampling))
+ {
+ context.AppendLine();
+ AppendHelperFunction(context, $"Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_{stage}.glsl");
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
private static void AppendHelperFunction(CodeGenContext context, string filename)
{
string code = EmbeddedResources.ReadAllText(filename);