Revert "Memory Changes"

This reverts commit d5c9bc662c.

Solves crash in Kirby Star Allies after a few mins of gameplay, possibly other titles.
This commit is contained in:
KeatonTheBot 2025-08-16 23:15:55 -05:00
parent 7fd01214cf
commit 48c809a80d
17 changed files with 736 additions and 1583 deletions

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <summary>
/// Buffer, used to store vertex and index data, uniform and storage buffers, and others.
/// </summary>
class Buffer : INonOverlappingRange, ISyncActionHandler, IDisposable
class Buffer : IRange, ISyncActionHandler, IDisposable
{
private const ulong GranularBufferThreshold = 4096;
@ -35,7 +35,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <summary>
/// Size of the buffer in bytes.
/// </summary>
public ulong Size { get; private set; }
public ulong Size { get; }
/// <summary>
/// End address of the buffer in guest memory.
@ -60,13 +60,13 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <remarks>
/// This is null until at least one modification occurs.
/// </remarks>
private BufferModifiedRangeList _modifiedRanges;
private BufferModifiedRangeList _modifiedRanges = null;
/// <summary>
/// A structure that is used to flush buffer data back to a host mapped buffer for cached readback.
/// Only used if the buffer data is explicitly owned by device local memory.
/// </summary>
private BufferPreFlush _preFlush;
private BufferPreFlush _preFlush = null;
/// <summary>
/// Usage tracking state that determines what type of backing the buffer should use.
@ -110,7 +110,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
ulong size,
BufferStage stage,
bool sparseCompatible,
List<Buffer> baseBuffers)
IEnumerable<Buffer> baseBuffers = null)
{
_context = context;
_physicalMemory = physicalMemory;
@ -126,22 +126,21 @@ namespace Ryujinx.Graphics.Gpu.Memory
_useGranular = size > GranularBufferThreshold;
List<IRegionHandle> baseHandles = null;
IEnumerable<IRegionHandle> baseHandles = null;
if (baseBuffers.Count != 0)
if (baseBuffers != null)
{
baseHandles = new List<IRegionHandle>();
foreach (Buffer buffer in baseBuffers)
baseHandles = baseBuffers.SelectMany(buffer =>
{
if (buffer._useGranular)
{
baseHandles.AddRange((buffer._memoryTrackingGranular.GetHandles()));
return buffer._memoryTrackingGranular.GetHandles();
}
else
{
baseHandles.Add(buffer._memoryTracking);
return Enumerable.Repeat(buffer._memoryTracking, 1);
}
}
});
}
if (_useGranular)
@ -172,9 +171,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
_memoryTracking.RegisterPreciseAction(PreciseAction);
}
_externalFlushDelegate = ExternalFlush;
_loadDelegate = LoadRegion;
_modifiedDelegate = RegionModified;
_externalFlushDelegate = new RegionSignal(ExternalFlush);
_loadDelegate = new Action<ulong, ulong>(LoadRegion);
_modifiedDelegate = new Action<ulong, ulong>(RegionModified);
_virtualDependenciesLock = new ReaderWriterLockSlim();
}
@ -248,11 +247,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
return Address < address + size && address < EndAddress;
}
public INonOverlappingRange Split(ulong splitAddress)
{
throw new NotImplementedException();
}
/// <summary>
/// Checks if a given range is fully contained in the buffer.
/// </summary>
@ -441,7 +435,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <param name="from">The buffer to inherit from</param>
public void InheritModifiedRanges(Buffer from)
{
if (from._modifiedRanges is { HasRanges: true })
if (from._modifiedRanges != null && from._modifiedRanges.HasRanges)
{
if (from._syncActionRegistered && !_syncActionRegistered)
{
@ -449,7 +443,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
_syncActionRegistered = true;
}
void RegisterRangeAction(ulong address, ulong size)
void registerRangeAction(ulong address, ulong size)
{
if (_useGranular)
{
@ -463,7 +457,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
EnsureRangeList();
_modifiedRanges.InheritRanges(from._modifiedRanges, RegisterRangeAction);
_modifiedRanges.InheritRanges(from._modifiedRanges, registerRangeAction);
}
if (from._dirtyStart != ulong.MaxValue)
@ -505,7 +499,14 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
// Cut off the start.
_dirtyStart = end < _dirtyEnd ? end : ulong.MaxValue;
if (end < _dirtyEnd)
{
_dirtyStart = end;
}
else
{
_dirtyStart = ulong.MaxValue;
}
}
else if (end >= _dirtyEnd)
{