From 33f544fd9248361440afd6013e0ef9d69971d6da Mon Sep 17 00:00:00 2001 From: riperiperi Date: Mon, 14 Aug 2023 07:41:11 +0100 Subject: [PATCH] GPU: Track basic buffer copies that modify texture memory (#5554) This branch changes the buffer copy fast path to notify memory tracking for all resources that aren't buffers. This fixes cases where games would copy buffer data directly into texture memory, which before would only work if the texture did not already exist. I imagine this happens when the guest driver is moving data between allocations or uploading it. Since this only affects the fast path, cases where the source data has been modified from GPU (fast path copy destination doesn't count) will still fail to notify the texture, though I don't imagine games will do this. This should be resolved in future. This should fix some texture issues with guest OpenGL games on switch, such as Dragon Quest Builders. This may also be useful in future for games that move shader data around memory, if we end up using memory tracking for those. --- src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs | 2 +- src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs index 99c571ba..f8f572c6 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs @@ -344,7 +344,7 @@ namespace Ryujinx.Graphics.Gpu.Memory // Optimization: If the data being copied is already in memory, then copy it directly instead of flushing from GPU. dstBuffer.ClearModified(dstAddress, size); - memoryManager.Physical.WriteUntracked(dstAddress, memoryManager.Physical.GetSpan(srcAddress, (int)size)); + memoryManager.Physical.WriteTrackedResource(dstAddress, memoryManager.Physical.GetSpan(srcAddress, (int)size), ResourceKind.Buffer); } } diff --git a/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index d0b4478e..1ca6071b 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -236,6 +236,18 @@ namespace Ryujinx.Graphics.Gpu.Memory _cpuMemory.WriteUntracked(address, data); } + /// + /// Writes data to the application process, triggering a precise memory tracking event. + /// + /// Address to write into + /// Data to be written + /// Kind of the resource being written, which will not be signalled as CPU modified + public void WriteTrackedResource(ulong address, ReadOnlySpan data, ResourceKind kind) + { + _cpuMemory.SignalMemoryTracking(address, (ulong)data.Length, true, precise: true, exemptId: (int)kind); + _cpuMemory.WriteUntracked(address, data); + } + /// /// Writes data to the application process. ///