summaryrefslogtreecommitdiffstats
path: root/tools/gfx/metal/metal-command-buffer.cpp
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2024-06-06 18:08:38 +0200
committerGitHub <noreply@github.com>2024-06-06 09:08:38 -0700
commit8ea3854d94eb1ff213be716a38493d601784810b (patch)
tree071be96574be4afa54afe0a1fe0d66f10eb2cd80 /tools/gfx/metal/metal-command-buffer.cpp
parent40d48bf1742cf21cc1ad3dd00d11fb04f37e512f (diff)
work on gfx metal backend (#4287)
* implement sampler state * implement input layout * implement fence object * buffer implementation * texture implementation * cleanup * add adapter enumeration * supported formats and allocation info * work on device and implement readBufferResource * skeleton for transient resource heap * initial work on command queue / buffers / encoders * fix uploading initial buffer data * implement buffer resource view * string utility functions * wip query pool implementation * cleanup * swapchain * wip * remove plain buffer view * extend gfxGetDeviceTypeName with metal * basic support for resource binding with compute shaders * needed for metal bindings * replace assert(0) with SLANG_UNIMPLEMENTED_X
Diffstat (limited to 'tools/gfx/metal/metal-command-buffer.cpp')
-rw-r--r--tools/gfx/metal/metal-command-buffer.cpp58
1 files changed, 53 insertions, 5 deletions
diff --git a/tools/gfx/metal/metal-command-buffer.cpp b/tools/gfx/metal/metal-command-buffer.cpp
index 08caa03dd..8aac6ea4b 100644
--- a/tools/gfx/metal/metal-command-buffer.cpp
+++ b/tools/gfx/metal/metal-command-buffer.cpp
@@ -21,12 +21,10 @@ ICommandBuffer* CommandBufferImpl::getInterface(const Guid& guid)
return nullptr;
}
-void CommandBufferImpl::comFree() { }
-
-Result CommandBufferImpl::init(DeviceImpl* renderer, TransientResourceHeapImpl* transientHeap)
+Result CommandBufferImpl::init(DeviceImpl* device, TransientResourceHeapImpl* transientHeap)
{
- m_renderer = renderer;
- m_commandBuffer = m_renderer->m_commandQueue->commandBuffer();
+ m_device = device;
+ m_commandBuffer = NS::RetainPtr(m_device->m_commandQueue->commandBuffer());
return SLANG_OK;
}
@@ -82,5 +80,55 @@ Result CommandBufferImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_E_NOT_IMPLEMENTED;
}
+MTL::RenderCommandEncoder* CommandBufferImpl::getMetalRenderCommandEncoder()
+{
+ if (!m_metalRenderCommandEncoder)
+ {
+ endMetalCommandEncoder();
+ // m_metalRenderCommandEncoder = NS::RetainPtr(m_commandBuffer->renderCommandEncoder());
+ }
+ return m_metalRenderCommandEncoder.get();
+}
+
+MTL::ComputeCommandEncoder* CommandBufferImpl::getMetalComputeCommandEncoder()
+{
+ if (!m_metalComputeCommandEncoder)
+ {
+ endMetalCommandEncoder();
+ m_metalComputeCommandEncoder = NS::RetainPtr(m_commandBuffer->computeCommandEncoder());
+ }
+ return m_metalComputeCommandEncoder.get();
+}
+
+MTL::BlitCommandEncoder* CommandBufferImpl::getMetalBlitCommandEncoder()
+{
+ if (!m_metalBlitCommandEncoder)
+ {
+ endMetalCommandEncoder();
+ m_metalBlitCommandEncoder = NS::RetainPtr(m_commandBuffer->blitCommandEncoder());
+ }
+ return m_metalBlitCommandEncoder.get();
+}
+
+void CommandBufferImpl::endMetalCommandEncoder()
+{
+ if (m_metalRenderCommandEncoder)
+ {
+ m_metalRenderCommandEncoder->endEncoding();
+ m_metalRenderCommandEncoder.reset();
+ }
+ if (m_metalComputeCommandEncoder)
+ {
+ m_metalComputeCommandEncoder->endEncoding();
+ m_metalComputeCommandEncoder.reset();
+ }
+ if (m_metalBlitCommandEncoder)
+ {
+ m_metalBlitCommandEncoder->endEncoding();
+ m_metalBlitCommandEncoder.reset();
+ }
+}
+
+
} // namespace metal
} // namespace gfx