2019-12-25 23:28:17 +00:00
|
|
|
using System;
|
2020-05-03 23:54:50 +01:00
|
|
|
using System.Runtime.CompilerServices;
|
2019-12-25 23:28:17 +00:00
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Memory
|
|
|
|
{
|
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
|
|
|
|
{
|
2020-05-03 23:54:50 +01:00
|
|
|
public const int PageSize = Cpu.MemoryManager.PageSize;
|
|
|
|
|
|
|
|
private readonly Cpu.MemoryManager _cpuMemory;
|
2019-12-25 23:28:17 +00:00
|
|
|
|
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>
|
2020-05-03 23:54:50 +01:00
|
|
|
public PhysicalMemory(Cpu.MemoryManager cpuMemory)
|
2019-12-25 23:28:17 +00:00
|
|
|
{
|
|
|
|
_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-05-03 23:54:50 +01:00
|
|
|
return _cpuMemory.GetSpan(address, (int)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
|
|
|
{
|
2020-05-03 23:54:50 +01:00
|
|
|
_cpuMemory.Write(address, data);
|
2019-12-25 23:28:17 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 03:22:58 +00:00
|
|
|
/// <summary>
|
2020-05-03 23:54:50 +01:00
|
|
|
/// Checks if a specified virtual memory region has been modified by the CPU since the last call.
|
2019-12-31 03:22:58 +00:00
|
|
|
/// </summary>
|
2020-05-03 23:54:50 +01: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 23:28:17 +00:00
|
|
|
{
|
2020-05-03 23:54:50 +01:00
|
|
|
return _cpuMemory.QueryModified(address, size, (int)name, modifiedRanges);
|
2019-12-25 23:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|