diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute.cs b/Ryujinx.Graphics.Gpu/Engine/Compute.cs index 60fba00606..d718d46937 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { uint qmdAddress = (uint)state.Get(MethodOffset.DispatchParamsAddress); - var qmd = _context.MemoryAccessor.Read((ulong)qmdAddress << 8); + var qmd = _context.MemoryManager.Read((ulong)qmdAddress << 8); GpuVa shaderBaseAddress = state.Get(MethodOffset.ShaderBaseAddress); diff --git a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoClass.cs b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoClass.cs index ec2e4bdc16..958253ecc4 100644 --- a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoClass.cs +++ b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoClass.cs @@ -80,13 +80,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo // TODO: Acquire operations (Wait), interrupts for invalid combinations. if (operation == SemaphoredOperation.Release) { - _context.MemoryAccessor.Write(address, value); + _context.MemoryManager.Write(address, value); } else if (operation == SemaphoredOperation.Reduction) { bool signed = _state.State.SemaphoredFormat == SemaphoredFormat.Signed; - int mem = _context.MemoryAccessor.Read(address); + int mem = _context.MemoryManager.Read(address); switch (_state.State.SemaphoredReduction) { @@ -116,7 +116,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo break; } - _context.MemoryAccessor.Write(address, value); + _context.MemoryManager.Write(address, value); } } diff --git a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs index 466bff8fd4..c68a3ef2e7 100644 --- a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs +++ b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs @@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo { if (Words == null) { - Words = MemoryMarshal.Cast(context.MemoryAccessor.GetSpan(EntryAddress, (int)EntryCount * 4)).ToArray(); + Words = MemoryMarshal.Cast(context.MemoryManager.GetSpan(EntryAddress, (int)EntryCount * 4)).ToArray(); } } } diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs b/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs index 225c732e9c..6bc1bef8ae 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Gpu.Engine else { evt.Flush(); - return (_context.MemoryAccessor.Read(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; + return (_context.MemoryManager.Read(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; } } @@ -87,11 +87,11 @@ namespace Ryujinx.Graphics.Gpu.Engine if (evt != null && evt2 == null) { - useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryAccessor.Read(gpuVa + 16), isEqual); + useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryManager.Read(gpuVa + 16), isEqual); } else if (evt == null && evt2 != null) { - useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryAccessor.Read(gpuVa), isEqual); + useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryManager.Read(gpuVa), isEqual); } else { @@ -107,8 +107,8 @@ namespace Ryujinx.Graphics.Gpu.Engine evt?.Flush(); evt2?.Flush(); - ulong x = _context.MemoryAccessor.Read(gpuVa); - ulong y = _context.MemoryAccessor.Read(gpuVa + 16); + ulong x = _context.MemoryManager.Read(gpuVa); + ulong y = _context.MemoryManager.Read(gpuVa + 16); return (isEqual ? x == y : x != y) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; } diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs b/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs index fcea438918..8320ba65d2 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodReport.cs @@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { var rs = state.Get(MethodOffset.ReportState); - _context.MemoryAccessor.Write(rs.Address.Pack(), rs.Payload); + _context.MemoryManager.Write(rs.Address.Pack(), rs.Payload); _context.AdvanceSequence(); } @@ -85,7 +85,7 @@ namespace Ryujinx.Graphics.Gpu.Engine if (counter?.Invalid != true) { - _context.MemoryAccessor.Write(gpuVa, counterData); + _context.MemoryManager.Write(gpuVa, counterData); } }; diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferUpdate.cs b/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferUpdate.cs index 032a58683a..61772327f2 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferUpdate.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferUpdate.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { var uniformBuffer = state.Get(MethodOffset.UniformBufferState); - _context.MemoryAccessor.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, argument); + _context.MemoryManager.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, argument); state.SetUniformBufferOffset(uniformBuffer.Offset + 4); @@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { var uniformBuffer = state.Get(MethodOffset.UniformBufferState); - _context.MemoryAccessor.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, MemoryMarshal.Cast(data)); + _context.MemoryManager.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, MemoryMarshal.Cast(data)); state.SetUniformBufferOffset(uniformBuffer.Offset + data.Length * 4); diff --git a/Ryujinx.Graphics.Gpu/GpuContext.cs b/Ryujinx.Graphics.Gpu/GpuContext.cs index 8e9f27329b..bdbf77a6cf 100644 --- a/Ryujinx.Graphics.Gpu/GpuContext.cs +++ b/Ryujinx.Graphics.Gpu/GpuContext.cs @@ -27,11 +27,6 @@ namespace Ryujinx.Graphics.Gpu /// public MemoryManager MemoryManager { get; } - /// - /// GPU memory accessor. - /// - public MemoryAccessor MemoryAccessor { get; } - /// /// GPU engine methods processing. /// @@ -75,8 +70,6 @@ namespace Ryujinx.Graphics.Gpu MemoryManager = new MemoryManager(this); - MemoryAccessor = new MemoryAccessor(this); - Methods = new Methods(this); GPFifo = new GPFifoDevice(this); diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs deleted file mode 100644 index 2c53f6991f..0000000000 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace Ryujinx.Graphics.Gpu.Memory -{ - /// - /// GPU mapped memory accessor. - /// - public class MemoryAccessor - { - private GpuContext _context; - - /// - /// Creates a new instance of the GPU memory accessor. - /// - /// GPU context that the memory accessor belongs to - public MemoryAccessor(GpuContext context) - { - _context = context; - } - - /// - /// Reads a byte array from GPU mapped memory. - /// - /// GPU virtual address where the data is located - /// Size of the data in bytes - /// Byte array with the data - public byte[] ReadBytes(ulong gpuVa, int size) - { - return GetSpan(gpuVa, size).ToArray(); - } - - /// - /// Gets a read-only span of data from GPU mapped memory. - /// This reads as much data as possible, up to the specified maximum size. - /// - /// GPU virtual address where the data is located - /// Size of the data - /// The span of the data at the specified memory location - public ReadOnlySpan GetSpan(ulong gpuVa, int size) - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - return _context.PhysicalMemory.GetSpan(processVa, size); - } - - /// - /// Reads data from GPU mapped memory. - /// - /// Type of the data - /// GPU virtual address where the data is located - /// The data at the specified memory location - public T Read(ulong gpuVa) where T : unmanaged - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - return MemoryMarshal.Cast(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf()))[0]; - } - - /// - /// Writes a 32-bits signed integer to GPU mapped memory. - /// - /// GPU virtual address to write the value into - /// The value to be written - public void Write(ulong gpuVa, T value) where T : unmanaged - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - _context.PhysicalMemory.Write(processVa, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); - } - - /// - /// Writes data to GPU mapped memory. - /// - /// GPU virtual address to write the data into - /// The data to be written - public void Write(ulong gpuVa, ReadOnlySpan data) - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - _context.PhysicalMemory.Write(processVa, data); - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index 2d988f8d8c..ace94442a4 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -62,7 +62,6 @@ namespace Ryujinx.Graphics.Gpu.Memory /// /// Gets a read-only span of data from GPU mapped memory. - /// This reads as much data as possible, up to the specified maximum size. /// /// GPU virtual address where the data is located /// Size of the data @@ -87,6 +86,19 @@ namespace Ryujinx.Graphics.Gpu.Memory return _context.PhysicalMemory.GetWritableRegion(processVa, size); } + /// + /// Writes data to GPU mapped memory. + /// + /// Type of the data + /// GPU virtual address to write the value into + /// The value to be written + public void Write(ulong gpuVa, T value) where T : unmanaged + { + ulong processVa = Translate(gpuVa); + + _context.PhysicalMemory.Write(processVa, MemoryMarshal.Cast(MemoryMarshal.CreateSpan(ref value, 1))); + } + /// /// Writes data to GPU mapped memory. /// diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index 2774b7d124..7c712a0f5d 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -81,7 +81,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// Data at the memory location public T MemoryRead(ulong address) where T : unmanaged { - return _context.MemoryAccessor.Read(address); + return _context.MemoryManager.Read(address); } /// diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index d16f105787..ab777162b4 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -262,13 +262,13 @@ namespace Ryujinx.Graphics.Gpu.Shader return true; } - ReadOnlySpan memoryCode = _context.MemoryAccessor.GetSpan(gpuVa, shader.Code.Length); + ReadOnlySpan memoryCode = _context.MemoryManager.GetSpan(gpuVa, shader.Code.Length); bool equals = memoryCode.SequenceEqual(shader.Code); if (equals && shader.Code2 != null) { - memoryCode = _context.MemoryAccessor.GetSpan(gpuVaA, shader.Code2.Length); + memoryCode = _context.MemoryManager.GetSpan(gpuVaA, shader.Code2.Length); equals = memoryCode.SequenceEqual(shader.Code2); } @@ -307,7 +307,7 @@ namespace Ryujinx.Graphics.Gpu.Shader program = Translator.Translate(gpuVa, gpuAccessor, DefaultFlags | TranslationFlags.Compute); - byte[] code = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size); + byte[] code = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray(); _dumper.Dump(code, compute: true, out string fullPath, out string codePath); @@ -344,8 +344,8 @@ namespace Ryujinx.Graphics.Gpu.Shader { ShaderProgram program = Translator.Translate(gpuVaA, gpuVa, gpuAccessor, DefaultFlags); - byte[] codeA = _context.MemoryAccessor.ReadBytes(gpuVaA, program.SizeA); - byte[] codeB = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size); + byte[] codeA = _context.MemoryManager.GetSpan(gpuVaA, program.SizeA).ToArray(); + byte[] codeB = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray(); _dumper.Dump(codeA, compute: false, out string fullPathA, out string codePathA); _dumper.Dump(codeB, compute: false, out string fullPathB, out string codePathB); @@ -364,7 +364,7 @@ namespace Ryujinx.Graphics.Gpu.Shader { ShaderProgram program = Translator.Translate(gpuVa, gpuAccessor, DefaultFlags); - byte[] code = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size); + byte[] code = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray(); _dumper.Dump(code, compute: false, out string fullPath, out string codePath);