0
0
Fork 0

Remove GPU MemoryAccessor (#1423)

* Remove GPU MemoryAccessor

* Update outdated XML doc

* Update more outdated stuff
This commit is contained in:
gdkchan 2020-07-25 03:39:45 -03:00 committed by GitHub
parent 80d4199fb3
commit 111534a74e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 114 deletions

View file

@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
uint qmdAddress = (uint)state.Get<int>(MethodOffset.DispatchParamsAddress);
var qmd = _context.MemoryAccessor.Read<ComputeQmd>((ulong)qmdAddress << 8);
var qmd = _context.MemoryManager.Read<ComputeQmd>((ulong)qmdAddress << 8);
GpuVa shaderBaseAddress = state.Get<GpuVa>(MethodOffset.ShaderBaseAddress);

View file

@ -80,13 +80,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
// TODO: Acquire operations (Wait), interrupts for invalid combinations.
if (operation == SemaphoredOperation.Release)
{
_context.MemoryAccessor.Write(address, value);
_context.MemoryManager.Write(address, value);
}
else if (operation == SemaphoredOperation.Reduction)
{
bool signed = _state.State.SemaphoredFormat == SemaphoredFormat.Signed;
int mem = _context.MemoryAccessor.Read<int>(address);
int mem = _context.MemoryManager.Read<int>(address);
switch (_state.State.SemaphoredReduction)
{
@ -116,7 +116,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
break;
}
_context.MemoryAccessor.Write(address, value);
_context.MemoryManager.Write(address, value);
}
}

View file

@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
{
if (Words == null)
{
Words = MemoryMarshal.Cast<byte, int>(context.MemoryAccessor.GetSpan(EntryAddress, (int)EntryCount * 4)).ToArray();
Words = MemoryMarshal.Cast<byte, int>(context.MemoryManager.GetSpan(EntryAddress, (int)EntryCount * 4)).ToArray();
}
}
}

View file

@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
else
{
evt.Flush();
return (_context.MemoryAccessor.Read<ulong>(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False;
return (_context.MemoryManager.Read<ulong>(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False;
}
}
@ -87,11 +87,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (evt != null && evt2 == null)
{
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryAccessor.Read<ulong>(gpuVa + 16), isEqual);
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryManager.Read<ulong>(gpuVa + 16), isEqual);
}
else if (evt == null && evt2 != null)
{
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryAccessor.Read<ulong>(gpuVa), isEqual);
useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryManager.Read<ulong>(gpuVa), isEqual);
}
else
{
@ -107,8 +107,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
evt?.Flush();
evt2?.Flush();
ulong x = _context.MemoryAccessor.Read<ulong>(gpuVa);
ulong y = _context.MemoryAccessor.Read<ulong>(gpuVa + 16);
ulong x = _context.MemoryManager.Read<ulong>(gpuVa);
ulong y = _context.MemoryManager.Read<ulong>(gpuVa + 16);
return (isEqual ? x == y : x != y) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False;
}

View file

@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
var rs = state.Get<SemaphoreState>(MethodOffset.ReportState);
_context.MemoryAccessor.Write(rs.Address.Pack(), rs.Payload);
_context.MemoryManager.Write(rs.Address.Pack(), rs.Payload);
_context.AdvanceSequence();
}
@ -85,7 +85,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (counter?.Invalid != true)
{
_context.MemoryAccessor.Write(gpuVa, counterData);
_context.MemoryManager.Write(gpuVa, counterData);
}
};

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
var uniformBuffer = state.Get<UniformBufferState>(MethodOffset.UniformBufferState);
_context.MemoryAccessor.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, argument);
_context.MemoryManager.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, argument);
state.SetUniformBufferOffset(uniformBuffer.Offset + 4);
@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
var uniformBuffer = state.Get<UniformBufferState>(MethodOffset.UniformBufferState);
_context.MemoryAccessor.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, MemoryMarshal.Cast<int, byte>(data));
_context.MemoryManager.Write(uniformBuffer.Address.Pack() + (uint)uniformBuffer.Offset, MemoryMarshal.Cast<int, byte>(data));
state.SetUniformBufferOffset(uniformBuffer.Offset + data.Length * 4);

View file

@ -27,11 +27,6 @@ namespace Ryujinx.Graphics.Gpu
/// </summary>
public MemoryManager MemoryManager { get; }
/// <summary>
/// GPU memory accessor.
/// </summary>
public MemoryAccessor MemoryAccessor { get; }
/// <summary>
/// GPU engine methods processing.
/// </summary>
@ -75,8 +70,6 @@ namespace Ryujinx.Graphics.Gpu
MemoryManager = new MemoryManager(this);
MemoryAccessor = new MemoryAccessor(this);
Methods = new Methods(this);
GPFifo = new GPFifoDevice(this);

View file

@ -1,85 +0,0 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Memory
{
/// <summary>
/// GPU mapped memory accessor.
/// </summary>
public class MemoryAccessor
{
private GpuContext _context;
/// <summary>
/// Creates a new instance of the GPU memory accessor.
/// </summary>
/// <param name="context">GPU context that the memory accessor belongs to</param>
public MemoryAccessor(GpuContext context)
{
_context = context;
}
/// <summary>
/// Reads a byte array from GPU mapped memory.
/// </summary>
/// <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, int size)
{
return GetSpan(gpuVa, size).ToArray();
}
/// <summary>
/// Gets a read-only span of data from GPU mapped 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="size">Size of the data</param>
/// <returns>The span of the data at the specified memory location</returns>
public ReadOnlySpan<byte> GetSpan(ulong gpuVa, int size)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
return _context.PhysicalMemory.GetSpan(processVa, size);
}
/// <summary>
/// Reads data from GPU mapped memory.
/// </summary>
/// <typeparam name="T">Type of the data</typeparam>
/// <param name="gpuVa">GPU virtual address where the data is located</param>
/// <returns>The data at the specified memory location</returns>
public T Read<T>(ulong gpuVa) where T : unmanaged
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf<T>()))[0];
}
/// <summary>
/// Writes a 32-bits signed integer to GPU mapped memory.
/// </summary>
/// <param name="gpuVa">GPU virtual address to write the value into</param>
/// <param name="value">The value to be written</param>
public void Write<T>(ulong gpuVa, T value) where T : unmanaged
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
_context.PhysicalMemory.Write(processVa, MemoryMarshal.Cast<T, byte>(MemoryMarshal.CreateSpan(ref value, 1)));
}
/// <summary>
/// Writes data to GPU mapped 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, ReadOnlySpan<byte> data)
{
ulong processVa = _context.MemoryManager.Translate(gpuVa);
_context.PhysicalMemory.Write(processVa, data);
}
}
}

View file

@ -62,7 +62,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <summary>
/// Gets a read-only span of data from GPU mapped 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="size">Size of the data</param>
@ -87,6 +86,19 @@ namespace Ryujinx.Graphics.Gpu.Memory
return _context.PhysicalMemory.GetWritableRegion(processVa, size);
}
/// <summary>
/// Writes data to GPU mapped memory.
/// </summary>
/// <typeparam name="T">Type of the data</typeparam>
/// <param name="gpuVa">GPU virtual address to write the value into</param>
/// <param name="value">The value to be written</param>
public void Write<T>(ulong gpuVa, T value) where T : unmanaged
{
ulong processVa = Translate(gpuVa);
_context.PhysicalMemory.Write(processVa, MemoryMarshal.Cast<T, byte>(MemoryMarshal.CreateSpan(ref value, 1)));
}
/// <summary>
/// Writes data to GPU mapped memory.
/// </summary>

View file

@ -81,7 +81,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <returns>Data at the memory location</returns>
public T MemoryRead<T>(ulong address) where T : unmanaged
{
return _context.MemoryAccessor.Read<T>(address);
return _context.MemoryManager.Read<T>(address);
}
/// <summary>

View file

@ -262,13 +262,13 @@ namespace Ryujinx.Graphics.Gpu.Shader
return true;
}
ReadOnlySpan<byte> memoryCode = _context.MemoryAccessor.GetSpan(gpuVa, shader.Code.Length);
ReadOnlySpan<byte> memoryCode = _context.MemoryManager.GetSpan(gpuVa, shader.Code.Length);
bool equals = memoryCode.SequenceEqual(shader.Code);
if (equals && shader.Code2 != null)
{
memoryCode = _context.MemoryAccessor.GetSpan(gpuVaA, shader.Code2.Length);
memoryCode = _context.MemoryManager.GetSpan(gpuVaA, shader.Code2.Length);
equals = memoryCode.SequenceEqual(shader.Code2);
}
@ -307,7 +307,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
program = Translator.Translate(gpuVa, gpuAccessor, DefaultFlags | TranslationFlags.Compute);
byte[] code = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size);
byte[] code = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray();
_dumper.Dump(code, compute: true, out string fullPath, out string codePath);
@ -344,8 +344,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
{
ShaderProgram program = Translator.Translate(gpuVaA, gpuVa, gpuAccessor, DefaultFlags);
byte[] codeA = _context.MemoryAccessor.ReadBytes(gpuVaA, program.SizeA);
byte[] codeB = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size);
byte[] codeA = _context.MemoryManager.GetSpan(gpuVaA, program.SizeA).ToArray();
byte[] codeB = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray();
_dumper.Dump(codeA, compute: false, out string fullPathA, out string codePathA);
_dumper.Dump(codeB, compute: false, out string fullPathB, out string codePathB);
@ -364,7 +364,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{
ShaderProgram program = Translator.Translate(gpuVa, gpuAccessor, DefaultFlags);
byte[] code = _context.MemoryAccessor.ReadBytes(gpuVa, program.Size);
byte[] code = _context.MemoryManager.GetSpan(gpuVa, program.Size).ToArray();
_dumper.Dump(code, compute: false, out string fullPath, out string codePath);