using System;
namespace Ryujinx.Graphics.Gpu.Memory
{
using CpuMemoryManager = ARMeilleure.Memory.MemoryManager;
///
/// Represents physical memory, accessible from the GPU.
/// This is actually working CPU virtual addresses, of memory mapped on the application process.
///
class PhysicalMemory
{
private readonly CpuMemoryManager _cpuMemory;
///
/// Creates a new instance of the physical memory.
///
/// CPU memory manager of the application process
public PhysicalMemory(CpuMemoryManager cpuMemory)
{
_cpuMemory = cpuMemory;
}
///
/// Reads data from the application process.
///
/// Address to be read
/// Size in bytes to be read
/// The data at the specified memory location
public Span Read(ulong address, ulong size)
{
return _cpuMemory.ReadBytes((long)address, (long)size);
}
///
/// Writes data to the application process.
///
/// Address to write into
/// Data to be written
public void Write(ulong address, Span data)
{
_cpuMemory.WriteBytes((long)address, data.ToArray());
}
///
/// Gets the modified ranges for a given range of the application process mapped memory.
///
/// Start address of the range
/// Size, in bytes, of the range
/// Name of the GPU resource being checked
/// Ranges, composed of address and size, modified by the application process, form the CPU
public (ulong, ulong)[] GetModifiedRanges(ulong address, ulong size, ResourceName name)
{
return _cpuMemory.GetModifiedRanges(address, size, (int)name);
}
}
}