// metal-command-buffer.h #pragma once #include "../simple-transient-resource-heap.h" #include "metal-base.h" #include "metal-command-encoder.h" #include "metal-shader-object.h" namespace gfx { using namespace Slang; namespace metal { class CommandBufferImpl : public ICommandBuffer, public ComObject { public: SLANG_COM_OBJECT_IUNKNOWN_ALL ICommandBuffer* getInterface(const Guid& guid); public: RefPtr m_device; NS::SharedPtr m_commandBuffer; RootShaderObjectImpl m_rootObject; // RefPtr m_mutableRootShaderObject; RefPtr m_resourceCommandEncoder = nullptr; RefPtr m_computeCommandEncoder = nullptr; RefPtr m_renderCommandEncoder = nullptr; RefPtr m_rayTracingCommandEncoder = nullptr; NS::SharedPtr m_metalRenderCommandEncoder; NS::SharedPtr m_metalComputeCommandEncoder; NS::SharedPtr m_metalBlitCommandEncoder; // Command buffers are deallocated by its command pool, // so no need to free individually. ~CommandBufferImpl() = default; Result init(DeviceImpl* device, TransientResourceHeapImpl* transientHeap); void beginCommandBuffer(); MTL::RenderCommandEncoder* getMetalRenderCommandEncoder( MTL::RenderPassDescriptor* renderPassDesc); MTL::ComputeCommandEncoder* getMetalComputeCommandEncoder(); MTL::BlitCommandEncoder* getMetalBlitCommandEncoder(); void endMetalCommandEncoder(); public: virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands( IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder) override; virtual SLANG_NO_THROW void SLANG_MCALL encodeComputeCommands(IComputeCommandEncoder** outEncoder) override; virtual SLANG_NO_THROW void SLANG_MCALL encodeResourceCommands(IResourceCommandEncoder** outEncoder) override; virtual SLANG_NO_THROW void SLANG_MCALL encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override; virtual SLANG_NO_THROW void SLANG_MCALL close() override; virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override; }; } // namespace metal } // namespace gfx