Skip to content

Clamp branching factor#611

Open
stefanatwork wants to merge 6 commits into
masterfrom
sw/clamp_branching_factor
Open

Clamp branching factor#611
stefanatwork wants to merge 6 commits into
masterfrom
sw/clamp_branching_factor

Conversation

@stefanatwork

Copy link
Copy Markdown
Collaborator

Limiting the branching factor of the standalone BVH builder.

stefanatwork and others added 2 commits July 6, 2026 16:16
Clamp BVHBuilderMorton settings to MAX_BRANCHING_FACTOR when an oversized maxBranchingFactor is provided via RTCBuildArguments.\n\nAdd an integration test that exercises rtcBuildBVH with RTC_BUILD_QUALITY_LOW and maxBranchingFactor=64 to verify the Morton build path returns a valid root.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stefanatwork stefanatwork added this to the 4.4.2 milestone Jul 9, 2026
@stefanatwork stefanatwork self-assigned this Jul 9, 2026
@stefanatwork
stefanatwork marked this pull request as draft July 9, 2026 11:11

@johguenther johguenther left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just some questions/comments

  • the regression test does nowhere check whether children are <=8 (MAX_BRANCHING_FACTOR), so basically without the fix, the builder would crash (stack overflow)? But what if maxBranchingFactor is set to 9 without the fix / clamp, it may not crash (just slightly above the limit), just be corrupt?
  • needs un-draft and should be squashed

Comment thread tests/CMakeLists.txt Outdated

@johguenther johguenther left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

actually, embree_regression_morton_builder_clamp already crashes (without modifications)

Comment thread tests/regression/morton_builder_clamp_regression.cpp
Comment thread kernels/builders/bvh_builder_morton.h
@stefanatwork
stefanatwork marked this pull request as ready for review July 15, 2026 22:18
@stefanatwork
stefanatwork requested a review from johguenther July 15, 2026 22:18

@johguenther johguenther left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • test passes, good
  • when I remove the fix (clamp branching in builder), the test segfaults (expected, but a fail would be better)
  • when I now reduce test requested branching to 6 via runCase(6), the test still segfaults, bad (segfault is in embree/kernels/common/alloc.h:517 all slotMutex[] are nullptr, called by morton_builder_clamp_regression.cpp:createLeaf()->rtcThreadLocalAlloc())

I'd recommend to replace the asserts by std::throw and remove all other code which allocates or writes to memory. This way the regression test does not depend on asserts being compiled and the thrown exception (in case of a regression) is handled by the test framework (then failing properly instead of crashing -- at least not crashing in the test, but maybe in the builder).

the new file morton_builder_clamp_regression.cpp still needs clang-formated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants