Skip to content

borealis: encode four M5 nodes per workgroup, one child per lane - #1423

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/borealis-m5-node-encode-lanes
Dec 1, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/borealis-m5-node-encode-lanes

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 30, 2026 •

Copy link
Copy Markdown

What: The M5 node encoder ran one node per 8-lane workgroup with most of the work on one or two lanes: lane 0 fitted the root and quantized every child's bounds in turn, and one lane per QTB block quantized all of its triangles' vertices (up to 48 values). An 8-lane workgroup also leaves three quarters of each 32-lane SIMD group idle. It now encodes like the GEN1 encoder (agx3_leaf.comp): a 32-lane workgroup encodes four node jobs, eight lanes each, and every lane handles one child (its bounds, its root word, its record and its triangle's QTB bytes). Node and QTB block bounds and the checks come from clustered subgroup operations, so there is no shared memory and no barrier. The M5 arithmetic and record layouts are unchanged, and the encoded images are byte-identical. The planner now writes the encode dispatch after its state, as GEN1's does, and the update prefix sizes the batched node encoding the same way. One update call of 207 GTA-shaped BLAS goes from 4.59 ms to 1.13 ms. GTA V Enhanced at Very High ray tracing goes from 40.7 to 50.8 FPS on the M5 Pro (+25 %).

Tested: J714s (M5 Pro, G17S), stock 7.3.0-m5-pr67, SLC on, rows at this head b952bb08f38 (tree 65d3639fd31: aurora-wip 717a7d62e00 plus this commit), built natively on the M5:

  • Byte identity, old against new encoder (a private build that switches encoders per command; never published): 9 and 207 GTA-shaped BLAS plus a TLAS with moving instances, updated by each encoder in turn, and each structure built by one encoder and then updated by the other. All 20 comparisons are identical, every word.
  • CTS 1.4.7.1, ray_query.acceleration_structures (traditional, GPU-built) plus ray_query.{misc,builtin,watertightness,advanced} (first 630), 11667 cases: 7249 pass, 0 fail, 4418 not supported, the same as aurora-wip.
  • Refit-versus-rebuild ray test (262144 rays per round, three rounds, two directions): nine GTA-shaped BLAS packed in one buffer; 207 BLAS updated in one call together with 207 rebuilds; updates into another structure; top-level updates with moving instances; 64 BLAS updated into other structures plus a top-level update, traced in the same command buffer. All match their rebuilt references.
  • hk_agx3_as_format unit test passes (x86_64 build). GEN1 SPIR-V is byte-identical before and after (all 25 bvh programs compiled standalone; only the M5 leaf and plan programs change).
  • GTA V Enhanced built-in benchmark, 2560x1440, Very High ray tracing, FSR Quality, on a private M5 ray-tracing trial build (borealis: hardware ray queries on M5 with a generated intersection runtime #337 rebased with borealis: refit M5 acceleration structures without re-planning them #1419; not published), without and with this commit, alternated B A A B B A in one boot: 40.66 FPS (n=3, 40.52 to 40.86) → 50.81 FPS (n=3, 50.57 to 50.98), +25.0 %; 0 GPU faults and 0 s at the 338 MHz clamp in every run. Screenshot-layer frames of the benchmark with this commit (Grove Street, the Vinewood sign, Sandy Shores at night, frames 3200 to 12500) show intact geometry and ray-traced shadows, with the same capture-path desaturation and top-left inset as frames without it and with ray tracing off.

Risk: two-way · M5 family only (the M5 native acceleration-structure builder: G17G, G17S, G17C). No GEN1 program or C path changes. The M5 encode scratch grows by 16 bytes (the dispatch arguments after the plan state).

Not yet: a base M5 (G17G) row.

Evidence

GPU time (rqbatch2, timestamps around one vkCmdBuildAccelerationStructuresKHR; 207 GTA-shaped BLAS, 319102 triangles; mean of 20 updates or 10 builds after two warm-ups; two alternating rounds each, default software traversal builds):

aurora-wip 717a7d62e00 this commit
update of 207 BLAS in place, one call 4.587 / 4.584 ms 1.130 / 1.132 ms
build of 207 BLAS, one call 22.867 / 22.866 ms 18.115 / 18.123 ms
build of one TLAS, 1600 instances 0.436 / 0.436 ms 0.427 / 0.428 ms

GTA V Enhanced (built-in benchmark, 2560x1440, Very High ray tracing, FSR Quality, J714s stock 7.3.0-m5-pr67, SLC on):

Slot Build FPS Passes
s1 with (first run, cold shader cache; not in the means) 51.10 41.5 52.3 51.6 64.1 45.9
s3 without 40.60 29.6 45.2 42.3 49.6 36.3
s3 with 50.88 41.0 52.4 51.5 63.1 46.4
s3 with 50.98 41.2 52.3 50.5 64.0 46.8
s3 without 40.52 31.6 45.0 40.1 49.2 36.6
s4 without 40.86 30.9 45.1 40.8 51.5 35.9
s4 with 50.57 40.4 52.4 50.0 64.0 46.1

Every run: 0 GPU faults, 0 s at the 338 MHz clamp, same boot. The ray-tracing build is a private trial (#337 rebased with #1419) without and with this commit; the two builds differ only by it.

The M5 node encoder ran one node per 8-lane workgroup, and most of the
work on one or two lanes: lane 0 fitted the root and quantized every
child's bounds in turn, and one lane per QTB block quantized all of its
triangles' vertices (up to 48 values). An 8-lane workgroup also leaves
three quarters of each 32-lane SIMD group idle.

Encode like the GEN1 encoder (agx3_leaf.comp): a 32-lane workgroup
encodes four node jobs, eight lanes each, and every lane handles one
child: its bounds, its root word, its record and its triangle's QTB
bytes. The node's and each QTB block's bounds and the checks come from
clustered subgroup operations, so encoding needs no shared memory or
barriers. The M5 arithmetic (root fit, child quantization, record
layouts) is unchanged, so the encoded images are the same.

The planner now writes the encoding dispatch after its state, as GEN1's
does (whole workgroups of four jobs), and bounds the last workgroup with
its job count; the update prefix pass sizes the batched node encoding
the same way.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 30, 2026 17:50

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at b952bb08

Blockers:

  • Second M5 variant hardware row (base M5 G17G), plus completion of the author's queued third control run / visual check listed under Not yet.

Checked:

  • src/asahi/vulkan/bvh/agx3_m5_legacy_leaf.comp:
    • Verified uniform control flow into every subgroup operation (subgroupClusteredOr, subgroupClusteredMin, subgroupClusteredMax, subgroupShuffleXor, subgroupShuffle): early returns are strictly workgroup-uniform (gl_WorkGroupID.x * JOBS >= total), while trailing/invalid slots set live = false with empty ±INF bounds and my_bad = 0 and exit only after node_bad is reduced.
    • Verified batched update binary search over batch.bases[0..batch.count] handles non-multiple-of-4 job totals and zero-job updates safely (lo < batch.count, trailing lanes yield id >= jobs -> live = false).
    • Verified 4-lane quad reductions match QTB block partitioning for both 1..4 and 5..8 child leaves, and in_block == 0u header/tail zeroing is disjoint from per-lane 3-word QTB vertex writes (no write-write races).
    • Verified every vectorized store128 (encode_instance 128B record, 64B transform, 16B pointer pair; 48B AABB record; 64B triangle record; QTB header) preserves exact byte layout and 16-byte alignment.
  • agx3_m5_legacy_plan.comp, agx3_m5_legacy_refit.comp, hk_build_interface.h, hk_agx3_as_format.h, hk_m5_acceleration_structure.c, test-hk-agx3-as-format.c:
    • Both planner exits (finish() and plan_single_leaf()) write VkDispatchIndirectCommand (ceil(jobs / 4), 1, 1) at args.state + HK_AGX3_PLAN_ENCODE_DISPATCH; unbatched encode reads job_count at offset 0 via .counts = args->state and dispatches indirectly from args->state + HK_AGX3_PLAN_ENCODE_DISPATCH; batched refit prefix() computes ceil(sum / 4); HK_AGX3_M5_PLAN_TAIL_B (48) and HK_AGX3_M5_NODE_GROUP_LANES (32) static assertions and unit tests match; GEN1 SPIR-V is unchanged.
Evidence
  • Code is clean with zero defects found; strong J714s (G17S) parity, CTS (7249 pass, 0 fail), refit-vs-rebuild ray checks, and +25.7% GTA V Enhanced speedup (40.56 -> 50.99 FPS, 0 faults). Ready to approve once the base M5 (G17G) row lands.

@DjDeveloperr

Copy link
Copy Markdown
Author

Clean code review at b952bb08f380. A partial workgroup skips missing jobs before reading them. For nodes with one to eight children, each lane writes its own root word. Each triangle writes three whole words of its QTB block, and the first lane clears only the unused tail. The writes do not overlap. All lanes reach the subgroup reductions before any individual job exits.

Dispatch, shader comparison and one documentation nit

Both planner exits and the batched update prefix round the job count up to groups of four. I checked the batched lookup against a flat job list for 9,330 combinations, including empty updates and groups that span update boundaries. The indirect command fits after the plan state, and the existing barrier covers the indirect read.

I compiled all 27 BVH shader variants against 717a7d62. Twenty-three matched byte for byte, including every GEN1 and software variant. Only the two M5 leaf variants, the M5 planner and batched M5 refit changed. The device selector is unchanged. The patch adds no runtime switch or board check. Both leaf variants and the planner passed standalone SPIR-V validation. Batched refit has the same device-scope validator diagnostic on both revisions at src/asahi/vulkan/bvh/agx3_m5_legacy_refit.comp:120.

One documentation nit at src/asahi/vulkan/hk_agx3_as_format.h:20. The M5 overview still says one node per eight-lane workgroup. It should say four nodes per 32-lane workgroup, eight lanes per node.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at b952bb08

Blockers: none.

Checked:

  • agx3_m5_legacy_leaf.comp, agx3_m5_legacy_plan.comp, agx3_m5_legacy_refit.comp, hk_build_interface.h, hk_agx3_as_format.h, hk_m5_acceleration_structure.c, test-hk-agx3-as-format.c:
    • Scoped strictly to the M5 native AS builder (single GPU generation; independent 27-variant shader check confirms all 23 non-M5/GEN1/software SPIR-V variants are byte-identical).
    • Subgroup uniformity, 4-jobs/workgroup batched binary search, race-free QTB quad reductions and header/tail writes, 16-byte aligned store128 records, planner/refit HK_AGX3_PLAN_ENCODE_DISPATCH indirect dispatch rounding, and HK_AGX3_M5_PLAN_TAIL_B (48) / HK_AGX3_M5_NODE_GROUP_LANES (32) static assertions and unit tests all verified clean.
  • Exact-head b952bb08 J714s (M5 Pro, G17S) verification complete:
    • 20/20 word-for-word parity vs prior encoder (9 and 207 GTA-shaped BLAS + TLAS with moving instances).
    • CTS 1.4.7.1 11,667 cases (7,249 pass, 0 fail, 4,418 not supported, identical to aurora-wip).
    • Refit-vs-rebuild ray test (262,144 rays × 3 rounds × 2 directions) exact match; hk_agx3_as_format unit test passes.
    • rqbatch2 207-BLAS update 4.587 -> 1.130 ms, build 22.867 -> 18.115 ms; GTA V Enhanced 40.56 -> 50.99 FPS (+25.7%, 0 GPU faults, 0 s at 338 MHz clamp).
Evidence
  • Single-generation M5-only change with full exact-head J714s parity, CTS, unit test, and benchmark evidence plus clean independent verification across all 27 BVH shader variants.
  • Non-blocking nits: src/asahi/vulkan/hk_agx3_as_format.h:20 overview comment still mentions one node per 8-lane workgroup (instead of four nodes per 32-lane workgroup); optional base M5 (G17G) row / third GTA V control run / screenshot-layer frames can follow without holding merge.

@sithglan

Copy link
Copy Markdown

Base M5 (J813, Apple M5 G17G C0) same-boot userspace Vulkan ICD A/B row at exact head b952bb08f380 vs base 717a7d62e004 (kernel 7.3.0-aurora-j813-sgv2+, deqp-runner --jobs 2, regression request 3d61b0de): PASS

  • Base 717a7d62e004 (libvulkan_asahi.so sha256 18e64f54...):
    • dEQP-VK.ray_query.* (49,360): 14,536 Pass / 0 Fail / 0 Crash / 34,824 Skip (acceleration_structures: 13,817 Pass / 19,752 Skip; misc: 52 Pass; builtin: 258 Pass / 258 Skip; watertightness: 18 Pass / 18 Skip; advanced: 14 Pass / 12 Skip) — 0 GPU faults/recoveries/timeouts.
    • dEQP-VK.ray_tracing_pipeline.acceleration_structures.* (10,279): 10 Pass / 0 Fail / 0 Crash / 10,269 Skip — 0 GPU faults/recoveries/timeouts.
  • Head b952bb08f380 (libvulkan_asahi.so sha256 d5c5b609...):
    • dEQP-VK.ray_query.* (49,360): 14,536 Pass / 0 Fail / 0 Crash / 34,824 Skip (identical across every subgroup) — 0 GPU faults/recoveries/timeouts.
    • dEQP-VK.ray_tracing_pipeline.acceleration_structures.* (10,279): 10 Pass / 0 Fail / 0 Crash / 10,269 Skip — 0 GPU faults/recoveries/timeouts.
  • Transitions: 0 across all 59,639 cases (0 Pass -> Fail/Crash/Timeout), 0 GPU faults/recoveries/timeouts in dmesg. Temporary ICDs removed; stock driver untouched.

@DjDeveloperr
DjDeveloperr merged commit cfe8a3a into aurora-wip Dec 1, 2026
@DjDeveloperr
DjDeveloperr deleted the perf/borealis-m5-node-encode-lanes branch December 1, 2026 00:00
@m0d16l14n1

Copy link
Copy Markdown

Base M5 row (MacBook Air 15" M5, J815, G17G), kernel 7.3.0-aurora-j815-dev, PR head on aurora-wip 6e153e5 vs that base, release builds, dEQP-VK 1.4.7.1 (+ KhronosGroup/VK-GL-CTS@c2c05e95f97f):

  • every mustpass acceleration_structure case outside ray_query/ray_tracing (2,785): 1,925 = 1,925 Pass, 0 diffs.
  • every mustpass dEQP-VK.ray_query case (49,359): 14,535 = 14,535 Pass, 0 diffs.
  • dEQP gate (15,958): 11,297 = 11,297 Pass, 0 diffs. 0 GPU faults in every run.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at b952bb08f380 from a different lane. This PR goes into the merge train's next combined A/B (batch 23, stacked on batch 22: #631 #664 #673 #1422 #1423 #1429 #1431 #1432 #1433 #1434 #1436) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants