yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
3.0 KiB94 linesraw
1// d3d12-transient-heap.h
2#pragma once
3
4#include "d3d12-base.h"
5
6namespace gfx
7{
8namespace d3d12
9{
10
11using namespace Slang;
12
13class TransientResourceHeapImpl
14    : public TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl>,
15      public ITransientResourceHeapD3D12
16{
17private:
18    typedef TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl> Super;
19
20public:
21    ComPtr<ID3D12CommandAllocator> m_commandAllocator;
22    List<ComPtr<ID3D12GraphicsCommandList>> m_d3dCommandListPool;
23    List<RefPtr<RefObject>> m_commandBufferPool;
24    uint32_t m_commandListAllocId = 0;
25    // Wait values for each command queue.
26    struct QueueWaitInfo
27    {
28        uint64_t waitValue;
29        HANDLE fenceEvent;
30        ComPtr<ID3D12CommandQueue> queue;
31        ComPtr<ID3D12Fence> fence = nullptr;
32    };
33    ShortList<QueueWaitInfo, 4> m_waitInfos;
34    ShortList<HANDLE, 4> m_waitHandles;
35
36    QueueWaitInfo& getQueueWaitInfo(uint32_t queueIndex);
37    // During command submission, we need all the descriptor tables that get
38    // used to come from a single heap (for each descriptor heap type).
39    //
40    // We will thus keep a single heap of each type that we hope will hold
41    // all the descriptors that actually get needed in a frame.
42    ShortList<D3D12DescriptorHeap, 4> m_viewHeaps;    // Cbv, Srv, Uav
43    ShortList<D3D12DescriptorHeap, 4> m_samplerHeaps; // Heap for samplers
44    int32_t m_currentViewHeapIndex = -1;
45    int32_t m_currentSamplerHeapIndex = -1;
46    bool m_canResize = false;
47
48    uint32_t m_viewHeapSize;
49    uint32_t m_samplerHeapSize;
50
51    D3D12DescriptorHeap& getCurrentViewHeap();
52    D3D12DescriptorHeap& getCurrentSamplerHeap();
53
54    D3D12LinearExpandingDescriptorHeap m_stagingCpuViewHeap;
55    D3D12LinearExpandingDescriptorHeap m_stagingCpuSamplerHeap;
56
57    virtual SLANG_NO_THROW Result SLANG_MCALL
58    queryInterface(SlangUUID const& uuid, void** outObject) override;
59
60    virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return Super::addRef(); }
61    virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return Super::release(); }
62
63    virtual SLANG_NO_THROW Result SLANG_MCALL allocateTransientDescriptorTable(
64        DescriptorType type,
65        GfxCount count,
66        Offset& outDescriptorOffset,
67        void** outD3DDescriptorHeapHandle) override;
68
69    ~TransientResourceHeapImpl();
70
71    bool canResize() { return m_canResize; }
72
73    Result init(
74        const ITransientResourceHeap::Desc& desc,
75        DeviceImpl* device,
76        uint32_t viewHeapSize,
77        uint32_t samplerHeapSize);
78
79    Result allocateNewViewDescriptorHeap(DeviceImpl* device);
80
81    Result allocateNewSamplerDescriptorHeap(DeviceImpl* device);
82
83    virtual SLANG_NO_THROW Result SLANG_MCALL
84    createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
85
86    Result synchronize();
87
88    virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override;
89
90    virtual SLANG_NO_THROW Result SLANG_MCALL finish() override;
91};
92
93} // namespace d3d12
94} // namespace gfx