Add a pass to turn global memory access into storage access, and do all storage related transformations on IR
This commit is contained in:
parent
396768f3b4
commit
6a98c643ca
28 changed files with 532 additions and 282 deletions
|
@ -5,11 +5,10 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
[Flags]
|
||||
enum HelperFunctionsMask
|
||||
{
|
||||
GlobalMemory = 1 << 0,
|
||||
Shuffle = 1 << 1,
|
||||
ShuffleDown = 1 << 2,
|
||||
ShuffleUp = 1 << 3,
|
||||
ShuffleXor = 1 << 4,
|
||||
SwizzleAdd = 1 << 5
|
||||
Shuffle = 1 << 0,
|
||||
ShuffleDown = 1 << 1,
|
||||
ShuffleUp = 1 << 2,
|
||||
ShuffleXor = 1 << 3,
|
||||
SwizzleAdd = 1 << 4
|
||||
}
|
||||
}
|
|
@ -25,16 +25,16 @@ 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.AtomicAdd, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicAnd, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicCompareAndSwap, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32, VariableType.U32);
|
||||
Add(Instruction.AtomicMaxS32, VariableType.S32, VariableType.S32, VariableType.S32, VariableType.S32);
|
||||
Add(Instruction.AtomicMaxU32, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicMinS32, VariableType.S32, VariableType.S32, VariableType.S32, VariableType.S32);
|
||||
Add(Instruction.AtomicMinU32, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicOr, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicSwap, VariableType.U32, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.AtomicXor, VariableType.U32, VariableType.S32, VariableType.S32, 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);
|
||||
|
@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
Add(Instruction.LoadGlobal, VariableType.U32, VariableType.S32, VariableType.S32);
|
||||
Add(Instruction.LoadLocal, VariableType.U32, VariableType.S32);
|
||||
Add(Instruction.LoadShared, VariableType.U32, VariableType.S32);
|
||||
Add(Instruction.LoadStorage, VariableType.U32, VariableType.S32);
|
||||
Add(Instruction.LoadStorage, VariableType.U32, VariableType.S32, 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);
|
||||
|
@ -111,7 +111,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
Add(Instruction.StoreGlobal, VariableType.None, VariableType.S32, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.StoreLocal, VariableType.None, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.StoreShared, VariableType.None, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.StoreStorage, VariableType.None, VariableType.S32, VariableType.U32);
|
||||
Add(Instruction.StoreStorage, VariableType.None, VariableType.S32, 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);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -80,7 +81,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
}
|
||||
else if (UsesStorage(inst))
|
||||
{
|
||||
context.Info.SBuffers.Add(operation.Index);
|
||||
AddSBufferUse(context.Info.SBuffers, operation);
|
||||
}
|
||||
|
||||
AstAssignment assignment;
|
||||
|
@ -159,7 +160,7 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
{
|
||||
if (UsesStorage(inst))
|
||||
{
|
||||
context.Info.SBuffers.Add(operation.Index);
|
||||
AddSBufferUse(context.Info.SBuffers, operation);
|
||||
}
|
||||
|
||||
context.AddNode(new AstOperation(inst, operation.Index, sources));
|
||||
|
@ -170,10 +171,6 @@ 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;
|
||||
|
@ -192,6 +189,26 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
|
|||
}
|
||||
}
|
||||
|
||||
private static void AddSBufferUse(HashSet<int> sBuffers, Operation operation)
|
||||
{
|
||||
Operand slot = operation.GetSource(0);
|
||||
|
||||
if (slot.Type == OperandType.Constant)
|
||||
{
|
||||
sBuffers.Add(slot.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the value is not constant, then we don't know
|
||||
// how many storage buffers are used, so we assume
|
||||
// all of them are used.
|
||||
for (int index = 0; index < GlobalMemory.StorageMaxCount; index++)
|
||||
{
|
||||
sBuffers.Add(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static VariableType GetVarTypeFromUses(Operand dest)
|
||||
{
|
||||
HashSet<Operand> visited = new HashSet<Operand>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue