Refactor attribute handling on the shader generator (#4565)

* Refactor attribute handling on the shader generator

* Implement gl_ViewportMask[]

* Add back the Intel FrontFacing bug workaround

* Fix GLSL transform feedback outputs mistmatch with fragment stage

* Shader cache version bump

* Fix geometry shader recognition

* PR feedback

* Delete GetOperandDef and GetOperandUse

* Remove replacements that are no longer needed on GLSL compilation on Vulkan

* Fix incorrect load for per-patch outputs

* Fix build
This commit is contained in:
gdkchan 2023-04-25 19:51:07 -03:00 committed by GitHub
parent 097562bc6c
commit 9f12e50a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 1967 additions and 1746 deletions

View file

@ -37,43 +37,26 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
Config = config;
if (config.Stage == ShaderStage.TessellationControl)
{
// Required to index outputs.
Info.Inputs.Add(AttributeConsts.InvocationId);
}
else if (config.GpPassthrough)
if (config.GpPassthrough)
{
int passthroughAttributes = config.PassthroughAttributes;
while (passthroughAttributes != 0)
{
int index = BitOperations.TrailingZeroCount(passthroughAttributes);
int attrBase = AttributeConsts.UserAttributeBase + index * 16;
Info.Inputs.Add(attrBase);
Info.Inputs.Add(attrBase + 4);
Info.Inputs.Add(attrBase + 8);
Info.Inputs.Add(attrBase + 12);
Info.IoDefinitions.Add(new IoDefinition(StorageKind.Input, IoVariable.UserDefined, index));
passthroughAttributes &= ~(1 << index);
}
Info.Inputs.Add(AttributeConsts.PositionX);
Info.Inputs.Add(AttributeConsts.PositionY);
Info.Inputs.Add(AttributeConsts.PositionZ);
Info.Inputs.Add(AttributeConsts.PositionW);
Info.Inputs.Add(AttributeConsts.PointSize);
for (int i = 0; i < 8; i++)
{
Info.Inputs.Add(AttributeConsts.ClipDistance0 + i * 4);
}
Info.IoDefinitions.Add(new IoDefinition(StorageKind.Input, IoVariable.Position));
Info.IoDefinitions.Add(new IoDefinition(StorageKind.Input, IoVariable.PointSize));
Info.IoDefinitions.Add(new IoDefinition(StorageKind.Input, IoVariable.ClipDistance));
}
else if (config.Stage == ShaderStage.Fragment)
{
// Potentially used for texture coordinate scaling.
Info.Inputs.Add(AttributeConsts.PositionX);
Info.Inputs.Add(AttributeConsts.PositionY);
Info.IoDefinitions.Add(new IoDefinition(StorageKind.Input, IoVariable.FragmentCoord));
}
}
@ -281,7 +264,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
}
else
{
cond = GetOperandUse(branchOp.GetSource(0));
cond = GetOperand(branchOp.GetSource(0));
Instruction invInst = type == AstBlockType.If
? Instruction.BranchIfTrue
@ -315,41 +298,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
return newTemp;
}
public AstOperand GetOperandDef(Operand operand)
{
if (operand.Type == OperandType.Attribute)
{
Info.Outputs.Add(operand.Value & AttributeConsts.Mask);
}
else if (operand.Type == OperandType.AttributePerPatch)
{
Info.OutputsPerPatch.Add(operand.Value & AttributeConsts.Mask);
}
return GetOperand(operand);
}
public AstOperand GetOperandUse(Operand operand)
{
// If this flag is set, we're reading from an output attribute instead.
if (operand.Type.IsAttribute() && (operand.Value & AttributeConsts.LoadOutputMask) != 0)
{
return GetOperandDef(operand);
}
if (operand.Type == OperandType.Attribute)
{
Info.Inputs.Add(operand.Value);
}
else if (operand.Type == OperandType.AttributePerPatch)
{
Info.InputsPerPatch.Add(operand.Value);
}
return GetOperand(operand);
}
private AstOperand GetOperand(Operand operand)
public AstOperand GetOperand(Operand operand)
{
if (operand == null)
{