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/Translation/Optimizations | |
| 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/Translation/Optimizations')
3 files changed, 49 insertions, 9 deletions
diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs index 97852ac1..b6958929 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs @@ -256,7 +256,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { int value = operation.GetSource(0).Value; - value = (value >> operation.ComponentIndex * 16) & 0xffff; + value = (value >> operation.Index * 16) & 0xffff; operation.TurnIntoCopy(ConstF(HalfConversion.HalfToSingle(value))); } diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs index 3d89faf6..2fafa5ad 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs @@ -1,8 +1,6 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation; using System.Collections.Generic; -using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper; - namespace Ryujinx.Graphics.Shader.Translation.Optimizations { static class GlobalToStorage @@ -27,7 +25,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations continue; } - if (operation.Inst == Instruction.LoadGlobal || + if (operation.Inst.IsAtomic() || + operation.Inst == Instruction.LoadGlobal || operation.Inst == Instruction.StoreGlobal) { Operand source = operation.GetSource(0); @@ -51,18 +50,31 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operation storageOp; - if (operation.Inst == Instruction.LoadGlobal) + if (operation.Inst.IsAtomic()) + { + Operand[] sources = new Operand[operation.SourcesCount]; + + for (int index = 0; index < operation.SourcesCount; index++) + { + sources[index] = operation.GetSource(index); + } + + Instruction inst = (operation.Inst & ~Instruction.MrMask) | Instruction.MrStorage; + + storageOp = new Operation(inst, storageIndex, operation.Dest, sources); + } + else if (operation.Inst == Instruction.LoadGlobal) { Operand source = operation.GetSource(0); - storageOp = new Operation(Instruction.LoadStorage, operation.Dest, Const(storageIndex), source); + storageOp = new Operation(Instruction.LoadStorage, storageIndex, operation.Dest, source); } else { Operand src1 = operation.GetSource(0); Operand src2 = operation.GetSource(1); - storageOp = new Operation(Instruction.StoreStorage, null, Const(storageIndex), src1, src2); + storageOp = new Operation(Instruction.StoreStorage, storageIndex, null, src1, src2); } for (int index = 0; index < operation.SourcesCount; index++) @@ -114,6 +126,11 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return -1; } + public static int GetStorageCbOffset(ShaderStage stage, int slot) + { + return GetStorageBaseCbOffset(stage) + slot * StorageDescSize; + } + private static int GetStorageBaseCbOffset(ShaderStage stage) { switch (stage) diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs index 6ee27884..93d86541 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs @@ -133,7 +133,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations if (operation.GetSource(0) == dest) { - operation.TurnIntoCopy(operation.ComponentIndex == 1 ? src1 : src0); + operation.TurnIntoCopy(operation.Index == 1 ? src1 : src0); modified = true; } @@ -251,7 +251,30 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations private static bool IsUnused(INode node) { - return DestIsLocalVar(node) && node.Dest.UseOps.Count == 0; + return !HasSideEffects(node) && DestIsLocalVar(node) && node.Dest.UseOps.Count == 0; + } + + private static bool HasSideEffects(INode node) + { + if (node is Operation operation) + { + switch (operation.Inst & Instruction.Mask) + { + case Instruction.AtomicAdd: + case Instruction.AtomicAnd: + case Instruction.AtomicCompareAndSwap: + case Instruction.AtomicMaxS32: + case Instruction.AtomicMaxU32: + case Instruction.AtomicMinS32: + case Instruction.AtomicMinU32: + case Instruction.AtomicOr: + case Instruction.AtomicSwap: + case Instruction.AtomicXor: + return true; + } + } + + return false; } private static bool DestIsLocalVar(INode node) |
