2019-12-25 23:28:17 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Memory
|
|
|
|
{
|
|
|
|
using CpuMemoryManager = ARMeilleure.Memory.MemoryManager;
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Represents physical memory, accessible from the GPU.
|
2019-12-31 04:46:57 +00:00
|
|
|
/// This is actually working CPU virtual addresses, of memory mapped on the application process.
|
2019-12-31 03:22:58 +00:00
|
|
|
/// </summary>
|
2019-12-25 23:28:17 +00:00
|
|
|
class PhysicalMemory
|
|
|
|
{
|
|
|
|
private readonly CpuMemoryManager _cpuMemory;
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance of the physical memory.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="cpuMemory">CPU memory manager of the application process</param>
|
2019-12-25 23:28:17 +00:00
|
|
|
public PhysicalMemory(CpuMemoryManager cpuMemory)
|
|
|
|
{
|
|
|
|
_cpuMemory = cpuMemory;
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
2020-01-12 23:27:50 +00:00
|
|
|
/// Gets a span of data from the application process.
|
2019-12-31 03:22:58 +00:00
|
|
|
/// </summary>
|
2020-01-12 23:27:50 +00:00
|
|
|
/// <param name="address">Start address of the range</param>
|
|
|
|
/// <param name="size">Size in bytes to be range</param>
|
|
|
|
/// <returns>A read only span of the data at the specified memory location</returns>
|
|
|
|
public ReadOnlySpan<byte> GetSpan(ulong address, ulong size)
|
2019-12-25 23:28:17 +00:00
|
|
|
{
|
2020-01-12 23:27:50 +00:00
|
|
|
return _cpuMemory.GetSpan(address, size);
|
2019-12-25 23:28:17 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Writes data to the application process.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address">Address to write into</param>
|
|
|
|
/// <param name="data">Data to be written</param>
|
2020-01-12 23:27:50 +00:00
|
|
|
public void Write(ulong address, ReadOnlySpan<byte> data)
|
2019-12-25 23:28:17 +00:00
|
|
|
{
|
|
|
|
_cpuMemory.WriteBytes((long)address, data.ToArray());
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the modified ranges for a given range of the application process mapped memory.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="address">Start address of the range</param>
|
|
|
|
/// <param name="size">Size, in bytes, of the range</param>
|
|
|
|
/// <param name="name">Name of the GPU resource being checked</param>
|
|
|
|
/// <returns>Ranges, composed of address and size, modified by the application process, form the CPU</returns>
|
2019-12-25 23:28:17 +00:00
|
|
|
public (ulong, ulong)[] GetModifiedRanges(ulong address, ulong size, ResourceName name)
|
|
|
|
{
|
|
|
|
return _cpuMemory.GetModifiedRanges(address, size, (int)name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|