Repository navigation
borealis: speed up M5 acceleration-structure builds and refits - #1482
Conversation
Build M5 native acceleration structures with H-PLOC and use its single-workgroup shuffle path for up to 4096 leaves. Dispatch each pass of the Morton sort separately to avoid relying on forward progress between workgroups. Signed-off-by: DjDeveloperr <hey@djdev.me>
Store the native table index on the Vulkan object at registration. Use it directly when building, updating, copying or destroying the object to avoid scanning the resource table for every lookup. Signed-off-by: DjDeveloperr <hey@djdev.me>
Run the same planning phase for each independent build before issuing a compute barrier. Add a single-workgroup planner for small builds, with workgroup barriers between phases. Leave indirect command visibility to the barrier after the final planning phase. Derive the instance table offsets from the completed plan so node encoding, envelope emission and retained-plan saves can write their disjoint ranges without intervening barriers. Signed-off-by: DjDeveloperr <hey@djdev.me>
Read updated vertices from the application buffers and write native leaf clusters without generating a temporary triangle IR. Reuse the retained native plan to propagate bounds using acquire-release arrival counters, and reload task and job fields at their use sites to shorten live ranges. Keep the batched refit path for other updates. Write the retained IR and plan span after the native image, including empty images, and preserve it through copies, compaction and serialization. Share envelope scaling with the ordinary build path so finite degenerate bounds remain representable. Signed-off-by: DjDeveloperr <hey@djdev.me>
Convert the replacement Vulkan address to the aligned native BLAS address before writing the instance record and looking up its resource ID. The resource table keys entries by native address. Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: MERGE at ced9f46
Checked: Read all six commits against aurora-wip c5bf0a7, focusing on the host side (hk_m5_acceleration_structure.c, hk_agx3_as_layout.h, m5_as_metadata.h, vk_acceleration_structure.h), copy.cl, and the new agx3_m5_legacy_direct_refit.comp / refit / envelope shaders.
Checked: Direct refit eligibility (hk_m5_direct_triangle_update): only when src == dst, BOTTOM_LEVEL, TRIANGLES, leaf_node_count > 0, updateable, no quads and not indirect. Everything else drops to the batched fallback, and order/bottom are recomputed for the remaining updates. hk_encode_dispatch emits a compute barrier after the PREPARE dispatch (which zeroes the per-internal-node arrival counters) and before hk_update_batched. Leaf tri_id maps back through a first_id binary search over the non-empty geometries, using the same prefix and geometry index j as the build-time vk_fill_geometry_data. Transforms and NaN-to-origin match leaf.h for ALWAYS_ACTIVE. The climb spin-wait waits only for a counter that its own 8-lane group has already completed (the prev+1 == child_count winner), so it never depends on another workgroup making progress.
Checked: Scratch sizing: update scratch shrinks to scratch.size + lbvh + (node_bound - leaves)*4. Both refit shaders now index arrivals by parent - leaf_bound, and internal_bound = node_bound - leaf_bound, so the new size covers them. Retained span and metadata: as_bytes adds the 16-byte trailer for M5, the envelope publishes the trailer for every build including empty ones, and the direct path writes it in write_envelope. Copy, compact, serialize and deserialize copy image+trailer from the native VA and the retained span at base+retained_offset. retained_offset is at least the worst-case as_bytes, which already includes the 1023-byte alignment slack, so a compacted destination with a different 1024 phase cannot overlap the image and the retained span. Copy thread counts cover as->size - padding, which is >= retained_bytes.
Checked: TLAS relink: the resource table key is ALIGN_POT(va, 1024) and hk_as_native_va in the M5 file aligns the same way, so aligning the replacement address before the lookup is correct. Aligning 0 stays 0.
Checked: Built the head in the B1 x86 container with tests (glslang compiled the new direct-refit and fused-plan shaders, libagx copy.cl compiled): BUILD-OK, meson test 266/266 OK.
Checked: No AI attribution in commits or PR body. No Apple-derived tables or values in the diff.
Follow-ups:
- Size: +1804/-331 over 14 files. Next time, please split along the commit lines (H-PLOC/Morton, resource-ID cache, batched planning, direct refit, TLAS relink fix). Not a hold.
- Overlap with #1488: both branch from c5bf0a7. f47dd44 here and 79e8773 there are the same H-PLOC/phased-Morton change, and
git merge-tree pr1482 pr1488conflicts in bvh/meson.build and hk_m5_acceleration_structure.c (this PR replaces the single-build encode path that #1488 edits). Merge this one first; #1488 then rebases, drops its duplicate commit and moves pairs into the batched stages. - The body says the H-PLOC/Morton work overlaps #1440/#1453 and the relink fix overlaps #1422. Close or rebase those once this lands.
- The
selftestcheck is red. It is the repo-wide agent-policy-test.sh failure ("push to the default branch heals it"), the same on all four PRs, and unrelated to this diff.
|
A same-boot, interleaved G17C A/B on stock Linux isolates a standalone BLAS refit regression to the #1482 merge (
CPU recording improved (about 14 → 2 µs and 168 → 2–6 µs). The first follow-up is to compare the current direct triangle refit with the batched fallback on the same build and workload. Keep the original nine-BLAS row and ray-query correctness in that comparison so a fix preserves the gains this PR shipped. |
|
Disabling only the direct in-place triangle path on the merged tree (
The batched path also beats the pre-merge throughput by 13.4% and 25.2%. CPU recording took 13.42 µs and 151.5 µs with batching, versus 1.71 µs and 2.17 µs with direct refit. Compare both paths on the current tip with single and batched updates, including CPU recording and total submit time, before choosing the default. The driver’s acceleration-structure layout and copy/serialization changes stay in the comparison. |
What: Speed up the M5 native acceleration-structure builder with H-PLOC, phased Morton sorting, cached resource IDs, and batched planning and encoding. Refit eligible triangle BLASes directly and align replacement BLAS addresses when relinking TLAS instances.
Tested: Apple M5 Pro J714s (G17S B1) at
ced9f46842c001972717c6eb14501dbefa1f63b7. Four-TLAS build median fell from 1.1920 to 0.3320 ms (−72.15%) and nine-BLAS in-place refit from 0.0775 to 0.0640 ms (−17.42%). The out-of-place refit ranges overlap. The ray-query AS-builder CTS list passed 35/35, and 7,864,320 refit-versus-rebuild rays matched.Risk: Two-way door for Macs using the M5 native acceleration-structure path. Direct refit reuses retained native planning metadata. Other updates use the batched refit path.
Not yet: Hardware evidence covers G17S B1. The original mixed CTS list includes 12 pipeline cases marked NotSupported because the standalone driver leaves
VK_KHR_ray_tracing_pipelinedisabled on G17S.Details
The H-PLOC and Morton-sort work overlaps #1440 and #1453. The TLAS relink fix overlaps #1422.
Evidence
Testing
Native AArch64 Arch Linux ARM on one J714s Apple M5 Pro, G17S B1, kernel
7.3.0-m5-pr67(#171 SMP PREEMPT), GPU firmware 27.0 (26A428), SLC enabled on 16 planes. GPU fault lines were zero before and after. The machine had one pre-existing failed service and a kernel built without SELinux. The failed-service count was unchanged.libvulkan_asahi.soSHA-256aurora-wipat test time and the series merge basec5bf0a743d3c0c0b31cbfd53c5d3ca10e5c0a15b1aa324f78350c203af44f2e0190d58bf726f3f11dae75c428a400f6ca9cffafdced9f46842c001972717c6eb14501dbefa1f63b7bf8c5a65e5018603a84920743f4a684fa4dc5a699797b3d29885af3b389221d8At publication,
aurora-wiphad advanced to456457aa93d16441ecfabdaf7179c18200ee32fdwith a DRM primary-node reporting fix outside the series' changed files. The tested head merges cleanly with that revision. The table uses the tested merge base.Both Mesa 26.3.0-devel ICDs were built with identical native release options using GCC 16.1.1, Meson 1.12.1, Ninja 1.13.2 and glslang 16.4.0. The build command was
ninja -j 12 -C "$BUILD_DIR" src/asahi/vulkan/libvulkan_asahi.so. The runner pinned each ICD withVK_DRIVER_FILES, usedLC_ALL=Cand a shared shader cache directory, and left trace and compiler debug flags unset for timings.Benchmark
rqbatch2and its TLAS-update variant use the pinned C sources, scene data and SPIR-V in the benchmark kit and raw outputs. The recordedrqbatch2binary SHA-256 is6fdf03d807a6b924a4d785d5177cf2c438491ff1625fdcf66c45390eb6bf8585. The refit batch used nine BLASes with 13,874 triangles total. Each TLAS batch had four structures with 512 instances each. The TLAS-update variant builds updateable structures before timing their in-place updates.The following are the timing commands for each pinned ICD, with the inputs staged in the working directory.
Four independent processes per arm in ABBA ABBA order. Each process averaged 32 GPU timestamp measurements after two warmups. Cells show min / median / max across process means in ms per batch. Changes use the medians.
The out-of-place refit ranges overlap and the slowest proposed process was slower than the slowest baseline process. One in-place baseline process averaged 0.123 ms and contained a 0.332 ms iteration. All samples are included.
Path verification and correctness
direct_refitshader (c733e7e4) used 207 GPRs, 512 resident threads, zero spills/fills and 0 B scratch.0d18b347943e5e843529a05c95220e27fe30c538) recorded 23 Pass, 12 NotSupported, 0 Fail on the original 35-case list. The 12 cases requireVK_KHR_ray_tracing_pipeline. The separate ray-query-only list retained the 23 applicable cases and added 12 AABB cases for 35 Pass, 0 NotSupported, 0 Fail. These CTS rows were run on the proposed ICD.mesa:asahisuite passed all 286 runnable tests, with one skip and zero failures, in both default and serialized modes. All eight M5 SPIR-V variants passedspirv-val --target-env vulkan1.2 --scalar-block-layout.Benchmark source, runner, build settings, raw outputs from both arms, path traces and CTS verdicts