Only initialize shader outputs that are actually used on the next stage (#3054)

* Only initialize shader outputs that are actually used on the next stage

* Shader cache version bump
This commit is contained in:
gdkchan 2022-03-06 16:42:13 -03:00 committed by GitHub
parent b97ff4da5e
commit 0bcbe32367
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 14 deletions

View file

@ -214,24 +214,24 @@ namespace Ryujinx.Graphics.Shader.Translation
InitializeOutput(context, AttributeConsts.PositionX, perPatch: false);
}
int usedAttributes = context.Config.UsedOutputAttributes;
while (usedAttributes != 0)
UInt128 usedAttributes = context.Config.NextInputAttributesComponents;
while (usedAttributes != UInt128.Zero)
{
int index = BitOperations.TrailingZeroCount(usedAttributes);
int index = usedAttributes.TrailingZeroCount();
InitializeOutput(context, AttributeConsts.UserAttributeBase + index * 16, perPatch: false);
InitializeOutputComponent(context, AttributeConsts.UserAttributeBase + index * 4, perPatch: false);
usedAttributes &= ~(1 << index);
usedAttributes &= ~UInt128.Pow2(index);
}
int usedAttributesPerPatch = context.Config.UsedOutputAttributesPerPatch;
while (usedAttributesPerPatch != 0)
UInt128 usedAttributesPerPatch = context.Config.NextInputAttributesPerPatchComponents;
while (usedAttributesPerPatch != UInt128.Zero)
{
int index = BitOperations.TrailingZeroCount(usedAttributesPerPatch);
int index = usedAttributesPerPatch.TrailingZeroCount();
InitializeOutput(context, AttributeConsts.UserAttributeBase + index * 16, perPatch: true);
InitializeOutputComponent(context, AttributeConsts.UserAttributeBase + index * 4, perPatch: true);
usedAttributesPerPatch &= ~(1 << index);
usedAttributesPerPatch &= ~UInt128.Pow2(index);
}
if (config.NextUsesFixedFuncAttributes)
@ -260,6 +260,12 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
private static void InitializeOutputComponent(EmitterContext context, int attrOffset, bool perPatch)
{
int c = (attrOffset >> 2) & 3;
context.Copy(perPatch ? AttributePerPatch(attrOffset) : Attribute(attrOffset), ConstF(c == 3 ? 1f : 0f));
}
private static void EmitOps(EmitterContext context, Block block)
{
for (int opIndex = 0; opIndex < block.OpCodes.Count; opIndex++)