From b8eb6abeccbd4a468214a4d2ad3a9b6e5e06973c Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 5 May 2020 22:02:28 -0300 Subject: Refactor shader GPU state and memory access (#1203) * Refactor shader GPU state and memory access * Fix NVDEC project build * Address PR feedback and add missing XML comments --- Ryujinx.Graphics.Shader/Decoders/Decoder.cs | 34 ++++++++--------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'Ryujinx.Graphics.Shader/Decoders/Decoder.cs') diff --git a/Ryujinx.Graphics.Shader/Decoders/Decoder.cs b/Ryujinx.Graphics.Shader/Decoders/Decoder.cs index 3e322e45..e2c9212b 100644 --- a/Ryujinx.Graphics.Shader/Decoders/Decoder.cs +++ b/Ryujinx.Graphics.Shader/Decoders/Decoder.cs @@ -1,6 +1,5 @@ using Ryujinx.Graphics.Shader.Instructions; using System; -using System.Buffers.Binary; using System.Collections.Generic; using System.Linq; @@ -10,7 +9,7 @@ namespace Ryujinx.Graphics.Shader.Decoders { static class Decoder { - public static Block[] Decode(ReadOnlySpan code, ulong headerSize) + public static Block[] Decode(IGpuAccessor gpuAccessor, ulong startAddress) { List blocks = new List(); @@ -18,8 +17,6 @@ namespace Ryujinx.Graphics.Shader.Decoders Dictionary visited = new Dictionary(); - ulong maxAddress = (ulong)code.Length - headerSize; - Block GetBlock(ulong blkAddress) { if (!visited.TryGetValue(blkAddress, out Block block)) @@ -56,7 +53,7 @@ namespace Ryujinx.Graphics.Shader.Decoders } // If we have a block after the current one, set the limit address. - ulong limitAddress = maxAddress; + ulong limitAddress = ulong.MaxValue; if (nBlkIndex != blocks.Count) { @@ -74,7 +71,7 @@ namespace Ryujinx.Graphics.Shader.Decoders } } - FillBlock(code, currBlock, limitAddress, headerSize); + FillBlock(gpuAccessor, currBlock, limitAddress, startAddress); if (currBlock.OpCodes.Count != 0) { @@ -82,11 +79,6 @@ namespace Ryujinx.Graphics.Shader.Decoders // including those from SSY/PBK instructions. foreach (OpCodePush pushOp in currBlock.PushOpCodes) { - if (pushOp.GetAbsoluteAddress() >= maxAddress) - { - return null; - } - GetBlock(pushOp.GetAbsoluteAddress()); } @@ -98,11 +90,6 @@ namespace Ryujinx.Graphics.Shader.Decoders if (lastOp is OpCodeBranch opBr) { - if (opBr.GetAbsoluteAddress() >= maxAddress) - { - return null; - } - currBlock.Branch = GetBlock(opBr.GetAbsoluteAddress()); } else if (lastOp is OpCodeBranchIndir opBrIndir) @@ -141,7 +128,7 @@ namespace Ryujinx.Graphics.Shader.Decoders } // Do we have a block after the current one? - if (!IsExit(currBlock.GetLastOp()) && currBlock.BrIndir != null && currBlock.EndAddress < maxAddress) + if (!IsExit(currBlock.GetLastOp()) && currBlock.BrIndir != null) { bool targetVisited = visited.ContainsKey(currBlock.EndAddress); @@ -203,10 +190,10 @@ namespace Ryujinx.Graphics.Shader.Decoders } private static void FillBlock( - ReadOnlySpan code, - Block block, - ulong limitAddress, - ulong startAddress) + IGpuAccessor gpuAccessor, + Block block, + ulong limitAddress, + ulong startAddress) { ulong address = block.Address; @@ -225,14 +212,11 @@ namespace Ryujinx.Graphics.Shader.Decoders continue; } - uint word0 = BinaryPrimitives.ReadUInt32LittleEndian(code.Slice((int)(startAddress + address))); - uint word1 = BinaryPrimitives.ReadUInt32LittleEndian(code.Slice((int)(startAddress + address + 4))); - ulong opAddress = address; address += 8; - long opCode = word0 | (long)word1 << 32; + long opCode = gpuAccessor.MemoryRead(startAddress + opAddress); (InstEmitter emitter, OpCodeTable.OpActivator opActivator) = OpCodeTable.GetEmitter(opCode); -- cgit v1.2.3