Skip to content
Open
Show file tree
Hide file tree
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 Mar 28, 2026
ba08cfc
Add implementation report for BVH acceleration
rwydaegh Mar 28, 2026
198952f
Add BVH-accelerated visibility and compute_paths integration
rwydaegh Mar 28, 2026
8ea64d3
Vectorize active_triangles filtering in BVH functions
rwydaegh Mar 28, 2026
af61258
Add BVH registry for XLA FFI (Phase 2 foundation)
rwydaegh Mar 28, 2026
560c054
Update report with Phase 2 foundation progress
rwydaegh Mar 28, 2026
969f35d
Add XLA FFI for BVH queries inside JIT (Phase 2)
rwydaegh Mar 28, 2026
c5dbab3
Wire BVH FFI into compute_paths for all methods (Phase 3)
rwydaegh Mar 28, 2026
c6f3b34
Update report: Phase 2 and 3 complete
rwydaegh Mar 28, 2026
59e43cb
Rewrite report for final state (Phases 1-3 complete)
rwydaegh Mar 28, 2026
e1badd5
Fix empty BVH infinite loop and registry leak, improve SBR test
rwydaegh Mar 28, 2026
ae89ae4
Pass active_mask through BVH traversal instead of post-hoc filtering
rwydaegh Mar 28, 2026
5d92c7b
Remove implementation report (content moves to PR body)
rwydaegh Mar 28, 2026
5f1cc21
Add bvh parameter to all compute_paths overload signatures
rwydaegh Mar 28, 2026
a19c921
Make xla-ffi feature opt-in to fix CI build isolation
rwydaegh Mar 29, 2026
516be5d
Fix ruff lint, ruff format, and cargo fmt issues
rwydaegh Mar 29, 2026
b20361f
Fix CI: skip FFI tests without xla-ffi, add type stubs, fix lint
rwydaegh Mar 29, 2026
ed3319b
Add BVH benchmarks for CodSpeed and fix remaining CI issues
rwydaegh Mar 29, 2026
d718aa8
Fix nightly cargo fmt and typecheck issues
rwydaegh Mar 29, 2026
eaeb083
Fix ruff format on stub file and typecheck return type
rwydaegh Mar 29, 2026
c97a332
Add differt.accel to documentation reference
rwydaegh Mar 29, 2026
b84aee0
Fix CI: cargo fmt, Sphinx warnings, and MSRV compatibility
rwydaegh Mar 29, 2026
5279602
Retry CI (runner shutdown)
rwydaegh Mar 29, 2026
fd3b332
Add coverage tests for BVH acceleration
rwydaegh Mar 29, 2026
f9a6286
Fix MSRV check and pre-commit ty linter
rwydaegh Mar 29, 2026
22e1a9d
Fix ruff lint and cargo fmt
rwydaegh Mar 29, 2026
31378dc
Fix nightly rustfmt formatting in build.rs
rwydaegh Mar 29, 2026
a2b1859
Add differentiable BVH acceleration for compute_paths soft mode
rwydaegh Mar 30, 2026
d4b5191
Fix ty typecheck for smoothing_factor float conversion
rwydaegh Mar 30, 2026
ace4aca
Add coverage test for soft BVH branch and fix codespell
rwydaegh Mar 30, 2026
85b1f7c
Fix pre-commit (ruff, cargo fmt) and improve BVH test coverage
rwydaegh Mar 31, 2026
dc7f589
Fix nightly cargo fmt formatting
rwydaegh Mar 31, 2026
3e55d4e
Merge branch 'main' into feature/bvh-acceleration
jeertmans Apr 3, 2026
5f2b040
Address maintainer review comments on PR #406
rwydaegh Apr 10, 2026
b63becc
Fix build: keep xla-ffi optional, graceful JAX fallback in build.rs
rwydaegh Apr 10, 2026
128acd1
Fix jaxtyping runtime check: use flexible return type annotations
rwydaegh Apr 10, 2026
1a6cdae
Rename hard/soft to smoothing convention, clean up imports
rwydaegh Apr 10, 2026
f32b116
Fix batch_shape broadcasting bug in BVH wrappers
rwydaegh Apr 10, 2026
bc37452
Update __init__.py example to show BVH hit vs miss
rwydaegh Apr 13, 2026
bc7c1d7
Fix ruff formatting in __init__.py example
rwydaegh Apr 13, 2026
0b6fed3
Merge remote-tracking branch 'DiffeRT/main' into feature/bvh-accelera…
jeertmans Apr 16, 2026
338fe13
refactor(lib): re-organize structure and cleanup docs
jeertmans Apr 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions differt-core/Cargo.toml
Comment thread
jeertmans marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
harness = false
name = "bench_main"

[build-dependencies]
cxx-build = {version = ">=1.0,<1.0.178"}
pyo3-build-config = {version = "0.25"}

[dependencies]
cxx = {version = ">=1.0,<1.0.178"}
indexmap = {version = "2.5.0", features = ["serde"]}
log = "0.4"
nalgebra = "0.32.3"
Expand Down
60 changes: 60 additions & 0 deletions differt-core/build.rs
Comment thread
jeertmans marked this conversation as resolved.
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);
}
}
17 changes: 17 additions & 0 deletions differt-core/include/ffi.h
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);
4 changes: 3 additions & 1 deletion differt-core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = "maturin"
requires = ["maturin>=1.9.6,<2"]
requires = ["maturin>=1.9.6,<2", "jax>=0.8.1"]

[project]
authors = [
Expand Down Expand Up @@ -31,6 +31,8 @@ bindings = "pyo3"
features = ["pyo3/extension-module"]
include = [
{path = "src/**/*", format = "sdist"},
{path = "include/**/*", format = "sdist"},
{path = "build.rs", format = "sdist"},
{path = "LICENSE.md", format = "sdist"},
{path = "README.md", format = "sdist"},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from types import ModuleType
__version__: str
__version_info__: tuple[int, int, int]

accel: ModuleType
geometry: ModuleType
rt: ModuleType
scene: ModuleType
Empty file.
32 changes: 32 additions & 0 deletions differt-core/python/differt_core/_differt_core/accel/bvh.pyi
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: ...
1 change: 1 addition & 0 deletions differt-core/python/differt_core/accel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Acceleration structures for ray tracing."""
7 changes: 7 additions & 0 deletions differt-core/python/differt_core/accel/bvh.py
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
Loading
Loading