diff options
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index 1ff086ee..bfd3c04f 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -7,8 +7,6 @@ using Ryujinx.Memory.Range; using Ryujinx.Memory.Tracking; using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Threading; namespace Ryujinx.Graphics.Gpu.Memory @@ -19,8 +17,6 @@ namespace Ryujinx.Graphics.Gpu.Memory /// </summary> class PhysicalMemory : IDisposable { - public const int PageSize = 0x1000; - private readonly GpuContext _context; private IVirtualMemoryManagerTracked _cpuMemory; private int _referenceCount; @@ -103,24 +99,28 @@ namespace Ryujinx.Graphics.Gpu.Memory if (range.Count == 1) { var singleRange = range.GetSubRange(0); - return _cpuMemory.GetSpan(singleRange.Address, (int)singleRange.Size, tracked); + if (singleRange.Address != MemoryManager.PteUnmapped) + { + return _cpuMemory.GetSpan(singleRange.Address, (int)singleRange.Size, tracked); + } } - else - { - Span<byte> data = new byte[range.GetSize()]; - int offset = 0; + Span<byte> data = new byte[range.GetSize()]; - for (int i = 0; i < range.Count; i++) + int offset = 0; + + for (int i = 0; i < range.Count; i++) + { + var currentRange = range.GetSubRange(i); + int size = (int)currentRange.Size; + if (currentRange.Address != MemoryManager.PteUnmapped) { - var currentRange = range.GetSubRange(i); - int size = (int)currentRange.Size; _cpuMemory.GetSpan(currentRange.Address, size, tracked).CopyTo(data.Slice(offset, size)); - offset += size; } - - return data; + offset += size; } + + return data; } /// <summary> @@ -156,11 +156,13 @@ namespace Ryujinx.Graphics.Gpu.Memory int offset = 0; for (int i = 0; i < range.Count; i++) { - MemoryRange subrange = range.GetSubRange(i); - - GetSpan(subrange.Address, (int)subrange.Size).CopyTo(memory.Span.Slice(offset, (int)subrange.Size)); - - offset += (int)subrange.Size; + var currentRange = range.GetSubRange(i); + int size = (int)currentRange.Size; + if (currentRange.Address != MemoryManager.PteUnmapped) + { + GetSpan(currentRange.Address, size).CopyTo(memory.Span.Slice(offset, size)); + } + offset += size; } return new WritableRegion(new MultiRangeWritableBlock(range, this), 0, memory, tracked); @@ -253,7 +255,10 @@ namespace Ryujinx.Graphics.Gpu.Memory if (range.Count == 1) { var singleRange = range.GetSubRange(0); - writeCallback(singleRange.Address, data); + if (singleRange.Address != MemoryManager.PteUnmapped) + { + writeCallback(singleRange.Address, data); + } } else { @@ -263,7 +268,10 @@ namespace Ryujinx.Graphics.Gpu.Memory { var currentRange = range.GetSubRange(i); int size = (int)currentRange.Size; - writeCallback(currentRange.Address, data.Slice(offset, size)); + if (currentRange.Address != MemoryManager.PteUnmapped) + { + writeCallback(currentRange.Address, data.Slice(offset, size)); + } offset += size; } } @@ -288,11 +296,20 @@ namespace Ryujinx.Graphics.Gpu.Memory public GpuRegionHandle BeginTracking(MultiRange range) { var cpuRegionHandles = new CpuRegionHandle[range.Count]; + int count = 0; for (int i = 0; i < range.Count; i++) { var currentRange = range.GetSubRange(i); - cpuRegionHandles[i] = _cpuMemory.BeginTracking(currentRange.Address, currentRange.Size); + if (currentRange.Address != MemoryManager.PteUnmapped) + { + cpuRegionHandles[count++] = _cpuMemory.BeginTracking(currentRange.Address, currentRange.Size); + } + } + + if (count != range.Count) + { + Array.Resize(ref cpuRegionHandles, count); } return new GpuRegionHandle(cpuRegionHandles); |