aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen
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
parent3323a3a042c85ce88926771159fc041b5576de60 (diff)
Support non-constant texture offsets on non-NVIDIA gpus
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.cs60
3 files changed, 56 insertions, 8 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
index b6cdd7f6..73a71f9e 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs
@@ -133,6 +133,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
case Instruction.LoadStorage:
return InstGenMemory.LoadStorage(context, operation);
+ case Instruction.Lod:
+ return InstGenMemory.Lod(context, operation);
+
case Instruction.PackHalf2x16:
return InstGenPacking.PackHalf2x16(context, operation);
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
index 2b4ae7f1..ef998fdd 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs
@@ -73,6 +73,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
Add(Instruction.LoadLocal, InstType.Special);
Add(Instruction.LoadShared, InstType.Special);
Add(Instruction.LoadStorage, InstType.Special);
+ Add(Instruction.Lod, InstType.Special);
Add(Instruction.LogarithmB2, InstType.CallUnary, "log2");
Add(Instruction.LogicalAnd, InstType.OpBinaryCom, "&&", 9);
Add(Instruction.LogicalExclusiveOr, InstType.OpBinaryCom, "^^", 10);
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)