2019-12-25 15:28:17 -08:00
|
|
|
using System;
|
2020-05-03 15:54:50 -07:00
|
|
|
using System.Runtime.CompilerServices;
|
2019-12-25 15:28:17 -08:00
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Memory
|
|
|
|
{
|
2019-12-30 19:22:58 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Represents physical memory, accessible from the GPU.
|
2019-12-30 20:46:57 -08:00
|
|
|
/// This is actually working CPU virtual addresses, of memory mapped on the application process.
|
2019-12-30 19:22:58 -08:00
|
|
|
/// </summary>
|
2019-12-25 15:28:17 -08:00
|
|
|
class PhysicalMemory
|
|
|
|
{
|
2020-05-03 15:54:50 -07:00
|
|
|
public const int PageSize = Cpu.MemoryManager.PageSize;
|
|
|
|
|
|
|
|
private readonly Cpu.MemoryManager _cpuMemory;
|
2019-12-25 15:28:17 -08:00
|
|
|
|
2019-12-30 19:22:58 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance of the physical memory.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="cpuMemory">CPU memory manager of the application process</param>
|
2020-05-03 15:54:50 -07:00
|
|
|
public PhysicalMemory(Cpu.MemoryManager cpuMemory)
|
2019-12-25 15:28:17 -08:00
|
|
|
{
|
|
|
|
_cpuMemory = cpuMemory;
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:22:58 -08:00
|
|
|
/// <summary>
|
2020-01-12 15:27:50 -08:00
|
|
|
/// Gets a span of data from the application process.
|
2019-12-30 19:22:58 -08:00
|
|
|
/// </summary>
|
2020-01-12 15:27:50 -08: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 15:28:17 -08:00
|
|
|
{
|
2020-05-03 15:54:50 -07:00
|
|
|
return _cpuMemory.GetSpan(address, (int)size);
|
2019-12-25 15:28:17 -08:00
|
|
|
}
|
|
|
|
|
2019-12-30 19:22:58 -08: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 15:27:50 -08:00
|
|
|
public void Write(ulong address, ReadOnlySpan<byte> data)
|
2019-12-25 15:28:17 -08:00
|
|
|
{
|
2020-05-03 15:54:50 -07:00
|
|
|
_cpuMemory.Write(address, data);
|
2019-12-25 15:28:17 -08:00
|
|
|
}
|
|
|
|
|
2019-12-30 19:22:58 -08:00
|
|
|
/// <summary>
|
2020-05-03 15:54:50 -07:00
|
|
|
/// Checks if a specified virtual memory region has been modified by the CPU since the last call.
|
2019-12-30 19:22:58 -08:00
|
|
|
/// </summary>
|
2020-05-03 15:54:50 -07:00
|
|
|
/// <param name="address">CPU virtual address of the region</param>
|
|
|
|
/// <param name="size">Size of the region</param>
|
|
|
|
/// <param name="name">Resource name</param>
|
|
|
|
/// <param name="modifiedRanges">Optional array where the modified ranges should be written</param>
|
|
|
|
/// <returns>The number of modified ranges</returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public int QueryModified(ulong address, ulong size, ResourceName name, (ulong, ulong)[] modifiedRanges = null)
|
2019-12-25 15:28:17 -08:00
|
|
|
{
|
2020-05-03 15:54:50 -07:00
|
|
|
return _cpuMemory.QueryModified(address, size, (int)name, modifiedRanges);
|
2019-12-25 15:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|