aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2019-12-11 03:54:18 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commitf2c85c5d58a0aeda5d5fe2d7a980cc7284330288 (patch)
treee9a3b2100de28120cd52239b5af9615b750ec352 /Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
parent3323a3a042c85ce88926771159fc041b5576de60 (diff)
Support non-constant texture offsets on non-NVIDIA gpus
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs60
1 files changed, 52 insertions, 8 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index ffed4c71..5687ce7e 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -148,6 +148,48 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
return GetStorageBufferAccessor(indexExpr, offsetExpr, context.Config.Stage);
}
+ public static string Lod(CodeGenContext context, AstOperation operation)
+ {
+ AstTextureOperation texOp = (AstTextureOperation)operation;
+
+ int coordsCount = texOp.Type.GetDimensions();
+
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+
+ bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
+
+ string indexExpr = null;
+
+ if (isIndexed)
+ {
+ indexExpr = GetSoureExpr(context, texOp.GetSource(0), VariableType.S32);
+ }
+
+ string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
+
+ int coordsIndex = isBindless || isIndexed ? 1 : 0;
+
+ string coordsExpr;
+
+ if (coordsCount > 1)
+ {
+ string[] elems = new string[coordsCount];
+
+ for (int index = 0; index < coordsCount; index++)
+ {
+ elems[index] = GetSoureExpr(context, texOp.GetSource(coordsIndex + index), VariableType.F32);
+ }
+
+ coordsExpr = "vec" + coordsCount + "(" + string.Join(", ", elems) + ")";
+ }
+ else
+ {
+ coordsExpr = GetSoureExpr(context, texOp.GetSource(coordsIndex), VariableType.F32);
+ }
+
+ return $"textureQueryLod({samplerName}, {coordsExpr}){GetMask(texOp.Index)}";
+ }
+
public static string StoreLocal(CodeGenContext context, AstOperation operation)
{
return StoreLocalOrShared(context, operation, DefaultNames.LocalMemoryName);
@@ -359,15 +401,15 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
}
}
- if (hasDerivatives)
+ if (hasExtraCompareArg)
{
- Append(AssembleDerivativesVector(coordsCount)); // dPdx
- Append(AssembleDerivativesVector(coordsCount)); // dPdy
+ Append(Src(VariableType.F32));
}
- if (hasExtraCompareArg)
+ if (hasDerivatives)
{
- Append(Src(VariableType.F32));
+ Append(AssembleDerivativesVector(coordsCount)); // dPdx
+ Append(AssembleDerivativesVector(coordsCount)); // dPdy
}
if (isMultisample)
@@ -446,11 +488,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
- IAstNode src0 = operation.GetSource(isBindless || isIndexed ? 1 : 0);
+ int lodSrcIndex = isBindless || isIndexed ? 1 : 0;
+
+ IAstNode lod = operation.GetSource(lodSrcIndex);
- string src0Expr = GetSoureExpr(context, src0, GetSrcVarType(operation.Inst, 0));
+ string lodExpr = GetSoureExpr(context, lod, GetSrcVarType(operation.Inst, lodSrcIndex));
- return $"textureSize({samplerName}, {src0Expr}){GetMask(texOp.Index)}";
+ return $"textureSize({samplerName}, {lodExpr}){GetMask(texOp.Index)}";
}
private static string GetStorageBufferAccessor(string slotExpr, string offsetExpr, ShaderStage stage)