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-queue.cpp | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tools/gfx/metal/metal-command-queue.cpp (limited to 'tools/gfx/metal/metal-command-queue.cpp') diff --git a/tools/gfx/metal/metal-command-queue.cpp b/tools/gfx/metal/metal-command-queue.cpp new file mode 100644 index 000000000..c8b36ff1e --- /dev/null +++ b/tools/gfx/metal/metal-command-queue.cpp @@ -0,0 +1,75 @@ +// metal-command-queue.cpp +#include "metal-command-queue.h" + +#include "metal-command-buffer.h" +#include "metal-fence.h" + +namespace gfx +{ + +using namespace Slang; + +namespace metal +{ + +ICommandQueue* CommandQueueImpl::getInterface(const Guid& guid) +{ + if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ICommandQueue) + return static_cast(this); + return nullptr; +} + +CommandQueueImpl::~CommandQueueImpl() +{ +} + +void CommandQueueImpl::init(DeviceImpl* renderer) +{ + m_renderer = renderer; + + MTL::Device* device = m_renderer->m_device; + m_commandQueue = device->newCommandQueue(8); +} + +void CommandQueueImpl::waitOnHost() +{ +} + +Result CommandQueueImpl::getNativeHandle(InteropHandle* outHandle) +{ + outHandle->api = InteropHandleAPI::Metal; + outHandle->handleValue = reinterpret_cast(m_commandQueue); + return SLANG_OK; +} + +const CommandQueueImpl::Desc& CommandQueueImpl::getDesc() { return m_desc; } + +Result CommandQueueImpl::waitForFenceValuesOnDevice( + GfxCount fenceCount, IFence** fences, uint64_t* waitValues) +{ + return SLANG_E_NOT_IMPLEMENTED; +} + +void CommandQueueImpl::queueSubmitImpl( + uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) +{ + for (uint32_t i = 0; i < count; ++i) + { + CommandBufferImpl* cmdBufImpl = static_cast(commandBuffers[i]); + cmdBufImpl->m_commandBuffer->presentDrawable(m_renderer->m_drawable); + cmdBufImpl->m_commandBuffer->commit(); + } +} + +void CommandQueueImpl::executeCommandBuffers( + GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) +{ + if (count == 0 && fence == nullptr) + { + return; + } + queueSubmitImpl(count, commandBuffers, fence, valueToSignal); +} + +} // namespace metal +} // namespace gfx -- cgit v1.2.3