Better ModifiedSequence handling

This should handle PreciseEvents properly, and simplifies a few things.
This commit is contained in:
riperiperi 2022-06-12 21:31:31 +01:00
parent 6b22f41e10
commit d727e819af
3 changed files with 36 additions and 26 deletions

View file

@ -17,6 +17,7 @@ namespace Ryujinx.Graphics.Gpu.Image
protected GpuContext Context; protected GpuContext Context;
protected PhysicalMemory PhysicalMemory; protected PhysicalMemory PhysicalMemory;
protected int SequenceNumber; protected int SequenceNumber;
protected int ModifiedSequenceNumber;
protected T1[] Items; protected T1[] Items;
protected T2[] DescriptorCache; protected T2[] DescriptorCache;
@ -42,6 +43,7 @@ namespace Ryujinx.Graphics.Gpu.Image
private readonly CpuMultiRegionHandle _memoryTracking; private readonly CpuMultiRegionHandle _memoryTracking;
private readonly Action<ulong, ulong> _modifiedDelegate; private readonly Action<ulong, ulong> _modifiedDelegate;
private int _modifiedSequenceOffset;
private bool _modified; private bool _modified;
/// <summary> /// <summary>
@ -104,11 +106,15 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This causes invalidation of pool entries, /// This causes invalidation of pool entries,
/// if a modification of entries by the CPU is detected. /// if a modification of entries by the CPU is detected.
/// </summary> /// </summary>
public bool SynchronizeMemory() public void SynchronizeMemory()
{ {
_modified = false; _modified = false;
_memoryTracking.QueryModified(_modifiedDelegate); _memoryTracking.QueryModified(_modifiedDelegate);
return _modified;
if (_modified)
{
UpdateModifiedSequence();
}
} }
/// <summary> /// <summary>
@ -135,6 +141,15 @@ namespace Ryujinx.Graphics.Gpu.Image
InvalidateRangeImpl(mAddress, mSize); InvalidateRangeImpl(mAddress, mSize);
} }
/// <summary>
/// Updates the modified sequence number using the current sequence number and offset,
/// indicating that it has been modified.
/// </summary>
protected void UpdateModifiedSequence()
{
ModifiedSequenceNumber = SequenceNumber + _modifiedSequenceOffset;
}
/// <summary> /// <summary>
/// An action to be performed when a precise memory access occurs to this resource. /// An action to be performed when a precise memory access occurs to this resource.
/// Makes sure that the dirty flags are checked. /// Makes sure that the dirty flags are checked.
@ -146,7 +161,16 @@ namespace Ryujinx.Graphics.Gpu.Image
{ {
if (write && Context.SequenceNumber == SequenceNumber) 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--; SequenceNumber--;
} }

View file

@ -8,7 +8,6 @@ namespace Ryujinx.Graphics.Gpu.Image
class SamplerPool : Pool<Sampler, SamplerDescriptor> class SamplerPool : Pool<Sampler, SamplerDescriptor>
{ {
private float _forcedAnisotropy; private float _forcedAnisotropy;
private int _modifiedSequenceNumber;
/// <summary> /// <summary>
/// Constructs a new instance of the sampler pool. /// Constructs a new instance of the sampler pool.
@ -53,10 +52,7 @@ namespace Ryujinx.Graphics.Gpu.Image
SequenceNumber = Context.SequenceNumber; SequenceNumber = Context.SequenceNumber;
if (SynchronizeMemory()) SynchronizeMemory();
{
_modifiedSequenceNumber = SequenceNumber;
}
} }
Sampler sampler = Items[id]; Sampler sampler = Items[id];
@ -78,7 +74,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <summary> /// <summary>
/// Checks if the pool was modified, and returns the last sequence number where a modification was detected. /// Checks if the pool was modified, and returns the last sequence number where a modification was detected.
/// </summary> /// </summary>
/// <returns>The last sequence number where a modification was detected</returns> /// <returns>A number that increments each time a modification is detected</returns>
public int CheckModified() public int CheckModified()
{ {
if (SequenceNumber != Context.SequenceNumber) if (SequenceNumber != Context.SequenceNumber)
@ -99,16 +95,13 @@ namespace Ryujinx.Graphics.Gpu.Image
} }
} }
_modifiedSequenceNumber = SequenceNumber; UpdateModifiedSequence();
} }
if (SynchronizeMemory()) SynchronizeMemory();
{
_modifiedSequenceNumber = SequenceNumber;
}
} }
return _modifiedSequenceNumber; return ModifiedSequenceNumber;
} }
/// <summary> /// <summary>

View file

@ -14,7 +14,6 @@ namespace Ryujinx.Graphics.Gpu.Image
{ {
private readonly GpuChannel _channel; private readonly GpuChannel _channel;
private readonly ConcurrentQueue<Texture> _dereferenceQueue = new ConcurrentQueue<Texture>(); private readonly ConcurrentQueue<Texture> _dereferenceQueue = new ConcurrentQueue<Texture>();
private int _modifiedSequenceNumber;
private TextureDescriptor _defaultDescriptor; private TextureDescriptor _defaultDescriptor;
/// <summary> /// <summary>
@ -106,10 +105,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{ {
SequenceNumber = Context.SequenceNumber; SequenceNumber = Context.SequenceNumber;
if (SynchronizeMemory()) SynchronizeMemory();
{
_modifiedSequenceNumber = SequenceNumber;
}
} }
GetInternal(id, out Texture texture); GetInternal(id, out Texture texture);
@ -142,20 +138,17 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <summary> /// <summary>
/// Checks if the pool was modified, and returns the last sequence number where a modification was detected. /// Checks if the pool was modified, and returns the last sequence number where a modification was detected.
/// </summary> /// </summary>
/// <returns>The last sequence number where a modifiaction was detected</returns> /// <returns>A number that increments each time a modification is detected</returns>
public int CheckModified() public int CheckModified()
{ {
if (SequenceNumber != Context.SequenceNumber) if (SequenceNumber != Context.SequenceNumber)
{ {
SequenceNumber = Context.SequenceNumber; SequenceNumber = Context.SequenceNumber;
if (SynchronizeMemory()) SynchronizeMemory();
{
_modifiedSequenceNumber = SequenceNumber;
}
} }
return _modifiedSequenceNumber; return ModifiedSequenceNumber;
} }
/// <summary> /// <summary>