diff --git a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs index 0eaf0123..81f70684 100644 --- a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs +++ b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs @@ -299,24 +299,28 @@ namespace Ryujinx.Graphics.Gpu.Memory _syncActionRegistered = true; } + Action registerRangeAction = (ulong address, ulong size) => + { + if (_useGranular) + { + _memoryTrackingGranular.RegisterAction(address, size, _externalFlushDelegate); + } + else + { + _memoryTracking.RegisterAction(_externalFlushDelegate); + } + }; + if (_modifiedRanges == null) { _modifiedRanges = from._modifiedRanges; + _modifiedRanges.ReregisterRanges(registerRangeAction); + from._modifiedRanges = null; } else { - _modifiedRanges.InheritRanges(from._modifiedRanges, (ulong address, ulong size) => - { - if (_useGranular) - { - _memoryTrackingGranular.RegisterAction(address, size, _externalFlushDelegate); - } - else - { - _memoryTracking.RegisterAction(_externalFlushDelegate); - } - }); + _modifiedRanges.InheritRanges(from._modifiedRanges, registerRangeAction); } } } diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs b/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs index 84cf0dd8..b9b533fb 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferModifiedRangeList.cs @@ -318,6 +318,40 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Calls the given action for modified ranges that aren't from the current sync number. + /// + /// The action to call for each modified range + public void ReregisterRanges(Action rangeAction) + { + ref var ranges = ref ThreadStaticArray.Get(); + + // Range list must be consistent for this operation. + lock (_lock) + { + if (ranges.Length < Count) + { + Array.Resize(ref ranges, Count); + } + + int i = 0; + foreach (BufferModifiedRange range in this) + { + ranges[i++] = range; + } + } + + ulong currentSync = _context.SyncNumber; + for (int i = 0; i < Count; i++) + { + BufferModifiedRange range = ranges[i]; + if (range.SyncNumber != currentSync) + { + rangeAction(range.Address, range.Size); + } + } + } + private void ClearPart(BufferModifiedRange overlap, ulong address, ulong endAddress) { Remove(overlap);