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

100 lines
3.6 KiB
C#
Raw Normal View History

2024-05-18 22:54:55 +00:00
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
using System.Collections.Generic;
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 Pipeline = 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()
{
2024-05-19 07:10:14 +00:00
Pipeline = true;
DepthStencil = true;
2024-05-19 15:05:50 +00:00
}
public void Clear()
{
Pipeline = false;
DepthStencil = false;
2024-05-19 07:10:14 +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 MTLTexture[] FragmentTextures = new MTLTexture[Constants.MaxTextures];
public MTLSamplerState[] FragmentSamplers = new MTLSamplerState[Constants.MaxSamplers];
2024-05-18 22:54:55 +00:00
public MTLTexture[] VertexTextures = new MTLTexture[Constants.MaxTextures];
public MTLSamplerState[] VertexSamplers = new MTLSamplerState[Constants.MaxSamplers];
2024-05-18 22:54:55 +00:00
public List<BufferInfo> UniformBuffers = [];
public List<BufferInfo> StorageBuffers = [];
public MTLBuffer IndexBuffer = default;
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;
public MTLStencilDescriptor BackFaceStencil = new();
public MTLStencilDescriptor FrontFaceStencil = new();
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 = (MTLTexture[])FragmentTextures.Clone();
clone.FragmentSamplers = (MTLSamplerState[])FragmentSamplers.Clone();
clone.VertexTextures = (MTLTexture[])VertexTextures.Clone();
clone.VertexSamplers = (MTLSamplerState[])VertexSamplers.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
}
}