From 070996ad6df0345bc376fff742d835aea91b667a Mon Sep 17 00:00:00 2001 From: gdk Date: Thu, 7 Apr 2022 12:07:34 -0300 Subject: [PATCH] Ignore unsupported attributes rather than throwing (matches current GLSL behaviour) --- .../CodeGen/Spirv/CodeGenContext.cs | 5 +++++ Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs | 10 ++++++++++ .../CodeGen/Spirv/SpirvGenerator.cs | 9 ++++++--- Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs index 753273faa..0f3ae2548 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs @@ -308,6 +308,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv public Instruction GetAttribute(AggregateType type, int attr, bool isOutAttr, Instruction index = null) { + if (!AttributeInfo.Validate(Config, attr, isOutAttr: false)) + { + return GetConstant(type, new AstOperand(IrOperandType.Constant, 0)); + } + var elemPointer = GetAttributeElemPointer(attr, isOutAttr, index, out var elemType); return BitcastIfNeeded(type, elemType, Load(GetType(elemType), elemPointer)); } diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index f3c16e919..9baf292e8 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -360,6 +360,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv foreach (int attr in info.Inputs) { + if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: false)) + { + continue; + } + bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd; if (iaIndexing && isUserAttr) @@ -405,6 +410,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv foreach (int attr in info.Outputs) { + if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: true)) + { + continue; + } + bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd; if (oaIndexing && isUserAttr) diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs index 6c6836b69..7dd4a12c0 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/SpirvGenerator.cs @@ -200,7 +200,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv context.AddExecutionMode(spvFunc, ExecutionMode.EarlyFragmentTests); } - if ((info.HelperFunctionsMask & HelperFunctionsMask.FSI) != 0 && + if ((info.HelperFunctionsMask & HelperFunctionsMask.FSI) != 0 && context.Config.GpuAccessor.QueryHostSupportsFragmentShaderInterlock()) { context.AddExecutionMode(spvFunc, ExecutionMode.PixelInterlockOrderedEXT); @@ -331,8 +331,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv } else if (dest.Type == OperandType.Attribute) { - var elemPointer = context.GetAttributeElemPointer(dest.Value, true, null, out var elemType); - context.Store(elemPointer, context.Get(elemType, assignment.Source)); + if (AttributeInfo.Validate(context.Config, dest.Value, isOutAttr: true)) + { + var elemPointer = context.GetAttributeElemPointer(dest.Value, true, null, out var elemType); + context.Store(elemPointer, context.Get(elemType, assignment.Source)); + } } else if (dest.Type == OperandType.Argument) { diff --git a/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs b/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs index 8e253c961..f69548507 100644 --- a/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs +++ b/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs @@ -70,6 +70,11 @@ namespace Ryujinx.Graphics.Shader.Translation return (Value - BaseValue) / 4; } + public static bool Validate(ShaderConfig config, int value, bool isOutAttr) + { + return From(config, value, isOutAttr).IsValid; + } + public static AttributeInfo From(ShaderConfig config, int value, bool isOutAttr) { value &= ~3;