diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-08-26 20:44:47 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-27 01:44:47 +0200 |
| commit | ee1038e54255797a94b89091f4d59b77daad1a7b (patch) | |
| tree | 5ea62d8a2bae97004a4abe2ebf0a21c634b912dc /Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs | |
| parent | ec3e848d7998038ce22c41acdbf81032bf47991f (diff) | |
Initial support for shader attribute indexing (#2546)
* Initial support for shader attribute indexing
* Support output indexing too, other improvements
* Fix order
* Address feedback
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs')
| -rw-r--r-- | Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index 60a471eb..b9f1b4ef 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -99,7 +99,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return operand.Type switch { OperandType.Argument => GetArgumentName(operand.Value), - OperandType.Attribute => GetAttributeName(operand, config), + OperandType.Attribute => GetAttributeName(operand.Value, config), OperandType.Constant => NumberFormatter.FormatInt(operand.Value), OperandType.ConstantBuffer => GetConstantBufferName( operand.CbufSlot, @@ -142,15 +142,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return GetVec4Indexed(GetUbName(stage, slotExpr) + $"[{offsetExpr} >> 2]", offsetExpr + " & 3", indexElement); } - public static string GetOutAttributeName(AstOperand attr, ShaderConfig config) + public static string GetOutAttributeName(int value, ShaderConfig config) { - return GetAttributeName(attr, config, isOutAttr: true); + return GetAttributeName(value, config, isOutAttr: true); } - public static string GetAttributeName(AstOperand attr, ShaderConfig config, bool isOutAttr = false, string indexExpr = "0") + public static string GetAttributeName(int value, ShaderConfig config, bool isOutAttr = false, string indexExpr = "0") { - int value = attr.Value; - char swzMask = GetSwizzleMask((value >> 2) & 3); if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd) @@ -161,7 +159,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl ? DefaultNames.OAttributePrefix : DefaultNames.IAttributePrefix; - if ((config.Options.Flags & TranslationFlags.Feedback) != 0) + if (config.UsedFeatures.HasFlag(isOutAttr ? FeatureFlags.OaIndexing : FeatureFlags.IaIndexing)) + { + string name = prefix; + + if (config.Stage == ShaderStage.Geometry && !isOutAttr) + { + name += $"[{indexExpr}]"; + } + + return name + $"[{(value >> 4)}]." + swzMask; + } + else if (config.Options.Flags.HasFlag(TranslationFlags.Feedback)) { string name = $"{prefix}{(value >> 4)}_{swzMask}"; @@ -231,6 +240,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return isOutAttr ? "// bad_attr0x" + value.ToString("X") : "0.0"; } + public static string GetAttributeName(string attrExpr, ShaderConfig config, bool isOutAttr = false, string indexExpr = "0") + { + string name = isOutAttr + ? DefaultNames.OAttributePrefix + : DefaultNames.IAttributePrefix; + + if (config.Stage == ShaderStage.Geometry && !isOutAttr) + { + name += $"[{indexExpr}]"; + } + + return $"{name}[{attrExpr} >> 2][{attrExpr} & 3]"; + } + public static string GetUbName(ShaderStage stage, int slot, bool cbIndexable) { if (cbIndexable) @@ -314,12 +337,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { if (node is AstOperation operation) { - // Load attribute basically just returns the attribute value. - // Some built-in attributes may have different types, so we need - // to return the type based on the attribute that is being read. if (operation.Inst == Instruction.LoadAttribute) { - return GetOperandVarType((AstOperand)operation.GetSource(0)); + // Load attribute basically just returns the attribute value. + // Some built-in attributes may have different types, so we need + // to return the type based on the attribute that is being read. + if (operation.GetSource(0) is AstOperand operand && operand.Type == OperandType.Constant) + { + if (_builtInAttributes.TryGetValue(operand.Value & ~3, out BuiltInAttribute builtInAttr)) + { + return builtInAttr.Type; + } + } + + return OperandInfo.GetVarType(OperandType.Attribute); } else if (operation.Inst == Instruction.Call) { |
