0
0
Fork 0

Fix SPIR-V when all inputs/outputs are indexed (#4389)

This commit is contained in:
gdkchan 2023-02-09 00:48:25 -03:00 committed by GitHub
parent 7bae440d3a
commit 5f38086f94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -397,20 +397,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info, bool perPatch) private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info, bool perPatch)
{ {
bool iaIndexing = context.Config.UsedFeatures.HasFlag(FeatureFlags.IaIndexing); bool iaIndexing = context.Config.UsedFeatures.HasFlag(FeatureFlags.IaIndexing);
var inputs = perPatch ? info.InputsPerPatch : info.Inputs;
foreach (int attr in inputs) if (iaIndexing && !perPatch)
{
if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: false, perPatch))
{
continue;
}
bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd;
if (iaIndexing && isUserAttr && !perPatch)
{
if (context.InputsArray == null)
{ {
var attrType = context.TypeVector(context.TypeFP32(), (LiteralInteger)4); var attrType = context.TypeVector(context.TypeFP32(), (LiteralInteger)4);
attrType = context.TypeArray(attrType, context.Constant(context.TypeU32(), (LiteralInteger)MaxAttributes)); attrType = context.TypeArray(attrType, context.Constant(context.TypeU32(), (LiteralInteger)MaxAttributes));
@ -433,9 +421,23 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
context.AddGlobalVariable(spvVar); context.AddGlobalVariable(spvVar);
context.InputsArray = spvVar; context.InputsArray = spvVar;
} }
}
else var inputs = perPatch ? info.InputsPerPatch : info.Inputs;
foreach (int attr in inputs)
{ {
if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: false, perPatch))
{
continue;
}
bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd;
if (iaIndexing && isUserAttr && !perPatch)
{
continue;
}
PixelImap iq = PixelImap.Unused; PixelImap iq = PixelImap.Unused;
if (context.Config.Stage == ShaderStage.Fragment) if (context.Config.Stage == ShaderStage.Fragment)
@ -459,25 +461,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
DeclareInputOrOutput(context, attr, perPatch, isOutAttr: false, iq); DeclareInputOrOutput(context, attr, perPatch, isOutAttr: false, iq);
} }
} }
}
private static void DeclareOutputAttributes(CodeGenContext context, StructuredProgramInfo info, bool perPatch) private static void DeclareOutputAttributes(CodeGenContext context, StructuredProgramInfo info, bool perPatch)
{ {
bool oaIndexing = context.Config.UsedFeatures.HasFlag(FeatureFlags.OaIndexing); bool oaIndexing = context.Config.UsedFeatures.HasFlag(FeatureFlags.OaIndexing);
var outputs = perPatch ? info.OutputsPerPatch : info.Outputs;
foreach (int attr in outputs) if (oaIndexing && !perPatch)
{
if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: true, perPatch))
{
continue;
}
bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd;
if (oaIndexing && isUserAttr && !perPatch)
{
if (context.OutputsArray == null)
{ {
var attrType = context.TypeVector(context.TypeFP32(), (LiteralInteger)4); var attrType = context.TypeVector(context.TypeFP32(), (LiteralInteger)4);
attrType = context.TypeArray(attrType, context.Constant(context.TypeU32(), (LiteralInteger)MaxAttributes)); attrType = context.TypeArray(attrType, context.Constant(context.TypeU32(), (LiteralInteger)MaxAttributes));
@ -495,11 +484,24 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
context.AddGlobalVariable(spvVar); context.AddGlobalVariable(spvVar);
context.OutputsArray = spvVar; context.OutputsArray = spvVar;
} }
}
else var outputs = perPatch ? info.OutputsPerPatch : info.Outputs;
foreach (int attr in outputs)
{ {
DeclareOutputAttribute(context, attr, perPatch); if (!AttributeInfo.Validate(context.Config, attr, isOutAttr: true, perPatch))
{
continue;
} }
bool isUserAttr = attr >= AttributeConsts.UserAttributeBase && attr < AttributeConsts.UserAttributeEnd;
if (oaIndexing && isUserAttr && !perPatch)
{
continue;
}
DeclareOutputAttribute(context, attr, perPatch);
} }
if (context.Config.Stage == ShaderStage.Vertex) if (context.Config.Stage == ShaderStage.Vertex)