From ee1038e54255797a94b89091f4d59b77daad1a7b Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 26 Aug 2021 20:44:47 -0300 Subject: Initial support for shader attribute indexing (#2546) * Initial support for shader attribute indexing * Support output indexing too, other improvements * Fix order * Address feedback --- .../CodeGen/Glsl/Declarations.cs | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs') diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs index 2a93be32..7b26801a 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs @@ -402,14 +402,23 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info) { - int usedAttribtes = context.Config.UsedInputAttributes; - while (usedAttribtes != 0) + if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IaIndexing)) { - int index = BitOperations.TrailingZeroCount(usedAttribtes); + string suffix = context.Config.Stage == ShaderStage.Geometry ? "[]" : string.Empty; - DeclareInputAttribute(context, info, index); + context.AppendLine($"layout (location = 0) in vec4 {DefaultNames.IAttributePrefix}{suffix}[{Constants.MaxAttributes}];"); + } + else + { + int usedAttributes = context.Config.UsedInputAttributes; + while (usedAttributes != 0) + { + int index = BitOperations.TrailingZeroCount(usedAttributes); + + DeclareInputAttribute(context, info, index); - usedAttribtes &= ~(1 << index); + usedAttributes &= ~(1 << index); + } } } @@ -448,14 +457,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl private static void DeclareOutputAttributes(CodeGenContext context, StructuredProgramInfo info) { - int usedAttribtes = context.Config.UsedOutputAttributes; - while (usedAttribtes != 0) + if (context.Config.UsedFeatures.HasFlag(FeatureFlags.OaIndexing)) { - int index = BitOperations.TrailingZeroCount(usedAttribtes); + context.AppendLine($"layout (location = 0) out vec4 {DefaultNames.OAttributePrefix}[{Constants.MaxAttributes}];"); + } + else + { + int usedAttributes = context.Config.UsedOutputAttributes; + while (usedAttributes != 0) + { + int index = BitOperations.TrailingZeroCount(usedAttributes); - DeclareOutputAttribute(context, index); + DeclareOutputAttribute(context, index); - usedAttribtes &= ~(1 << index); + usedAttributes &= ~(1 << index); + } } } -- cgit v1.2.3