Use vector outputs for texture operations (#3939)

* Change AggregateType to include vector type counts

* Replace VariableType uses with AggregateType and delete VariableType

* Support new local vector types on SPIR-V and GLSL

* Start using vector outputs for texture operations

* Use vectors on more texture operations

* Use vector output for ImageLoad operations

* Replace all uses of single destination texture constructors with multi destination ones

* Update textureGatherOffsets replacement to split vector operations

* Shader cache version bump

Co-authored-by: Ac_K <Acoustik666@gmail.com>
This commit is contained in:
gdkchan 2022-12-29 12:09:34 -03:00 committed by GitHub
parent 52c115a1f8
commit 9dfe81770a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 1100 additions and 747 deletions

View file

@ -1,7 +1,9 @@
using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.Translation;
using System;
using System.Collections.Generic;
using System.Numerics;
using static Ryujinx.Graphics.Shader.Instructions.InstEmitHelper;
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
@ -217,15 +219,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
return context.Copy(Register(srcB++, RegisterType.Gpr));
}
Operand GetDest()
{
if (dest >= RegisterConsts.RegisterZeroIndex)
{
return null;
}
return Register(dest++, RegisterType.Gpr);
}
Operand destOperand = dest != RegisterConsts.RegisterZeroIndex ? Register(dest, RegisterType.Gpr) : null;
List<Operand> sourcesList = new List<Operand>();
@ -291,7 +285,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags,
imm,
0,
GetDest(),
new[] { destOperand },
sources);
context.Add(operation);
@ -371,36 +365,40 @@ namespace Ryujinx.Graphics.Shader.Instructions
if (useComponents)
{
for (int compMask = (int)componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) == 0)
{
continue;
}
Operand[] dests = new Operand[BitOperations.PopCount((uint)componentMask)];
if (srcB == RegisterConsts.RegisterZeroIndex)
int outputIndex = 0;
for (int i = 0; i < dests.Length; i++)
{
if (srcB + i >= RegisterConsts.RegisterZeroIndex)
{
break;
}
Operand rd = Register(srcB++, RegisterType.Gpr);
TextureOperation operation = context.CreateTextureOperation(
Instruction.ImageLoad,
type,
flags,
handle,
compIndex,
rd,
sources);
if (!isBindless)
{
operation.Format = context.Config.GetTextureFormat(handle);
}
context.Add(operation);
dests[outputIndex++] = Register(srcB + i, RegisterType.Gpr);
}
if (outputIndex != dests.Length)
{
Array.Resize(ref dests, outputIndex);
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.ImageLoad,
type,
flags,
handle,
(int)componentMask,
dests,
sources);
if (!isBindless)
{
operation.Format = context.Config.GetTextureFormat(handle);
}
context.Add(operation);
}
else
{
@ -412,35 +410,45 @@ namespace Ryujinx.Graphics.Shader.Instructions
}
int components = GetComponents(size);
int compMask = (1 << components) - 1;
for (int compIndex = 0; compIndex < components; compIndex++)
Operand[] dests = new Operand[components];
int outputIndex = 0;
for (int i = 0; i < dests.Length; i++)
{
if (srcB == RegisterConsts.RegisterZeroIndex)
if (srcB + i >= RegisterConsts.RegisterZeroIndex)
{
break;
}
Operand rd = Register(srcB++, RegisterType.Gpr);
dests[outputIndex++] = Register(srcB + i, RegisterType.Gpr);
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.ImageLoad,
type,
GetTextureFormat(size),
flags,
handle,
compIndex,
rd,
sources);
if (outputIndex != dests.Length)
{
Array.Resize(ref dests, outputIndex);
}
context.Add(operation);
TextureOperation operation = context.CreateTextureOperation(
Instruction.ImageLoad,
type,
GetTextureFormat(size),
flags,
handle,
compMask,
dests,
sources);
switch (size)
{
case SuSize.U8: context.Copy(rd, ZeroExtendTo32(context, rd, 8)); break;
case SuSize.U16: context.Copy(rd, ZeroExtendTo32(context, rd, 16)); break;
case SuSize.S8: context.Copy(rd, SignExtendTo32(context, rd, 8)); break;
case SuSize.S16: context.Copy(rd, SignExtendTo32(context, rd, 16)); break;
}
context.Add(operation);
switch (size)
{
case SuSize.U8: context.Copy(dests[0], ZeroExtendTo32(context, dests[0], 8)); break;
case SuSize.U16: context.Copy(dests[0], ZeroExtendTo32(context, dests[0], 16)); break;
case SuSize.S8: context.Copy(dests[0], SignExtendTo32(context, dests[0], 8)); break;
case SuSize.S16: context.Copy(dests[0], SignExtendTo32(context, dests[0], 16)); break;
}
}
}

View file

@ -3,6 +3,7 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.Translation;
using System;
using System.Collections.Generic;
using System.Numerics;
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
@ -303,42 +304,37 @@ namespace Ryujinx.Graphics.Shader.Instructions
}
Operand[] sources = sourcesList.ToArray();
Operand[] dests = new Operand[BitOperations.PopCount((uint)componentMask)];
Operand GetDest()
int outputIndex = 0;
for (int i = 0; i < dests.Length; i++)
{
if (rdIndex >= RegisterConsts.RegisterZeroIndex)
if (rdIndex + i >= RegisterConsts.RegisterZeroIndex)
{
return null;
break;
}
return Register(rdIndex++, RegisterType.Gpr);
dests[outputIndex++] = Register(rdIndex + i, RegisterType.Gpr);
}
if (outputIndex != dests.Length)
{
Array.Resize(ref dests, outputIndex);
}
int handle = !isBindless ? imm : 0;
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) != 0)
{
Operand dest = GetDest();
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
componentMask,
dests,
sources);
if (dest == null)
{
break;
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
compIndex,
dest,
sources);
context.Add(operation);
}
}
context.Add(operation);
}
private static void EmitTexs(
@ -624,18 +620,23 @@ namespace Ryujinx.Graphics.Shader.Instructions
Operand[] rd0 = new Operand[2] { ConstF(0), ConstF(0) };
Operand[] rd1 = new Operand[2] { ConstF(0), ConstF(0) };
int destIncrement = 0;
int handle = imm;
int componentMask = _maskLut[dest2 == RegisterConsts.RegisterZeroIndex ? 0 : 1, writeMask];
Operand GetDest()
int componentsCount = BitOperations.PopCount((uint)componentMask);
Operand[] dests = new Operand[componentsCount];
int outputIndex = 0;
for (int i = 0; i < componentsCount; i++)
{
int high = destIncrement >> 1;
int low = destIncrement & 1;
destIncrement++;
int high = i >> 1;
int low = i & 1;
if (isF16)
{
return high != 0
dests[outputIndex++] = high != 0
? (rd1[low] = Local())
: (rd0[low] = Local());
}
@ -648,30 +649,26 @@ namespace Ryujinx.Graphics.Shader.Instructions
rdIndex += low;
}
return Register(rdIndex, RegisterType.Gpr);
dests[outputIndex++] = Register(rdIndex, RegisterType.Gpr);
}
}
int handle = imm;
int componentMask = _maskLut[dest2 == RegisterConsts.RegisterZeroIndex ? 0 : 1, writeMask];
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
if (outputIndex != dests.Length)
{
if ((compMask & 1) != 0)
{
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
compIndex,
GetDest(),
sources);
context.Add(operation);
}
Array.Resize(ref dests, outputIndex);
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
componentMask,
dests,
sources);
context.Add(operation);
if (isF16)
{
context.Copy(Register(dest, RegisterType.Gpr), context.PackHalf2x16(rd0[0], rd0[1]));
@ -797,42 +794,37 @@ namespace Ryujinx.Graphics.Shader.Instructions
sourcesList.Add(Const((int)component));
Operand[] sources = sourcesList.ToArray();
Operand[] dests = new Operand[BitOperations.PopCount((uint)componentMask)];
Operand GetDest()
int outputIndex = 0;
for (int i = 0; i < dests.Length; i++)
{
if (dest >= RegisterConsts.RegisterZeroIndex)
if (dest + i >= RegisterConsts.RegisterZeroIndex)
{
return null;
break;
}
return Register(dest++, RegisterType.Gpr);
dests[outputIndex++] = Register(dest + i, RegisterType.Gpr);
}
if (outputIndex != dests.Length)
{
Array.Resize(ref dests, outputIndex);
}
int handle = imm;
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) != 0)
{
Operand destOperand = GetDest();
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
componentMask,
dests,
sources);
if (destOperand == null)
{
break;
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
compIndex,
destOperand,
sources);
context.Add(operation);
}
}
context.Add(operation);
}
private static void EmitTmml(
@ -951,7 +943,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags,
handle,
compIndex ^ 1, // The instruction component order is the inverse of GLSL's.
tempDest,
new[] { tempDest },
sources);
context.Add(operation);
@ -1071,42 +1063,37 @@ namespace Ryujinx.Graphics.Shader.Instructions
}
Operand[] sources = sourcesList.ToArray();
Operand[] dests = new Operand[BitOperations.PopCount((uint)componentMask)];
Operand GetDest()
int outputIndex = 0;
for (int i = 0; i < dests.Length; i++)
{
if (dest >= RegisterConsts.RegisterZeroIndex)
if (dest + i >= RegisterConsts.RegisterZeroIndex)
{
return null;
break;
}
return Register(dest++, RegisterType.Gpr);
dests[outputIndex++] = Register(dest + i, RegisterType.Gpr);
}
if (outputIndex != dests.Length)
{
Array.Resize(ref dests, outputIndex);
}
int handle = imm;
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) != 0)
{
Operand destOperand = GetDest();
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
componentMask,
dests,
sources);
if (destOperand == null)
{
break;
}
TextureOperation operation = context.CreateTextureOperation(
Instruction.TextureSample,
type,
flags,
handle,
compIndex,
destOperand,
sources);
context.Add(operation);
}
}
context.Add(operation);
}
private static void EmitTxq(
@ -1188,7 +1175,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags,
imm,
compIndex,
destOperand,
new[] { destOperand },
sources);
context.Add(operation);