aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Memory/Tracking
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2021-06-24 00:31:26 +0100
committerGitHub <noreply@github.com>2021-06-24 01:31:26 +0200
commit12a7a2ead812d46deb9d978b6758731157be1cbc (patch)
treee2b5ca9c8ce9d7087c0eff4a5de8e2927f4bb9a1 /Ryujinx.Memory/Tracking
parente053663f27132baec4a4d7c223894eb0322c6c03 (diff)
Inherit buffer tracking handles rather than recreating on resize (#2330)
This greatly speeds up games that constantly resize buffers, and removes stuttering on games that resize large buffers occasionally: - Large improvement on Super Mario 3D All-Stars (#1663 needed for best performance) - Improvement to Hyrule Warriors: AoC, and UE4 games. These games can still stutter due to texture creation/loading. - Small improvement to other games, potential 1-frame stutters avoided. `ForceSynchronizeMemory`, which was added with POWER, is no longer needed. Some tests have been added for the MultiRegionHandle.
Diffstat (limited to 'Ryujinx.Memory/Tracking')
-rw-r--r--Ryujinx.Memory/Tracking/MemoryTracking.cs5
-rw-r--r--Ryujinx.Memory/Tracking/MultiRegionHandle.cs64
2 files changed, 64 insertions, 5 deletions
diff --git a/Ryujinx.Memory/Tracking/MemoryTracking.cs b/Ryujinx.Memory/Tracking/MemoryTracking.cs
index 70951e8c..aafb418d 100644
--- a/Ryujinx.Memory/Tracking/MemoryTracking.cs
+++ b/Ryujinx.Memory/Tracking/MemoryTracking.cs
@@ -134,13 +134,14 @@ namespace Ryujinx.Memory.Tracking
/// </summary>
/// <param name="address">CPU virtual address of the region</param>
/// <param name="size">Size of the region</param>
+ /// <param name="handles">Handles to inherit state from or reuse. When none are present, provide null</param>
/// <param name="granularity">Desired granularity of write tracking</param>
/// <returns>The memory tracking handle</returns>
- public MultiRegionHandle BeginGranularTracking(ulong address, ulong size, ulong granularity)
+ public MultiRegionHandle BeginGranularTracking(ulong address, ulong size, IEnumerable<IRegionHandle> handles, ulong granularity)
{
(address, size) = PageAlign(address, size);
- return new MultiRegionHandle(this, address, size, granularity);
+ return new MultiRegionHandle(this, address, size, handles, granularity);
}
/// <summary>
diff --git a/Ryujinx.Memory/Tracking/MultiRegionHandle.cs b/Ryujinx.Memory/Tracking/MultiRegionHandle.cs
index 1f09807a..638e7290 100644
--- a/Ryujinx.Memory/Tracking/MultiRegionHandle.cs
+++ b/Ryujinx.Memory/Tracking/MultiRegionHandle.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
namespace Ryujinx.Memory.Tracking
{
@@ -18,16 +19,68 @@ namespace Ryujinx.Memory.Tracking
public bool Dirty { get; private set; } = true;
- internal MultiRegionHandle(MemoryTracking tracking, ulong address, ulong size, ulong granularity)
+ internal MultiRegionHandle(MemoryTracking tracking, ulong address, ulong size, IEnumerable<IRegionHandle> handles, ulong granularity)
{
_handles = new RegionHandle[size / granularity];
Granularity = granularity;
- for (int i = 0; i < _handles.Length; i++)
+ int i = 0;
+
+ if (handles != null)
+ {
+ // Inherit from the handles we were given. Any gaps must be filled with new handles,
+ // and old handles larger than our granularity must copy their state onto new granular handles and dispose.
+ // It is assumed that the provided handles do not overlap, in order, are on page boundaries,
+ // and don't extend past the requested range.
+
+ foreach (RegionHandle handle in handles)
+ {
+ int startIndex = (int)((handle.Address - address) / granularity);
+
+ // Fill any gap left before this handle.
+ while (i < startIndex)
+ {
+ RegionHandle fillHandle = tracking.BeginTracking(address + (ulong)i * granularity, granularity);
+ fillHandle.Parent = this;
+ _handles[i++] = fillHandle;
+ }
+
+ if (handle.Size == granularity)
+ {
+ handle.Parent = this;
+ _handles[i++] = handle;
+ }
+ else
+ {
+ int endIndex = (int)((handle.EndAddress - address) / granularity);
+
+ while (i < endIndex)
+ {
+ RegionHandle splitHandle = tracking.BeginTracking(address + (ulong)i * granularity, granularity);
+ splitHandle.Parent = this;
+
+ splitHandle.Reprotect(handle.Dirty);
+
+ RegionSignal signal = handle.PreAction;
+ if (signal != null)
+ {
+ splitHandle.RegisterAction(signal);
+ }
+
+ _handles[i++] = splitHandle;
+ }
+
+ handle.Dispose();
+ }
+ }
+ }
+
+ // Fill any remaining space with new handles.
+ while (i < _handles.Length)
{
RegionHandle handle = tracking.BeginTracking(address + (ulong)i * granularity, granularity);
handle.Parent = this;
- _handles[i] = handle;
+ _handles[i++] = handle;
}
Address = address;
@@ -48,6 +101,11 @@ namespace Ryujinx.Memory.Tracking
}
}
+ public IEnumerable<RegionHandle> GetHandles()
+ {
+ return _handles;
+ }
+
public void SignalWrite()
{
Dirty = true;