Declare and use gl_PerVertex block for VTG per-vertex built-ins (#5576)

* Declare and use gl_PerVertex block for VTG per-vertex built-ins

* Shader cache version bump
This commit is contained in:
gdkchan 2023-08-16 18:16:25 -03:00 committed by GitHub
parent 0c445184c1
commit 17354d59d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 176 additions and 3 deletions

View file

@ -1788,6 +1788,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
StorageClass storageClass;
SpvInstruction baseObj;
int srcIndex = 0;
IoVariable? perVertexBuiltIn = null;
switch (storageKind)
{
@ -1881,6 +1882,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
else
{
(_, varType) = IoMap.GetSpirvBuiltIn(ioVariable);
if (IoMap.IsPerVertexBuiltIn(ioVariable))
{
perVertexBuiltIn = ioVariable;
ioVariable = IoVariable.Position;
}
}
varType &= AggregateType.ElementTypeMask;
@ -1902,6 +1909,31 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
bool isStoreOrAtomic = operation.Inst == Instruction.Store || operation.Inst.IsAtomic();
int inputsCount = (isStoreOrAtomic ? operation.SourcesCount - 1 : operation.SourcesCount) - srcIndex;
if (perVertexBuiltIn.HasValue)
{
int fieldIndex = IoMap.GetPerVertexStructFieldIndex(perVertexBuiltIn.Value);
var indexes = new SpvInstruction[inputsCount + 1];
int index = 0;
if (IoMap.IsPerVertexArrayBuiltIn(storageKind, context.Definitions.Stage))
{
indexes[index++] = context.Get(AggregateType.S32, operation.GetSource(srcIndex++));
indexes[index++] = context.Constant(context.TypeS32(), fieldIndex);
}
else
{
indexes[index++] = context.Constant(context.TypeS32(), fieldIndex);
}
for (; index < inputsCount + 1; srcIndex++, index++)
{
indexes[index] = context.Get(AggregateType.S32, operation.GetSource(srcIndex));
}
return context.AccessChain(context.TypePointer(storageClass, context.GetType(varType)), baseObj, indexes);
}
if (operation.Inst == Instruction.AtomicCompareAndSwap)
{
inputsCount--;