From 82cefc8dd3babb781d4b7229435e26911fb083dd Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 29 Aug 2021 16:52:38 -0300 Subject: Handle indirect draw counts with non-zero draw starts properly (#2593) --- Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 27 +++++++++++++++++++++++++-- Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 15 +++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory') diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index b747b558..2dc1edd2 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -63,10 +63,33 @@ namespace Ryujinx.Graphics.Gpu.Memory /// /// Type of the data /// GPU virtual address where the data is located + /// True if read tracking is triggered on the memory region /// The data at the specified memory location - public T Read(ulong va) where T : unmanaged + public T Read(ulong va, bool tracked = false) where T : unmanaged { - return MemoryMarshal.Cast(GetSpan(va, Unsafe.SizeOf()))[0]; + int size = Unsafe.SizeOf(); + + if (IsContiguous(va, size)) + { + ulong address = Translate(va); + + if (tracked) + { + return Physical.ReadTracked(address); + } + else + { + return Physical.Read(address); + } + } + else + { + Span data = new byte[size]; + + ReadImpl(va, data, tracked); + + return MemoryMarshal.Cast(data)[0]; + } } /// diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index 8df3c8fb..fd2a7476 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -139,11 +139,22 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Reads data from the application process. /// /// Type of the structure - /// Address to read from + /// Address to read from /// The data at the specified memory location public T Read(ulong address) where T : unmanaged { - return MemoryMarshal.Cast(GetSpan(address, Unsafe.SizeOf()))[0]; + return _cpuMemory.Read(address); + } + + /// + /// Reads data from the application process, with write tracking. + /// + /// Type of the structure + /// Address to read from + /// The data at the specified memory location + public T ReadTracked(ulong address) where T : unmanaged + { + return _cpuMemory.ReadTracked(address); } /// -- cgit v1.2.3