Skip to content

Commit

Permalink
Save yourself the trouble
Browse files Browse the repository at this point in the history
- Don't initialize instancers if they have 0 instances
- Never shrink the index pool
- Actually process recently allocated meshes to avoid growing the list
  forever
  • Loading branch information
Jozufozu committed Nov 9, 2024
1 parent 68453d8 commit 5b97a56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public Plan<RenderContext> createFramePlan() {
public void flush(LightStorage lightStorage, EnvironmentStorage environmentStorage) {
// Thread safety: flush is called from the render thread after all visual updates have been made,
// so there are no:tm: threads we could be racing with.
for (var instancer : initializationQueue) {
initialize(instancer.key(), instancer.instancer());
for (var init : initializationQueue) {
var instancer = init.instancer();
if (instancer.instanceCount() > 0) {
initialize(init.key(), instancer);
} else {
instancers.remove(init.key());
}
}
initializationQueue.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,17 @@ public void flush() {
if (anyToRemove) {
anyToRemove = false;
processDeletions();
}

// Might want to shrink the index pool if something was removed.
indexPool.reset();
for (PooledMesh mesh : meshList) {
indexPool.updateCount(mesh.mesh.indexSequence(), mesh.indexCount());
}
} else {
if (!recentlyAllocated.isEmpty()) {
// Otherwise, just update the index with the new counts.
for (PooledMesh mesh : recentlyAllocated) {
indexPool.updateCount(mesh.mesh.indexSequence(), mesh.indexCount());
}
indexPool.flush();
recentlyAllocated.clear();
}

// Always need to flush the index pool.
indexPool.flush();

uploadAll();
dirty = false;
}
Expand Down

0 comments on commit 5b97a56

Please sign in to comment.