From 43e1b7cdc70b2fcac8a3e8ee72f5bc91726f4ec5 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Thu, 26 May 2022 10:54:35 -0700 Subject: Split render-vk.h/.cpp into a set of smaller files (#2244) * Some preliminary work on splitting render-vk * render-vk split, tests currently crash on null reference * fixed circular include --- tools/gfx/vulkan/vk-command-buffer.h | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tools/gfx/vulkan/vk-command-buffer.h (limited to 'tools/gfx/vulkan/vk-command-buffer.h') diff --git a/tools/gfx/vulkan/vk-command-buffer.h b/tools/gfx/vulkan/vk-command-buffer.h new file mode 100644 index 000000000..3d6c86a95 --- /dev/null +++ b/tools/gfx/vulkan/vk-command-buffer.h @@ -0,0 +1,71 @@ +// vk-command-buffer.h +#pragma once + +#include "vk-base.h" +#include "vk-command-encoder.h" +#include "vk-shader-object.h" +#include "vk-transient-heap.h" + +namespace gfx +{ + +using namespace Slang; + +namespace vk +{ + +class CommandBufferImpl + : public ICommandBuffer + , public ComObject +{ +public: + // There are a pair of cyclic references between a `TransientResourceHeap` and + // a `CommandBuffer` created from the heap. We need to break the cycle when + // the public reference count of a command buffer drops to 0. + SLANG_COM_OBJECT_IUNKNOWN_ALL + ICommandBuffer* getInterface(const Guid& guid); + virtual void comFree() override; + +public: + VkCommandBuffer m_commandBuffer; + VkCommandBuffer m_preCommandBuffer = VK_NULL_HANDLE; + VkCommandPool m_pool; + DeviceImpl* m_renderer; + BreakableReference m_transientHeap; + bool m_isPreCommandBufferEmpty = true; + RootShaderObjectImpl m_rootObject; + + RefPtr m_resourceCommandEncoder; + RefPtr m_computeCommandEncoder; + RefPtr m_renderCommandEncoder; + RefPtr m_rayTracingCommandEncoder; + + // Command buffers are deallocated by its command pool, + // so no need to free individually. + ~CommandBufferImpl() = default; + + Result init(DeviceImpl* renderer, VkCommandPool pool, TransientResourceHeapImpl* transientHeap); + + void beginCommandBuffer(); + + Result createPreCommandBuffer(); + + VkCommandBuffer getPreCommandBuffer(); + +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 vk +} // namespace gfx -- cgit v1.2.3