From 2c39a4f15d44156779c6c926d8feda26a4a24605 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 3 Dec 2020 18:34:32 +0000 Subject: [PATCH] Cache delegate for QueryModified, use regular multi handle. (#1771) --- Ryujinx.Graphics.Gpu/Image/Pool.cs | 35 ++++++++++++------- Ryujinx.Graphics.Gpu/Memory/Buffer.cs | 50 ++++++++++++++++----------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Image/Pool.cs b/Ryujinx.Graphics.Gpu/Image/Pool.cs index dc0774ec..c2c1a9a1 100644 --- a/Ryujinx.Graphics.Gpu/Image/Pool.cs +++ b/Ryujinx.Graphics.Gpu/Image/Pool.cs @@ -36,6 +36,7 @@ namespace Ryujinx.Graphics.Gpu.Image public ulong Size { get; } private readonly CpuMultiRegionHandle _memoryTracking; + private readonly Action _modifiedDelegate; public Pool(GpuContext context, ulong address, int maximumId) { @@ -44,7 +45,7 @@ namespace Ryujinx.Graphics.Gpu.Image int count = maximumId + 1; - ulong size = (ulong)(uint)count * DescriptorSize;; + ulong size = (ulong)(uint)count * DescriptorSize; Items = new T[count]; @@ -52,6 +53,7 @@ namespace Ryujinx.Graphics.Gpu.Image Size = size; _memoryTracking = context.PhysicalMemory.BeginGranularTracking(address, size); + _modifiedDelegate = RegionModified; } /// @@ -68,22 +70,29 @@ namespace Ryujinx.Graphics.Gpu.Image /// public void SynchronizeMemory() { - _memoryTracking.QueryModified((ulong mAddress, ulong mSize) => + _memoryTracking.QueryModified(_modifiedDelegate); + } + + /// + /// Indicate that a region of the pool was modified, and must be loaded from memory. + /// + /// Start address of the modified region + /// Size of the modified region + private void RegionModified(ulong mAddress, ulong mSize) + { + if (mAddress < Address) { - if (mAddress < Address) - { - mAddress = Address; - } + mAddress = Address; + } - ulong maxSize = Address + Size - mAddress; + ulong maxSize = Address + Size - mAddress; - if (mSize > maxSize) - { - mSize = maxSize; - } + if (mSize > maxSize) + { + mSize = maxSize; + } - InvalidateRangeImpl(mAddress, mSize); - }); + InvalidateRangeImpl(mAddress, mSize); } protected abstract void InvalidateRangeImpl(ulong address, ulong size); diff --git a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs index 3cc96432..bf245283 100644 --- a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs +++ b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs @@ -34,8 +34,9 @@ namespace Ryujinx.Graphics.Gpu.Memory /// public ulong EndAddress => Address + Size; - private CpuSmartMultiRegionHandle _memoryTrackingGranular; + private CpuMultiRegionHandle _memoryTrackingGranular; private CpuRegionHandle _memoryTracking; + private readonly Action _modifiedDelegate; private int _sequenceNumber; private bool _useGranular; @@ -58,12 +59,14 @@ namespace Ryujinx.Graphics.Gpu.Memory if (_useGranular) { - _memoryTrackingGranular = context.PhysicalMemory.BeginSmartGranularTracking(address, size); + _memoryTrackingGranular = context.PhysicalMemory.BeginGranularTracking(address, size); } else { _memoryTracking = context.PhysicalMemory.BeginTracking(address, size); } + + _modifiedDelegate = new Action(RegionModified); } /// @@ -106,24 +109,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { if (_useGranular) { - _memoryTrackingGranular.QueryModified(address, size, (ulong mAddress, ulong mSize) => - { - if (mAddress < Address) - { - mAddress = Address; - } - - ulong maxSize = Address + Size - mAddress; - - if (mSize > maxSize) - { - mSize = maxSize; - } - - int offset = (int)(mAddress - Address); - - _context.Renderer.SetBufferData(Handle, offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize)); - }, _context.SequenceNumber); + _memoryTrackingGranular.QueryModified(address, size, _modifiedDelegate, _context.SequenceNumber); } else { @@ -136,6 +122,30 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Indicate that a region of the buffer was modified, and must be loaded from memory. + /// + /// Start address of the modified region + /// Size of the modified region + private void RegionModified(ulong mAddress, ulong mSize) + { + if (mAddress < Address) + { + mAddress = Address; + } + + ulong maxSize = Address + Size - mAddress; + + if (mSize > maxSize) + { + mSize = maxSize; + } + + int offset = (int)(mAddress - Address); + + _context.Renderer.SetBufferData(Handle, offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize)); + } + /// /// Performs copy of all the buffer data from one buffer to another. ///