-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(lib): add BVH acceleration #406
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
rwydaegh
wants to merge
42
commits into
jeertmans:main
Choose a base branch
from
rwydaegh:feature/bvh-acceleration
base: main
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.
+3,755
−26
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
5784cff
Add BVH acceleration structure for ray-triangle intersection
rwydaegh ba08cfc
Add implementation report for BVH acceleration
rwydaegh 198952f
Add BVH-accelerated visibility and compute_paths integration
rwydaegh 8ea64d3
Vectorize active_triangles filtering in BVH functions
rwydaegh af61258
Add BVH registry for XLA FFI (Phase 2 foundation)
rwydaegh 560c054
Update report with Phase 2 foundation progress
rwydaegh 969f35d
Add XLA FFI for BVH queries inside JIT (Phase 2)
rwydaegh c5dbab3
Wire BVH FFI into compute_paths for all methods (Phase 3)
rwydaegh c6f3b34
Update report: Phase 2 and 3 complete
rwydaegh 59e43cb
Rewrite report for final state (Phases 1-3 complete)
rwydaegh e1badd5
Fix empty BVH infinite loop and registry leak, improve SBR test
rwydaegh ae89ae4
Pass active_mask through BVH traversal instead of post-hoc filtering
rwydaegh 5d92c7b
Remove implementation report (content moves to PR body)
rwydaegh 5f1cc21
Add bvh parameter to all compute_paths overload signatures
rwydaegh a19c921
Make xla-ffi feature opt-in to fix CI build isolation
rwydaegh 516be5d
Fix ruff lint, ruff format, and cargo fmt issues
rwydaegh b20361f
Fix CI: skip FFI tests without xla-ffi, add type stubs, fix lint
rwydaegh ed3319b
Add BVH benchmarks for CodSpeed and fix remaining CI issues
rwydaegh d718aa8
Fix nightly cargo fmt and typecheck issues
rwydaegh eaeb083
Fix ruff format on stub file and typecheck return type
rwydaegh c97a332
Add differt.accel to documentation reference
rwydaegh b84aee0
Fix CI: cargo fmt, Sphinx warnings, and MSRV compatibility
rwydaegh 5279602
Retry CI (runner shutdown)
rwydaegh fd3b332
Add coverage tests for BVH acceleration
rwydaegh f9a6286
Fix MSRV check and pre-commit ty linter
rwydaegh 22e1a9d
Fix ruff lint and cargo fmt
rwydaegh 31378dc
Fix nightly rustfmt formatting in build.rs
rwydaegh a2b1859
Add differentiable BVH acceleration for compute_paths soft mode
rwydaegh d4b5191
Fix ty typecheck for smoothing_factor float conversion
rwydaegh ace4aca
Add coverage test for soft BVH branch and fix codespell
rwydaegh 85b1f7c
Fix pre-commit (ruff, cargo fmt) and improve BVH test coverage
rwydaegh dc7f589
Fix nightly cargo fmt formatting
rwydaegh 3e55d4e
Merge branch 'main' into feature/bvh-acceleration
jeertmans 5f2b040
Address maintainer review comments on PR #406
rwydaegh b63becc
Fix build: keep xla-ffi optional, graceful JAX fallback in build.rs
rwydaegh 128acd1
Fix jaxtyping runtime check: use flexible return type annotations
rwydaegh 1a6cdae
Rename hard/soft to smoothing convention, clean up imports
rwydaegh f32b116
Fix batch_shape broadcasting bug in BVH wrappers
rwydaegh bc37452
Update __init__.py example to show BVH hit vs miss
rwydaegh bc7c1d7
Fix ruff formatting in __init__.py example
rwydaegh 0b6fed3
Merge remote-tracking branch 'DiffeRT/main' into feature/bvh-accelera…
jeertmans 338fe13
refactor(lib): re-organize structure and cleanup docs
jeertmans 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
|
jeertmans 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,60 @@ | ||
| /// Build script for differt-core. | ||
| /// | ||
| /// 1. Queries JAX for XLA FFI header locations | ||
| /// 2. Compiles the C++ FFI shim via cxx-build | ||
| use std::process::exit; | ||
|
|
||
| fn main() { | ||
| // Only build FFI when the feature is enabled | ||
| use std::{env, path::PathBuf, str::from_utf8}; | ||
|
|
||
| // Find the Python interpreter: | ||
| // 1. PYTHON env var (covers VIRTUAL_ENV and explicit overrides) | ||
| // 2. pyo3_build_config: the interpreter pyo3 itself was built against | ||
| // 3. Fall back to "python3" | ||
| let python = env::var("PYTHON") | ||
| .ok() | ||
| .or_else(|| pyo3_build_config::get().executable.clone()) | ||
| .unwrap_or_else(|| "python3".to_owned()); | ||
|
|
||
| // Query JAX for its XLA FFI include directory | ||
| let output = std::process::Command::new(&python) | ||
| .args([ | ||
| "-c", | ||
| "from jax.ffi import include_dir; print(include_dir())", | ||
| ]) | ||
| .output(); | ||
|
|
||
| let include_path = match output { | ||
| Ok(ref out) if out.status.success() => { | ||
| let path = from_utf8(&out.stdout) | ||
| .expect("Invalid UTF-8 from JAX include_dir()") | ||
| .trim() | ||
| .to_string(); | ||
| if path.is_empty() { | ||
| None | ||
| } else { | ||
| Some(PathBuf::from(path)) | ||
| } | ||
| }, | ||
| _ => None, | ||
| }; | ||
|
|
||
| if let Some(include_path) = include_path { | ||
| println!("cargo:rerun-if-changed=src/ffi.cc"); | ||
| println!("cargo:rerun-if-changed=include/ffi.h"); | ||
|
|
||
| cxx_build::bridge("src/accel/ffi.rs") | ||
| .file("src/ffi.cc") | ||
| .std("c++17") | ||
| .include(&include_path) | ||
| .include("include") | ||
| .compile("differt-ffi"); | ||
| } else { | ||
| println!( | ||
| "cargo:error=JAX not found or missing jax.ffi.include_dir(). Python interpreter used: \ | ||
| {python}" | ||
| ); | ||
| exit(1); | ||
| } | ||
| } |
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,17 @@ | ||
| #pragma once | ||
|
|
||
| #include "xla/ffi/api/ffi.h" | ||
|
|
||
| // BVH nearest-hit: for each ray, find the closest active triangle. | ||
| // Inputs: ray_origins [num_rays, 3], ray_directions [num_rays, 3], | ||
| // active_mask [num_triangles] (PRED, or [0] for no mask) | ||
| // Attrs: bvh_id (u64) | ||
| // Outputs: hit_indices [num_rays] (i32), hit_t [num_rays] (f32) | ||
| extern "C" XLA_FFI_Error *BvhNearestHit(XLA_FFI_CallFrame *call_frame); | ||
|
|
||
| // BVH get-candidates: for each ray, find candidate triangles with expanded AABBs. | ||
| // Inputs: ray_origins [num_rays, 3], ray_directions [num_rays, 3] | ||
| // Attrs: bvh_id (u64), expansion (f32), max_candidates (i32) | ||
| // Outputs: candidate_indices [num_rays, max_candidates] (i32), | ||
| // candidate_counts [num_rays] (i32) | ||
| extern "C" XLA_FFI_Error *BvhGetCandidates(XLA_FFI_CallFrame *call_frame); |
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
Empty file.
32 changes: 32 additions & 0 deletions
32
differt-core/python/differt_core/_differt_core/accel/bvh.pyi
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,32 @@ | ||
| import numpy as np | ||
| from jaxtyping import Float, Int | ||
|
|
||
| class TriangleBvh: | ||
| def __init__( | ||
| self, triangle_vertices: Float[np.ndarray, "num_triangles 9"] | ||
| ) -> None: ... | ||
| @property | ||
| def num_triangles(self) -> int: ... | ||
| @property | ||
| def num_nodes(self) -> int: ... | ||
| def register(self) -> int: ... | ||
| def unregister(self) -> None: ... | ||
| def nearest_hit( | ||
| self, | ||
| ray_origins: Float[np.ndarray, "num_rays 3"], | ||
| ray_directions: Float[np.ndarray, "num_rays 3"], | ||
| active_mask: np.ndarray | None = None, | ||
| ) -> tuple[Int[np.ndarray, " num_rays"], Float[np.ndarray, " num_rays"]]: ... | ||
| def get_candidates( | ||
| self, | ||
| ray_origins: Float[np.ndarray, "num_rays 3"], | ||
| ray_directions: Float[np.ndarray, "num_rays 3"], | ||
| expansion: float = 0.0, | ||
| max_candidates: int = 256, | ||
| ) -> tuple[ | ||
| Int[np.ndarray, "num_rays max_candidates"], | ||
| Int[np.ndarray, " num_rays"], | ||
| ]: ... | ||
|
|
||
| def bvh_nearest_hit_capsule() -> object: ... | ||
| def bvh_get_candidates_capsule() -> object: ... |
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 @@ | ||
| """Acceleration structures for ray tracing.""" |
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,7 @@ | ||
| __all__ = ("TriangleBvh",) | ||
|
|
||
| from differt_core import _differt_core | ||
|
|
||
| TriangleBvh = _differt_core.accel.bvh.TriangleBvh | ||
| bvh_nearest_hit_capsule = _differt_core.accel.bvh.bvh_nearest_hit_capsule | ||
| bvh_get_candidates_capsule = _differt_core.accel.bvh.bvh_get_candidates_capsule |
Oops, something went wrong.
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.