From 7379bc2f39557929f283a423fe7f4b7390d08261 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sun, 19 Sep 2021 13:22:26 +0100 Subject: Array based RangeList that caches Address/EndAddress (#2642) * Array based RangeList that caches Address/EndAddress In isolation, this was more than 2x faster than the RangeList that checks using the interface. In practice I'm seeing much better results than I expected. The array is used because checking it is slightly faster than using a list, which loses time to struct copies, but I still want that data locality. A method has been added to the list to update the cached end address, as some users of the RangeList currently modify it dynamically. Greatly improves performance in Super Mario Odyssey, Xenoblade and any other GPU limited games. * Address Feedback --- Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs') diff --git a/Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs b/Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs index 46399504..1417f7d5 100644 --- a/Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs +++ b/Ryujinx.Memory/WindowsShared/EmulatedSharedMemoryWindows.cs @@ -41,10 +41,12 @@ namespace Ryujinx.Memory.WindowsShared return Address < address + size && address < EndAddress; } - public void ExtendTo(ulong endAddress) + public void ExtendTo(ulong endAddress, RangeList list) { EndAddress = endAddress; Size = endAddress - Address; + + list.UpdateEndAddress(this); } public void AddBlocks(IEnumerable blocks) @@ -300,14 +302,14 @@ namespace Ryujinx.Memory.WindowsShared _mappings.Remove(endOverlap); - startOverlap.ExtendTo(endOverlap.EndAddress); + startOverlap.ExtendTo(endOverlap.EndAddress, _mappings); startOverlap.AddBlocks(blocks); startOverlap.AddBlocks(endOverlap.Blocks); } else if (startOverlap != null) { - startOverlap.ExtendTo(endAddress); + startOverlap.ExtendTo(endAddress, _mappings); startOverlap.AddBlocks(blocks); } @@ -317,7 +319,7 @@ namespace Ryujinx.Memory.WindowsShared if (endOverlap != null) { - mapping.ExtendTo(endOverlap.EndAddress); + mapping.ExtendTo(endOverlap.EndAddress, _mappings); mapping.AddBlocks(endOverlap.Blocks); @@ -381,6 +383,7 @@ namespace Ryujinx.Memory.WindowsShared if (mapping.EndAddress > endAddress) { var newMapping = (SharedMemoryMapping)mapping.Split(endAddress); + _mappings.UpdateEndAddress(mapping); _mappings.Add(newMapping); if ((endAddress & MappingMask) != 0) @@ -400,7 +403,9 @@ namespace Ryujinx.Memory.WindowsShared // If the first region starts before the decommit address, split it by modifying its end address. if (mapping.Address < address) { + var oldMapping = mapping; mapping = (SharedMemoryMapping)mapping.Split(address); + _mappings.UpdateEndAddress(oldMapping); if ((address & MappingMask) != 0) { -- cgit v1.2.3