Implement support for triangulated volumes in simphony#333
Open
ggalgoczi wants to merge 2 commits into
Open
Conversation
Adds the wiring needed so triangulated solids (forced via `stree__force_triangulate_solid`) traverse the OptiX builtin triangle BVH inside the same IAS as the analytic CSG GAS. * PIP.cc: enable `OPTIX_PRIMITIVE_TYPE_FLAGS_TRIANGLE` alongside `_CUSTOM` in `usesPrimitiveTypeFlags`; create a second hitgroup program group `hitgroup_pg_tri` with `entryFunctionNameIS = nullptr` (OptiX 9 requires no IS program for triangle hitgroups). Both PGs are passed to `optixPipelineCreate` and accumulated in `configureStack`. * PIP.h: declare `hitgroup_pg_tri` alongside the existing analytic PG. * SBT.cc: `createHitgroup` now packs each record header with the PG matching its GAS kind (`hitgroup_pg_tri` when `isSolidTrimesh(gas_idx)`, `hitgroup_pg` otherwise) instead of using a single PG for all records. The TriMesh HitGroupData layout (`Binding.h`), the triangle build input (`SOPTIX_BuildInput_Mesh`), and the `__closesthit__ch` triangle branch already existed; this commit fills in the pipeline + SBT side so they are actually exercised on a physics launch.
Add a CI test that reuses the existing GPURaytrace binary on tests/geom/opticks_raindrop.gdml. Runs once with the default analytic CSG path and once with `stree__force_triangulate_solid=G4_WATER_solid`, asserting bit-identical Opticks NumHits. A G4Box triangulates to 12 flat triangles that exactly coincide with the analytic surface (validated across multiple seeds), so a strict equality check is appropriate: any divergence indicates a regression in the triangulated-GAS pipeline wiring (PIP primitive flags, second hitgroup PG, or SBT per-record header packing). Hooked into .github/workflows/build-pull-request.yaml next to the existing test_GPURaytrace.sh invocation.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds OptiX builtin triangle-BVH support to the physics simulation pipeline so volumes flagged via
stree__force_triangulate_solid=<lv_name>traverse as triangle GAS instances instead of analytic CSG, mixed inside the same IAS as the analytic CSG GAS.The TriMesh HitGroupData layout (
Binding.h), the triangle build input (sysrap/SOPTIX_BuildInput_Mesh.h), the mesh-sideSOPTIX_MeshGroupplumbing and the__closesthit__chtriangle branch were already in place. This PR adds the pipeline + SBT wiring that was missing to actually exercise them.Changes
feat(csgoptix)commit:CSGOptiX/PIP.cc: enableOPTIX_PRIMITIVE_TYPE_FLAGS_TRIANGLEalongside_CUSTOMinusesPrimitiveTypeFlags; create a second hitgroup programgroup
hitgroup_pg_triwithentryFunctionNameIS = nullptr(OptiX 9 forbidsan IS program on a triangle hitgroup); add it to
optixPipelineCreateandoptixUtilAccumulateStackSizes.CSGOptiX/PIP.h: declarehitgroup_pg_trialongside the analytic PG.CSGOptiX/SBT.cc::createHitgroup: pack each SBT record header with the PGmatching its GAS kind _
hitgroup_pg_triwhenfoundry->isSolidTrimesh(gas_idx),hitgroup_pgotherwise _ instead of a single PG for all records.test(ci)commit:tests/test_triangulated.sh: runsGPURaytraceon the existingopticks_raindrop.gdmltwice _ once analytic, once withstree__force_triangulate_solid=G4_WATER_solid_ and asserts theOpticks: NumHits:counts are bit-identical. AG4Boxtriangulates to12 flat triangles that coincide with the analytic surface, so strict
equality is the right check.
.github/workflows/build-pull-request.yaml: invoke the new test nextto
test_GPURaytrace.sh.Behaviour for runs that don't trigger triangulation
Functionally equivalent to upstream
main:hitgroup_pg_triis created but unreferenced (no triangle GAS exists).SBT::createHitgroupfalls back tohitgroup_pgfor every record.optixUtilComputeStackSizesoverhead from the extra PG, negligible.12664hits in both branches, matches existing tolerance.Mixed analytic + triangulated
Supported. The CI test itself runs a mixed scene (analytic Pb/AIR/VACUUM + triangulated WATER) in a single IAS. The constraint inherited from the existing CSG bookkeeping is that within a single compound CSGSolid all CSGPrim layers must be either all analytic or all triangulated (see comment at
SBT.cc:1021). Across different LVs / GAS indices, mixing works.Validation
Beyond the CI test, manually validated on a deformed raindrop where
G4Boxsolids were replaced withG4Sphere:Deficit scales as 1/N_ as expected from the inscribed-polyhedron error. N=34 was an outlier (+0.405%) _
G4PolyhedronSpherewith prime-factor rotation counts produces non-smooth meshes; multiples of 24 stay on the clean 1/N_ curve.GPU
Simulation time:measured aroundgx->simulate()+cudaDeviceSynchronizeinsrc/GPURaytrace.h. On a single warm-run measurement at N=200 with 6.08M photons (RTX 4090), triangle BVH was ~10% faster than the analytic CSG-sphere path _ RT cores beat the custom__intersection__issoftware intersect for the simple sphere; the gap likely flips back to ana for deep CSG trees.How to enable
export stree__force_triangulate_solid=lv_name_A,lv_name_Bor
export stree__force_triangulate_solid='filepath:$HOME/.opticks/GEOM/${GEOM}_meshname_stree__force_triangulate_solid.txt'Names are post-
StripTail(no0x_suffix). Must be set before the G4_Opticks geometry conversion. With no envvar, behaviour matchesmain.