Spanify Graphics Abstraction Layer (#1226)

* Spanify Graphics Abstraction Layer

* Be explicit about BufferHandle size
This commit is contained in:
gdkchan 2020-05-23 06:46:09 -03:00 committed by GitHub
parent cc8dbdd3fb
commit 5011640b30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 208 additions and 134 deletions

View file

@ -45,6 +45,11 @@ namespace Ryujinx.Graphics.Gpu
/// </summary>
public const int ShaderStages = 5;
/// <summary>
/// Maximum number of vertex attributes.
/// </summary>
public const int TotalVertexAttribs = 16;
/// <summary>
/// Maximum number of vertex buffers.
/// </summary>

View file

@ -570,9 +570,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
/// <param name="state">Current GPU state</param>
private void UpdateVertexAttribState(GpuState state)
{
VertexAttribDescriptor[] vertexAttribs = new VertexAttribDescriptor[16];
Span<VertexAttribDescriptor> vertexAttribs = stackalloc VertexAttribDescriptor[Constants.TotalVertexAttribs];
for (int index = 0; index < 16; index++)
for (int index = 0; index < Constants.TotalVertexAttribs; index++)
{
var vertexAttrib = state.Get<VertexAttribState>(MethodOffset.VertexAttribState, index);
@ -660,7 +660,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
_isAnyVbInstanced = false;
for (int index = 0; index < 16; index++)
for (int index = 0; index < Constants.TotalVertexBuffers; index++)
{
var vertexBuffer = state.Get<VertexBufferState>(MethodOffset.VertexBufferState, index);
@ -728,7 +728,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
bool rtColorMaskShared = state.Get<Boolean32>(MethodOffset.RtColorMaskShared);
uint[] componentMasks = new uint[Constants.TotalRenderTargets];
Span<uint> componentMasks = stackalloc uint[Constants.TotalRenderTargets];
for (int index = 0; index < Constants.TotalRenderTargets; index++)
{

View file

@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
private readonly GpuContext _context;
/// <summary>
/// Host buffer object.
/// Host buffer handle.
/// </summary>
public IBuffer HostBuffer { get; }
public BufferHandle Handle { get; }
/// <summary>
/// Start address of the buffer in guest memory.
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
Address = address;
Size = size;
HostBuffer = context.Renderer.CreateBuffer((int)size);
Handle = context.Renderer.CreateBuffer((int)size);
_modifiedRanges = new (ulong, ulong)[size / PhysicalMemory.PageSize];
@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
int offset = (int)(address - Address);
return new BufferRange(HostBuffer, offset, (int)size);
return new BufferRange(Handle, offset, (int)size);
}
/// <summary>
@ -125,7 +125,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
int offset = (int)(mAddress - Address);
HostBuffer.SetData(offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize));
_context.Renderer.SetBufferData(Handle, offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize));
}
}
@ -136,7 +136,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// <param name="dstOffset">The offset of the destination buffer to copy into</param>
public void CopyTo(Buffer destination, int dstOffset)
{
HostBuffer.CopyTo(destination.HostBuffer, 0, dstOffset, (int)Size);
_context.Renderer.Pipeline.CopyBuffer(Handle, destination.Handle, 0, dstOffset, (int)Size);
}
/// <summary>
@ -149,7 +149,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
int offset = (int)(address - Address);
byte[] data = HostBuffer.GetData(offset, (int)size);
byte[] data = _context.Renderer.GetBufferData(Handle, offset, (int)size);
_context.PhysicalMemory.Write(address, data);
}
@ -159,7 +159,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
/// </summary>
public void Dispose()
{
HostBuffer.Dispose();
_context.Renderer.DeleteBuffer(Handle);
}
}
}

View file

@ -477,7 +477,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
_vertexBuffersDirty = false;
VertexBufferDescriptor[] vertexBuffers = new VertexBufferDescriptor[Constants.TotalVertexBuffers];
Span<VertexBufferDescriptor> vertexBuffers = stackalloc VertexBufferDescriptor[Constants.TotalVertexBuffers];
for (int index = 0; (vbEnableMask >> index) != 0; index++)
{
@ -666,8 +666,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
int srcOffset = (int)(srcAddress - srcBuffer.Address);
int dstOffset = (int)(dstAddress - dstBuffer.Address);
srcBuffer.HostBuffer.CopyTo(
dstBuffer.HostBuffer,
_context.Renderer.Pipeline.CopyBuffer(
srcBuffer.Handle,
dstBuffer.Handle,
srcOffset,
dstOffset,
(int)size);