yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.3 KiB70 linesraw
1// vk-command-buffer.h
2#pragma once
3
4#include "vk-base.h"
5#include "vk-command-encoder.h"
6#include "vk-shader-object.h"
7#include "vk-transient-heap.h"
8
9namespace gfx
10{
11
12using namespace Slang;
13
14namespace vk
15{
16
17class CommandBufferImpl : public ICommandBuffer, public ComObject
18{
19public:
20    // There are a pair of cyclic references between a `TransientResourceHeap` and
21    // a `CommandBuffer` created from the heap. We need to break the cycle when
22    // the public reference count of a command buffer drops to 0.
23    SLANG_COM_OBJECT_IUNKNOWN_ALL
24    ICommandBuffer* getInterface(const Guid& guid);
25    virtual void comFree() override;
26
27public:
28    VkCommandBuffer m_commandBuffer;
29    VkCommandBuffer m_preCommandBuffer = VK_NULL_HANDLE;
30    VkCommandPool m_pool;
31    DeviceImpl* m_renderer;
32    BreakableReference<TransientResourceHeapImpl> m_transientHeap;
33    bool m_isPreCommandBufferEmpty = true;
34    RootShaderObjectImpl m_rootObject;
35    RefPtr<MutableRootShaderObjectImpl> m_mutableRootShaderObject;
36
37    RefPtr<ResourceCommandEncoder> m_resourceCommandEncoder;
38    RefPtr<ComputeCommandEncoder> m_computeCommandEncoder;
39    RefPtr<RenderCommandEncoder> m_renderCommandEncoder;
40    RefPtr<RayTracingCommandEncoder> m_rayTracingCommandEncoder;
41
42    // Command buffers are deallocated by its command pool,
43    // so no need to free individually.
44    ~CommandBufferImpl() = default;
45
46    Result init(DeviceImpl* renderer, VkCommandPool pool, TransientResourceHeapImpl* transientHeap);
47
48    void beginCommandBuffer();
49
50    Result createPreCommandBuffer();
51
52    VkCommandBuffer getPreCommandBuffer();
53
54public:
55    virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands(
56        IRenderPassLayout* renderPass,
57        IFramebuffer* framebuffer,
58        IRenderCommandEncoder** outEncoder) override;
59    virtual SLANG_NO_THROW void SLANG_MCALL
60    encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
61    virtual SLANG_NO_THROW void SLANG_MCALL
62    encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
63    virtual SLANG_NO_THROW void SLANG_MCALL
64    encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
65    virtual SLANG_NO_THROW void SLANG_MCALL close() override;
66    virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
67};
68
69} // namespace vk
70} // namespace gfx