Skip to content

Commit

Permalink
clusterizer: Remove redundant live_triangles buffer
Browse files Browse the repository at this point in the history
live_triangles can alias adjacency.counts as they always contain the same
data; this saves a little bit of memory and time.

The same optimization was applied to meshopt_optimizeVertexCache with
the same considerations in the past.
  • Loading branch information
zeux committed Jan 18, 2025
1 parent 64f031b commit bde7c19
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/clusterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ size_t meshopt_buildMeshlets(meshopt_Meshlet* meshlets, unsigned int* meshlet_ve
TriangleAdjacency2 adjacency = {};
buildTriangleAdjacency(adjacency, indices, index_count, vertex_count, allocator);

unsigned int* live_triangles = allocator.allocate<unsigned int>(vertex_count);
memcpy(live_triangles, adjacency.counts, vertex_count * sizeof(unsigned int));
// live triangle counts; note, we alias adjacency.counts as we remove triangles after emitting them so the counts always match
unsigned int* live_triangles = adjacency.counts;

size_t face_count = index_count / 3;

Expand Down Expand Up @@ -625,12 +625,9 @@ size_t meshopt_buildMeshlets(meshopt_Meshlet* meshlets, unsigned int* meshlet_ve
memset(&meshlet_cone_acc, 0, sizeof(meshlet_cone_acc));
}

live_triangles[a]--;
live_triangles[b]--;
live_triangles[c]--;

// remove emitted triangle from adjacency data
// this makes sure that we spend less time traversing these lists on subsequent iterations
// live triangle counts are updated as a byproduct of these adjustments
for (size_t k = 0; k < 3; ++k)
{
unsigned int index = indices[best_triangle * 3 + k];
Expand Down

0 comments on commit bde7c19

Please sign in to comment.