From d727e819af57cf2fe6953da6e1ffb358f8111e5b Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sun, 12 Jun 2022 21:31:31 +0100 Subject: [PATCH] Better ModifiedSequence handling This should handle PreciseEvents properly, and simplifies a few things. --- Ryujinx.Graphics.Gpu/Image/Pool.cs | 30 ++++++++++++++++++++--- Ryujinx.Graphics.Gpu/Image/SamplerPool.cs | 17 ++++--------- Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 15 +++--------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Image/Pool.cs b/Ryujinx.Graphics.Gpu/Image/Pool.cs index ee931c199..8e2105134 100644 --- a/Ryujinx.Graphics.Gpu/Image/Pool.cs +++ b/Ryujinx.Graphics.Gpu/Image/Pool.cs @@ -17,6 +17,7 @@ namespace Ryujinx.Graphics.Gpu.Image protected GpuContext Context; protected PhysicalMemory PhysicalMemory; protected int SequenceNumber; + protected int ModifiedSequenceNumber; protected T1[] Items; protected T2[] DescriptorCache; @@ -42,6 +43,7 @@ namespace Ryujinx.Graphics.Gpu.Image private readonly CpuMultiRegionHandle _memoryTracking; private readonly Action _modifiedDelegate; + private int _modifiedSequenceOffset; private bool _modified; /// @@ -104,11 +106,15 @@ namespace Ryujinx.Graphics.Gpu.Image /// This causes invalidation of pool entries, /// if a modification of entries by the CPU is detected. /// - public bool SynchronizeMemory() + public void SynchronizeMemory() { _modified = false; _memoryTracking.QueryModified(_modifiedDelegate); - return _modified; + + if (_modified) + { + UpdateModifiedSequence(); + } } /// @@ -135,6 +141,15 @@ namespace Ryujinx.Graphics.Gpu.Image InvalidateRangeImpl(mAddress, mSize); } + /// + /// Updates the modified sequence number using the current sequence number and offset, + /// indicating that it has been modified. + /// + protected void UpdateModifiedSequence() + { + ModifiedSequenceNumber = SequenceNumber + _modifiedSequenceOffset; + } + /// /// An action to be performed when a precise memory access occurs to this resource. /// Makes sure that the dirty flags are checked. @@ -146,7 +161,16 @@ namespace Ryujinx.Graphics.Gpu.Image { if (write && Context.SequenceNumber == SequenceNumber) { - //Common.Logging.Logger.Error?.Print(Common.Logging.LogClass.Gpu, "Precise action..."); + if (ModifiedSequenceNumber == SequenceNumber + _modifiedSequenceOffset) + { + // The modified sequence number is offset when PreciseActions occur so that + // users checking it will see an increment and know the pool has changed since + // their last look, even though the main SequenceNumber has not been changed. + + _modifiedSequenceOffset++; + } + + // Force the pool to be checked again the next time it is used. SequenceNumber--; } diff --git a/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs b/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs index daa2a0def..5576908e7 100644 --- a/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs +++ b/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs @@ -8,7 +8,6 @@ namespace Ryujinx.Graphics.Gpu.Image class SamplerPool : Pool { private float _forcedAnisotropy; - private int _modifiedSequenceNumber; /// /// Constructs a new instance of the sampler pool. @@ -53,10 +52,7 @@ namespace Ryujinx.Graphics.Gpu.Image SequenceNumber = Context.SequenceNumber; - if (SynchronizeMemory()) - { - _modifiedSequenceNumber = SequenceNumber; - } + SynchronizeMemory(); } Sampler sampler = Items[id]; @@ -78,7 +74,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// Checks if the pool was modified, and returns the last sequence number where a modification was detected. /// - /// The last sequence number where a modification was detected + /// A number that increments each time a modification is detected public int CheckModified() { if (SequenceNumber != Context.SequenceNumber) @@ -99,16 +95,13 @@ namespace Ryujinx.Graphics.Gpu.Image } } - _modifiedSequenceNumber = SequenceNumber; + UpdateModifiedSequence(); } - if (SynchronizeMemory()) - { - _modifiedSequenceNumber = SequenceNumber; - } + SynchronizeMemory(); } - return _modifiedSequenceNumber; + return ModifiedSequenceNumber; } /// diff --git a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index 5b3ca5cc8..3c646b458 100644 --- a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -14,7 +14,6 @@ namespace Ryujinx.Graphics.Gpu.Image { private readonly GpuChannel _channel; private readonly ConcurrentQueue _dereferenceQueue = new ConcurrentQueue(); - private int _modifiedSequenceNumber; private TextureDescriptor _defaultDescriptor; /// @@ -106,10 +105,7 @@ namespace Ryujinx.Graphics.Gpu.Image { SequenceNumber = Context.SequenceNumber; - if (SynchronizeMemory()) - { - _modifiedSequenceNumber = SequenceNumber; - } + SynchronizeMemory(); } GetInternal(id, out Texture texture); @@ -142,20 +138,17 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// Checks if the pool was modified, and returns the last sequence number where a modification was detected. /// - /// The last sequence number where a modifiaction was detected + /// A number that increments each time a modification is detected public int CheckModified() { if (SequenceNumber != Context.SequenceNumber) { SequenceNumber = Context.SequenceNumber; - if (SynchronizeMemory()) - { - _modifiedSequenceNumber = SequenceNumber; - } + SynchronizeMemory(); } - return _modifiedSequenceNumber; + return ModifiedSequenceNumber; } ///