From fbb4019ed5c12c4a888c7b09db648ac595366896 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 29 Jun 2021 14:32:02 -0300 Subject: Initial support for separate GPU address spaces (#2394) * Make GPU memory manager a member of GPU channel * Move physical memory instance to the memory manager, and the caches to the physical memory * PR feedback --- Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 31 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs') diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index 5776836c..b747b558 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -34,15 +34,28 @@ namespace Ryujinx.Graphics.Gpu.Memory public event EventHandler MemoryUnmapped; - private GpuContext _context; + /// + /// Physical memory where the virtual memory is mapped into. + /// + internal PhysicalMemory Physical { get; } + + /// + /// Cache of GPU counters. + /// + internal CounterCache CounterCache { get; } /// /// Creates a new instance of the GPU memory manager. /// - public MemoryManager(GpuContext context) + /// Physical memory that this memory manager will map into + internal MemoryManager(PhysicalMemory physicalMemory) { - _context = context; + Physical = physicalMemory; + CounterCache = new CounterCache(); _pageTable = new ulong[PtLvl0Size][]; + MemoryUnmapped += Physical.TextureCache.MemoryUnmappedHandler; + MemoryUnmapped += Physical.BufferCache.MemoryUnmappedHandler; + MemoryUnmapped += CounterCache.MemoryUnmappedHandler; } /// @@ -67,7 +80,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { if (IsContiguous(va, size)) { - return _context.PhysicalMemory.GetSpan(Translate(va), size, tracked); + return Physical.GetSpan(Translate(va), size, tracked); } else { @@ -100,7 +113,7 @@ namespace Ryujinx.Graphics.Gpu.Memory size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask)); - _context.PhysicalMemory.GetSpan(pa, size, tracked).CopyTo(data.Slice(0, size)); + Physical.GetSpan(pa, size, tracked).CopyTo(data.Slice(0, size)); offset += size; } @@ -111,7 +124,7 @@ namespace Ryujinx.Graphics.Gpu.Memory size = Math.Min(data.Length - offset, (int)PageSize); - _context.PhysicalMemory.GetSpan(pa, size, tracked).CopyTo(data.Slice(offset, size)); + Physical.GetSpan(pa, size, tracked).CopyTo(data.Slice(offset, size)); } } @@ -125,7 +138,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { if (IsContiguous(va, size)) { - return _context.PhysicalMemory.GetWritableRegion(Translate(va), size); + return Physical.GetWritableRegion(Translate(va), size); } else { @@ -155,7 +168,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// The data to be written public void Write(ulong va, ReadOnlySpan data) { - WriteImpl(va, data, _context.PhysicalMemory.Write); + WriteImpl(va, data, Physical.Write); } /// @@ -165,7 +178,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// The data to be written public void WriteUntracked(ulong va, ReadOnlySpan data) { - WriteImpl(va, data, _context.PhysicalMemory.WriteUntracked); + WriteImpl(va, data, Physical.WriteUntracked); } private delegate void WriteCallback(ulong address, ReadOnlySpan data); -- cgit v1.2.3