Repository navigation
Description
An Overlay of many regions has no Accelerate::BVH: a tape evaluates it as a plain union, and every region query loops over all regions. An assembly read as one region per part (the language's meshes() with a list in a region line, #259) is the case that needs it: the studio renders a RegionView of it.
Measured (2026-11-15)
NASA's gantry, 730 parts (rmrsk/meshes, Clean/STL/Binary/Gantry), through ebgstudio render at 800×500 on the host:
| Model | Frame |
|---|---|
bvh_union of the 730 parts |
0.6 s |
overlay with a region per part |
2.4 s |
F18 (67 parts) is still fine as a plain overlay: 1.1 s on the device and 3.0 s on the host at 1200×750, against 0.8 s and 0.7 s for its bvh_union.
What loops over every region
All in EBGeometry_TapeImplem.hpp:
region(p): the last region whose solid holds the point, by evaluating every region from the last down.signedDistance(p, region), the region's own functionmax(S_k, -min_{j>k} S_j): every later region.closestSurface(p, region): the same loop, tagged; for the background, every region.regionDistances(p, visit): every region's function. It is used byDomain::signedDistances()(a subdomain's function, what a solver reads) and byRegionView(itssignedDistance(), section fills, contours and domain samples).firstRegionChange()andfirstSurface(): at each crossing, every region from the current one on is traced.
The whole object's value, signedDistance(p) and the rays of the whole object, is a plain union of the operands too.
API
Approved at the checkpoint on 2026-11-15:
/**
* @brief Regions by priority, of any number of operands (see Overlay()), optionally through a BVH.
* @details The regions, their order and every value are those of Accelerate::None. With Accelerate::BVH, a Tape
* evaluates the whole object as a BVH union of the operands, and answers the region queries (region(),
* signedDistance(p, region), closestSurface(), firstRegionChange(), firstSurface(), ...) through a BVH over the
* operands' boxes, visiting only the regions near the point or the ray instead of every region.
* @param[in] a_operands The regions, in priority order (must not be empty).
* @param[in] a_accelerate Whether the tape answers through a BVH.
*/
template <class A>
[[nodiscard]] EBGEOMETRY_HOST
inline Expr<ExprPrecision<A>>
Overlay(const std::vector<A>& a_operands, Accelerate a_accelerate = Accelerate::None);- Operands: a BVH overlay's operands are plain solids only (maps allowed). A nested overlay, or a region clipped by a mask, aborts with a message; either can follow later.
- Language:
object overlay(bvh = true) { ... }, explicit likebvh_union. A large plain overlay prints a warning suggesting it, as a large plain union does. This is a small commit on the language stack once this lands onmain.
Design
- The BVH: a
PackedBVHof region numbers in the tape's pool, built when the tape is compiled, like a BVH union's (TapeDetail::UnionBVH). Each region's box is that of its operand under its maps. Regions with unbounded boxes go in a separate list that every query checks, as a BVH union does. region(p): a walk over the boxes holding the point, keeping the highest region whose solid holds it.signedDistance(p, k)andclosestSurface(p, k): only later regions near enough to decide matter. That means regions whose box holds the point when the point is outside region k, and otherwise those within |S_k|, with the bound shrinking as later regions are found.- The background's
closestSurface: a nearest-first search for the region whose solid comes nearest. - The rays: a walk over the region boxes along the ray, nearest first, bounded by the first crossing found.
- Values: exact wherever the regions' functions are distances. With operands that are only bounds, a value can be larger but keeps its sign and stays a bound, the same contract as
Union(..., Accelerate::BVH).
Open decision: regionDistances(). It hands every region's function to a caller that takes minima over sets of regions (subdomains, visible regions). Visiting every region exactly keeps today's cost for those functions. The proposal:
- visit the point's own region, and every region whose box lies within twice the distance to that region's own boundary;
- return that radius, and a set with no visited region counts as at least that far.
That makes a subdomain's function exact near every interface (where an EB code cuts cells, and where sections and contours are drawn), right in sign everywhere, and a distance bound far from interfaces. The point and ray queries above are not affected by this choice.
Testing and performance
- Unit tests: every query compared with the same overlay without the BVH, at random points and rays, for regions that overlap, touch and nest. Plus
[gpu]cases. - Probes:
hostdevicepairs forregion(), a subdomain's function and aRegionViewframe of a many-part overlay. - Device checks: the register and stack checks for the tape's ray and region kernels.
Status
Paused before any code, to work on the gantry and on seeing a union's parts first. A branch overlay-bvh off main (569fff8) is created, with no commits.
Related:
- A CSG language (.ebg) and ebgstudio: models at run time, live reload, and the setup written from the viewer #259: the language. Its
meshes()lists are on the stack, atcsg-languaged29bcd8. - Tape: a mesh in a tape traces and renders 2-6× slower than the mesh alone (inside queries, second pass, shadow rays, call depth) #255: a mesh in a tape as fast as the mesh alone. This is ordered after it.
- Roadmap: Roadmap: merge order of features #232.
Generated by Claude Code
Activity
rmrsk commentedon Nov 29, 2026
Status (2026-11-29): the language is frozen as
ebg 1(#384), with this issue's setting reserved:overlay(bvh = true|false)is accepted, validated (a Bool, set once) and held to #349's rules, then evaluated as a plain overlay until this lands:So landing #349 adds no syntax and breaks no
ebg 1file. What remains is the evaluation (aLanguage::Modelaccessor and theRegionBVHpath), still parked on the ptxas crash.