yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
2.8 KiB91 linesraw
1// d3d12-command-buffer.h
2#pragma once
3
4#include "d3d12-base.h"
5#include "d3d12-command-encoder.h"
6#include "d3d12-shader-object.h"
7
8#ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__
9// If can't find a definition of CommandList1, just use an empty definition
10struct ID3D12GraphicsCommandList1
11{
12};
13#endif
14
15namespace gfx
16{
17namespace d3d12
18{
19
20using namespace Slang;
21
22class CommandBufferImpl : public ICommandBufferD3D12, public ComObject
23{
24public:
25    // There are a pair of cyclic references between a `TransientResourceHeap` and
26    // a `CommandBuffer` created from the heap. We need to break the cycle upon
27    // the public reference count of a command buffer dropping to 0.
28    SLANG_COM_OBJECT_IUNKNOWN_ALL
29
30    ICommandBufferD3D12* getInterface(const Guid& guid);
31    virtual void comFree() override { m_transientHeap.breakStrongReference(); }
32
33    virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* handle) override;
34
35public:
36    ComPtr<ID3D12GraphicsCommandList> m_cmdList;
37    ComPtr<ID3D12GraphicsCommandList1> m_cmdList1;
38    ComPtr<ID3D12GraphicsCommandList4> m_cmdList4;
39    ComPtr<ID3D12GraphicsCommandList6> m_cmdList6;
40
41    BreakableReference<TransientResourceHeapImpl> m_transientHeap;
42    // Weak reference is fine here since `m_transientHeap` already holds strong reference to
43    // device.
44    DeviceImpl* m_renderer;
45    RootShaderObjectImpl m_rootShaderObject;
46    RefPtr<MutableRootShaderObjectImpl> m_mutableRootShaderObject;
47    bool m_descriptorHeapsBound = false;
48
49    void bindDescriptorHeaps();
50
51    virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding() override
52    {
53        m_descriptorHeapsBound = false;
54    }
55    virtual SLANG_NO_THROW void SLANG_MCALL ensureInternalDescriptorHeapsBound() override
56    {
57        bindDescriptorHeaps();
58    }
59
60    void reinit();
61
62    void init(
63        DeviceImpl* renderer,
64        ID3D12GraphicsCommandList* d3dCommandList,
65        TransientResourceHeapImpl* transientHeap);
66
67    ResourceCommandEncoderImpl m_resourceCommandEncoder;
68
69    virtual SLANG_NO_THROW void SLANG_MCALL
70    encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
71
72    RenderCommandEncoderImpl m_renderCommandEncoder;
73    virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands(
74        IRenderPassLayout* renderPass,
75        IFramebuffer* framebuffer,
76        IRenderCommandEncoder** outEncoder) override;
77
78    ComputeCommandEncoderImpl m_computeCommandEncoder;
79    virtual SLANG_NO_THROW void SLANG_MCALL
80    encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
81
82#if SLANG_GFX_HAS_DXR_SUPPORT
83    RayTracingCommandEncoderImpl m_rayTracingCommandEncoder;
84#endif
85    virtual SLANG_NO_THROW void SLANG_MCALL
86    encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
87    virtual SLANG_NO_THROW void SLANG_MCALL close() override;
88};
89
90} // namespace d3d12
91} // namespace gfx