diff options
| author | gdk <gab.dark.100@gmail.com> | 2019-11-08 17:29:41 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | 769c02235f489f02b1791e6e76dc8b3ab18028ee (patch) | |
| tree | ef0a2ffc5030360d5cef78e7c67e131e44348d50 /Ryujinx.Graphics.Shader/StructuredIr | |
| parent | 1e8bc29f32cde08616175f8f87405dfa7b8c4025 (diff) | |
Add ATOMS, LDS, POPC, RED, STS and VOTE shader instructions, start changing the way how global memory is handled
Diffstat (limited to 'Ryujinx.Graphics.Shader/StructuredIr')
5 files changed, 53 insertions, 38 deletions
diff --git a/Ryujinx.Graphics.Shader/StructuredIr/AstOperation.cs b/Ryujinx.Graphics.Shader/StructuredIr/AstOperation.cs index 1607ffec..76eee71e 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/AstOperation.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/AstOperation.cs @@ -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) diff --git a/Ryujinx.Graphics.Shader/StructuredIr/AstTextureOperation.cs b/Ryujinx.Graphics.Shader/StructuredIr/AstTextureOperation.cs index d6d40732..5473978e 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/AstTextureOperation.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/AstTextureOperation.cs @@ -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; diff --git a/Ryujinx.Graphics.Shader/StructuredIr/HelperFunctionsMask.cs b/Ryujinx.Graphics.Shader/StructuredIr/HelperFunctionsMask.cs index e2eee78d..b262e6bc 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/HelperFunctionsMask.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/HelperFunctionsMask.cs @@ -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 } }
\ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs b/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs index 381cf292..4f4ebb99 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs @@ -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) diff --git a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs index ef8443ab..a81b3d12 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/StructuredProgram.cs @@ -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; + } } }
\ No newline at end of file |
