using System;
using System.Runtime.CompilerServices;
namespace Ryujinx.Graphics.Gpu.Memory
{
///
/// Represents physical memory, accessible from the GPU.
/// This is actually working CPU virtual addresses, of memory mapped on the application process.
///
class PhysicalMemory
{
public const int PageSize = Cpu.MemoryManager.PageSize;
private readonly Cpu.MemoryManager _cpuMemory;
///
/// Creates a new instance of the physical memory.
///
/// CPU memory manager of the application process
public PhysicalMemory(Cpu.MemoryManager 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, (int)size);
}
///
/// Writes data to the application process.
///
/// Address to write into
/// Data to be written
public void Write(ulong address, ReadOnlySpan data)
{
_cpuMemory.Write(address, data);
}
///
/// Checks if a specified virtual memory region has been modified by the CPU since the last call.
///
/// CPU virtual address of the region
/// Size of the region
/// Resource name
/// Optional array where the modified ranges should be written
/// The number of modified ranges
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int QueryModified(ulong address, ulong size, ResourceName name, (ulong, ulong)[] modifiedRanges = null)
{
return _cpuMemory.QueryModified(address, size, (int)name, modifiedRanges);
}
}
}