aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-11-30 23:53:09 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit6a98c643cabeea25dc42e19fe475a687a034a532 (patch)
treeccb1ecbfc5b79852be8a1f52e241015142a8a7a9 /Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions
parent396768f3b4494c7dcb0c03942eeb50ef4d47adde (diff)
Add a pass to turn global memory access into storage access, and do all storage related transformations on IR
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs12
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs65
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstType.cs8
3 files changed, 22 insertions, 63 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
index b5cab54e..b6cdd7f6 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
@@ -49,12 +49,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
if (argIndex == 0 && atomic)
{
- switch (inst & Instruction.MrMask)
+ Instruction memRegion = inst & Instruction.MrMask;
+
+ switch (memRegion)
{
- // TODO: Global.
case Instruction.MrShared: args += LoadShared (context, operation); break;
case Instruction.MrStorage: args += LoadStorage(context, operation); break;
+
+ default: throw new InvalidOperationException($"Invalid memory region \"{memRegion}\".");
}
+
+ // We use the first 2 operands above.
+ argIndex++;
}
else
{
@@ -150,8 +156,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
}
}
- return "0";
-
throw new InvalidOperationException($"Unexpected instruction type \"{info.Type}\".");
}
}
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index c535d8fc..5c2ea85e 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -119,19 +119,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return OperandManager.GetConstantBufferName(src1, offsetExpr, context.Config.Stage);
}
- public static string LoadGlobal(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
-
- string addrLowExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string addrHighExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
-
- context.AppendLine($"{DefaultNames.GmemOffsetName} = {HelperFunctionNames.GetStorageBuffer}({addrLowExpr}, {addrHighExpr});");
-
- return GetStorageBufferAccessor($"{DefaultNames.GmemOffsetName}.x", $"{DefaultNames.GmemOffsetName}.y", context.Config.Stage);
- }
-
public static string LoadLocal(CodeGenContext context, AstOperation operation)
{
return LoadLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
@@ -154,27 +141,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
public static string LoadStorage(CodeGenContext context, AstOperation operation)
{
IAstNode src1 = operation.GetSource(0);
-
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
-
- return GetStorageBufferAccessor(operation.Index, offsetExpr, context.Config.Stage);
- }
-
- public static string StoreGlobal(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
IAstNode src2 = operation.GetSource(1);
- IAstNode src3 = operation.GetSource(2);
-
- string addrLowExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string addrHighExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
- string valueExpr = GetSoureExpr(context, src3, GetSrcVarType(operation.Inst, 2));
-
- context.AppendLine($"{DefaultNames.GmemOffsetName} = {HelperFunctionNames.GetStorageBuffer}({addrLowExpr}, {addrHighExpr});");
- string sb = GetStorageBufferAccessor($"{DefaultNames.GmemOffsetName}.x", $"{DefaultNames.GmemOffsetName}.y", context.Config.Stage);
+ string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
+ string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
- return $"{sb} = {valueExpr}";
+ return GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
}
public static string StoreLocal(CodeGenContext context, AstOperation operation)
@@ -205,14 +177,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
{
IAstNode src1 = operation.GetSource(0);
IAstNode src2 = operation.GetSource(1);
+ IAstNode src3 = operation.GetSource(2);
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
+ string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
+ string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
- VariableType srcType = OperandManager.GetNodeDestType(src2);
+ VariableType srcType = OperandManager.GetNodeDestType(src3);
- string src = TypeConversion.ReinterpretCast(context, src2, srcType, VariableType.U32);
+ string src = TypeConversion.ReinterpretCast(context, src3, srcType, VariableType.U32);
- string sb = GetStorageBufferAccessor(operation.Index, offsetExpr, context.Config.Stage);
+ string sb = GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
return $"{sb} = {src}";
}
@@ -489,27 +463,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return $"{sbName}[{slotExpr}].{DefaultNames.DataName}[{offsetExpr}]";
}
- private static string GetStorageBufferAccessor(int slot, string offsetExpr, ShaderStage stage)
- {
- string sbName = OperandManager.GetShaderStagePrefix(stage);
-
- sbName += "_" + DefaultNames.StorageNamePrefix;
-
- string mask = NumberFormatter.FormatUint(~(64u - 1));
-
- // Subtract the base address of the global memory, to get the
- // storage buffer offset. The mask is used to keep the lower bits,
- // since the bound storage buffer must match the host alignment
- // restrictions.
- int ubOffset = GlobalToStorage.GetStorageCbOffset(stage, slot);
-
- string ubName = OperandManager.GetConstantBufferName(0, ubOffset, stage);
-
- offsetExpr = $"{offsetExpr} - int((floatBitsToUint({ubName}) & {mask}) >> 2)";
-
- return $"{sbName}[{NumberFormatter.FormatInt(slot)}].{DefaultNames.DataName}[{offsetExpr}]";
- }
-
private static string GetMask(int index)
{
return '.' + "rgba".Substring(index, 1);
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstType.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstType.cs
index 5836e981..84e36cdd 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstType.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstType.cs
@@ -11,15 +11,17 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
OpBinaryCom = Op | 2 | Commutative,
OpTernary = Op | 3,
- AtomicBinary = CallBinary | Atomic,
- AtomicTernary = CallTernary | Atomic,
-
CallNullary = Call | 0,
CallUnary = Call | 1,
CallBinary = Call | 2,
CallTernary = Call | 3,
CallQuaternary = Call | 4,
+ // The atomic instructions have one extra operand,
+ // for the storage slot and offset pair.
+ AtomicBinary = Call | Atomic | 3,
+ AtomicTernary = Call | Atomic | 4,
+
Commutative = 1 << 8,
Op = 1 << 9,
Call = 1 << 10,