Ryujinx/src/Ryujinx.Graphics.Metal/EncoderState.cs

107 lines
4.1 KiB
C#
Raw Normal View History

2024-05-18 22:54:55 +00:00
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
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
{
public struct DirtyFlags
{
public bool RenderPipeline = false;
public bool ComputePipeline = false;
public bool DepthStencil = false;
public DirtyFlags() { }
2024-05-19 07:10:14 +00:00
2024-05-23 18:08:34 +00:00
public void MarkAll()
{
RenderPipeline = true;
ComputePipeline = true;
2024-05-19 07:10:14 +00:00
DepthStencil = true;
2024-05-19 15:05:50 +00:00
}
}
2024-05-18 22:54:55 +00:00
[SupportedOSPlatform("macos")]
struct EncoderState
2024-05-18 22:54:55 +00:00
{
public MTLFunction? VertexFunction = null;
public MTLFunction? FragmentFunction = null;
public MTLFunction? ComputeFunction = null;
2024-05-18 22:54:55 +00:00
public TextureBase[] FragmentTextures = new TextureBase[Constants.MaxTextures];
public MTLSamplerState[] FragmentSamplers = new MTLSamplerState[Constants.MaxSamplers];
2024-05-18 22:54:55 +00:00
public TextureBase[] VertexTextures = new TextureBase[Constants.MaxTextures];
public MTLSamplerState[] VertexSamplers = new MTLSamplerState[Constants.MaxSamplers];
2024-05-18 22:54:55 +00:00
public TextureBase[] ComputeTextures = new TextureBase[Constants.MaxTextures];
public MTLSamplerState[] ComputeSamplers = new MTLSamplerState[Constants.MaxSamplers];
public BufferAssignment[] UniformBuffers = [];
public BufferAssignment[] StorageBuffers = [];
2024-05-18 22:54:55 +00:00
public BufferRange 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;
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;
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();
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
public VertexBufferDescriptor[] VertexBuffers = [];
public VertexAttribDescriptor[] VertexAttribs = [];
// Dirty flags
public DirtyFlags Dirty = new();
// Only to be used for present
public bool ClearLoadAction = false;
2024-05-18 22:54:55 +00:00
public EncoderState() { }
2024-05-27 22:09:29 +00:00
public readonly EncoderState Clone()
{
// Certain state (like viewport and scissor) doesn't need to be cloned, as it is always reacreated when assigned to
EncoderState clone = this;
clone.FragmentTextures = (TextureBase[])FragmentTextures.Clone();
clone.FragmentSamplers = (MTLSamplerState[])FragmentSamplers.Clone();
clone.VertexTextures = (TextureBase[])VertexTextures.Clone();
clone.VertexSamplers = (MTLSamplerState[])VertexSamplers.Clone();
clone.ComputeTextures = (TextureBase[])ComputeTextures.Clone();
clone.ComputeSamplers = (MTLSamplerState[])ComputeSamplers.Clone();
clone.BlendDescriptors = (BlendDescriptor?[])BlendDescriptors.Clone();
clone.VertexBuffers = (VertexBufferDescriptor[])VertexBuffers.Clone();
clone.VertexAttribs = (VertexAttribDescriptor[])VertexAttribs.Clone();
return clone;
}
2024-05-18 22:54:55 +00:00
}
}