From d9443d670ef8413971fe7c3f02368b60a7fc5904 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Mon, 27 May 2024 06:03:13 -0700 Subject: [gfx] metal backend skeleton (#4223) * add metal-cpp submodule * add metal-cpp cmake target * gfx metal backend skeleton * add premake support * add foundation framework * add metal-cpp include to premake * update vs project file --------- Co-authored-by: Simon Kallweit Co-authored-by: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> --- tools/gfx/metal/metal-command-buffer.cpp | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tools/gfx/metal/metal-command-buffer.cpp (limited to 'tools/gfx/metal/metal-command-buffer.cpp') diff --git a/tools/gfx/metal/metal-command-buffer.cpp b/tools/gfx/metal/metal-command-buffer.cpp new file mode 100644 index 000000000..08caa03dd --- /dev/null +++ b/tools/gfx/metal/metal-command-buffer.cpp @@ -0,0 +1,86 @@ +// metal-command-buffer.cpp +#include "metal-command-buffer.h" + +#include "metal-device.h" +#include "metal-command-encoder.h" +#include "metal-shader-object.h" +#include "metal-command-queue.h" + +namespace gfx +{ + +using namespace Slang; + +namespace metal +{ + +ICommandBuffer* CommandBufferImpl::getInterface(const Guid& guid) +{ + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ICommandBuffer) + return static_cast(this); + return nullptr; +} + +void CommandBufferImpl::comFree() { } + +Result CommandBufferImpl::init(DeviceImpl* renderer, TransientResourceHeapImpl* transientHeap) +{ + m_renderer = renderer; + m_commandBuffer = m_renderer->m_commandQueue->commandBuffer(); + return SLANG_OK; +} + +void CommandBufferImpl::encodeRenderCommands( + IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder) +{ + if (!m_renderCommandEncoder) + { + m_renderCommandEncoder = new RenderCommandEncoder; + m_renderCommandEncoder->init(this); + } + m_renderCommandEncoder->beginPass(renderPass, framebuffer); + *outEncoder = m_renderCommandEncoder; +} + +void CommandBufferImpl::encodeComputeCommands(IComputeCommandEncoder** outEncoder) +{ + if (!m_computeCommandEncoder) + { + m_computeCommandEncoder = new ComputeCommandEncoder; + m_computeCommandEncoder->init(this); + } + *outEncoder = m_computeCommandEncoder; +} + +void CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEncoder) +{ + if (!m_resourceCommandEncoder) + { + m_resourceCommandEncoder = new ResourceCommandEncoder; + m_resourceCommandEncoder->init(this); + } + *outEncoder = m_resourceCommandEncoder; +} + +void CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) +{ + if (!m_rayTracingCommandEncoder) + { + m_rayTracingCommandEncoder = new RayTracingCommandEncoder; + m_rayTracingCommandEncoder->init(this); + } + *outEncoder = m_rayTracingCommandEncoder; +} + +void CommandBufferImpl::close() +{ + //m_commandBuffer->commit(); +} + +Result CommandBufferImpl::getNativeHandle(InteropHandle* outHandle) +{ + return SLANG_E_NOT_IMPLEMENTED; +} + +} // namespace metal +} // namespace gfx -- cgit v1.2.3