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

@ -0,0 +1,22 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.GAL
{
[StructLayout(LayoutKind.Sequential, Size = 8)]
public struct BufferHandle : IEquatable<BufferHandle>
{
private readonly ulong _value;
public static BufferHandle Null => new BufferHandle(0);
private BufferHandle(ulong value) => _value = value;
public override bool Equals(object obj) => obj is BufferHandle handle && Equals(handle);
public bool Equals([AllowNull] BufferHandle other) => other._value == _value;
public override int GetHashCode() => _value.GetHashCode();
public static bool operator ==(BufferHandle left, BufferHandle right) => left.Equals(right);
public static bool operator !=(BufferHandle left, BufferHandle right) => !(left == right);
}
}

View file

@ -2,18 +2,18 @@ namespace Ryujinx.Graphics.GAL
{
public struct BufferRange
{
private static BufferRange _empty = new BufferRange(null, 0, 0);
private static readonly BufferRange _empty = new BufferRange(BufferHandle.Null, 0, 0);
public BufferRange Empty => _empty;
public IBuffer Buffer { get; }
public BufferHandle Handle { get; }
public int Offset { get; }
public int Size { get; }
public BufferRange(IBuffer buffer, int offset, int size)
public BufferRange(BufferHandle handle, int offset, int size)
{
Buffer = buffer;
Handle = handle;
Offset = offset;
Size = size;
}

View file

@ -1,15 +0,0 @@
using System;
namespace Ryujinx.Graphics.GAL
{
public interface IBuffer : IDisposable
{
void CopyTo(IBuffer destination, int srcOffset, int dstOffset, int size);
byte[] GetData(int offset, int size);
void SetData(ReadOnlySpan<byte> data);
void SetData(int offset, ReadOnlySpan<byte> data);
}
}

View file

@ -1,4 +1,5 @@
using Ryujinx.Graphics.Shader;
using System;
namespace Ryujinx.Graphics.GAL
{
@ -14,6 +15,8 @@ namespace Ryujinx.Graphics.GAL
int stencilValue,
int stencilMask);
void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size);
void DispatchCompute(int groupsX, int groupsY, int groupsZ);
void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance);
@ -49,7 +52,7 @@ namespace Ryujinx.Graphics.GAL
void SetRasterizerDiscard(bool discard);
void SetRenderTargetColorMasks(uint[] componentMask);
void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask);
void SetRenderTargets(ITexture[] colors, ITexture depthStencil);
@ -68,10 +71,10 @@ namespace Ryujinx.Graphics.GAL
void SetUserClipDistance(int index, bool enableClip);
void SetVertexAttribs(VertexAttribDescriptor[] vertexAttribs);
void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers);
void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs);
void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers);
void SetViewports(int first, Viewport[] viewports);
void SetViewports(int first, ReadOnlySpan<Viewport> viewports);
void TextureBarrier();
void TextureBarrierTiled();

View file

@ -11,15 +11,21 @@ namespace Ryujinx.Graphics.GAL
IShader CompileShader(ShaderProgram shader);
IBuffer CreateBuffer(int size);
BufferHandle CreateBuffer(int size);
IProgram CreateProgram(IShader[] shaders);
ISampler CreateSampler(SamplerCreateInfo info);
ITexture CreateTexture(TextureCreateInfo info);
void DeleteBuffer(BufferHandle buffer);
byte[] GetBufferData(BufferHandle buffer, int offset, int size);
Capabilities GetCapabilities();
void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data);
void UpdateCounters();
ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler);