11namespace DX12
22{
3-
4-
5-
63 enum class HandleType : char
74 {
85 CBV,
96 RTV,
107 DSV,
118 SRV,
12- UAV
9+ UAV,
10+ SMP
1311 };
1412
1513 enum class DescriptorHeapType : char
@@ -18,13 +16,36 @@ namespace DX12
1816 SAMPLER = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
1917 RTV = D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
2018 DSV = D3D12_DESCRIPTOR_HEAP_TYPE_DSV
19+ , GENERATE_OPS
2120 };
2221 enum class DescriptorHeapFlags : char
2322 {
2423 NONE = D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
2524 SHADER_VISIBLE = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE
2625
2726 };
27+
28+ static inline DescriptorHeapType get_heap_type (HandleType type)
29+ {
30+ switch (type)
31+ {
32+ case HandleType::CBV:
33+ case HandleType::SRV:
34+ case HandleType::UAV:
35+ return DescriptorHeapType::CBV_SRV_UAV;
36+
37+ case HandleType::RTV:
38+ return DescriptorHeapType::RTV;
39+
40+ case HandleType::DSV:
41+ return DescriptorHeapType::DSV;
42+
43+ case HandleType::SMP:
44+ return DescriptorHeapType::SAMPLER;
45+ }
46+
47+ return DescriptorHeapType ();
48+ }
2849 class Resource ;
2950
3051 enum class ResourceType : char
@@ -161,7 +182,7 @@ namespace DX12
161182 return false ;
162183 }
163184
164- void place (const Handle& r, D3D12_DESCRIPTOR_HEAP_TYPE t = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ) const ;
185+ void place (const Handle& r) const ;
165186
166187 void clear (CommandList& list, float4 = { 0 , 0 , 0 , 0 }) const ;
167188 };
@@ -394,8 +415,7 @@ namespace DX12
394415 return !!info;
395416 }
396417
397- void place (const HandleTable& r, D3D12_DESCRIPTOR_HEAP_TYPE t = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
398-
418+
399419 private:
400420 friend class DescriptorHeap ;
401421
@@ -684,23 +704,23 @@ namespace DX12
684704 DescriptorHeap::ptr heap_ds;
685705
686706
687-
688707 DescriptorHeapManager ();
689708
690709 public:
691710
692- ~DescriptorHeapManager ()
711+ enum_array<DescriptorHeapType, DescriptorHeapPaged::ptr> cpu_heaps;
712+ enum_array<DescriptorHeapType, DescriptorHeapPaged::ptr> gpu_heaps;
713+
714+
715+ DescriptorHeapPaged::ptr get_cpu_heap (DescriptorHeapType type)
693716 {
694- heap_cb_sr_ua_static-> reset () ;
717+ return cpu_heaps[type] ;
695718 }
696- DescriptorHeapPaged::ptr gpu_srv;
697- DescriptorHeapPaged::ptr gpu_smp;
698719
699-
700- DescriptorHeapPaged::ptr cpu_srv;
701- DescriptorHeapPaged::ptr cpu_rtv;
702- DescriptorHeapPaged::ptr cpu_dsv;
703- DescriptorHeapPaged::ptr cpu_smp;
720+ DescriptorHeapPaged::ptr get_gpu_heap (DescriptorHeapType type)
721+ {
722+ return gpu_heaps[type];
723+ }
704724
705725 DescriptorHeap::ptr& get_csu_static ()
706726 {
@@ -713,7 +733,7 @@ namespace DX12
713733
714734 DescriptorHeapPaged::ptr& get_samplers ()
715735 {
716- return cpu_smp ;
736+ return cpu_heaps[DescriptorHeapType::SAMPLER] ;
717737 }
718738 };
719739
@@ -759,36 +779,14 @@ namespace DX12
759779 typename LockPolicy::mutex m;
760780 void create_heap (UINT count)
761781 {
762-
763-
764782 if constexpr (flags == DescriptorHeapFlags::SHADER_VISIBLE)
765783 {
766-
767- if constexpr (type == DescriptorHeapType::CBV_SRV_UAV)
768- pages.push_back (DescriptorHeapManager::get ().gpu_srv ->create_page (count));
769-
770- if constexpr (type == DescriptorHeapType::SAMPLER)
771- pages.push_back (DescriptorHeapManager::get ().gpu_smp ->create_page (count));
772-
784+ pages.push_back (DescriptorHeapManager::get ().get_gpu_heap (type)->create_page (count));
773785 }
774786 else
775787 {
776- if constexpr (type == DescriptorHeapType::CBV_SRV_UAV)
777- pages.push_back (DescriptorHeapManager::get ().cpu_srv ->create_page (count));
778-
779-
780- if constexpr (type == DescriptorHeapType::RTV)
781- pages.push_back (DescriptorHeapManager::get ().cpu_rtv ->create_page (count));
782-
783- if constexpr (type == DescriptorHeapType::SAMPLER)
784- pages.push_back (DescriptorHeapManager::get ().cpu_smp ->create_page (count));
785-
786- if constexpr (type == DescriptorHeapType::DSV)
787- pages.push_back (DescriptorHeapManager::get ().cpu_dsv ->create_page (count));
788-
788+ pages.push_back (DescriptorHeapManager::get ().get_cpu_heap (type)->create_page (count));
789789 }
790-
791- // assert(pages.size() < 100);
792790 }
793791
794792
0 commit comments