@@ -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+
0 commit comments