-
Notifications
You must be signed in to change notification settings - Fork 435
Clamp branching factor #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stefanatwork
wants to merge
6
commits into
master
Choose a base branch
from
sw/clamp_branching_factor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
357c7a5
Clamp Morton branching factor and add regression test
stefanatwork 55ca27c
Created regression test for morton builder clamp
stefanatwork 9d504af
Fixed regression test
stefanatwork f591cf3
Renamed paramters so they wouldn't shadow members
stefanatwork cbe7df2
Fixed indentation
stefanatwork 2b6ff51
Merge branch 'master' into sw/clamp_branching_factor
stefanatwork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,4 +105,3 @@ TEST_CASE("Minimal test", "[minimal]") | |
|
|
||
| REQUIRE(true); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright 2009-2021 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| add_executable(embree_regression_morton_builder_clamp morton_builder_clamp_regression.cpp) | ||
| target_link_libraries(embree_regression_morton_builder_clamp PRIVATE embree) | ||
| set_property(TARGET embree_regression_morton_builder_clamp PROPERTY FOLDER tests/regression) | ||
|
|
||
| if (BUILD_TESTING) | ||
| add_test(NAME regression_morton_builder_clamp COMMAND embree_regression_morton_builder_clamp) | ||
| endif() |
|
johguenther marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright 2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <embree4/rtcore.h> | ||
| #include <embree4/rtcore_builder.h> | ||
|
|
||
| #include <cassert> | ||
| #include <cstring> | ||
| #include <iostream> | ||
| #include <limits> | ||
| #include <vector> | ||
|
|
||
| constexpr unsigned int max_branching_factor = 8; | ||
|
|
||
| struct Node | ||
| { | ||
| Node() | ||
| { | ||
| for (unsigned int i = 0; i < max_branching_factor; ++i) | ||
| children[i] = nullptr; | ||
| } | ||
| virtual ~Node() = default; | ||
| Node *children[max_branching_factor]; | ||
| }; | ||
|
|
||
| static bool buildProgress(void * /*userPtr*/, double /*f*/) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| bool memoryMonitor(void * /*userPtr*/, ssize_t /*bytes*/, bool /*post*/) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| static void *createNode(RTCThreadLocalAllocator alloc, unsigned int childCount, void * /*userPtr*/) | ||
| { | ||
| assert(childCount <= max_branching_factor); | ||
| if (childCount > max_branching_factor) | ||
| return nullptr; | ||
|
|
||
| Node *node = (Node *)rtcThreadLocalAlloc(alloc, sizeof(Node), 16); | ||
| new (node) Node(); | ||
| return node; | ||
| } | ||
|
|
||
| static void setNodeChildren(void *nodePtr, void **children, unsigned int childCount, void * /*userPtr*/) | ||
| { | ||
| assert(childCount <= max_branching_factor); | ||
| if (childCount > max_branching_factor) | ||
| return; | ||
| Node *node = (Node *)nodePtr; | ||
| for (unsigned int i = 0; i < childCount; ++i) | ||
| node->children[i] = (Node *)children[i]; | ||
| } | ||
|
|
||
| static void setNodeBounds(void *nodePtr, const RTCBounds **bounds, unsigned int childCount, void * /*userPtr*/) | ||
| { | ||
| assert(childCount <= max_branching_factor); | ||
| /* deliberately empty in regression test */ | ||
| } | ||
|
|
||
| static void *createLeaf(RTCThreadLocalAllocator alloc, | ||
| const RTCBuildPrimitive *prims, | ||
| size_t primCount, | ||
| void * /*userPtr*/) | ||
| { | ||
|
|
||
| Node *node = (Node *)rtcThreadLocalAlloc(alloc, sizeof(Node), 16); | ||
| new (node) Node(); | ||
| return node; | ||
| } | ||
|
|
||
| static std::vector<RTCBuildPrimitive> makeGridPrimitives(size_t primitiveCount) | ||
| { | ||
| std::vector<RTCBuildPrimitive> prims(primitiveCount); | ||
| for (size_t i = 0; i < primitiveCount; ++i) | ||
| { | ||
| const float x = float(i % 32); | ||
| const float y = float((i / 32) % 32); | ||
|
|
||
| RTCBuildPrimitive p{}; | ||
| p.lower_x = x * 2.0f; | ||
| p.lower_y = y * 2.0f; | ||
| p.lower_z = 0.0f; | ||
| p.upper_x = p.lower_x + 0.5f; | ||
| p.upper_y = p.lower_y + 0.5f; | ||
| p.upper_z = 0.5f; | ||
| p.geomID = 0; | ||
| p.primID = (unsigned int)i; | ||
| prims[i] = p; | ||
| } | ||
| return prims; | ||
| } | ||
|
|
||
| static bool runCase(unsigned int maxBranchingFactor) | ||
| { | ||
| RTCDevice device = rtcNewDevice(nullptr); | ||
| if (device == nullptr) | ||
| return false; | ||
|
|
||
| RTCBVH bvh = rtcNewBVH(device); | ||
| if (bvh == nullptr) | ||
| { | ||
| rtcReleaseDevice(device); | ||
| return false; | ||
| } | ||
|
|
||
| std::vector<RTCBuildPrimitive> prims = makeGridPrimitives(1024); | ||
|
|
||
| RTCBuildArguments args = rtcDefaultBuildArguments(); | ||
| args.byteSize = sizeof(args); | ||
| args.buildQuality = RTC_BUILD_QUALITY_LOW; | ||
| args.maxBranchingFactor = maxBranchingFactor; | ||
| args.maxDepth = 1024; | ||
| args.minLeafSize = 1; | ||
| args.maxLeafSize = 1; | ||
| args.bvh = bvh; | ||
| args.primitives = prims.data(); | ||
| args.primitiveCount = prims.size(); | ||
| args.primitiveArrayCapacity = prims.size(); | ||
| args.createNode = createNode; | ||
| args.setNodeChildren = setNodeChildren; | ||
| args.setNodeBounds = setNodeBounds; | ||
| args.createLeaf = createLeaf; | ||
| args.buildProgress = buildProgress; | ||
|
|
||
| void *root = rtcBuildBVH(&args); | ||
|
|
||
| rtcReleaseBVH(bvh); | ||
| rtcReleaseDevice(device); | ||
| return root != nullptr; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| /* In the failure case, this test should assert or result in a segfault from stack overflow. */ | ||
|
|
||
| bool okOversized = runCase(64); | ||
| bool okExtreme = runCase(std::numeric_limits<unsigned int>::max()); | ||
|
|
||
| if (!okOversized) | ||
| std::cerr << "Morton clamp regression failed for maxBranchingFactor=64\n"; | ||
| if (!okExtreme) | ||
| std::cerr << "Morton clamp regression failed for maxBranchingFactor=UINT_MAX\n"; | ||
|
|
||
| std::cout << "Morton clamp regression test completed.\n"; | ||
| return (okOversized && okExtreme) ? 0 : 1; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.