Skip to content

Commit

Permalink
feat(compression): add descendant indices to topology metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrechette committed Jan 18, 2025
1 parent eed33bd commit a048ce1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
17 changes: 17 additions & 0 deletions includes/acl/compression/impl/topology_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ namespace acl
// Number of leaves beneath this transform (and present in the list above)
uint32_t num_leaves = 0;

// A list of descendant transform indices beneath this transform (points into 'aggregate_descendant_indices' in owner clip_topology_t)
// Descendants are sorted parent first
const uint32_t* descendants = nullptr;

// Number of descendants beneath this transform (and present in the list above)
uint32_t num_descendants = 0;

// Whether or not this transform is a leaf
bool is_leaf() const { return num_children == 0; }

Expand All @@ -72,6 +79,9 @@ namespace acl

// Returns a transform index iterator over the list of leaves
const_array_iterator<uint32_t> leaves_iterator() const;

// Returns a transform index iterator over the list of descendants
const_array_iterator<uint32_t> descendants_iterator() const;
};

// Topology metadata for a clip
Expand Down Expand Up @@ -118,6 +128,13 @@ namespace acl
// Size of global list of leaf indices
uint32_t num_aggregate_leaf_indices = 0;

// Global list of descendant indices
// Each transform contains a pointer into this list
uint32_t* aggregate_descendant_indices = nullptr;

// Size of global list of descendant indices
uint32_t num_aggregate_descendant_indices = 0;

// The allocator used for the topology metadata, never null if initialized
iallocator* allocator = nullptr;

Expand Down
54 changes: 54 additions & 0 deletions includes/acl/compression/impl/topology_metadata.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace acl
return make_iterator(leaves, num_leaves);
}

inline const_array_iterator<uint32_t> transform_topology_t::descendants_iterator() const
{
return make_iterator(descendants, num_descendants);
}

inline const_array_iterator<uint32_t> clip_topology_t::roots_first_iterator() const
{
return make_iterator(static_cast<const uint32_t*>(transform_indices_sorted_parent_first), num_transforms);
Expand All @@ -73,6 +78,7 @@ namespace acl
deallocate_type_array(*allocator, transform_indices_sorted_parent_first, num_transforms);
deallocate_type_array(*allocator, aggregate_children_indices, num_aggregate_children_indices);
deallocate_type_array(*allocator, aggregate_leaf_indices, num_aggregate_leaf_indices);
deallocate_type_array(*allocator, aggregate_descendant_indices, num_aggregate_descendant_indices);
}

inline void build_clip_topology(iallocator& allocator, const track_array_qvvf& track_list, clip_topology_t& out_topology)
Expand Down Expand Up @@ -221,6 +227,52 @@ namespace acl
std::sort(transform_indices_sorted_parent_first, transform_indices_sorted_parent_first + num_transforms, sort_predicate);
}

uint32_t num_aggregate_descendant_indices = 0;
uint32_t* aggregate_descendant_indices = nullptr;
{
// Find our descendants
for (uint32_t transform_index : make_iterator(transform_indices_sorted_parent_first, num_transforms))
{
uint32_t cursor_index = topology_per_transform[transform_index].parent_index;
while (cursor_index != k_invalid_track_index)
{
topology_per_transform[cursor_index].num_descendants++;
num_aggregate_descendant_indices++;

cursor_index = topology_per_transform[cursor_index].parent_index;
}
}

// Allocate the list of descendant indices and partition it among the transforms
aggregate_descendant_indices = allocate_type_array<uint32_t>(allocator, num_aggregate_descendant_indices);
uint32_t num_assigned_descendant_indices = 0;

for (uint32_t transform_index = 0; transform_index < num_transforms; ++transform_index)
{
topology_per_transform[transform_index].descendants = aggregate_descendant_indices + num_assigned_descendant_indices;
num_assigned_descendant_indices += topology_per_transform[transform_index].num_descendants;

// Reset the descendant count, we'll use it to write our indices below and repopulate it
topology_per_transform[transform_index].num_descendants = 0;
}

// Populate the list of descendants
for (uint32_t transform_index : make_iterator(transform_indices_sorted_parent_first, num_transforms))
{
uint32_t cursor_index = topology_per_transform[transform_index].parent_index;
while (cursor_index != k_invalid_track_index)
{
const ptrdiff_t indices_offset = topology_per_transform[cursor_index].descendants - aggregate_descendant_indices;
uint32_t* cursor_descendants = aggregate_descendant_indices + indices_offset;

cursor_descendants[topology_per_transform[cursor_index].num_descendants] = transform_index;
topology_per_transform[cursor_index].num_descendants++;

cursor_index = topology_per_transform[cursor_index].parent_index;
}
}
}

uint32_t num_max_leaves_per_transform = 0;
for (uint32_t root_index = 0; root_index < num_root_transforms; ++root_index)
{
Expand Down Expand Up @@ -252,6 +304,8 @@ namespace acl
out_topology.num_aggregate_children_indices = num_children_transforms;
out_topology.aggregate_leaf_indices = clip_leaf_indices;
out_topology.num_aggregate_leaf_indices = num_leaf_transform_indices;
out_topology.aggregate_descendant_indices = aggregate_descendant_indices;
out_topology.num_aggregate_descendant_indices = num_aggregate_descendant_indices;
out_topology.allocator = &allocator;
}
}
Expand Down
15 changes: 13 additions & 2 deletions tools/vs_visualizers/acl.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@
</Type>

<Type Name="acl::acl_impl::transform_topology_t">
<DisplayString Condition="num_children == 0">parent={parent_index}, num_children={num_children} (leaf)</DisplayString>
<DisplayString>parent={parent_index}, num_children={num_children}</DisplayString>
<DisplayString Condition="num_children == 0 &amp;&amp; parent_index == k_invalid_track_index">(root + leaf)</DisplayString>
<DisplayString Condition="num_children == 0">parent={parent_index} (leaf)</DisplayString>
<DisplayString Condition="parent_index == k_invalid_track_index">num_children={num_children}, num_descendants={num_descendants} (root)</DisplayString>
<DisplayString>parent={parent_index}, num_children={num_children}, num_descendants={num_descendants}</DisplayString>
<Expand>
<Item Name="parent_index">parent_index</Item>
<Item Name="depth_from_root">depth_from_root</Item>
Expand All @@ -205,6 +207,15 @@
</ArrayItems>
</Expand>
</Synthetic>
<Synthetic Name="descendants">
<DisplayString>count={num_descendants}</DisplayString>
<Expand>
<ArrayItems>
<Size>num_descendants</Size>
<ValuePointer>descendants</ValuePointer>
</ArrayItems>
</Expand>
</Synthetic>
</Expand>
</Type>

Expand Down

0 comments on commit a048ce1

Please sign in to comment.