aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2021-08-31 06:51:57 +0100
committerGitHub <noreply@github.com>2021-08-31 02:51:57 -0300
commit142cededd4db2ff4f83a4833580d343a4f0a8cde (patch)
tree426e8ed20d182663a7666666c08a5566c8d204fb /Ryujinx.Graphics.Shader/CodeGen
parent416dc8fde49f8eb42d47b1ab606028a5cabe8f90 (diff)
Implement Shader Instructions SUATOM and SURED (#2090)
* Initial Implementation * Further improvements (no support for float/64-bit types) * Merge atomic and reduce instructions, add missing format switch * Fix rebase issues. * Not used. * Whoops. Fixed. * Partial implementation of inc/dec, cleanup and TODOs * Remove testing path * Address Feedback
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs3
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs1
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs62
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs3
4 files changed, 61 insertions, 8 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
index 41a8b942..24d4cabd 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
@@ -132,9 +132,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return Call(context, operation);
case Instruction.ImageLoad:
- return ImageLoadOrStore(context, operation);
-
case Instruction.ImageStore:
+ case Instruction.ImageAtomic:
return ImageLoadOrStore(context, operation);
case Instruction.LoadAttribute:
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
index a4957658..6f4f0c4e 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
@@ -72,6 +72,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.GroupMemoryBarrier, InstType.CallNullary, "groupMemoryBarrier");
Add(Instruction.ImageLoad, InstType.Special);
Add(Instruction.ImageStore, InstType.Special);
+ Add(Instruction.ImageAtomic, InstType.Special);
Add(Instruction.IsNan, InstType.CallUnary, "isnan");
Add(Instruction.LoadAttribute, InstType.Special);
Add(Instruction.LoadConstant, InstType.Special);
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index a0aec28e..89215736 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -18,13 +18,39 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
// TODO: Bindless texture support. For now we just return 0/do nothing.
if (isBindless)
{
- return texOp.Inst == Instruction.ImageLoad ? NumberFormatter.FormatFloat(0) : "// imageStore(bindless)";
+ return texOp.Inst switch
+ {
+ Instruction.ImageStore => "// imageStore(bindless)",
+ Instruction.ImageLoad => NumberFormatter.FormatFloat(0),
+ _ => NumberFormatter.FormatInt(0)
+ };
}
bool isArray = (texOp.Type & SamplerType.Array) != 0;
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
- string texCall = texOp.Inst == Instruction.ImageLoad ? "imageLoad" : "imageStore";
+ string texCall;
+
+ if (texOp.Inst == Instruction.ImageAtomic)
+ {
+ texCall = (texOp.Flags & TextureFlags.AtomicMask) switch {
+ TextureFlags.Add => "imageAtomicAdd",
+ TextureFlags.Minimum => "imageAtomicMin",
+ TextureFlags.Maximum => "imageAtomicMax",
+ TextureFlags.Increment => "imageAtomicAdd", // TODO: Clamp value.
+ TextureFlags.Decrement => "imageAtomicAdd", // TODO: Clamp value.
+ TextureFlags.BitwiseAnd => "imageAtomicAnd",
+ TextureFlags.BitwiseOr => "imageAtomicOr",
+ TextureFlags.BitwiseXor => "imageAtomicXor",
+ TextureFlags.Swap => "imageAtomicExchange",
+ TextureFlags.CAS => "imageAtomicCompSwap",
+ _ => "imageAtomicAdd",
+ };
+ }
+ else
+ {
+ texCall = texOp.Inst == Instruction.ImageLoad ? "imageLoad" : "imageStore";
+ }
int srcIndex = isBindless ? 1 : 0;
@@ -95,8 +121,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
if (texOp.Inst == Instruction.ImageStore)
{
- int texIndex = context.FindImageDescriptorIndex(texOp);
-
VariableType type = texOp.Format.GetComponentType();
string[] cElems = new string[4];
@@ -128,7 +152,35 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Append(prefix + "vec4(" + string.Join(", ", cElems) + ")");
}
- texCall += ")" + (texOp.Inst == Instruction.ImageLoad ? GetMask(texOp.Index) : "");
+ if (texOp.Inst == Instruction.ImageAtomic)
+ {
+ VariableType type = texOp.Format.GetComponentType();
+
+ if ((texOp.Flags & TextureFlags.AtomicMask) == TextureFlags.CAS)
+ {
+ Append(Src(type)); // Compare value.
+ }
+
+ string value = (texOp.Flags & TextureFlags.AtomicMask) switch
+ {
+ TextureFlags.Increment => NumberFormatter.FormatInt(1, type), // TODO: Clamp value
+ TextureFlags.Decrement => NumberFormatter.FormatInt(-1, type), // TODO: Clamp value
+ _ => Src(type)
+ };
+
+ Append(value);
+
+ texCall += ")";
+
+ if (type != VariableType.S32)
+ {
+ texCall = "int(" + texCall + ")";
+ }
+ }
+ else
+ {
+ texCall += ")" + (texOp.Inst == Instruction.ImageLoad ? GetMask(texOp.Index) : "");
+ }
return texCall;
}
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
index b9f1b4ef..deea6c72 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
@@ -362,7 +362,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
else if (operation is AstTextureOperation texOp &&
(texOp.Inst == Instruction.ImageLoad ||
- texOp.Inst == Instruction.ImageStore))
+ texOp.Inst == Instruction.ImageStore ||
+ texOp.Inst == Instruction.ImageAtomic))
{
return texOp.Format.GetComponentType();
}