aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-11-24 19:49:19 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit73e68edd09cc322579ec832576f766c836851fdf (patch)
treee2c1a457666a11427ca3a26d701720bfe508e0e3 /Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
parent1df78e7ad65459d990fa2dcf391da1296dfd886c (diff)
Revert "Simplify shader uniform buffer access codegen"
This reverts commit 2fe9ebaf118d690be8d0cb302529dd359d7c402b.
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs24
1 files changed, 18 insertions, 6 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
index 802b32e1..4c9d5b55 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
@@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
return NumberFormatter.FormatInt(operand.Value);
case OperandType.ConstantBuffer:
- return GetUniformBufferAccessor(operand.CbufSlot, operand.CbufOffset, stage);
+ return GetConstantBufferName(operand.CbufSlot, operand.CbufOffset, stage);
case OperandType.LocalVariable:
return _locals[operand];
@@ -105,16 +105,28 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
throw new ArgumentException($"Invalid operand type \"{operand.Type}\".");
}
- public static string GetUniformBufferAccessor(int slot, int offset, ShaderStage stage)
+ public static string GetConstantBufferName(int slot, int offset, ShaderStage stage)
{
- return GetUniformBufferAccessor(slot, NumberFormatter.FormatInt(offset), stage);
+ string ubName = GetUbName(stage, slot);
+
+ ubName += "[" + (offset >> 2) + "]";
+
+ return ubName + "." + GetSwizzleMask(offset & 3);
}
- public static string GetUniformBufferAccessor(int slot, string offsetExpr, ShaderStage stage)
+ public static string GetConstantBufferName(IAstNode slot, string offsetExpr, ShaderStage stage)
{
- string ubName = GetUbName(stage, slot);
+ // Non-constant slots are not supported.
+ // It is expected that upstream stages are never going to generate non-constant
+ // slot access.
+ AstOperand operand = (AstOperand)slot;
+
+ string ubName = GetUbName(stage, operand.Value);
+
+ string index0 = "[" + offsetExpr + " >> 2]";
+ string index1 = "[" + offsetExpr + " & 3]";
- return $"{ubName}[{offsetExpr}]";
+ return ubName + index0 + index1;
}
public static string GetOutAttributeName(AstOperand attr, ShaderStage stage)