From efb135b74c9c0ff1de2dfd7d2a431bd23185ca66 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 16 Feb 2023 18:28:49 -0300 Subject: Clear CPU side data on GPU buffer clears (#4125) * Clear CPU side data on GPU buffer clears * Implement tracked fill operation that can signal other resource types except buffer * Fix tests, add missing XML doc * PR feedback --- Ryujinx.Cpu/AppleHv/HvMemoryManager.cs | 20 ++++++++++---------- Ryujinx.Cpu/IVirtualMemoryManagerTracked.cs | 9 ++++++--- Ryujinx.Cpu/Jit/MemoryManager.cs | 18 +++++++++--------- Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs | 20 ++++++++++---------- Ryujinx.Cpu/MemoryEhMeilleure.cs | 2 +- 5 files changed, 36 insertions(+), 33 deletions(-) (limited to 'Ryujinx.Cpu') diff --git a/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs b/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs index 222dcae1..437e02ae 100644 --- a/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs +++ b/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs @@ -634,13 +634,13 @@ namespace Ryujinx.Cpu.AppleHv /// /// This function also validates that the given range is both valid and mapped, and will throw if it is not. /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false) + public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); if (precise) { - Tracking.VirtualMemoryEvent(va, size, write, precise: true); + Tracking.VirtualMemoryEvent(va, size, write, precise: true, exemptId); return; } @@ -663,7 +663,7 @@ namespace Ryujinx.Cpu.AppleHv if (state >= tag) { - Tracking.VirtualMemoryEvent(va, size, write); + Tracking.VirtualMemoryEvent(va, size, write, precise: false, exemptId); return; } else if (state == 0) @@ -706,7 +706,7 @@ namespace Ryujinx.Cpu.AppleHv // Only trigger tracking from reads if both bits are set on any page. if (write || (pte & (pte >> 1) & BlockMappedMask) != 0) { - Tracking.VirtualMemoryEvent(va, size, write); + Tracking.VirtualMemoryEvent(va, size, write, precise: false, exemptId); break; } } @@ -822,21 +822,21 @@ namespace Ryujinx.Cpu.AppleHv } /// - public CpuRegionHandle BeginTracking(ulong address, ulong size) + public CpuRegionHandle BeginTracking(ulong address, ulong size, int id) { - return new CpuRegionHandle(Tracking.BeginTracking(address, size)); + return new CpuRegionHandle(Tracking.BeginTracking(address, size, id)); } /// - public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity) + public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity, int id) { - return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity)); + return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity, id)); } /// - public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity) + public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity, int id) { - return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity)); + return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity, id)); } /// diff --git a/Ryujinx.Cpu/IVirtualMemoryManagerTracked.cs b/Ryujinx.Cpu/IVirtualMemoryManagerTracked.cs index 8004d39b..92d3c76c 100644 --- a/Ryujinx.Cpu/IVirtualMemoryManagerTracked.cs +++ b/Ryujinx.Cpu/IVirtualMemoryManagerTracked.cs @@ -28,8 +28,9 @@ namespace Ryujinx.Cpu /// /// CPU virtual address of the region /// Size of the region + /// Handle ID /// The memory tracking handle - CpuRegionHandle BeginTracking(ulong address, ulong size); + CpuRegionHandle BeginTracking(ulong address, ulong size, int id); /// /// Obtains a memory tracking handle for the given virtual region, with a specified granularity. This should be disposed when finished with. @@ -38,8 +39,9 @@ namespace Ryujinx.Cpu /// Size of the region /// Handles to inherit state from or reuse. When none are present, provide null /// Desired granularity of write tracking + /// Handle ID /// The memory tracking handle - CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity); + CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity, int id); /// /// Obtains a smart memory tracking handle for the given virtual region, with a specified granularity. This should be disposed when finished with. @@ -47,7 +49,8 @@ namespace Ryujinx.Cpu /// CPU virtual address of the region /// Size of the region /// Desired granularity of write tracking + /// Handle ID /// The memory tracking handle - CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity); + CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity, int id); } } diff --git a/Ryujinx.Cpu/Jit/MemoryManager.cs b/Ryujinx.Cpu/Jit/MemoryManager.cs index 014d843b..8542d53e 100644 --- a/Ryujinx.Cpu/Jit/MemoryManager.cs +++ b/Ryujinx.Cpu/Jit/MemoryManager.cs @@ -629,31 +629,31 @@ namespace Ryujinx.Cpu.Jit } /// - public CpuRegionHandle BeginTracking(ulong address, ulong size) + public CpuRegionHandle BeginTracking(ulong address, ulong size, int id) { - return new CpuRegionHandle(Tracking.BeginTracking(address, size)); + return new CpuRegionHandle(Tracking.BeginTracking(address, size, id)); } /// - public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity) + public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity, int id) { - return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity)); + return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity, id)); } /// - public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity) + public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity, int id) { - return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity)); + return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity, id)); } /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false) + public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); if (precise) { - Tracking.VirtualMemoryEvent(va, size, write, precise: true); + Tracking.VirtualMemoryEvent(va, size, write, precise: true, exemptId); return; } @@ -676,7 +676,7 @@ namespace Ryujinx.Cpu.Jit if ((pte & tag) != 0) { - Tracking.VirtualMemoryEvent(va, size, write); + Tracking.VirtualMemoryEvent(va, size, write, precise: false, exemptId); break; } diff --git a/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs b/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs index 856b6b9b..090740ab 100644 --- a/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs +++ b/Ryujinx.Cpu/Jit/MemoryManagerHostMapped.cs @@ -518,13 +518,13 @@ namespace Ryujinx.Cpu.Jit /// /// This function also validates that the given range is both valid and mapped, and will throw if it is not. /// - public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false) + public void SignalMemoryTracking(ulong va, ulong size, bool write, bool precise = false, int? exemptId = null) { AssertValidAddressAndSize(va, size); if (precise) { - Tracking.VirtualMemoryEvent(va, size, write, precise: true); + Tracking.VirtualMemoryEvent(va, size, write, precise: true, exemptId); return; } @@ -547,7 +547,7 @@ namespace Ryujinx.Cpu.Jit if (state >= tag) { - Tracking.VirtualMemoryEvent(va, size, write); + Tracking.VirtualMemoryEvent(va, size, write, precise: false, exemptId); return; } else if (state == 0) @@ -590,7 +590,7 @@ namespace Ryujinx.Cpu.Jit // Only trigger tracking from reads if both bits are set on any page. if (write || (pte & (pte >> 1) & BlockMappedMask) != 0) { - Tracking.VirtualMemoryEvent(va, size, write); + Tracking.VirtualMemoryEvent(va, size, write, precise: false, exemptId); break; } } @@ -706,21 +706,21 @@ namespace Ryujinx.Cpu.Jit } /// - public CpuRegionHandle BeginTracking(ulong address, ulong size) + public CpuRegionHandle BeginTracking(ulong address, ulong size, int id) { - return new CpuRegionHandle(Tracking.BeginTracking(address, size)); + return new CpuRegionHandle(Tracking.BeginTracking(address, size, id)); } /// - public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity) + public CpuMultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable handles, ulong granularity, int id) { - return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity)); + return new CpuMultiRegionHandle(Tracking.BeginGranularTracking(address, size, handles, granularity, id)); } /// - public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity) + public CpuSmartMultiRegionHandle BeginSmartGranularTracking(ulong address, ulong size, ulong granularity, int id) { - return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity)); + return new CpuSmartMultiRegionHandle(Tracking.BeginSmartGranularTracking(address, size, granularity, id)); } /// diff --git a/Ryujinx.Cpu/MemoryEhMeilleure.cs b/Ryujinx.Cpu/MemoryEhMeilleure.cs index 806ef811..0b434ea7 100644 --- a/Ryujinx.Cpu/MemoryEhMeilleure.cs +++ b/Ryujinx.Cpu/MemoryEhMeilleure.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Cpu { public class MemoryEhMeilleure : IDisposable { - private delegate bool TrackingEventDelegate(ulong address, ulong size, bool write, bool precise = false); + private delegate bool TrackingEventDelegate(ulong address, ulong size, bool write); private readonly MemoryTracking _tracking; private readonly TrackingEventDelegate _trackingEvent; -- cgit v1.2.3