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;
}
///
/// Gets a span of data from the application process.
///
/// Start address of the range
/// Size in bytes to be range
/// A read only span of the data at the specified memory location
public ReadOnlySpan GetSpan(ulong address, ulong size)
{
return _cpuMemory.GetSpan(address, size);
}
///
/// Writes data to the application process.
///
/// Address to write into
/// Data to be written
public void Write(ulong address, ReadOnlySpan 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);
}
}
}