Skip to content

Commit 60a67f5

Browse files
committed
small fixes
1 parent ef43a77 commit 60a67f5

File tree

14 files changed

+176
-171
lines changed

14 files changed

+176
-171
lines changed

sources/DirectXFramework/DX12/CommandList.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ namespace DX12
9595
Sendable::reset();
9696

9797
if (type != CommandListType::COPY) {
98-
set_heap(DescriptorHeapType::SAMPLER, DescriptorHeapManager::get().gpu_smp);
99-
set_heap(DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapManager::get().gpu_srv);
98+
set_heap(DescriptorHeapType::SAMPLER, DescriptorHeapManager::get().get_gpu_heap(DescriptorHeapType::SAMPLER));
99+
set_heap(DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapManager::get().get_gpu_heap(DescriptorHeapType::CBV_SRV_UAV));
100100
}
101101
//set_heap(DescriptorHeapType::SAMPLER, smp_descriptors.get_heap());
102102
}
@@ -687,7 +687,7 @@ namespace DX12
687687
// todo: move to queue tasks to save some heaps
688688
for (auto& e : tile_updates)
689689
{
690-
e.resource->on_tile_update(e);
690+
e.resource->tracked_info->on_tile_update(e);
691691
}
692692

693693

sources/DirectXFramework/DX12/Descriptors.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ namespace DX12 {
88
heap_ds.reset(new DescriptorHeap(65536, DescriptorHeapType::DSV, DescriptorHeapFlags::NONE));
99

1010

11-
gpu_srv.reset(new DescriptorHeapPaged(65536*8, DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapFlags::SHADER_VISIBLE));
12-
gpu_smp.reset(new DescriptorHeapPaged(2048, DescriptorHeapType::SAMPLER, DescriptorHeapFlags::SHADER_VISIBLE));
11+
gpu_heaps[DescriptorHeapType::CBV_SRV_UAV].reset(new DescriptorHeapPaged(65536*8, DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapFlags::SHADER_VISIBLE));
12+
gpu_heaps[DescriptorHeapType::SAMPLER].reset(new DescriptorHeapPaged(2048, DescriptorHeapType::SAMPLER, DescriptorHeapFlags::SHADER_VISIBLE));
1313

14-
cpu_srv.reset(new DescriptorHeapPaged(65536, DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapFlags::NONE));
15-
cpu_rtv.reset(new DescriptorHeapPaged(65536, DescriptorHeapType::RTV, DescriptorHeapFlags::NONE));
16-
cpu_dsv.reset(new DescriptorHeapPaged(65536, DescriptorHeapType::DSV, DescriptorHeapFlags::NONE));
17-
cpu_smp.reset(new DescriptorHeapPaged(65536, DescriptorHeapType::SAMPLER, DescriptorHeapFlags::NONE));
14+
cpu_heaps[DescriptorHeapType::CBV_SRV_UAV].reset(new DescriptorHeapPaged(65536, DescriptorHeapType::CBV_SRV_UAV, DescriptorHeapFlags::NONE));
15+
cpu_heaps[DescriptorHeapType::RTV].reset(new DescriptorHeapPaged(65536, DescriptorHeapType::RTV, DescriptorHeapFlags::NONE));
16+
cpu_heaps[DescriptorHeapType::DSV].reset(new DescriptorHeapPaged(65536, DescriptorHeapType::DSV, DescriptorHeapFlags::NONE));
17+
cpu_heaps[DescriptorHeapType::SAMPLER].reset(new DescriptorHeapPaged(65536, DescriptorHeapType::SAMPLER, DescriptorHeapFlags::NONE));
1818
}
1919

2020

@@ -45,18 +45,18 @@ namespace DX12 {
4545
}
4646

4747

48-
void Handle::place(const Handle& r, D3D12_DESCRIPTOR_HEAP_TYPE type) const
48+
void Handle::place(const Handle& r) const
4949
{
50+
51+
D3D12_DESCRIPTOR_HEAP_TYPE type = (D3D12_DESCRIPTOR_HEAP_TYPE)get_heap_type(r.resource_info->type);
52+
53+
5054
if (cpu != r.cpu)
5155
Device::get().get_native_device()->CopyDescriptorsSimple(1, cpu, r.cpu, type);
5256

5357
*resource_info = *r.resource_info;
5458
}
5559

56-
void HandleTable::place(const HandleTable& r, D3D12_DESCRIPTOR_HEAP_TYPE t)
57-
{
58-
Device::get().get_native_device()->CopyDescriptorsSimple(r.get_count(), get_base().cpu, r.get_base().cpu, t);
59-
}
6060

6161
void Handle::clear(CommandList& list, float4 color) const
6262
{

sources/DirectXFramework/DX12/Descriptors.h

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
namespace 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

sources/DirectXFramework/DX12/Resource.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ namespace DX12
4444

4545
class TrackedResource
4646
{
47+
friend class TiledResourceManager;
48+
49+
std::vector<grid<uint3, ResourceTile>> gpu_tiles;
50+
ResourceTile gpu_packed_tile;
51+
public:
52+
void on_tile_update(const update_tiling_info& info)
53+
{
54+
for (auto& [heap, tiles] : info.tiles)
55+
{
56+
for (auto tile : tiles)
57+
{
58+
if (tile.subresource == gpu_tiles.size())
59+
gpu_packed_tile = tile;
60+
else
61+
gpu_tiles[tile.subresource][tile.pos] = tile;
62+
}
63+
}
64+
}
65+
4766
public:
4867
ComPtr<ID3D12Resource> m_Resource;
4968
ResourceHandle alloc_handle;
@@ -59,6 +78,7 @@ namespace DX12
5978
m_Resource = resource;
6079
}
6180

81+
6282
TrackedResource(ComPtr<ID3D12Resource> resource) :m_Resource(resource)
6383
{
6484
}

sources/DirectXFramework/DX12/Tiling.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ namespace DX12 {
228228
// UINT first_sub_res;
229229
D3D12_SUBRESOURCE_TILING tilings[20];
230230

231-
auto desc = static_cast<Resource*>(this)->get_desc();
231+
auto resource = static_cast<Resource*>(this);
232232

233-
Device::get().get_native_device()->GetResourceTiling(static_cast<Resource*>(this)->get_native().Get(), &num_tiles, &mip_info, &tile_shape, &num_sub_res, 0, tilings);
233+
auto desc = resource->get_desc();
234+
235+
Device::get().get_native_device()->GetResourceTiling(resource->get_native().Get(), &num_tiles, &mip_info, &tile_shape, &num_sub_res, 0, tilings);
234236
packed_mip_count = mip_info.NumTilesForPackedMips;
235237
packed_subresource_offset = mip_info.NumStandardMips;
236238
unpacked_mip_count = mip_info.NumStandardMips;
@@ -246,16 +248,16 @@ namespace DX12 {
246248
for (uint x = 0; x < tiles[0].size().x; x++)
247249
tiles[0][{x, 0, 0}].pos = { x,0,0 };
248250

249-
gpu_tiles.resize(1);
250-
gpu_tiles[0].resize(uint3(tilings[0].WidthInTiles, tilings[0].HeightInTiles, tilings[0].DepthInTiles));
251-
for (uint x = 0; x < gpu_tiles[0].size().x; x++)
252-
gpu_tiles[0][{x, 0, 0}].pos = { x,0,0 };
251+
resource->tracked_info->gpu_tiles.resize(1);
252+
resource->tracked_info->gpu_tiles[0].resize(uint3(tilings[0].WidthInTiles, tilings[0].HeightInTiles, tilings[0].DepthInTiles));
253+
for (uint x = 0; x < resource->tracked_info->gpu_tiles[0].size().x; x++)
254+
resource->tracked_info->gpu_tiles[0][{x, 0, 0}].pos = { x,0,0 };
253255

254256
}
255257
else
256258
{
257259
tiles.resize(mip_info.NumStandardMips);
258-
gpu_tiles.resize(mip_info.NumStandardMips);
260+
resource->tracked_info->gpu_tiles.resize(mip_info.NumStandardMips);
259261

260262
packed_tiles.pos = { 0,0,0 };
261263
packed_tiles.subresource = mip_info.NumStandardMips;
@@ -264,7 +266,7 @@ namespace DX12 {
264266
for (UINT i = 0; i < mip_info.NumStandardMips; i++)
265267
{
266268
tiles[i].resize(uint3(tilings[i].WidthInTiles, tilings[i].HeightInTiles, tilings[i].DepthInTiles));
267-
gpu_tiles[i].resize(uint3(tilings[i].WidthInTiles, tilings[i].HeightInTiles, tilings[i].DepthInTiles));
269+
resource->tracked_info->gpu_tiles[i].resize(uint3(tilings[i].WidthInTiles, tilings[i].HeightInTiles, tilings[i].DepthInTiles));
268270

269271
for (uint x = 0; x < tiles[i].size().x; x++)
270272
for (uint y = 0; y < tiles[i].size().y; y++)
@@ -274,8 +276,8 @@ namespace DX12 {
274276
tiles[i][{x, y, z}].pos = { x,y,z };
275277
tiles[i][{x, y, z}].subresource = i;
276278

277-
gpu_tiles[i][{x, y, z}].pos = { x,y,z };
278-
gpu_tiles[i][{x, y, z}].subresource = i;;
279+
resource->tracked_info->gpu_tiles[i][{x, y, z}].pos = { x,y,z };
280+
resource->tracked_info->gpu_tiles[i][{x, y, z}].subresource = i;;
279281
}
280282
}
281283
}

sources/DirectXFramework/DX12/Tiling.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,7 @@ namespace DX12
77

88
class TiledResourceManager
99
{
10-
std::vector<grid<uint3, ResourceTile>> gpu_tiles;
11-
ResourceTile gpu_packed_tile;
12-
public://for now
13-
void on_tile_update(const update_tiling_info& info)
14-
{
15-
for (auto& [heap, tiles] : info.tiles)
16-
{
17-
for (auto tile : tiles)
18-
{
19-
if (tile.subresource == packed_subresource_offset)
20-
gpu_packed_tile = tile;
21-
else
22-
gpu_tiles[tile.subresource][tile.pos] = tile;
23-
}
24-
}
25-
}
10+
2611
public://for now
2712
std::vector<grid<uint3, ResourceTile>> tiles;
2813

@@ -54,6 +39,10 @@ namespace DX12
5439
void load_tiles(CommandList* list, ivec3 from, ivec3 to, uint subres = 0);
5540
void zero_tiles(CommandList* list, ivec3 from, ivec3 to);
5641

42+
43+
template<std::ranges::view R>
44+
void load_tiles2(CommandList* list, R tiles, uint subres = 0, bool recursive=false);
45+
5746
void load_tiles(CommandList* list, std::list<ivec3>& tiles, uint subres = 0, bool recursive = false);
5847
void zero_tiles(CommandList* list, std::list<ivec3>& tiles);
5948
void zero_tiles(CommandList& list);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
namespace DX12
3+
{
4+
template<std::ranges::view R>
5+
void TiledResourceManager::load_tiles2(CommandList* list, R tiles, uint subres, bool recursive)
6+
{
7+
update_tiling_info info;
8+
info.resource = static_cast<Resource*>(this);
9+
10+
for (auto t : tiles)
11+
load_tile(info, t, subres, recursive);
12+
13+
14+
// TODO: make list
15+
if (list)
16+
{
17+
list->update_tilings(std::move(info));
18+
}
19+
else
20+
Device::get().get_queue(CommandListType::DIRECT)->update_tile_mappings(info);
21+
}
22+
23+
}

sources/DirectXFramework/SIG/RT.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RTHolder :public Table
5959
for (UINT i = 0; i < (UINT)compiled.table_rtv.get_count(); i++)
6060
{
6161
Render::Handle* handle = ptr + i;
62-
compiled.table_rtv[i].place(*handle, D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
62+
compiled.table_rtv[i].place(*handle);
6363

6464
//Render::Device::get().create_rtv(compiled.table_rtv[i], handle->resource_info->resource_ptr, handle->resource_info->rtv);
6565

@@ -75,7 +75,7 @@ class RTHolder :public Table
7575
for (UINT i = 0; i < (UINT)compiled.table_dsv.get_count(); i++)
7676
{
7777
Render::Handle* handle = ptr + i;
78-
compiled.table_dsv[i].place(*handle, D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
78+
compiled.table_dsv[i].place(*handle);
7979
}
8080
}
8181

0 commit comments

Comments
 (0)