aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
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/Translation/Rewriter.cs
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/Translation/Rewriter.cs')
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs b/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
index baa88251..f5a524a0 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
@@ -1,6 +1,8 @@
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.StructuredIr;
+using Ryujinx.Graphics.Shader.Translation.Optimizations;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
@@ -70,6 +72,15 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
}
+ else
+ {
+ node = InsertSharedStoreSmallInt(hfm, node);
+
+ if (config.Options.TargetLanguage != TargetLanguage.Spirv)
+ {
+ node = InsertSharedAtomicSigned(hfm, node);
+ }
+ }
}
}
}
@@ -171,6 +182,87 @@ namespace Ryujinx.Graphics.Shader.Translation
operation.TurnIntoCopy(result);
}
+ private static LinkedListNode<INode> InsertSharedStoreSmallInt(HelperFunctionManager hfm, LinkedListNode<INode> node)
+ {
+ Operation operation = (Operation)node.Value;
+ HelperFunctionName name;
+
+ if (operation.StorageKind == StorageKind.SharedMemory8)
+ {
+ name = HelperFunctionName.SharedStore8;
+ }
+ else if (operation.StorageKind == StorageKind.SharedMemory16)
+ {
+ name = HelperFunctionName.SharedStore16;
+ }
+ else
+ {
+ return node;
+ }
+
+ if (operation.Inst != Instruction.Store)
+ {
+ return node;
+ }
+
+ Operand memoryId = operation.GetSource(0);
+ Operand byteOffset = operation.GetSource(1);
+ Operand value = operation.GetSource(2);
+
+ Debug.Assert(memoryId.Type == OperandType.Constant);
+
+ int functionId = hfm.GetOrCreateFunctionId(name, memoryId.Value);
+
+ Operand[] callArgs = new Operand[] { Const(functionId), byteOffset, value };
+
+ LinkedListNode<INode> newNode = node.List.AddBefore(node, new Operation(Instruction.Call, 0, (Operand)null, callArgs));
+
+ Utils.DeleteNode(node, operation);
+
+ return newNode;
+ }
+
+ private static LinkedListNode<INode> InsertSharedAtomicSigned(HelperFunctionManager hfm, LinkedListNode<INode> node)
+ {
+ Operation operation = (Operation)node.Value;
+ HelperFunctionName name;
+
+ if (operation.Inst == Instruction.AtomicMaxS32)
+ {
+ name = HelperFunctionName.SharedAtomicMaxS32;
+ }
+ else if (operation.Inst == Instruction.AtomicMinS32)
+ {
+ name = HelperFunctionName.SharedAtomicMinS32;
+ }
+ else
+ {
+ return node;
+ }
+
+ if (operation.StorageKind != StorageKind.SharedMemory)
+ {
+ return node;
+ }
+
+ Operand result = operation.Dest;
+ Operand memoryId = operation.GetSource(0);
+ Operand byteOffset = operation.GetSource(1);
+ Operand value = operation.GetSource(2);
+
+ Debug.Assert(memoryId.Type == OperandType.Constant);
+
+ int functionId = hfm.GetOrCreateFunctionId(name, memoryId.Value);
+
+ Operand[] callArgs = new Operand[] { Const(functionId), byteOffset, value };
+
+ LinkedListNode<INode> newNode = node.List.AddBefore(node, new Operation(Instruction.Call, 0, result, callArgs));
+
+ Utils.DeleteNode(node, operation);
+
+ return newNode;
+ }
+
private static LinkedListNode<INode> InsertTexelFetchScale(HelperFunctionManager hfm, LinkedListNode<INode> node, ShaderConfig config)
{
TextureOperation texOp = (TextureOperation)node.Value;