Skip to content

Add Rightmost-Leaf Pruning to LBVH Traversal#222

Merged
zfergus merged 3 commits intomainfrom
accelerate-triangular-lbvh-traversal
Mar 9, 2026
Merged

Add Rightmost-Leaf Pruning to LBVH Traversal#222
zfergus merged 3 commits intomainfrom
accelerate-triangular-lbvh-traversal

Conversation

@zfergus
Copy link
Member

@zfergus zfergus commented Mar 8, 2026

Description

Use RightmostLeaves to skip subtrees fully left of a query during triangular (self-collision) traversal. Propagate the structure through init_bvh, traversal routines (including SIMD), detect_candidates, and clear(). Also, adjust attempt_add_candidate and add a benchmark test for edge-edge candidate detection.

This results in an 39% average speed-up in edge-edge traversal on benchmark scenes.

Scene # of Edges No Culling Culling Units Speed Up Percentage Improvement
Two cubes 720 119.171 87.1564 us 1.37 36.73%
Cloth-Ball 138825 47.2463 33.4936 ms 1.41 41.06%
Armadillo-Rollers 36363 34.7264 23.6737 ms 1.47 46.69%
Cloth-Funnel 27930 2.24412 1.39076 ms 1.61 61.36%
N-Body-Simulation 219840 122.811 94.2476 ms 1.30 30.31%
Rod-Twist 119796 25.2183 19.069 ms 1.32 32.25%
Puffer-Ball 1596324 1167.62 960.819 ms 1.22 21.52%
          Average: 38.56%

🐛 OGC Edge-Edge Feasibility

Also, fix three bugs in the OGC feasibility of an edge-edge pair.

Type of change

  • Enhancement (non-breaking change which improves existing functionality)

Use RightmostLeaves to skip subtrees fully left of a query during
triangular (self-collision) traversal. Propagate the structure through
init_bvh, traversal routines (including SIMD), detect_candidates, and
clear(). Also adjust attempt_add_candidate and add a benchmark test for
edge-edge candidate detection.
Copilot AI review requested due to automatic review settings March 8, 2026 22:36
@zfergus zfergus added the enhancement New feature or request label Mar 8, 2026
@zfergus zfergus added this to the v1.6.0 milestone Mar 8, 2026
@zfergus zfergus changed the title Add Rightmost-Leaf Tracking to LBVH Add Rightmost-Leaf Pruning to LBVH Traversal Mar 8, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces “rightmost leaf” metadata in the LBVH to accelerate triangular/self-collision traversal by pruning subtrees that are entirely left of the current query leaf, and wires that data through BVH construction, traversal (including SIMD), candidate detection, and clear(). It also adds a Catch2 benchmark for edge-edge candidate detection on several benchmark scenes.

Changes:

  • Add RightmostLeaves storage to LBVH and compute/populate it during init_bvh().
  • Use rightmost_leaves during triangular traversal to cull subtrees and remove the old (i >= j) triangular filter in attempt_add_candidate().
  • Add a new Catch2 benchmark test case for LBVH::detect_edge_edge_candidates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tests/src/tests/broad_phase/test_lbvh.cpp Adds a new benchmark test case for edge-edge candidate detection.
src/ipc/broad_phase/lbvh.hpp Extends the LBVH API/data members to carry RightmostLeaves and updates traversal/detection signatures.
src/ipc/broad_phase/lbvh.cpp Computes RightmostLeaves, uses it for triangular pruning in scalar/SIMD traversal, and clears the new buffers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

zfergus added 2 commits March 8, 2026 20:22
Correct vertex indices passed to point_edge_closest_point and
check_vertex_feasible_region in is_edge_edge_feasible. Previously the
EA/EB vertex arguments were swapped, causing incorrect closest-point
computations and feasibility checks
@zfergus zfergus added the bug Something isn't working label Mar 9, 2026
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.20%. Comparing base (746916e) to head (6a325e3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/ipc/broad_phase/lbvh.cpp 97.22% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #222   +/-   ##
=======================================
  Coverage   97.20%   97.20%           
=======================================
  Files         160      160           
  Lines       24906    24926   +20     
  Branches      897      899    +2     
=======================================
+ Hits        24209    24229   +20     
  Misses        697      697           
Flag Coverage Δ
unittests 97.20% <97.43%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zfergus zfergus merged commit e67f802 into main Mar 9, 2026
21 checks passed
@zfergus zfergus deleted the accelerate-triangular-lbvh-traversal branch March 9, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants