diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2020-04-21 20:35:28 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-22 09:35:28 +1000 |
| commit | 03711dd7b5d44e20fb45c728803ea6b9599dec87 (patch) | |
| tree | 2930956a377d9f79df2750aa06ce1f1928cd30e6 /Ryujinx.Graphics.Shader/CodeGen | |
| parent | 4738113f293ac2477a553225a24b6c489c6855f1 (diff) | |
Implement SULD shader instruction (#1117)
* Implement SULD shader instruction
* Some nits
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
4 files changed, 74 insertions, 41 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index b1291906..36aff3fc 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -326,9 +326,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl continue; } - string imageTypeName = GetImageTypeName(texOp.Type); + string layout = texOp.Format.ToGlslFormat(); - context.AppendLine("writeonly uniform " + imageTypeName + " " + imageName + ";"); + if (!string.IsNullOrEmpty(layout)) + { + layout = "layout(" + layout + ") "; + } + + string imageTypeName = GetImageTypeName(texOp.Type, texOp.Format.GetComponentType()); + + context.AppendLine("uniform " + layout + imageTypeName + " " + imageName + ";"); } foreach (KeyValuePair<string, AstTextureOperation> kv in images) @@ -455,7 +462,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return typeName; } - private static string GetImageTypeName(SamplerType type) + private static string GetImageTypeName(SamplerType type, VariableType componentType) { string typeName; @@ -480,6 +487,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl typeName += "Array"; } + switch (componentType) + { + case VariableType.U32: typeName = 'u' + typeName; break; + case VariableType.S32: typeName = 'i' + typeName; break; + } + return typeName; } } diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs index fe982770..f1537c3d 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGen.cs @@ -4,6 +4,7 @@ using System; using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenHelper; using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenMemory; +using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenPacking; using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo; namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions @@ -115,53 +116,56 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { switch (inst) { + case Instruction.ImageLoad: + return ImageLoadOrStore(context, operation); + case Instruction.ImageStore: - return InstGenMemory.ImageStore(context, operation); + return ImageLoadOrStore(context, operation); case Instruction.LoadAttribute: - return InstGenMemory.LoadAttribute(context, operation); + return LoadAttribute(context, operation); case Instruction.LoadConstant: - return InstGenMemory.LoadConstant(context, operation); + return LoadConstant(context, operation); case Instruction.LoadLocal: - return InstGenMemory.LoadLocal(context, operation); + return LoadLocal(context, operation); case Instruction.LoadShared: - return InstGenMemory.LoadShared(context, operation); + return LoadShared(context, operation); case Instruction.LoadStorage: - return InstGenMemory.LoadStorage(context, operation); + return LoadStorage(context, operation); case Instruction.Lod: - return InstGenMemory.Lod(context, operation); + return Lod(context, operation); case Instruction.PackDouble2x32: - return InstGenPacking.PackDouble2x32(context, operation); + return PackDouble2x32(context, operation); case Instruction.PackHalf2x16: - return InstGenPacking.PackHalf2x16(context, operation); + return PackHalf2x16(context, operation); case Instruction.StoreLocal: - return InstGenMemory.StoreLocal(context, operation); + return StoreLocal(context, operation); case Instruction.StoreShared: - return InstGenMemory.StoreShared(context, operation); + return StoreShared(context, operation); case Instruction.StoreStorage: - return InstGenMemory.StoreStorage(context, operation); + return StoreStorage(context, operation); case Instruction.TextureSample: - return InstGenMemory.TextureSample(context, operation); + return TextureSample(context, operation); case Instruction.TextureSize: - return InstGenMemory.TextureSize(context, operation); + return TextureSize(context, operation); case Instruction.UnpackDouble2x32: - return InstGenPacking.UnpackDouble2x32(context, operation); + return UnpackDouble2x32(context, operation); case Instruction.UnpackHalf2x16: - return InstGenPacking.UnpackHalf2x16(context, operation); + return UnpackHalf2x16(context, operation); } } diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index 74828702..d05c77df 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -9,16 +9,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions { static class InstGenMemory { - public static string ImageStore(CodeGenContext context, AstOperation operation) + public static string ImageLoadOrStore(CodeGenContext context, AstOperation operation) { AstTextureOperation texOp = (AstTextureOperation)operation; 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 texCall = texOp.Inst == Instruction.ImageLoad ? "imageLoad" : "imageStore"; int srcIndex = isBindless ? 1 : 0; @@ -40,14 +40,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions int coordsCount = texOp.Type.GetDimensions(); - int pCount = coordsCount; - - int arrayIndexElem = -1; - - if (isArray) - { - arrayIndexElem = pCount++; - } + int pCount = coordsCount + (isArray ? 1 : 0); void Append(string str) { @@ -70,23 +63,40 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions Append(Src(VariableType.S32)); } - string[] cElems = new string[4]; - - for (int index = 0; index < 4; index++) + if (texOp.Inst == Instruction.ImageStore) { - if (srcIndex < texOp.SourcesCount) + VariableType type = texOp.Format.GetComponentType(); + + string[] cElems = new string[4]; + + for (int index = 0; index < 4; index++) { - cElems[index] = Src(VariableType.F32); + if (srcIndex < texOp.SourcesCount) + { + cElems[index] = Src(type); + } + else + { + cElems[index] = type switch + { + VariableType.S32 => NumberFormatter.FormatInt(0), + VariableType.U32 => NumberFormatter.FormatUint(0), + _ => NumberFormatter.FormatFloat(0) + }; + } } - else + + string prefix = type switch { - cElems[index] = NumberFormatter.FormatFloat(0); - } - } + VariableType.S32 => "i", + VariableType.U32 => "u", + _ => string.Empty + }; - Append("vec4(" + string.Join(", ", cElems) + ")"); + Append(prefix + "vec4(" + string.Join(", ", cElems) + ")"); + } - texCall += ")"; + texCall += ")" + (texOp.Inst == Instruction.ImageLoad ? GetMask(texOp.Index) : ""); return texCall; } diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index 8d092d4e..e9a37d87 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -280,6 +280,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { return GetOperandVarType((AstOperand)operation.GetSource(0)); } + else if (operation is AstTextureOperation texOp && + (texOp.Inst == Instruction.ImageLoad || + texOp.Inst == Instruction.ImageStore)) + { + return texOp.Format.GetComponentType(); + } return GetDestVarType(operation.Inst); } |
