using Ryujinx.Graphics.GAL; using SharpMetal.Metal; using System.Runtime.Versioning; namespace Ryujinx.Graphics.Metal { [SupportedOSPlatform("macos")] struct RenderEncoderState { private MTLDevice _device; private MTLDepthStencilState _depthStencilState = null; private MTLCompareFunction _depthCompareFunction = MTLCompareFunction.Always; private bool _depthWriteEnabled = false; private MTLStencilDescriptor _backFaceStencil = null; private MTLStencilDescriptor _frontFaceStencil = null; public MTLRenderPipelineState CopyPipeline; public PrimitiveTopology Topology = PrimitiveTopology.Triangles; public MTLCullMode CullMode = MTLCullMode.None; public MTLWinding Winding = MTLWinding.Clockwise; public RenderEncoderState(MTLRenderPipelineState copyPipeline, MTLDevice device) { _device = device; CopyPipeline = copyPipeline; } public void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder) { renderCommandEncoder.SetRenderPipelineState(CopyPipeline); renderCommandEncoder.SetCullMode(CullMode); renderCommandEncoder.SetFrontFacingWinding(Winding); // renderCommandEncoder.SetDepthStencilState(_depthStencilState); } public MTLDepthStencilState UpdateStencilState(MTLStencilDescriptor backFace, MTLStencilDescriptor frontFace) { _backFaceStencil = backFace; _frontFaceStencil = frontFace; return _depthStencilState = _device.NewDepthStencilState(new MTLDepthStencilDescriptor { DepthCompareFunction = _depthCompareFunction, DepthWriteEnabled = _depthWriteEnabled, BackFaceStencil = _backFaceStencil, FrontFaceStencil = _frontFaceStencil }); } public MTLDepthStencilState UpdateDepthState(MTLCompareFunction depthCompareFunction, bool depthWriteEnabled) { _depthCompareFunction = depthCompareFunction; _depthWriteEnabled = depthWriteEnabled; return _depthStencilState = _device.NewDepthStencilState(new MTLDepthStencilDescriptor { DepthCompareFunction = _depthCompareFunction, DepthWriteEnabled = _depthWriteEnabled, BackFaceStencil = _backFaceStencil, FrontFaceStencil = _frontFaceStencil }); } } }