0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs

54 lines
1.5 KiB
C#
Raw Normal View History

2019-10-13 06:02:07 +00:00
using System;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Memory
{
class MemoryAccessor
{
private GpuContext _context;
public MemoryAccessor(GpuContext context)
{
_context = context;
}
public Span<byte> Read(ulong gpuVa, ulong maxSize)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
ulong size = Math.Min(_context.MemoryManager.GetSubSize(gpuVa), maxSize);
return _context.PhysicalMemory.Read(processVa, size);
}
public T Read<T>(ulong gpuVa) where T : struct
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
ulong size = (uint)Marshal.SizeOf<T>();
return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.Read(processVa, size))[0];
}
public int ReadInt32(ulong gpuVa)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
return BitConverter.ToInt32(_context.PhysicalMemory.Read(processVa, 4));
}
public void Write(ulong gpuVa, int value)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
_context.PhysicalMemory.Write(processVa, BitConverter.GetBytes(value));
}
public void Write(ulong gpuVa, Span<byte> data)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
_context.PhysicalMemory.Write(processVa, data);
}
}
}