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/Buffer.cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory/Buffer.cs') diff --git a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs index b4854d81..96e10e77 100644 --- a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs +++ b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs @@ -13,9 +13,10 @@ namespace Ryujinx.Graphics.Gpu.Memory /// class Buffer : IRange, IDisposable { - private static ulong GranularBufferThreshold = 4096; + private const ulong GranularBufferThreshold = 4096; private readonly GpuContext _context; + private readonly PhysicalMemory _physicalMemory; /// /// Host buffer handle. @@ -68,14 +69,16 @@ namespace Ryujinx.Graphics.Gpu.Memory /// Creates a new instance of the buffer. /// /// GPU context that the buffer belongs to + /// Physical memory where the buffer is mapped /// Start address of the buffer /// Size of the buffer in bytes /// Buffers which this buffer contains, and will inherit tracking handles from - public Buffer(GpuContext context, ulong address, ulong size, IEnumerable baseBuffers = null) + public Buffer(GpuContext context, PhysicalMemory physicalMemory, ulong address, ulong size, IEnumerable baseBuffers = null) { - _context = context; - Address = address; - Size = size; + _context = context; + _physicalMemory = physicalMemory; + Address = address; + Size = size; Handle = context.Renderer.CreateBuffer((int)size); @@ -100,11 +103,11 @@ namespace Ryujinx.Graphics.Gpu.Memory if (_useGranular) { - _memoryTrackingGranular = context.PhysicalMemory.BeginGranularTracking(address, size, baseHandles); + _memoryTrackingGranular = physicalMemory.BeginGranularTracking(address, size, baseHandles); } else { - _memoryTracking = context.PhysicalMemory.BeginTracking(address, size); + _memoryTracking = physicalMemory.BeginTracking(address, size); if (baseHandles != null) { @@ -207,9 +210,9 @@ namespace Ryujinx.Graphics.Gpu.Memory } else { - _context.Renderer.SetBufferData(Handle, 0, _context.PhysicalMemory.GetSpan(Address, (int)Size)); + _context.Renderer.SetBufferData(Handle, 0, _physicalMemory.GetSpan(Address, (int)Size)); } - + _sequenceNumber = _context.SequenceNumber; } } @@ -363,7 +366,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { int offset = (int)(mAddress - Address); - _context.Renderer.SetBufferData(Handle, offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize)); + _context.Renderer.SetBufferData(Handle, offset, _physicalMemory.GetSpan(mAddress, (int)mSize)); } /// @@ -412,7 +415,7 @@ namespace Ryujinx.Graphics.Gpu.Memory byte[] data = _context.Renderer.GetBufferData(Handle, offset, (int)size); // TODO: When write tracking shaders, they will need to be aware of changes in overlapping buffers. - _context.PhysicalMemory.WriteUntracked(address, data); + _physicalMemory.WriteUntracked(address, data); } /// -- cgit v1.2.3