Refactor shader GPU state and memory access (#1203)

* Refactor shader GPU state and memory access

* Fix NVDEC project build

* Address PR feedback and add missing XML comments
This commit is contained in:
gdkchan 2020-05-05 22:02:28 -03:00 committed by GitHub
parent 7f500e7cae
commit b8eb6abecc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 633 additions and 684 deletions

View file

@ -125,7 +125,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
int offset = (int)(mAddress - Address);
HostBuffer.SetData(offset, _context.PhysicalMemory.GetSpan(mAddress, mSize));
HostBuffer.SetData(offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize));
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Memory
@ -25,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <param name="gpuVa">GPU virtual address where the data is located</param>
/// <param name="size">Size of the data in bytes</param>
/// <returns>Byte array with the data</returns>
public byte[] ReadBytes(ulong gpuVa, ulong size)
public byte[] ReadBytes(ulong gpuVa, int size)
{
return GetSpan(gpuVa, size).ToArray();
}
@ -35,14 +36,12 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// This reads as much data as possible, up to the specified maximum size.
/// </summary>
/// <param name="gpuVa">GPU virtual address where the data is located</param>
/// <param name="maxSize">Maximum size of the data</param>
/// <param name="size">Size of the data</param>
/// <returns>The span of the data at the specified memory location</returns>
public ReadOnlySpan<byte> GetSpan(ulong gpuVa, ulong maxSize)
public ReadOnlySpan<byte> GetSpan(ulong gpuVa, int size)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
ulong size = _context.MemoryManager.GetSubSize(gpuVa, maxSize);
return _context.PhysicalMemory.GetSpan(processVa, size);
}
@ -52,13 +51,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <typeparam name="T">Type of the structure</typeparam>
/// <param name="gpuVa">GPU virtual address where the structure is located</param>
/// <returns>The structure at the specified memory location</returns>
public T Read<T>(ulong gpuVa) where T : struct
public T Read<T>(ulong gpuVa) where T : unmanaged
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
ulong size = (uint)Marshal.SizeOf<T>();
return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, size))[0];
return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf<T>()))[0];
}
/// <summary>
@ -114,7 +111,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// </summary>
/// <param name="gpuVa">GPU virtual address to write the data into</param>
/// <param name="data">The data to be written</param>
public void Write(ulong gpuVa, Span<byte> data)
public void Write(ulong gpuVa, ReadOnlySpan<byte> data)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);

View file

@ -240,28 +240,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
return PteUnmapped;
}
/// <summary>
/// Gets the number of mapped or reserved pages on a given region.
/// </summary>
/// <param name="gpuVa">Start GPU virtual address of the region</param>
/// <param name="maxSize">Maximum size of the data</param>
/// <returns>Mapped size in bytes of the specified region</returns>
internal ulong GetSubSize(ulong gpuVa, ulong maxSize)
{
ulong size = 0;
while (GetPte(gpuVa + size) != PteUnmapped)
{
size += PageSize;
if (size >= maxSize)
{
return maxSize;
}
}
return size;
}
/// <summary>
/// Translates a GPU virtual address to a CPU virtual address.
/// </summary>
@ -279,25 +257,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
return baseAddress + (gpuVa & PageMask);
}
/// <summary>
/// Checks if a given memory region is currently unmapped.
/// </summary>
/// <param name="gpuVa">Start GPU virtual address of the region</param>
/// <param name="size">Size in bytes of the region</param>
/// <returns>True if the region is unmapped (free), false otherwise</returns>
public bool IsRegionFree(ulong gpuVa, ulong size)
{
for (ulong offset = 0; offset < size; offset += PageSize)
{
if (IsPageInUse(gpuVa + offset))
{
return false;
}
}
return true;
}
/// <summary>
/// Checks if a given memory page is mapped or reserved.
/// </summary>

View file

@ -28,9 +28,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <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)
public ReadOnlySpan<byte> GetSpan(ulong address, int size)
{
return _cpuMemory.GetSpan(address, (int)size);
return _cpuMemory.GetSpan(address, size);
}
/// <summary>