// // Copyright Contributors to the MaterialX Project // SPDX-License-Identifier: Apache-2.0 // #ifndef MATERIALXVIEW_METALSTATE_H #define MATERIALXVIEW_METALSTATE_H #include #include #include #include #import #include #include MATERIALX_NAMESPACE_BEGIN class MetalFramebuffer; // Shared pointer to a MetalFramebuffer using MetalFramebufferPtr = std::shared_ptr; struct MX_RENDERMSL_API MetalState { static MetalState* getSingleton() { if (!singleton) { singleton = std::unique_ptr(new MetalState()); } return singleton.get(); } MetalState(); void initialize(id mtlDevice, id mtlCmdQueue); void initLinearToSRGBKernel(); void triggerProgrammaticCapture(); void stopProgrammaticCapture(); void beginCommandBuffer(); void beginEncoder(MTLRenderPassDescriptor* renderpassDesc); void endEncoder(); void endCommandBuffer(); void waitForCompletion(); MaterialX::MetalFramebufferPtr currentFramebuffer(); static std::unique_ptr singleton; id device = nil; id cmdQueue = nil; id cmdBuffer = nil; id linearToSRGB_pso = nil; id renderCmdEncoder = nil; std::stack framebufferStack; bool supportsTiledPipeline; id opaqueDepthStencilState = nil; id transparentDepthStencilState = nil; id envMapDepthStencilState = nil; std::condition_variable inFlightCV; std::mutex inFlightMutex; std::atomic inFlightCommandBuffers; }; MATERIALX_NAMESPACE_END #define MTL(a) (MaterialX::MetalState::getSingleton()->a) #define MTL_DEPTHSTENCIL_STATE(a) (MaterialX::MetalState::getSingleton()->a##DepthStencilState) #define MTL_TRIGGER_CAPTURE MaterialX::MetalState::getSingleton()->triggerProgrammaticCapture() #define MTL_STOP_CAPTURE MaterialX::MetalState::getSingleton()->stopProgrammaticCapture() #define MTL_PUSH_FRAMEBUFFER(a) MaterialX::MetalState::getSingleton()->framebufferStack.push(a) #define MTL_POP_FRAMEBUFFER(a) MaterialX::MetalState::getSingleton()->framebufferStack.pop() #endif // MATERIALXVIEW_METALSTATE_H