aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs')
-rw-r--r--src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs89
1 files changed, 12 insertions, 77 deletions
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index dfc8197b..c8084d9d 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -210,17 +210,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return $"{arrayName}[{offsetExpr}]";
}
- public static string LoadStorage(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
-
- string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
-
- return GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
- }
-
public static string Lod(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;
@@ -326,60 +315,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return $"{HelperFunctionNames.StoreShared8}({offsetExpr}, {src})";
}
- public static string StoreStorage(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
- IAstNode src3 = operation.GetSource(2);
-
- string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src3);
-
- string src = TypeConversion.ReinterpretCast(context, src3, srcType, AggregateType.U32);
-
- string sb = GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
-
- return $"{sb} = {src}";
- }
-
- public static string StoreStorage16(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
- IAstNode src3 = operation.GetSource(2);
-
- string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src3);
-
- string src = TypeConversion.ReinterpretCast(context, src3, srcType, AggregateType.U32);
-
- string sb = GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
-
- return $"{HelperFunctionNames.StoreStorage16}({indexExpr}, {offsetExpr}, {src})";
- }
-
- public static string StoreStorage8(CodeGenContext context, AstOperation operation)
- {
- IAstNode src1 = operation.GetSource(0);
- IAstNode src2 = operation.GetSource(1);
- IAstNode src3 = operation.GetSource(2);
-
- string indexExpr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 0));
- string offsetExpr = GetSoureExpr(context, src2, GetSrcVarType(operation.Inst, 1));
-
- AggregateType srcType = OperandManager.GetNodeDestType(context, src3);
-
- string src = TypeConversion.ReinterpretCast(context, src3, srcType, AggregateType.U32);
-
- string sb = GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
-
- return $"{HelperFunctionNames.StoreStorage8}({indexExpr}, {offsetExpr}, {src})";
- }
-
public static string TextureSample(CodeGenContext context, AstOperation operation)
{
AstTextureOperation texOp = (AstTextureOperation)operation;
@@ -701,25 +636,34 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
}
}
- private static string GenerateLoadOrStore(CodeGenContext context, AstOperation operation, bool isStore)
+ public static string GenerateLoadOrStore(CodeGenContext context, AstOperation operation, bool isStore)
{
StorageKind storageKind = operation.StorageKind;
string varName;
AggregateType varType;
int srcIndex = 0;
- int inputsCount = isStore ? operation.SourcesCount - 1 : operation.SourcesCount;
+ bool isStoreOrAtomic = operation.Inst == Instruction.Store || operation.Inst.IsAtomic();
+ int inputsCount = isStoreOrAtomic ? operation.SourcesCount - 1 : operation.SourcesCount;
+
+ if (operation.Inst == Instruction.AtomicCompareAndSwap)
+ {
+ inputsCount--;
+ }
switch (storageKind)
{
case StorageKind.ConstantBuffer:
+ case StorageKind.StorageBuffer:
if (!(operation.GetSource(srcIndex++) is AstOperand bindingIndex) || bindingIndex.Type != OperandType.Constant)
{
throw new InvalidOperationException($"First input of {operation.Inst} with {storageKind} storage must be a constant operand.");
}
int binding = bindingIndex.Value;
- BufferDefinition buffer = context.Config.Properties.ConstantBuffers[binding];
+ BufferDefinition buffer = storageKind == StorageKind.ConstantBuffer
+ ? context.Config.Properties.ConstantBuffers[binding]
+ : context.Config.Properties.StorageBuffers[binding];
if (!(operation.GetSource(srcIndex++) is AstOperand fieldIndex) || fieldIndex.Type != OperandType.Constant)
{
@@ -825,15 +769,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return varName;
}
- private static string GetStorageBufferAccessor(string slotExpr, string offsetExpr, ShaderStage stage)
- {
- string sbName = OperandManager.GetShaderStagePrefix(stage);
-
- sbName += "_" + DefaultNames.StorageNamePrefix;
-
- return $"{sbName}[{slotExpr}].{DefaultNames.DataName}[{offsetExpr}]";
- }
-
private static string GetMask(int index)
{
return $".{"rgba".AsSpan(index, 1)}";