mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-30 03:47:57 +02:00
Memory Changes 3.2
Fixes a few crashes: - fixes a crash related to waking threads (priorities were wrong). - fixes a crash from reusing the SetRenderTargets texture array (left-over data causing issues). - fixes a mistake and an oversight in the buffer system. - buffers were getting updated wrong causing bad data to be stored or some times cut. - modified ranges would extend past their old buffers, crashing on syncs. Old buffers are now skipped as the new buffers already sync instead. Introduces pooling in a few more places to increase memory efficiency. simplified RangeList item logic. - removed RangeItem by making all the range objects use the I(NonOverlapping)Range interface. - BufferCache class no longer locks its RangeList, as the list is only ever accessed synchronously. Small change to how keyboard snapshots are stored. Increase ThreadedRenderer SpanPool size to fit slightly more data (4MB -> 8MB).
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// <summary>
|
||||
/// A region of memory.
|
||||
/// </summary>
|
||||
abstract class AbstractRegion : INonOverlappingRange
|
||||
abstract class AbstractRegion<T> : INonOverlappingRange<T> where T : class, INonOverlappingRange<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Base address.
|
||||
@@ -21,6 +21,9 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// End address.
|
||||
/// </summary>
|
||||
public ulong EndAddress => Address + Size;
|
||||
|
||||
public T Next { get; set; }
|
||||
public T Previous { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new region.
|
||||
@@ -37,11 +40,11 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// Check if this range overlaps with another.
|
||||
/// </summary>
|
||||
/// <param name="address">Base address</param>
|
||||
/// <param name="size">Size of the range</param>
|
||||
/// <param name="endAddress">End address</param>
|
||||
/// <returns>True if overlapping, false otherwise</returns>
|
||||
public bool OverlapsWith(ulong address, ulong size)
|
||||
public bool OverlapsWith(ulong address, ulong endAddress)
|
||||
{
|
||||
return Address < address + size && address < EndAddress;
|
||||
return Address < endAddress && address < EndAddress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,6 +71,6 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// </summary>
|
||||
/// <param name="splitAddress">Address to split the region around</param>
|
||||
/// <returns>The second part of the split region, with start address at the given split.</returns>
|
||||
public abstract INonOverlappingRange Split(ulong splitAddress);
|
||||
public abstract INonOverlappingRange<T> Split(ulong splitAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ namespace Ryujinx.Memory.Tracking
|
||||
{
|
||||
NonOverlappingRangeList<VirtualRegion> regions = type == 0 ? _virtualRegions : _guestVirtualRegions;
|
||||
regions.Lock.EnterReadLock();
|
||||
Span<RangeItem<VirtualRegion>> overlaps = regions.FindOverlapsAsSpan(va, size);
|
||||
ReadOnlySpan<VirtualRegion> overlaps = regions.FindOverlapsAsSpan(va, size);
|
||||
for (int i = 0; i < overlaps.Length; i++)
|
||||
{
|
||||
VirtualRegion region = overlaps[i].Value;
|
||||
VirtualRegion region = overlaps[i];
|
||||
|
||||
// If the region has been fully remapped, signal that it has been mapped again.
|
||||
bool remapped = _memoryManager.IsRangeMapped(region.Address, region.Size);
|
||||
@@ -117,11 +117,11 @@ namespace Ryujinx.Memory.Tracking
|
||||
{
|
||||
NonOverlappingRangeList<VirtualRegion> regions = type == 0 ? _virtualRegions : _guestVirtualRegions;
|
||||
regions.Lock.EnterReadLock();
|
||||
Span<RangeItem<VirtualRegion>> overlaps = regions.FindOverlapsAsSpan(va, size);
|
||||
ReadOnlySpan<VirtualRegion> overlaps = regions.FindOverlapsAsSpan(va, size);
|
||||
|
||||
for (int i = 0; i < overlaps.Length; i++)
|
||||
{
|
||||
overlaps[i].Value.SignalMappingChanged(false);
|
||||
overlaps[i].SignalMappingChanged(false);
|
||||
}
|
||||
regions.Lock.ExitReadLock();
|
||||
}
|
||||
@@ -301,7 +301,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
// We use the non-span method here because keeping the lock will cause a deadlock.
|
||||
regions.Lock.EnterReadLock();
|
||||
RangeItem<VirtualRegion>[] overlaps = regions.FindOverlapsAsArray(address, size, out int length);
|
||||
VirtualRegion[] overlaps = regions.FindOverlapsAsArray(address, size, out int length);
|
||||
regions.Lock.ExitReadLock();
|
||||
|
||||
if (length == 0 && !precise)
|
||||
@@ -327,7 +327,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
VirtualRegion region = overlaps[i].Value;
|
||||
VirtualRegion region = overlaps[i];
|
||||
|
||||
if (precise)
|
||||
{
|
||||
@@ -341,7 +341,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
|
||||
if (length != 0)
|
||||
{
|
||||
ArrayPool<RangeItem<VirtualRegion>>.Shared.Return(overlaps);
|
||||
ArrayPool<VirtualRegion>.Shared.Return(overlaps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
/// <summary>
|
||||
/// A region of virtual memory.
|
||||
/// </summary>
|
||||
class VirtualRegion : AbstractRegion
|
||||
class VirtualRegion : AbstractRegion<VirtualRegion>
|
||||
{
|
||||
public List<RegionHandle> Handles = [];
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace Ryujinx.Memory.Tracking
|
||||
}
|
||||
}
|
||||
|
||||
public override INonOverlappingRange Split(ulong splitAddress)
|
||||
public override INonOverlappingRange<VirtualRegion> Split(ulong splitAddress)
|
||||
{
|
||||
VirtualRegion newRegion = new(_tracking, splitAddress, EndAddress - splitAddress, Guest, _lastPermission);
|
||||
Size = splitAddress - Address;
|
||||
|
||||
Reference in New Issue
Block a user