2024-05-18 22:54:55 +00:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using SharpMetal.Metal;
|
2024-06-25 13:25:31 +00:00
|
|
|
using System;
|
2024-05-28 01:35:32 +00:00
|
|
|
using System.Linq;
|
2024-05-18 22:54:55 +00:00
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Metal
|
|
|
|
{
|
2024-06-25 13:25:31 +00:00
|
|
|
[Flags]
|
|
|
|
enum DirtyFlags
|
2024-05-19 06:08:12 +00:00
|
|
|
{
|
2024-06-25 13:25:31 +00:00
|
|
|
None = 0,
|
|
|
|
RenderPipeline = 1 << 0,
|
|
|
|
ComputePipeline = 1 << 1,
|
|
|
|
DepthStencil = 1 << 2,
|
|
|
|
DepthClamp = 1 << 3,
|
|
|
|
DepthBias = 1 << 4,
|
|
|
|
CullMode = 1 << 5,
|
|
|
|
FrontFace = 1 << 6,
|
|
|
|
StencilRef = 1 << 7,
|
|
|
|
Viewports = 1 << 8,
|
|
|
|
Scissors = 1 << 9,
|
|
|
|
VertexBuffers = 1 << 10,
|
|
|
|
Buffers = 1 << 11,
|
|
|
|
VertexTextures = 1 << 12,
|
|
|
|
FragmentTextures = 1 << 13,
|
|
|
|
ComputeTextures = 1 << 14,
|
|
|
|
|
|
|
|
RenderAll = RenderPipeline | DepthStencil | DepthClamp | DepthBias | CullMode | FrontFace | StencilRef | Viewports | Scissors | VertexBuffers | Buffers | VertexTextures | FragmentTextures,
|
|
|
|
ComputeAll = ComputePipeline | Buffers | ComputeTextures,
|
|
|
|
All = RenderAll | ComputeAll,
|
2024-05-19 06:08:12 +00:00
|
|
|
}
|
|
|
|
|
2024-06-20 23:21:06 +00:00
|
|
|
record struct BufferRef
|
2024-06-20 11:59:29 +00:00
|
|
|
{
|
|
|
|
public Auto<DisposableBuffer> Buffer;
|
|
|
|
public BufferRange? Range;
|
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public BufferRef(Auto<DisposableBuffer> buffer)
|
2024-06-20 11:59:29 +00:00
|
|
|
{
|
|
|
|
Buffer = buffer;
|
|
|
|
}
|
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public BufferRef(Auto<DisposableBuffer> buffer, ref BufferRange range)
|
2024-06-20 11:59:29 +00:00
|
|
|
{
|
|
|
|
Buffer = buffer;
|
|
|
|
Range = range;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
[SupportedOSPlatform("macos")]
|
2024-05-22 21:21:44 +00:00
|
|
|
struct EncoderState
|
2024-05-18 22:54:55 +00:00
|
|
|
{
|
|
|
|
public MTLFunction? VertexFunction = null;
|
|
|
|
public MTLFunction? FragmentFunction = null;
|
2024-05-29 15:21:59 +00:00
|
|
|
public MTLFunction? ComputeFunction = null;
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public TextureBase[] FragmentTextures = new TextureBase[Constants.MaxTexturesPerStage];
|
|
|
|
public MTLSamplerState[] FragmentSamplers = new MTLSamplerState[Constants.MaxTexturesPerStage];
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public TextureBase[] VertexTextures = new TextureBase[Constants.MaxTexturesPerStage];
|
|
|
|
public MTLSamplerState[] VertexSamplers = new MTLSamplerState[Constants.MaxTexturesPerStage];
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public TextureBase[] ComputeTextures = new TextureBase[Constants.MaxTexturesPerStage];
|
|
|
|
public MTLSamplerState[] ComputeSamplers = new MTLSamplerState[Constants.MaxTexturesPerStage];
|
2024-05-29 15:21:59 +00:00
|
|
|
|
2024-06-25 13:25:31 +00:00
|
|
|
public BufferRef[] UniformBuffers = new BufferRef[Constants.MaxUniformBuffersPerStage];
|
|
|
|
public BufferRef[] StorageBuffers = new BufferRef[Constants.MaxStorageBuffersPerStage];
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2024-06-20 11:59:29 +00:00
|
|
|
public Auto<DisposableBuffer> IndexBuffer = default;
|
2024-05-18 22:54:55 +00:00
|
|
|
public MTLIndexType IndexType = MTLIndexType.UInt16;
|
|
|
|
public ulong IndexBufferOffset = 0;
|
|
|
|
|
|
|
|
public MTLDepthStencilState? DepthStencilState = null;
|
|
|
|
|
2024-05-19 01:29:46 +00:00
|
|
|
public MTLDepthClipMode DepthClipMode = MTLDepthClipMode.Clip;
|
2024-05-18 22:54:55 +00:00
|
|
|
public MTLCompareFunction DepthCompareFunction = MTLCompareFunction.Always;
|
|
|
|
public bool DepthWriteEnabled = false;
|
|
|
|
|
2024-05-31 10:43:26 +00:00
|
|
|
public float DepthBias;
|
|
|
|
public float SlopeScale;
|
|
|
|
public float Clamp;
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public MTLStencilDescriptor BackFaceStencil = new();
|
|
|
|
public MTLStencilDescriptor FrontFaceStencil = new();
|
2024-05-28 02:00:48 +00:00
|
|
|
public int BackRefValue = 0;
|
|
|
|
public int FrontRefValue = 0;
|
2024-05-18 23:59:38 +00:00
|
|
|
public bool StencilTestEnabled = false;
|
2024-05-18 22:54:55 +00:00
|
|
|
|
|
|
|
public PrimitiveTopology Topology = PrimitiveTopology.Triangles;
|
|
|
|
public MTLCullMode CullMode = MTLCullMode.None;
|
2024-05-27 11:58:03 +00:00
|
|
|
public MTLWinding Winding = MTLWinding.CounterClockwise;
|
2024-05-18 22:54:55 +00:00
|
|
|
|
|
|
|
public MTLViewport[] Viewports = [];
|
|
|
|
public MTLScissorRect[] Scissors = [];
|
|
|
|
|
|
|
|
// Changes to attachments take recreation!
|
2024-05-23 00:26:54 +00:00
|
|
|
public Texture DepthStencil = default;
|
2024-05-22 21:21:44 +00:00
|
|
|
public Texture[] RenderTargets = new Texture[Constants.MaxColorAttachments];
|
2024-05-28 01:35:32 +00:00
|
|
|
|
|
|
|
public MTLColorWriteMask[] RenderTargetMasks = Enumerable.Repeat(MTLColorWriteMask.All, Constants.MaxColorAttachments).ToArray();
|
2024-05-27 11:58:03 +00:00
|
|
|
public BlendDescriptor?[] BlendDescriptors = new BlendDescriptor?[Constants.MaxColorAttachments];
|
2024-05-19 01:20:15 +00:00
|
|
|
public ColorF BlendColor = new();
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2024-05-19 02:06:53 +00:00
|
|
|
public VertexBufferDescriptor[] VertexBuffers = [];
|
|
|
|
public VertexAttribDescriptor[] VertexAttribs = [];
|
|
|
|
|
2024-05-19 06:08:12 +00:00
|
|
|
// Dirty flags
|
2024-06-25 13:25:31 +00:00
|
|
|
public DirtyFlags Dirty = DirtyFlags.None;
|
2024-05-19 06:08:12 +00:00
|
|
|
|
2024-05-27 13:47:50 +00:00
|
|
|
// Only to be used for present
|
|
|
|
public bool ClearLoadAction = false;
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public EncoderState() { }
|
2024-05-27 11:58:03 +00:00
|
|
|
|
2024-05-27 22:09:29 +00:00
|
|
|
public readonly EncoderState Clone()
|
2024-05-27 11:58:03 +00:00
|
|
|
{
|
|
|
|
// Certain state (like viewport and scissor) doesn't need to be cloned, as it is always reacreated when assigned to
|
|
|
|
EncoderState clone = this;
|
2024-05-29 15:21:59 +00:00
|
|
|
clone.FragmentTextures = (TextureBase[])FragmentTextures.Clone();
|
2024-05-27 11:58:03 +00:00
|
|
|
clone.FragmentSamplers = (MTLSamplerState[])FragmentSamplers.Clone();
|
2024-05-29 15:21:59 +00:00
|
|
|
clone.VertexTextures = (TextureBase[])VertexTextures.Clone();
|
2024-05-27 11:58:03 +00:00
|
|
|
clone.VertexSamplers = (MTLSamplerState[])VertexSamplers.Clone();
|
2024-05-29 15:21:59 +00:00
|
|
|
clone.ComputeTextures = (TextureBase[])ComputeTextures.Clone();
|
|
|
|
clone.ComputeSamplers = (MTLSamplerState[])ComputeSamplers.Clone();
|
2024-05-27 11:58:03 +00:00
|
|
|
clone.BlendDescriptors = (BlendDescriptor?[])BlendDescriptors.Clone();
|
|
|
|
clone.VertexBuffers = (VertexBufferDescriptor[])VertexBuffers.Clone();
|
|
|
|
clone.VertexAttribs = (VertexAttribDescriptor[])VertexAttribs.Clone();
|
2024-06-25 13:25:31 +00:00
|
|
|
clone.UniformBuffers = (BufferRef[])UniformBuffers.Clone();
|
|
|
|
clone.StorageBuffers = (BufferRef[])StorageBuffers.Clone();
|
2024-05-27 11:58:03 +00:00
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
2024-05-18 22:54:55 +00:00
|
|
|
}
|
|
|
|
}
|