From f2c85c5d58a0aeda5d5fe2d7a980cc7284330288 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 11 Dec 2019 03:54:18 -0300 Subject: Support non-constant texture offsets on non-NVIDIA gpus --- .../CodeGen/Glsl/Instructions/InstGen.cs | 3 ++ .../CodeGen/Glsl/Instructions/InstGenHelper.cs | 1 + .../CodeGen/Glsl/Instructions/InstGenMemory.cs | 60 +++++++++++++++++++--- 3 files changed, 56 insertions(+), 8 deletions(-) (limited to 'Ryujinx.Graphics.Shader/CodeGen') 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) -- cgit v1.2.3