diff options
author | gdkchan <gab.dark.100@gmail.com> | 2021-06-29 14:32:02 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 19:32:02 +0200 |
commit | fbb4019ed5c12c4a888c7b09db648ac595366896 (patch) | |
tree | a8be6bf5fc4f8b844683f1ef2ade588f3bb9bb0a /Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | |
parent | 8cc872fb60ec1b825655ba8dba06cc978fcd7e66 (diff) |
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
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 31 |
1 files changed, 22 insertions, 9 deletions
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<UnmapEventArgs> MemoryUnmapped; - private GpuContext _context; + /// <summary> + /// Physical memory where the virtual memory is mapped into. + /// </summary> + internal PhysicalMemory Physical { get; } + + /// <summary> + /// Cache of GPU counters. + /// </summary> + internal CounterCache CounterCache { get; } /// <summary> /// Creates a new instance of the GPU memory manager. /// </summary> - public MemoryManager(GpuContext context) + /// <param name="physicalMemory">Physical memory that this memory manager will map into</param> + 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; } /// <summary> @@ -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 /// <param name="data">The data to be written</param> public void Write(ulong va, ReadOnlySpan<byte> data) { - WriteImpl(va, data, _context.PhysicalMemory.Write); + WriteImpl(va, data, Physical.Write); } /// <summary> @@ -165,7 +178,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// <param name="data">The data to be written</param> public void WriteUntracked(ulong va, ReadOnlySpan<byte> data) { - WriteImpl(va, data, _context.PhysicalMemory.WriteUntracked); + WriteImpl(va, data, Physical.WriteUntracked); } private delegate void WriteCallback(ulong address, ReadOnlySpan<byte> data); |