From 3d98e1361b2f1c3993aa7f1e9b1ac49fc5b6e512 Mon Sep 17 00:00:00 2001
From: riperiperi <rhy3756547@hotmail.com>
Date: Sat, 29 Oct 2022 23:07:37 +0100
Subject: GPU: Use a bitmap to track buffer modified flags. (#3775)

* Initial implementation

* Some improvements.

* Fix incorrect cast

* Performance improvement and improved correctness

* Add very fast path when all handles are checked.

* Slightly faster

* Add comment

* De-virtualize region handle

All region handles are now bitmap backed.

* Remove non-bitmap tracking

* Remove unused methods

* Add docs, remove unused methods

* Address Feedback

* Rename file
---
 Ryujinx.Memory/Tracking/MemoryTracking.cs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'Ryujinx.Memory/Tracking/MemoryTracking.cs')

diff --git a/Ryujinx.Memory/Tracking/MemoryTracking.cs b/Ryujinx.Memory/Tracking/MemoryTracking.cs
index f2ac17ff..9aa7c7ff 100644
--- a/Ryujinx.Memory/Tracking/MemoryTracking.cs
+++ b/Ryujinx.Memory/Tracking/MemoryTracking.cs
@@ -176,6 +176,26 @@ namespace Ryujinx.Memory.Tracking
             }
         }
 
+        /// <summary>
+        /// Obtains a memory tracking handle for the given virtual region. This should be disposed when finished with.
+        /// </summary>
+        /// <param name="address">CPU virtual address of the region</param>
+        /// <param name="size">Size of the region</param>
+        /// <param name="bitmap">The bitmap owning the dirty flag for this handle</param>
+        /// <param name="bit">The bit of this handle within the dirty flag</param>
+        /// <returns>The memory tracking handle</returns>
+        internal RegionHandle BeginTrackingBitmap(ulong address, ulong size, ConcurrentBitmap bitmap, int bit)
+        {
+            (address, size) = PageAlign(address, size);
+
+            lock (TrackingLock)
+            {
+                RegionHandle handle = new RegionHandle(this, address, size, bitmap, bit, _memoryManager.IsRangeMapped(address, size));
+
+                return handle;
+            }
+        }
+
         /// <summary>
         /// Signal that a virtual memory event happened at the given location (one byte).
         /// </summary>
-- 
cgit v1.2.3-70-g09d2