diff options
| author | gdk <gab.dark.100@gmail.com> | 2019-11-02 23:07:21 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | 3ab5c23f492183ae6f5cf8f62c4239bf181d2630 (patch) | |
| tree | 288daa576efbbe3220d835834acd562dff7d6cbd /Ryujinx.Graphics.Shader/CodeGen | |
| parent | 63345a3098e05e0d0692bc46852dfbfccfdcfae2 (diff) | |
Add partial support for array of samplers, and add pass to identify them from bindless texture accesses
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
3 files changed, 97 insertions, 29 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index 7c67bc13..6c4ba949 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -231,7 +231,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl foreach (AstTextureOperation texOp in info.Samplers.OrderBy(x => x.Handle)) { - string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp); + string indexExpr = NumberFormatter.FormatInt(texOp.ArraySize); + + string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); if (!samplers.TryAdd(samplerName, texOp)) { @@ -257,12 +259,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl desc = new TextureDescriptor(samplerName, texOp.Type, operand.CbufSlot, operand.CbufOffset); } + else if ((texOp.Type & SamplerType.Indexed) != 0) + { + for (int index = 0; index < texOp.ArraySize; index++) + { + string indexExpr = NumberFormatter.FormatInt(index); + + string indexedSamplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); + + desc = new TextureDescriptor(indexedSamplerName, texOp.Type, texOp.Handle + index * 2); + + context.TextureDescriptors.Add(desc); + } + } else { desc = new TextureDescriptor(samplerName, texOp.Type, texOp.Handle); - } - context.TextureDescriptors.Add(desc); + context.TextureDescriptors.Add(desc); + } } } @@ -272,7 +287,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl foreach (AstTextureOperation texOp in info.Images.OrderBy(x => x.Handle)) { - string imageName = OperandManager.GetImageName(context.Config.Stage, texOp); + string indexExpr = NumberFormatter.FormatInt(texOp.ArraySize); + + string imageName = OperandManager.GetImageName(context.Config.Stage, texOp, indexExpr); if (!images.TryAdd(imageName, texOp)) { @@ -290,9 +307,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl AstTextureOperation texOp = kv.Value; - TextureDescriptor desc = new TextureDescriptor(imageName, texOp.Type, texOp.Handle); + if ((texOp.Type & SamplerType.Indexed) != 0) + { + for (int index = 0; index < texOp.ArraySize; index++) + { + string indexExpr = NumberFormatter.FormatInt(index); + + string indexedSamplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); + + var desc = new TextureDescriptor(indexedSamplerName, texOp.Type, texOp.Handle + index * 2); + + context.TextureDescriptors.Add(desc); + } + } + else + { + var desc = new TextureDescriptor(imageName, texOp.Type, texOp.Handle); - context.ImageDescriptors.Add(desc); + context.ImageDescriptors.Add(desc); + } } } diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index 913cace1..21e39fcf 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -15,11 +15,26 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0; - bool isArray = (texOp.Type & SamplerType.Array) != 0; + bool isArray = (texOp.Type & SamplerType.Array) != 0; + bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0; string texCall = "imageStore"; - string imageName = OperandManager.GetImageName(context.Config.Stage, texOp); + int srcIndex = isBindless ? 1 : 0; + + string Src(VariableType type) + { + return GetSoureExpr(context, texOp.GetSource(srcIndex++), type); + } + + string indexExpr = null; + + if (isIndexed) + { + indexExpr = Src(VariableType.S32); + } + + string imageName = OperandManager.GetImageName(context.Config.Stage, texOp, indexExpr); texCall += "(" + imageName; @@ -34,13 +49,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions arrayIndexElem = pCount++; } - int srcIndex = isBindless ? 1 : 0; - - string Src(VariableType type) - { - return GetSoureExpr(context, texOp.GetSource(srcIndex++), type); - } - void Append(string str) { texCall += ", " + str; @@ -174,6 +182,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions bool hasOffsets = (texOp.Flags & TextureFlags.Offsets) != 0; bool isArray = (texOp.Type & SamplerType.Array) != 0; + bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0; bool isMultisample = (texOp.Type & SamplerType.Multisample) != 0; bool isShadow = (texOp.Type & SamplerType.Shadow) != 0; @@ -209,7 +218,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions texCall += "Offsets"; } - string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp); + int srcIndex = isBindless ? 1 : 0; + + string Src(VariableType type) + { + return GetSoureExpr(context, texOp.GetSource(srcIndex++), type); + } + + string indexExpr = null; + + if (isIndexed) + { + indexExpr = Src(VariableType.S32); + } + + string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); texCall += "(" + samplerName; @@ -249,13 +272,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions hasExtraCompareArg = true; } - int srcIndex = isBindless ? 1 : 0; - - string Src(VariableType type) - { - return GetSoureExpr(context, texOp.GetSource(srcIndex++), type); - } - void Append(string str) { texCall += ", " + str; @@ -395,11 +411,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { AstTextureOperation texOp = (AstTextureOperation)operation; - bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0; + 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); + string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr); - IAstNode src0 = operation.GetSource(isBindless ? 1 : 0); + IAstNode src0 = operation.GetSource(isBindless || isIndexed ? 1 : 0); string src0Expr = GetSoureExpr(context, src0, GetSrcVarType(operation.Inst, 0)); diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index fe307396..36f76ec5 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -223,7 +223,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return ubName + "_" + DefaultNames.UniformNameSuffix; } - public static string GetSamplerName(ShaderStage stage, AstTextureOperation texOp) + public static string GetSamplerName(ShaderStage stage, AstTextureOperation texOp, string indexExpr) { string suffix; @@ -235,16 +235,26 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } else { - suffix = (texOp.Handle - 8).ToString(); + suffix = texOp.Handle.ToString(); + + if ((texOp.Type & SamplerType.Indexed) != 0) + { + suffix += $"a[{indexExpr}]"; + } } return GetShaderStagePrefix(stage) + "_" + DefaultNames.SamplerNamePrefix + suffix; } - public static string GetImageName(ShaderStage stage, AstTextureOperation texOp) + public static string GetImageName(ShaderStage stage, AstTextureOperation texOp, string indexExpr) { string suffix = texOp.Handle.ToString(); + if ((texOp.Type & SamplerType.Indexed) != 0) + { + suffix += $"a[{indexExpr}]"; + } + return GetShaderStagePrefix(stage) + "_" + DefaultNames.ImageNamePrefix + suffix; } |
