aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2023-06-15 17:31:53 -0300
committerGitHub <noreply@github.com>2023-06-15 17:31:53 -0300
commitf92921a6d118aa9c6acdb3ecaa3cd61a19fe341e (patch)
tree6cba0d6ad1dc27df5750cf671cd75f709082203d /src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions
parent32d21ddf17ff7d61d8185a79bec3f5d02706109b (diff)
Implement Load/Store Local/Shared and Atomic shared using new instructions (#5241)
* Implement Load/Store Local/Shared and Atomic shared using new instructions * Remove now unused code * Fix base offset register overwrite * Fix missing storage buffer set index when generating GLSL for Vulkan * Shader cache version bump * Remove more unused code * Some PR feedback
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions')
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs37
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs8
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs86
3 files changed, 16 insertions, 115 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
index 01d8a6e7..b2577a99 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
@@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
string args = string.Empty;
- if (atomic && operation.StorageKind == StorageKind.StorageBuffer)
+ if (atomic && (operation.StorageKind == StorageKind.StorageBuffer || operation.StorageKind == StorageKind.SharedMemory))
{
args = GenerateLoadOrStore(context, operation, isStore: false);
@@ -81,23 +81,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
args += ", " + GetSoureExpr(context, operation.GetSource(argIndex), dstType);
}
}
- else if (atomic && operation.StorageKind == StorageKind.SharedMemory)
- {
- args = LoadShared(context, operation);
-
- // For shared memory access, the second argument is unused and should be ignored.
- // It is there to make both storage and shared access have the same number of arguments.
- // For storage, both inputs are consumed when the argument index is 0, so we should skip it here.
-
- for (int argIndex = 2; argIndex < arity; argIndex++)
- {
- args += ", ";
-
- AggregateType dstType = GetSrcVarType(inst, argIndex);
-
- args += GetSoureExpr(context, operation.GetSource(argIndex), dstType);
- }
- }
else
{
for (int argIndex = 0; argIndex < arity; argIndex++)
@@ -179,12 +162,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
case Instruction.Load:
return Load(context, operation);
- case Instruction.LoadLocal:
- return LoadLocal(context, operation);
-
- case Instruction.LoadShared:
- return LoadShared(context, operation);
-
case Instruction.Lod:
return Lod(context, operation);
@@ -200,18 +177,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
case Instruction.Store:
return Store(context, operation);
- case Instruction.StoreLocal:
- return StoreLocal(context, operation);
-
- case Instruction.StoreShared:
- return StoreShared(context, operation);
-
- case Instruction.StoreShared16:
- return StoreShared16(context, operation);
-
- case Instruction.StoreShared8:
- return StoreShared8(context, operation);
-
case Instruction.TextureSample:
return TextureSample(context, operation);
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
index f42d9898..8b0b744a 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
@@ -17,9 +17,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.AtomicAdd, InstType.AtomicBinary, "atomicAdd");
Add(Instruction.AtomicAnd, InstType.AtomicBinary, "atomicAnd");
Add(Instruction.AtomicCompareAndSwap, InstType.AtomicTernary, "atomicCompSwap");
- Add(Instruction.AtomicMaxS32, InstType.CallTernary, HelperFunctionNames.AtomicMaxS32);
Add(Instruction.AtomicMaxU32, InstType.AtomicBinary, "atomicMax");
- Add(Instruction.AtomicMinS32, InstType.CallTernary, HelperFunctionNames.AtomicMinS32);
Add(Instruction.AtomicMinU32, InstType.AtomicBinary, "atomicMin");
Add(Instruction.AtomicOr, InstType.AtomicBinary, "atomicOr");
Add(Instruction.AtomicSwap, InstType.AtomicBinary, "atomicExchange");
@@ -83,8 +81,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.ImageAtomic, InstType.Special);
Add(Instruction.IsNan, InstType.CallUnary, "isnan");
Add(Instruction.Load, InstType.Special);
- Add(Instruction.LoadLocal, InstType.Special);
- Add(Instruction.LoadShared, InstType.Special);
Add(Instruction.Lod, InstType.Special);
Add(Instruction.LogarithmB2, InstType.CallUnary, "log2");
Add(Instruction.LogicalAnd, InstType.OpBinaryCom, "&&", 9);
@@ -118,10 +114,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.Sine, InstType.CallUnary, "sin");
Add(Instruction.SquareRoot, InstType.CallUnary, "sqrt");
Add(Instruction.Store, InstType.Special);
- Add(Instruction.StoreLocal, InstType.Special);
- Add(Instruction.StoreShared, InstType.Special);
- Add(Instruction.StoreShared16, InstType.Special);
- Add(Instruction.StoreShared8, InstType.Special);
Add(Instruction.Subtract, InstType.OpBinary, "-", 2);
Add(Instruction.SwizzleAdd, InstType.CallTernary, HelperFunctionNames.SwizzleAdd);
Add(Instruction.TextureSample, InstType.Special);
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index c8084d9d..99376ffb 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -191,25 +191,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return GenerateLoadOrStore(context, operation, isStore: false);
}
- public static string LoadLocal(CodeGenContext context, AstOperation operation)
- {
- return LoadLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
- }
-
- public static string LoadShared(CodeGenContext context, AstOperation operation)
- {
- return LoadLocalOrShared(context, operation, DefaultNames.SharedMemoryName);
- }
-
- private static string LoadLocalOrShared(CodeGenContext context, AstOperation operation, string arrayName)
- {
- IAstNode src1 = operation.GetSource(0);
-
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
-
- return $"{arrayName}[{offsetExpr}]";
- }
-
public static string Lod(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;
@@ -263,58 +244,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return GenerateLoadOrStore(context, operation, isStore: true);
}
- public static string StoreLocal(CodeGenContext context, AstOperation operation)
- {
- return StoreLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
- }
-
- public static string StoreShared(CodeGenContext context, AstOperation operation)
- {
- return StoreLocalOrShared(context, operation, DefaultNames.SharedMemoryName);
- }
-
- private static string StoreLocalOrShared(CodeGenContext context, AstOperation operation, string arrayName)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
-
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src2);
-
- string src = TypeConversion.ReinterpretCast(context, src2, srcType, AggregateType.U32);
-
- return $"{arrayName}[{offsetExpr}] = {src}";
- }
-
- public static string StoreShared16(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
-
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src2);
-
- string src = TypeConversion.ReinterpretCast(context, src2, srcType, AggregateType.U32);
-
- return $"{HelperFunctionNames.StoreShared16}({offsetExpr}, {src})";
- }
-
- public static string StoreShared8(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
-
- string offsetExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src2);
-
- string src = TypeConversion.ReinterpretCast(context, src2, srcType, AggregateType.U32);
-
- return $"{HelperFunctionNames.StoreShared8}({offsetExpr}, {src})";
- }
-
public static string TextureSample(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;
@@ -675,6 +604,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
varType = field.Type;
break;
+ case StorageKind.LocalMemory:
+ case StorageKind.SharedMemory:
+ if (!(operation.GetSource(srcIndex++) is AstOperand bindingId) || bindingId.Type != OperandType.Constant)
+ {
+ throw new InvalidOperationException($"First input of {operation.Inst} with {storageKind} storage must be a constant operand.");
+ }
+
+ MemoryDefinition memory = storageKind == StorageKind.LocalMemory
+ ? context.Config.Properties.LocalMemories[bindingId.Value]
+ : context.Config.Properties.SharedMemories[bindingId.Value];
+
+ varName = memory.Name;
+ varType = memory.Type;
+ break;
+
case StorageKind.Input:
case StorageKind.InputPerPatch:
case StorageKind.Output: