From 7882c0498bb1aee22879c6af7c7b6a79b2d09a7a Mon Sep 17 00:00:00 2001 From: riperiperi Date: Mon, 7 Mar 2022 23:36:39 +0000 Subject: [PATCH] SPIR-V: Only use input attribute type for input attributes Output vertex attributes should always be of type float. --- .../CodeGen/Spirv/CodeGenContext.cs | 4 ++-- .../CodeGen/Spirv/Declarations.cs | 4 ++-- .../Translation/AttributeInfo.cs | 22 ++++++++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs index b2b856e06..9820b2591 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs @@ -213,14 +213,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv public Instruction GetAttributeVectorPointer(AstOperand operand, bool isOutAttr) { - var attrInfo = AttributeInfo.From(Config, operand.Value); + var attrInfo = AttributeInfo.From(Config, operand.Value, isOutAttr); return isOutAttr ? Outputs[attrInfo.BaseValue] : Inputs[attrInfo.BaseValue]; } public Instruction GetAttributeElemPointer(int attr, bool isOutAttr, Instruction index, out AggregateType elemType) { - var attrInfo = AttributeInfo.From(Config, attr); + var attrInfo = AttributeInfo.From(Config, attr, isOutAttr); elemType = attrInfo.Type & AggregateType.ElementTypeMask; diff --git a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index f23444389..13f852d1d 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -391,7 +391,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv } var dict = isOutAttr ? context.Outputs : context.Inputs; - var attrInfo = AttributeInfo.From(context.Config, attr); + var attrInfo = AttributeInfo.From(context.Config, attr, isOutAttr); if (dict.ContainsKey(attrInfo.BaseValue)) { @@ -455,7 +455,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv private static void DeclareInputOrOutput(CodeGenContext context, int attr, int component, bool isOutAttr, PixelImap iq = PixelImap.Unused) { var dict = isOutAttr ? context.Outputs : context.Inputs; - var attrInfo = AttributeInfo.From(context.Config, attr); + var attrInfo = AttributeInfo.From(context.Config, attr, isOutAttr); if (dict.ContainsKey(attr)) { diff --git a/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs b/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs index d0394969d..8e253c961 100644 --- a/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs +++ b/Ryujinx.Graphics.Shader/Translation/AttributeInfo.cs @@ -70,19 +70,29 @@ namespace Ryujinx.Graphics.Shader.Translation return (Value - BaseValue) / 4; } - public static AttributeInfo From(ShaderConfig config, int value) + public static AttributeInfo From(ShaderConfig config, int value, bool isOutAttr) { value &= ~3; if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd) { int location = (value - AttributeConsts.UserAttributeBase) / 16; - var elemType = config.GpuAccessor.QueryAttributeType(location) switch + + AggregateType elemType; + + if (!isOutAttr) { - AttributeType.Sint => AggregateType.S32, - AttributeType.Uint => AggregateType.U32, - _ => AggregateType.FP32 - }; + elemType = config.GpuAccessor.QueryAttributeType(location) switch + { + AttributeType.Sint => AggregateType.S32, + AttributeType.Uint => AggregateType.U32, + _ => AggregateType.FP32 + }; + } + else + { + elemType = AggregateType.FP32; + } return new AttributeInfo(value & ~0xf, (value >> 2) & 3, 4, AggregateType.Vector | elemType, false); }