SPIR-V: Only use input attribute type for input attributes

Output vertex attributes should always be of type float.
This commit is contained in:
riperiperi 2022-03-07 23:36:39 +00:00
parent cbeb40934f
commit 7882c0498b
3 changed files with 20 additions and 10 deletions

View file

@ -213,14 +213,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
public Instruction GetAttributeVectorPointer(AstOperand operand, bool isOutAttr) 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]; return isOutAttr ? Outputs[attrInfo.BaseValue] : Inputs[attrInfo.BaseValue];
} }
public Instruction GetAttributeElemPointer(int attr, bool isOutAttr, Instruction index, out AggregateType elemType) 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; elemType = attrInfo.Type & AggregateType.ElementTypeMask;

View file

@ -391,7 +391,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
} }
var dict = isOutAttr ? context.Outputs : context.Inputs; 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)) 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) private static void DeclareInputOrOutput(CodeGenContext context, int attr, int component, bool isOutAttr, PixelImap iq = PixelImap.Unused)
{ {
var dict = isOutAttr ? context.Outputs : context.Inputs; 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)) if (dict.ContainsKey(attr))
{ {

View file

@ -70,19 +70,29 @@ namespace Ryujinx.Graphics.Shader.Translation
return (Value - BaseValue) / 4; return (Value - BaseValue) / 4;
} }
public static AttributeInfo From(ShaderConfig config, int value) public static AttributeInfo From(ShaderConfig config, int value, bool isOutAttr)
{ {
value &= ~3; value &= ~3;
if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd) if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd)
{ {
int location = (value - AttributeConsts.UserAttributeBase) / 16; int location = (value - AttributeConsts.UserAttributeBase) / 16;
var elemType = config.GpuAccessor.QueryAttributeType(location) switch
AggregateType elemType;
if (!isOutAttr)
{ {
AttributeType.Sint => AggregateType.S32, elemType = config.GpuAccessor.QueryAttributeType(location) switch
AttributeType.Uint => AggregateType.U32, {
_ => AggregateType.FP32 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); return new AttributeInfo(value & ~0xf, (value >> 2) & 3, 4, AggregateType.Vector | elemType, false);
} }