Skip to content

Commit dc29d2e

Browse files
committed
more tiling update
1 parent 212fc83 commit dc29d2e

34 files changed

+780
-257
lines changed

sources/DirectXFramework/DX12/CommandList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ namespace DX12
895895
base.get_native_list()->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
896896
}
897897

898-
void CopyContext::copy_texture(const Resource::ptr& from, ivec3 from_pos, const Resource::ptr& to, ivec3 to_pos, ivec3 size)
898+
void CopyContext::copy_texture( const Resource::ptr& to, ivec3 to_pos, const Resource::ptr& from, ivec3 from_pos, ivec3 size)
899899
{
900900
if (base.type != CommandListType::COPY) {
901901
base.transition(from, Render::ResourceState::COPY_SOURCE);

sources/DirectXFramework/DX12/Memory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ namespace DX12
174174
ResourceHandle handle;
175175
ResourceHeap::ptr heap;
176176
UINT offset;
177+
UINT count = 1;
177178
};
178179
enum class TileState : int
179180
{
@@ -242,18 +243,19 @@ namespace DX12
242243
return creator->alloc(size, alignment);
243244
}
244245

245-
TileHeapPosition create_tile(D3D12_HEAP_FLAGS flags, HeapType type)
246+
TileHeapPosition create_tile(D3D12_HEAP_FLAGS flags, HeapType type, UINT count = 1)
246247
{
247248
static const size_t TileSize = 64 * 1024_t;
248249

249-
auto handle = alloc(TileSize, TileSize, flags, type);
250+
auto handle = alloc(count*TileSize, TileSize, flags, type);
250251

251252
TileHeapPosition result;
252253

253254
result.offset = handle.get_offset() / (64 * 1024);
254255
result.heap = handle.get_heap();
255256

256257
result.handle = handle;
258+
result.count = count;
257259
return result;
258260
}
259261

sources/DirectXFramework/DX12/Queue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace DX12
207207
TRS.Width = 1;
208208
TRS.Height = 1;
209209
TRS.Depth = 1;
210-
TRS.NumTiles = TRS.Width * TRS.Height * TRS.Depth;
210+
TRS.NumTiles = tile.heap_position.count;
211211

212212
startCoordinates.push_back(TRC);
213213
regionSizes.push_back(TRS);
@@ -252,7 +252,7 @@ namespace DX12
252252
source.Subresource = infos.source_subres;
253253

254254
D3D12_TILE_REGION_SIZE TRS;
255-
TRS.UseBox = false;
255+
TRS.UseBox = true;
256256
TRS.Width = infos.size.x;
257257
TRS.Height = infos.size.y;
258258
TRS.Depth = infos.size.z;

sources/DirectXFramework/DX12/Tiling.cpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ namespace DX12 {
1919
tile.heap_position = ResourceHeapPageManager::get().create_tile(alloc_info.flags, HeapType::DEFAULT);
2020
target.add_tile(tile);
2121
on_load(ivec4(pos,subres));
22-
if (recursive && subres != tiles.size() - 1)
22+
if (recursive )
2323
{
24-
load_tile(target, pos / 2, subres + 1, recursive);
24+
if (subres != tiles.size() - 1)
25+
{
26+
load_tile(target, pos / 2, subres + 1, recursive);
27+
}
28+
else
29+
{
30+
load_packed(target);
31+
}
2532
}
2633
}
2734
}
@@ -48,7 +55,7 @@ namespace DX12 {
4855

4956
auto is_mapped = [&](ivec3 pos) {
5057

51-
if (math::all(pos > ivec3(0,0,0)) && math::all(pos < tiles[subres].size()))
58+
if (math::all(pos >= ivec3(0,0,0)) && math::all(pos < tiles[subres].size()))
5259
{
5360
return !!tiles[subres][pos].heap_position.heap;
5461
}
@@ -206,6 +213,7 @@ namespace DX12 {
206213
ivec3 TiledResourceManager::get_tiles_count(int mip_level)
207214
{
208215
return tiles[mip_level].size();
216+
209217
}
210218
ivec3 TiledResourceManager::get_tile_shape()
211219
{
@@ -223,9 +231,12 @@ namespace DX12 {
223231
auto desc = static_cast<Resource*>(this)->get_desc();
224232

225233
Device::get().get_native_device()->GetResourceTiling(static_cast<Resource*>(this)->get_native().Get(), &num_tiles, &mip_info, &tile_shape, &num_sub_res, 0, tilings);
226-
234+
packed_mip_count = mip_info.NumTilesForPackedMips;
235+
packed_subresource_offset = mip_info.NumStandardMips;
236+
unpacked_mip_count = mip_info.NumStandardMips;
227237
if (num_tiles > 0)
228238
{
239+
229240
this->tile_shape = { tile_shape.WidthInTexels,tile_shape.HeightInTexels,tile_shape.DepthInTexels };
230241

231242
if (desc.Dimension == D3D12_RESOURCE_DIMENSION::D3D12_RESOURCE_DIMENSION_BUFFER)
@@ -245,6 +256,11 @@ namespace DX12 {
245256
{
246257
tiles.resize(mip_info.NumStandardMips);
247258
gpu_tiles.resize(mip_info.NumStandardMips);
259+
260+
packed_tiles.pos = { 0,0,0 };
261+
packed_tiles.subresource = mip_info.NumStandardMips;
262+
263+
248264
for (UINT i = 0; i < mip_info.NumStandardMips; i++)
249265
{
250266
tiles[i].resize(uint3(tilings[i].WidthInTiles, tilings[i].HeightInTiles, tilings[i].DepthInTiles));
@@ -266,4 +282,38 @@ namespace DX12 {
266282

267283
}
268284
}
269-
}
285+
286+
287+
void TiledResourceManager::load_packed(CommandList& list)
288+
{
289+
if (packed_mip_count)
290+
{
291+
update_tiling_info info;
292+
info.resource = static_cast<Resource*>(this);
293+
auto& alloc_info = static_cast<Resource*>(this)->alloc_info;
294+
295+
if (!packed_tiles.heap_position.heap)
296+
packed_tiles.heap_position = ResourceHeapPageManager::get().create_tile(alloc_info.flags, HeapType::DEFAULT, packed_mip_count);
297+
298+
info.add_tile(packed_tiles);
299+
300+
list.update_tilings(std::move(info));
301+
}
302+
}
303+
304+
void TiledResourceManager::load_packed(update_tiling_info& info)
305+
{
306+
307+
if (packed_mip_count)
308+
{
309+
auto& alloc_info = static_cast<Resource*>(this)->alloc_info;
310+
311+
if (!packed_tiles.heap_position.heap)
312+
packed_tiles.heap_position = ResourceHeapPageManager::get().create_tile(alloc_info.flags, HeapType::DEFAULT, packed_mip_count);
313+
314+
info.add_tile(packed_tiles);
315+
}
316+
}
317+
}
318+
319+

sources/DirectXFramework/DX12/Tiling.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@ namespace DX12
88
class TiledResourceManager
99
{
1010
std::vector<grid<uint3, ResourceTile>> gpu_tiles;
11+
ResourceTile gpu_packed_tile;
1112
public://for now
1213
void on_tile_update(const update_tiling_info& info)
1314
{
1415
for (auto& [heap, tiles] : info.tiles)
1516
{
1617
for (auto tile : tiles)
1718
{
18-
gpu_tiles[tile.subresource][tile.pos] = tile;
19+
if (tile.subresource == packed_subresource_offset)
20+
gpu_packed_tile = tile;
21+
else
22+
gpu_tiles[tile.subresource][tile.pos] = tile;
1923
}
2024
}
2125
}
2226
public://for now
2327
std::vector<grid<uint3, ResourceTile>> tiles;
28+
29+
ResourceTile packed_tiles;
30+
UINT packed_mip_count;
31+
UINT unpacked_mip_count;
32+
33+
UINT packed_subresource_offset = 0;
2434
protected:
2535
ivec3 tile_shape;
2636
//virtual ComPtr<ID3D12Resource>& get_d3d_resource() = 0;
@@ -34,6 +44,9 @@ namespace DX12
3444
void zero_tile(update_tiling_info& target, ivec3 pos, uint subres);
3545
void copy_mappings(update_tiling_info& target, ivec3 target_pos, TiledResourceManager* source, ivec3 source_pos, ivec3 size);
3646

47+
void load_packed(update_tiling_info& target);
48+
49+
3750
ivec3 get_tiles_count(int mip_level = 0);
3851
ivec3 get_tile_shape();
3952
void map_buffer_part( size_t offset, size_t size);
@@ -53,7 +66,12 @@ namespace DX12
5366
void copy_mappings(CommandList& list, ivec3 target_pos, TiledResourceManager* source, ivec3 source_pos, ivec3 size);
5467

5568
void map_tile(update_tiling_info&, ivec3 target_pos, TileHeapPosition pos);
69+
70+
71+
void load_packed(CommandList& list);
72+
5673
Events::Event<uint4> on_load;
5774
Events::Event<uint4> on_zero;
75+
5876
};
5977
}

sources/RenderSystem/Effects/VoxelGI/VoxelGI.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ class VoxelGI :public Events::prop_handler, public FrameGraphGenerator
199199
std::shared_ptr<GBufferDownsampler> downsampler;
200200

201201
VisibilityBufferUniversal::ptr visibility;
202-
202+
203+
IndirectCommand dispatch_command;
203204

204205
TileDynamicGenerator dynamic_generator_voxelizing;
205206
TileDynamicGenerator dynamic_generator_lighted;
@@ -237,6 +238,7 @@ class VoxelGI :public Events::prop_handler, public FrameGraphGenerator
237238
ivec3 lighed_to_albedo_coeff;
238239
std::vector<GPUTilesBuffer::ptr> gpu_tiles_buffer;
239240

241+
GPUTilesBuffer::ptr albedo_tiles;
240242

241243
Texture3DMultiTiles albedo;
242244
Texture3DMultiTiles normal;

0 commit comments

Comments
 (0)