aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-10-17 23:41:18 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit1b7d95519569639135a68e7ebda5148f3263217c (patch)
tree52a5e471418bf28ce970a268e1b86b64abc9048f /Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
parent717ace6f6ed65118148dc78976c6e818a095fa4d (diff)
Initial support for image stores, support texture sample on compute
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs84
1 files changed, 79 insertions, 5 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index 5c9ec830..f2f6ae0c 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -9,6 +9,80 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
{
static class InstGenMemory
{
+ public static string ImageStore(CodeGenContext context, AstOperation operation)
+ {
+ AstTextureOperation texOp = (AstTextureOperation)operation;
+
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+
+ bool isArray = (texOp.Type & SamplerType.Array) != 0;
+
+ string texCall = "imageStore";
+
+ string imageName = OperandManager.GetImageName(context.Config.Stage, texOp);
+
+ texCall += "(" + imageName;
+
+ int coordsCount = texOp.Type.GetDimensions();
+
+ int pCount = coordsCount;
+
+ int arrayIndexElem = -1;
+
+ if (isArray)
+ {
+ arrayIndexElem = pCount++;
+ }
+
+ int srcIndex = isBindless ? 1 : 0;
+
+ string Src(VariableType type)
+ {
+ return GetSoureExpr(context, texOp.GetSource(srcIndex++), type);
+ }
+
+ void Append(string str)
+ {
+ texCall += ", " + str;
+ }
+
+ if (pCount > 1)
+ {
+ string[] elems = new string[pCount];
+
+ for (int index = 0; index < pCount; index++)
+ {
+ elems[index] = Src(VariableType.S32);
+ }
+
+ Append("ivec" + pCount + "(" + string.Join(", ", elems) + ")");
+ }
+ else
+ {
+ Append(Src(VariableType.S32));
+ }
+
+ string[] cElems = new string[4];
+
+ for (int index = 0; index < 4; index++)
+ {
+ if (srcIndex < texOp.SourcesCount)
+ {
+ cElems[index] = Src(VariableType.F32);
+ }
+ else
+ {
+ cElems[index] = NumberFormatter.FormatFloat(0);
+ }
+ }
+
+ Append("vec4(" + string.Join(", ", cElems) + ")");
+
+ texCall += ")";
+
+ return texCall;
+ }
+
public static string LoadAttribute(CodeGenContext context, AstOperation operation)
{
IAstNode src1 = operation.GetSource(0);
@@ -98,9 +172,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
bool hasOffset = (texOp.Flags & TextureFlags.Offset) != 0;
bool hasOffsets = (texOp.Flags & TextureFlags.Offsets) != 0;
- bool isArray = (texOp.Target & TextureTarget.Array) != 0;
- bool isMultisample = (texOp.Target & TextureTarget.Multisample) != 0;
- bool isShadow = (texOp.Target & TextureTarget.Shadow) != 0;
+ bool isArray = (texOp.Type & SamplerType.Array) != 0;
+ bool isMultisample = (texOp.Type & SamplerType.Multisample) != 0;
+ bool isShadow = (texOp.Type & SamplerType.Shadow) != 0;
// This combination is valid, but not available on GLSL.
// For now, ignore the LOD level and do a normal sample.
@@ -134,7 +208,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
texCall += "(" + samplerName;
- int coordsCount = texOp.Target.GetDimensions();
+ int coordsCount = texOp.Type.GetDimensions();
int pCount = coordsCount;
@@ -147,7 +221,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
// The sampler 1D shadow overload expects a
// dummy value on the middle of the vector, who knows why...
- bool hasDummy1DShadowElem = texOp.Target == (TextureTarget.Texture1D | TextureTarget.Shadow);
+ bool hasDummy1DShadowElem = texOp.Type == (SamplerType.Texture1D | SamplerType.Shadow);
if (hasDummy1DShadowElem)
{