Debian Codegraph @

Source/Core/VideoBackends/D3D12/DescriptorHeapManager.h

raw symbols SCIP
1 // Copyright 2019 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <bitset>
7 #include <unordered_map>
8
9 #include "VideoBackends/D3D12/Common.h"
10 #include "VideoCommon/RenderState.h"
11
12 namespace DX12
13 {
14 // This class provides an abstraction for D3D12 descriptor heaps.
15 struct DescriptorHandle final
16 {
17 D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle;
18 D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
19 u32 index;
20
21 operator bool() const { return cpu_handle.ptr != 0; }
22 };
23
24 class DescriptorHeapManager final
25 {
26 public:
27 DescriptorHeapManager();
28 ~DescriptorHeapManager();
29
30 ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.Get(); }
31 u32 GetDescriptorIncrementSize() const { return m_descriptor_increment_size; }
32
33 bool Create(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_TYPE type, u32 num_descriptors);
34
35 bool Allocate(DescriptorHandle* handle);
36 void Free(const DescriptorHandle& handle);
37 void Free(u32 index);
38
39 private:
40 ComPtr<ID3D12DescriptorHeap> m_descriptor_heap;
41 u32 m_num_descriptors = 0;
42 u32 m_descriptor_increment_size = 0;
43
44 D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu = {};
45
46 static constexpr u32 BITSET_SIZE = 1024;
47 using BitSetType = std::bitset<BITSET_SIZE>;
48 std::vector<BitSetType> m_free_slots = {};
49 };
50
51 class SamplerHeapManager final
52 {
53 public:
54 SamplerHeapManager();
55 ~SamplerHeapManager();
56
57 ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptor_heap.Get(); }
58
59 bool Create(ID3D12Device* device, u32 num_descriptors);
60 bool Lookup(const SamplerState& ss, D3D12_CPU_DESCRIPTOR_HANDLE* handle);
61 void Clear();
62
63 private:
64 ComPtr<ID3D12DescriptorHeap> m_descriptor_heap;
65 u32 m_num_descriptors = 0;
66 u32 m_descriptor_increment_size = 0;
67 u32 m_current_offset = 0;
68
69 D3D12_CPU_DESCRIPTOR_HANDLE m_heap_base_cpu{};
70
71 std::unordered_map<SamplerState, D3D12_CPU_DESCRIPTOR_HANDLE> m_sampler_map;
72 };
73 } // namespace DX12