aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Memory
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory')
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs36
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs60
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs12
3 files changed, 71 insertions, 37 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs
index 38f448d9..5cc8ec24 100644
--- a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs
+++ b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs
@@ -59,42 +59,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
- /// Reads a 32-bits signed integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <returns>The value at the specified memory location</returns>
- public int ReadInt32(ulong gpuVa)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- return _context.PhysicalMemory.Read<int>(processVa);
- }
-
- /// <summary>
- /// Reads a 64-bits unsigned integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <returns>The value at the specified memory location</returns>
- public ulong ReadUInt64(ulong gpuVa)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- return _context.PhysicalMemory.Read<ulong>(processVa);
- }
-
- /// <summary>
- /// Reads a 8-bits unsigned integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <param name="value">The value to be written</param>
- public void WriteByte(ulong gpuVa, byte value)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- _context.PhysicalMemory.Write(processVa, MemoryMarshal.CreateSpan(ref value, 1));
- }
-
- /// <summary>
/// Writes a 32-bits signed integer to GPU mapped memory.
/// </summary>
/// <param name="gpuVa">GPU virtual address to write the value into</param>
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
index a9a8fbac..2d988f8d 100644
--- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
+++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
@@ -1,4 +1,7 @@
+using Ryujinx.Cpu;
using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Memory
{
@@ -33,15 +36,70 @@ namespace Ryujinx.Graphics.Gpu.Memory
public event EventHandler<UnmapEventArgs> MemoryUnmapped;
+ private GpuContext _context;
+
/// <summary>
/// Creates a new instance of the GPU memory manager.
/// </summary>
- public MemoryManager()
+ public MemoryManager(GpuContext context)
{
+ _context = context;
_pageTable = new ulong[PtLvl0Size][];
}
/// <summary>
+ /// Reads data from GPU mapped memory.
+ /// </summary>
+ /// <typeparam name="T">Type of the data</typeparam>
+ /// <param name="gpuVa">GPU virtual address where the data is located</param>
+ /// <returns>The data at the specified memory location</returns>
+ public T Read<T>(ulong gpuVa) where T : unmanaged
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf<T>()))[0];
+ }
+
+ /// <summary>
+ /// Gets a read-only span of data from GPU mapped memory.
+ /// This reads as much data as possible, up to the specified maximum size.
+ /// </summary>
+ /// <param name="gpuVa">GPU virtual address where the data is located</param>
+ /// <param name="size">Size of the data</param>
+ /// <returns>The span of the data at the specified memory location</returns>
+ public ReadOnlySpan<byte> GetSpan(ulong gpuVa, int size)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return _context.PhysicalMemory.GetSpan(processVa, size);
+ }
+
+ /// <summary>
+ /// Gets a writable region from GPU mapped memory.
+ /// </summary>
+ /// <param name="address">Start address of the range</param>
+ /// <param name="size">Size in bytes to be range</param>
+ /// <returns>A writable region with the data at the specified memory location</returns>
+ public WritableRegion GetWritableRegion(ulong gpuVa, int size)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return _context.PhysicalMemory.GetWritableRegion(processVa, size);
+ }
+
+ /// <summary>
+ /// Writes data to GPU mapped memory.
+ /// </summary>
+ /// <param name="gpuVa">GPU virtual address to write the data into</param>
+ /// <param name="data">The data to be written</param>
+ public void Write(ulong gpuVa, ReadOnlySpan<byte> data)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ _context.PhysicalMemory.Write(processVa, data);
+ }
+
+ /// <summary>
/// Maps a given range of pages to the specified CPU virtual address.
/// </summary>
/// <remarks>
diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
index 4a80aa1a..88beab8f 100644
--- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
+++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
@@ -1,3 +1,4 @@
+using Ryujinx.Cpu;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -35,6 +36,17 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
+ /// Gets a writable region from the application process.
+ /// </summary>
+ /// <param name="address">Start address of the range</param>
+ /// <param name="size">Size in bytes to be range</param>
+ /// <returns>A writable region with the data at the specified memory location</returns>
+ public WritableRegion GetWritableRegion(ulong address, int size)
+ {
+ return _cpuMemory.GetWritableRegion(address, size);
+ }
+
+ /// <summary>
/// Reads data from the application process.
/// </summary>
/// <typeparam name="T">Type of the structure</typeparam>