Add ATOMS, LDS, POPC, RED, STS and VOTE shader instructions, start changing the way how global memory is handled

This commit is contained in:
gdk 2019-11-08 17:29:41 -03:00 committed by Thog
parent 1e8bc29f32
commit 769c02235f
44 changed files with 949 additions and 242 deletions

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
{
public Instruction Inst { get; }
public int ComponentMask { get; }
public int Index { get; }
private IAstNode[] _sources;
@ -24,12 +24,12 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
AddUse(source, this);
}
ComponentMask = 1;
Index = 0;
}
public AstOperation(Instruction inst, int compMask, params IAstNode[] sources) : this(inst, sources)
public AstOperation(Instruction inst, int index, params IAstNode[] sources) : this(inst, sources)
{
ComponentMask = compMask;
Index = index;
}
public IAstNode GetSource(int index)

View file

@ -16,8 +16,8 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
TextureFlags flags,
int handle,
int arraySize,
int compMask,
params IAstNode[] sources) : base(inst, compMask, sources)
int index,
params IAstNode[] sources) : base(inst, index, sources)
{
Type = type;
Flags = flags;

View file

@ -5,10 +5,11 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
[Flags]
enum HelperFunctionsMask
{
Shuffle = 1 << 0,
ShuffleDown = 1 << 1,
ShuffleUp = 1 << 2,
ShuffleXor = 1 << 3,
SwizzleAdd = 1 << 4
GlobalMemory = 1 << 0,
Shuffle = 1 << 1,
ShuffleDown = 1 << 2,
ShuffleUp = 1 << 3,
ShuffleXor = 1 << 4,
SwizzleAdd = 1 << 5
}
}

View file

@ -25,8 +25,19 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
_infoTbl = new InstInfo[(int)Instruction.Count];
// Inst Destination type Source 1 type Source 2 type Source 3 type Source 4 type
Add(Instruction.AtomicAdd, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicAnd, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicCompareAndSwap, VariableType.U32, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicMaxS32, VariableType.S32, VariableType.S32, VariableType.S32);
Add(Instruction.AtomicMaxU32, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicMinS32, VariableType.S32, VariableType.S32, VariableType.S32);
Add(Instruction.AtomicMinU32, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicOr, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicSwap, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.AtomicXor, VariableType.U32, VariableType.U32, VariableType.U32);
Add(Instruction.Absolute, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.Add, VariableType.Scalar, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.Ballot, VariableType.U32, VariableType.Bool);
Add(Instruction.BitCount, VariableType.Int, VariableType.Int);
Add(Instruction.BitfieldExtractS32, VariableType.S32, VariableType.S32, VariableType.S32, VariableType.S32);
Add(Instruction.BitfieldExtractU32, VariableType.U32, VariableType.U32, VariableType.S32, VariableType.S32);
@ -69,9 +80,10 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
Add(Instruction.IsNan, VariableType.Bool, VariableType.F32);
Add(Instruction.LoadAttribute, VariableType.F32, VariableType.S32, VariableType.S32);
Add(Instruction.LoadConstant, VariableType.F32, VariableType.S32, VariableType.S32);
Add(Instruction.LoadGlobal, VariableType.F32, VariableType.S32, VariableType.S32);
Add(Instruction.LoadGlobal, VariableType.U32, VariableType.S32, VariableType.S32);
Add(Instruction.LoadLocal, VariableType.F32, VariableType.S32);
Add(Instruction.LoadStorage, VariableType.F32, VariableType.S32, VariableType.S32);
Add(Instruction.LoadShared, VariableType.U32, VariableType.S32);
Add(Instruction.LoadStorage, VariableType.U32, VariableType.S32);
Add(Instruction.LogarithmB2, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.LogicalAnd, VariableType.Bool, VariableType.Bool, VariableType.Bool);
Add(Instruction.LogicalExclusiveOr, VariableType.Bool, VariableType.Bool, VariableType.Bool);
@ -95,15 +107,19 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
Add(Instruction.Round, VariableType.F32, VariableType.F32);
Add(Instruction.Sine, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.SquareRoot, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.StoreGlobal, VariableType.None, VariableType.S32, VariableType.S32, VariableType.F32);
Add(Instruction.StoreGlobal, VariableType.None, VariableType.S32, VariableType.S32, VariableType.U32);
Add(Instruction.StoreLocal, VariableType.None, VariableType.S32, VariableType.F32);
Add(Instruction.StoreStorage, VariableType.None, VariableType.S32, VariableType.S32, VariableType.F32);
Add(Instruction.StoreShared, VariableType.None, VariableType.S32, VariableType.U32);
Add(Instruction.StoreStorage, VariableType.None, VariableType.S32, VariableType.U32);
Add(Instruction.Subtract, VariableType.Scalar, VariableType.Scalar, VariableType.Scalar);
Add(Instruction.SwizzleAdd, VariableType.F32, VariableType.F32, VariableType.F32, VariableType.S32);
Add(Instruction.TextureSample, VariableType.F32);
Add(Instruction.TextureSize, VariableType.S32, VariableType.S32, VariableType.S32);
Add(Instruction.Truncate, VariableType.F32, VariableType.F32);
Add(Instruction.UnpackHalf2x16, VariableType.F32, VariableType.U32);
Add(Instruction.VoteAll, VariableType.Bool, VariableType.Bool);
Add(Instruction.VoteAllEqual, VariableType.Bool, VariableType.Bool);
Add(Instruction.VoteAny, VariableType.Bool, VariableType.Bool);
}
private static void Add(Instruction inst, VariableType destType, params VariableType[] srcTypes)

View file

@ -51,8 +51,6 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
sources[index] = context.GetOperandUse(operation.GetSource(index));
}
int componentMask = 1 << operation.ComponentIndex;
AstTextureOperation GetAstTextureOperation(TextureOperation texOp)
{
return new AstTextureOperation(
@ -61,7 +59,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
texOp.Flags,
texOp.Handle,
4, // TODO: Non-hardcoded array size.
componentMask,
texOp.Index,
sources);
}
@ -80,16 +78,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
context.Info.CBuffers.Add(slot.Value);
}
else if (inst == Instruction.LoadStorage)
else if (UsesStorage(inst))
{
Operand slot = operation.GetSource(0);
if (slot.Type != OperandType.Constant)
{
throw new InvalidOperationException("Found load or store with non-constant storage buffer slot.");
}
context.Info.SBuffers.Add(slot.Value);
context.Info.SBuffers.Add(operation.Index);
}
AstAssignment assignment;
@ -141,7 +132,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
}
else if (!isCopy)
{
source = new AstOperation(inst, componentMask, sources);
source = new AstOperation(inst, operation.Index, sources);
}
else
{
@ -166,19 +157,12 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
}
else
{
if (inst == Instruction.StoreStorage)
if (UsesStorage(inst))
{
Operand slot = operation.GetSource(0);
if (slot.Type != OperandType.Constant)
{
throw new InvalidOperationException("Found load or store with non-constant storage buffer slot.");
}
context.Info.SBuffers.Add(slot.Value);
context.Info.SBuffers.Add(operation.Index);
}
context.AddNode(new AstOperation(inst, sources));
context.AddNode(new AstOperation(inst, operation.Index, sources));
}
// Those instructions needs to be emulated by using helper functions,
@ -186,6 +170,10 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
// decide which helper functions are needed on the final generated code.
switch (operation.Inst)
{
case Instruction.LoadGlobal:
case Instruction.StoreGlobal:
context.Info.HelperFunctionsMask |= HelperFunctionsMask.GlobalMemory;
break;
case Instruction.Shuffle:
context.Info.HelperFunctionsMask |= HelperFunctionsMask.Shuffle;
break;
@ -320,5 +308,15 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
throw new ArgumentException($"Unexpected instruction \"{inst}\".");
}
private static bool UsesStorage(Instruction inst)
{
if (inst == Instruction.LoadStorage || inst == Instruction.StoreStorage)
{
return true;
}
return inst.IsAtomic() && (inst & Instruction.MrMask) == Instruction.MrStorage;
}
}
}