Skip to content

borealis: share bounds checks for aligned uniform loads - #556

Closed
erikwb wants to merge 2 commits into
aurora-wipfrom
j716c/g17c-robust-ubo-records
Closed

erikwb wants to merge 2 commits into
aurora-wipfrom
j716c/g17c-robust-ubo-records

Conversation

@erikwb

@erikwb erikwb commented Nov 20, 2026 •

Copy link
Copy Markdown

What: Keep naturally aligned 32-bit robustBufferAccess2 uniform-buffer loads together before explicit I/O lowering so adjacent fields share one 64-byte record bounds check and base select across AGX2, AGX3C, and AGX3D (leaving AGX3B on per-load unscaled byte-index checks and inline uniform blocks on exact range checks), and fold the known-zero offset for descriptor-generation-10 mutable UBO descriptors.
Tested: Host (x86_64, -Doptimization=2 -Ddebug=false -Db_ndebug=false -Dtools=drm-shim) at 7b85bd967b2d (merged with aurora-wip 6eb4883958d, which includes #630): meson test --suite asahi --suite poly 296/296 passed, agx_tests 1,459 passed, 1 skipped (NativeFMA.ExactDyadicOracle), brl_aligned_ubo_test OK; drm-shim release replay of the Cyberpunk 2077 caches at 7b85bd967b2d vs 6eb4883958d had 0 failures across 11,403 graphics / 1,919 compute pipelines on G17C (hard-fault coverage via libasahi_g17c_shim.so), and 6,952 failures (6,590 graphics, 362 compute) on G18G matching baseline totals with 6 new / 6 cleared graphics failures (0 new compute failures; all 6 new failures hit agx3_funop_core.c:162's 128-half floor limit that #629 widens). Prior head 1d373c4a21e4 vs #630 7a2f9ff108c5 passed 41,408 CTS cases and gained +3.83 FPS (+12.44%) in Cyberpunk 2077 T2 on J716c (G17C), passed CTS/readback on M2 (T8112, G14G) and M5 Pro (J714s, G17S B1), and showed 0 diffs on G17P (A18 Pro, M4 Pro); exact-head 7b85bd967b2d hardware rows remain to run.
Risk: two-way door · M1, M2, M5, and G18G (AGX2, AGX3C, AGX3D; AGX3B on M3, M4, and Neo keeps existing lowering)
Not yet:

  • G18G floor merge blocker (#629): The 6 newly failing G18G graphics pipelines (hitting the 128-half floor encoder limit fixed in open PR #629) block merge until #629 lands (or is avoided) and both arms replay with zero newly failing pipeline hashes.
  • Retarget PR base from j716c/spill-dce (#630, merged) to aurora-wip, and confirm mirror asahi CI on 7b85bd967b2d.
  • Exact-head (7b85bd967b2d vs 6eb4883958d) hardware rows on local lab Macs: J716c (M5 Max, G17C, AGX3C: dEQP-VK.ubo.*, dEQP-VK.robustness.robustness2.*uniform*, dEQP-VK.binding_model.mutable_descriptor.*, dEQP-VK.ssbo.layout.*, and Cyberpunk 2077 T2 A/B) and J313 (M1 Air, G13G, AGX2: same-machine performance A/B, UBO readback covering direct/indexed/inline cases, dEQP-VK.robustness.robustness2.*uniform*, and dEQP-VK.ubo.*, standing in for external J413).
  • Exact-head hardware rows on external Macs not present in this lab: J413 (M2 Air, G14G: buffer-readback and full-stride robustness conformance for direct, indexed, and inline uniform cases, plus AGX2 interleaved GPU-bound performance A/B), M5 / M5 Pro (G17G, G17S mutable_descriptor.*), and G17P (A18 Pro / M4 Pro dEQP-VK.robustness.robustness2.*uniform* and interleaved A/B).
Details

Problem

Explicit I/O lowering splits robust uniform-buffer reads into separate component loads and bounds checks. Adjacent fields can share the bounds check for their 64-byte record. This runs for robustBufferAccess2 uniform buffers on every generation except AGX3B (G15, G16, G17P): each advertises the 64-byte record as its robust UBO size alignment, and the zero page holds a whole record. Keeping the fields together cuts repeated address calculations in large shaders.

Change

Merged aurora-wip (6eb4883958d, which includes #630 ff4f03f6bdaa) into j716c/g17c-robust-ubo-records (7b85bd967b2d) without force-pushing, resolving conflicts in:

  • src/asahi/vulkan/hk_shader.c: kept NIR_PASS(lowered_buf_io, nir, brl_nir_lower_aligned_ubo, ...) after aurora-wip's shared nir_lower_explicit_io(nir_var_mem_ssbo) and before nir_lower_explicit_io(nir_var_mem_ubo) so need_pre_bounds_opt and can_post_lower track aligned-UBO lowering across all chips.
  • src/asahi/vulkan/meson.build: kept both brl_aligned_ubo and hk_vdm_indirect_count.

Implementation notes:

  • Applies to contiguous 32-bit scalar and vector reads that the compiler can place within a single 64-byte record (brl_nir_lower_aligned_ubo.c). Missing records read from the zero page.
  • Array indices (dynamic and constant) must be below ceil(BRL_MAX_UBO_RANGE / stride) (an index at or above it selects the zero page), checked before deref arithmetic scales them so 32-bit byte offsets cannot wrap into a valid record.
  • Inline uniform blocks keep nir_lower_explicit_io's exact range check: their size is not rounded to the 64-byte record, and descriptor lowering gives an inline block a constant bound while buffer descriptors read their bound from memory (brl_nir_lower_aligned_ubo.c:56).
  • AGX3B keeps the existing lowering: its device loads take an unscaled 32-bit byte index, so the per-load check needs no 64-bit add, while a shared record address adds one per record.
  • On descriptor generation 10 (G17G, G17S, G17C, G18G), mutable descriptors holding a uniform buffer get their known-zero offset folded (hk_nir_lower_descriptors.c:384-390), matching fixed UBO bindings.
  • Unit test brl_aligned_ubo (src/asahi/vulkan/tests/test-brl-aligned-ubo.c) folds the lowered address for in-bounds, out-of-bounds, last-record, and wrapping indices (dynamic and constant) and checks that inline-uniform-block descriptors are left alone.
Evidence

Host verification at 7b85bd967b2d (merged with aurora-wip 6eb4883958d)

  • Host assertions build (-Doptimization=2 -Ddebug=false -Db_ndebug=false -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dplatforms=wayland,x11 -Dbuild-tests=true -Dtools=drm-shim -Dllvm=enabled):
    • meson test -C _build --suite asahi --suite poly: 296/296 passed, 0 failed (including brl_aligned_ubo: OK).
    • agx_tests: 1,459 passed, 1 skipped (NativeFMA.ExactDyadicOracle), 0 failed.
  • Release drm-shim replay of both Cyberpunk 2077 pipeline caches (45f2e4a29987a5f1.foz, 45f2e4a29987a5f2.foz; MESA_SHADER_CACHE_DISABLE=true, --master-process --num-threads 8, -Db_ndebug=true) comparing origin/aurora-wip (6eb4883958d) vs 7b85bd967b2d:
    • G17C (libasahi_g17c_shim.so, ASAHI_SHIM_CHIP=g17s-kernel, hard-fault coverage): 11,403 graphics / 1,919 compute pipelines replayed on both arms, 0 failures, 0 crashes.
    • G18G (libasahi_noop_drm_shim.so, ASAHI_SHIM_CHIP=g18g): base 6,952 failures (6,590 graphics, 362 compute, 0 crashes), head 6,952 failures (6,590 graphics, 362 compute, 0 crashes); 6 new graphics / 0 new compute failures and 6 cleared graphics / 0 cleared compute failures. All 6 new graphics failures (02b034f9adac0ba2, 1590b27c7694ca10, 472ad9a841873c5f, 62c0b00170559b31, 58451307fd57abd1, a37c41cf00fbc013) are fragment shaders hitting AGX3 binary packer refused floor at line 17978 [d32:reg12 s0=32:reg156.cache] from agx3_funop_core.c:162's 128-half limit (#629).

Prior rebased head (1d373c4a21e4 vs #630 7a2f9ff108c5, on #629 ed79255b51ed, aurora-wip 1fdf5396758f)

  • M5 Max (J716c, G17C, AGX3C, Linux 7.3.0+) Vulkan CTS A/B (MESA_SHADER_CACHE_DISABLE=true, 0 GPU dmesg errors):
Group Cases Base (7a2f9ff108c5) Head (1d373c4a21e4) Diffs
dEQP-VK.ubo.* (full) 13,240 13,240 Pass 13,240 Pass 0
dEQP-VK.robustness.robustness2.*uniform* (full) 8,844 4,872 Pass, 3,972 NS 4,872 Pass, 3,972 NS 0
dEQP-VK.ssbo.layout.* (full) 5,275 5,254 Pass, 21 NS 5,254 Pass, 21 NS 0
dEQP-VK.robustness.buffer_access.* (full) 1,212 1,014 Pass, 198 NS 1,014 Pass, 198 NS 0
dEQP-VK.binding_model.mutable_descriptor.* (5,000 evenly spaced) 5,000 2,930 Pass, 2,070 NS 2,930 Pass, 2,070 NS 0
dEQP-VK.binding_model.* UBO cases 8,686 7,616 Pass, 1,070 NS 7,616 Pass, 1,070 NS 0

Total on J716c: 41,408 distinct cases (34,379 Pass, 7,029 NS, 0 Fail, 0 diffs, 0 GPU kernel errors).

  • M5 Max (J716c, G17C, Linux 7.3.0+) Cyberpunk 2077 T2 benchmark A/B (2560×1600 High, balanced 4+4 ABBA under mac-quiet, both arms with #450 + #456):
Build Pass 1 Pass 2 Pass 3 Pass 4 Mean FPS (spread) Mean p99
Control (7a2f9ff108c5 + #450 + #456) 30.62 30.78 30.77 30.95 30.78 (0.33) 38.68 ms
Candidate (1d373c4a21e4 + #450 + #456) 34.66 34.62 34.56 34.60 34.61 (0.10) 34.70 ms

Delta: +3.83 FPS (+12.44%), mean p99 -3.98 ms (38.68 -> 34.70 ms).

  • M2 (T8112, AGX2, G14G) Vulkan CTS & readback (1d373c4a21e4 vs 7a2f9ff108c5, 0 GPU firmware errors): dEQP-VK.robustness.robustness2.*uniform* (4,422 cases, 0 diffs), dEQP-VK.ubo.* (6,620 cases, 0 diffs), dEQP-VK.ssbo.layout.* (5,275 cases, 0 diffs), element-bounds readback (198 launches / 39,600 checks, 0 failures).
  • M5 Pro (J714s, G17S B1, AGX3C) (1d373c4a21e4 vs 7a2f9ff108c5, MESA_SHADER_CACHE_DISABLE=1, 0 GPU/MMU faults): meson test --suite asahi 158/158 PASS, mutable_descriptor.* (800-case subset: 461 Pass / 339 NS), ubo.* (600/600 Pass, 0 diffs), ssbo.layout.* (500-case subset: 498 Pass / 2 NS).
  • G17P no-regression CTS rows (1d373c4a21e4 vs 7a2f9ff108c5; excluded AGX3B path): A18 Pro (G17P) and M4 Pro (J616s, G17P) dEQP-VK.ubo.* 13,240 cases (8,944 Pass / 4,296 NS, 0 diffs) and dEQP-VK.ssbo.layout.* 5,275 cases (5,254 Pass / 21 NS, 0 diffs).

Earlier pre-rebase compiler statistics (b8762aab vs c64567fd)

Drm-shim identity Matched shaders Build Main instructions Preamble instructions Spills / fills Uniform-DMA copies
G17C 4,283 base 16,307,188 9,365,137 13,491 / 13,465 2,501
#556 13,859,362 4,040,844 7,392 / 7,896 3,051
G14G 4,299 base 18,191,355 9,090,692 16,227 / 12,564 –
#556 15,966,749 6,639,248 9,342 / 8,008 –
G18G 2,600 base 8,866,299 – 4,062 / 728 –
#556 6,150,259 – 4,031 / 677 –

@RyanTheTide

Copy link
Copy Markdown

Thanks, a +3.8 FPS gain in Cyberpunk is a great result, and the readback checks are reassuring.

We select behaviour by a hardware property, not by the GPU it was measured on, and the new pass is keyed on the chip: hk_shader.c:3332 runs hk_lower_aligned_ubo only when dev->dev.chip == AGX_CHIP_G17C. The lowering itself is generic: it needs robust UBOs (robustness2), the HK_MIN_UBO_ALIGNMENT record size and the zero page, all of which every Honeykrisp generation has.

Could you run it whenever rs->uniform_buffers is robustBufferAccess2, on every generation? If some generation can't use it, a comment with the hardware reason (e.g. a measured loss or a load-unit difference) would make the gate fine.

We're happy to provide CTS and benchmark rows on our M1 Pro (G13S), M2 (G14G), M4 Pro and A18 Pro (G17P) for the default-on version.

@DjDeveloperr

Copy link
Copy Markdown

Merge train: independent review (code only, Opus 5.5 xhigh)

Verdict: CLEAN WITH NITS. No blocker or major. The new hk_lower_aligned_ubo pass is G17C-only and correct: it relies on the advertised 64-byte robustness alignment and runs regardless of soft faults.

It reaches the M5 and M5 Pro, though, which the description doesn't say.

  • The descriptor change in hk_nir_lower_descriptors.c:380-390 is gated on descriptor generation 10, not G17C.
  • So it changes codegen on G17G, G17S, G17C and G18G for shaders that read a UBO from a MUTABLE_EXT binding, which mostly means vkd3d-proton (D3D12) games.
  • It's correct for all valid usage, but it was only tested on G17C.
  • Please either gate that part on G17C too, or let it get an M5 / M5 Pro row. The train can run dEQP-VK.binding_model.mutable_descriptor. on our M5 Pro (G17S) if this goes into a batch.

G17P is not affected. NIT (uncertain): inline uniform blocks also hit the pass.

Train: held on RyanTheTide's property-gate request (owner decision pending); the G17G/G17S reach above needs our M5 Pro gate either way.

@RyanTheTide RyanTheTide changed the title hk: share bounds checks for aligned G17C uniform loads borealis: share bounds checks for aligned G17C uniform loads Nov 20, 2026
@DjDeveloperr
DjDeveloperr force-pushed the j716c/g17c-robust-ubo-records branch from 299bba3 to ef90f94 Compare November 21, 2026 00:36
@DjDeveloperr

Copy link
Copy Markdown

Merge train: rebased onto aurora-wip afcc08b (conflict-free; authorship kept). Head 299bba3 -> ef90f94.

  • Why: so this exact head carries the current .github/workflows/asahi.yml and the policy-file copies that ci: sync the assistant-file copies with .github/aurora/AGENTS.md #580 synced, so its CI run and agent-policy.sh pr both apply to it. On the old base agent-policy.sh pr failed on the stale copies.
  • What changed: nothing in the PR's own commits (git range-diff: every commit identical). The train's batch stack built from the rebased heads has the same tree as the one already reviewed and host-tested.
  • CI: an asahi workflow run on this exact head is in progress on the DjDeveloperr/mesa mirror (branch ci/train-pr556), because aurora-silicon/mesa has Actions off. agent-policy.sh pr passes locally (rc=0).

@erikwb
erikwb force-pushed the j716c/g17c-robust-ubo-records branch from ef90f94 to 8c5ad76 Compare November 21, 2026 00:47
@erikwb erikwb changed the title borealis: share bounds checks for aligned G17C uniform loads borealis: share bounds checks for aligned uniform loads Nov 21, 2026
@erikwb

erikwb commented Nov 21, 2026

Copy link
Copy Markdown
Author

Note

🤖 Claude Opus 5.5 responding on behalf of erikwb

The lowering now runs on every generation for robustBufferAccess2 UBOs, with no chip check (8c5ad76).

  • It needs only what every Honeykrisp generation has. The 64-byte record is the advertised robustUniformBufferAccessSizeAlignment on all of them, and the 64 KiB zero page holds a whole record. Every UBO descriptor has the same four-word bounded address shape, with word 3 zero for valid UBO descriptors. The pass leaves any other address form alone.
  • @DjDeveloperr: the descriptor-generation-10 fold reaching G17G, G17S and G18G is now stated in the body and the commit message. On inline uniform blocks: they use the same four-word address shape and a 64-byte-aligned base, so the pass is correct for them too.
  • A review on this round found a real out-of-bounds read, also present in the G17C-only version. The deref arithmetic scales a dynamic array index into a 32-bit byte offset before the record check, so a stride-4 index of 2^30 wrapped to offset 0 and read record 0 instead of the zero page. Each dynamic index is now checked against HK_MAX_UBO_RANGE / stride first; any index at or above that is outside every UBO. That costs one compare per dynamic index, with no extra loads.
  • The Cyberpunk numbers in the body are from G17C on the earlier head. Rows from your M1 Pro, M2, M4 Pro and A18 Pro would cover the other generations; we'll add a J716c row on this head.

@RyanTheTide

Copy link
Copy Markdown

Thanks, this resolves our point: the UBO lowering now runs on every generation with no chip check, and the descriptor-generation-10 reach is stated. Good catch on the 32-bit index wrap; checking each dynamic index against HK_MAX_UBO_RANGE / stride first is the right fix.

We'll run rows on our M1 Pro, M2, M4 Pro and A18 Pro on this head (with #569 on top): dEQP-VK.robustness.robustness2.* and dEQP-VK.ubo.*, base vs head, no new failures, plus one GPU-bound A/B with alternating runs.

@RyanTheTide RyanTheTide 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.

One codegen point on top of our note above. It's not a correctness blocker.

  1. hk_shader.c:1579, AGX3B (G15, G16, G17P): real = base + u2u64(record) is a 64-bit add for each record, done before the select. The old bounded lowering selects base and offset separately, and the load folds base + zext(offset) into AGX3B's unscaled byte-index form, so it had no 64-bit add. #526 and #570 leave AGX3B on the old form for exactly this reason (fold_field: "a folded record address would add one ... for every record"). Here the same trade is turned on for AGX3B with no measurement. Please either use the same agx_chip_isa_encoding() != AGX_ISA_ENCODING_AGX3B condition and comment as #526, or show AGX3B instruction counts before and after (a shader-db run over a large UBO-heavy pipeline set compiled for g17p) showing no loss. Our A18 Pro and M4 Pro A/B rows will show any runtime effect, but an instruction-count diff settles it faster.
  2. The gen-10 mutable-UBO fold (hk_nir_lower_descriptors.c:380) reaches G17G, G17S and G18G. None of our Macs covers those, so it needs the train's M5 Pro row of dEQP-VK.binding_model.mutable_descriptor.*.

Assisted-by: LLM (Claude:Opus 5.5)

@erikwb

erikwb commented Nov 21, 2026

Copy link
Copy Markdown
Author

Note

🤖 Claude Opus 5.5 responding on behalf of erikwb

J716c row at 8c5ad76, measured together with #569 on top (26f9a51). See #569 for the table.

The pair gave +5.2 FPS (+16%) in Cyberpunk T2 over current aurora-wip + #450 (37.68 / 37.64 vs 32.34-32.56), with p99 frame time about 5 ms lower. The robustness2 uniform, buffer_access and binding_model UBO sets (18,742 cases) match the base case for case.

@RyanTheTide RyanTheTide 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.

Thanks for the numbers. They are from the M5 Max (AGX3C), so they don't cover point 1 of our last review: the per-record 64-bit add on AGX3B (G15, G16, G17P, hk_shader.c:1579) that #526 and #570 avoid. That is still open. Please either use #526's != AGX_ISA_ENCODING_AGX3B condition, or show an AGX3B (g17p) instruction-count diff with no loss. The +16% was measured together with #569, so it can't be split between the two PRs. That's fine for the pair, but not as evidence for this lowering on AGX3B.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr
DjDeveloperr force-pushed the j716c/g17c-robust-ubo-records branch from 8c5ad76 to e767fd2 Compare November 21, 2026 02:50
DjDeveloperr added a commit that referenced this pull request Nov 21, 2026
@DjDeveloperr

Copy link
Copy Markdown

Merge train: rebased onto aurora-wip 7ba2957 (#595, the CI fix that installs the GLVND EGL dispatcher, so the asahi job's EGL priority tests pass), conflict-free, every commit identical, authorship kept. New head e767fd2. A mirror asahi run on this exact head is in progress (ci/train-pr556 on DjDeveloperr/mesa), and agent-policy.sh pr is clean. Thanks for the rework (every generation + the index-wrap fix): this PR now reaches every chip including G17P, so the train has moved it to its G17P-gated group (M5 Pro gate + a G17P row; RyanTheTide's A18 Pro row counts), and the reworked code is getting a fresh independent review.

@DjDeveloperr

Copy link
Copy Markdown

Merge train: independent re-review of the reworked head (8c5ad76, rebased by the train as e767fd2)

Verdict: NOT CLEAN on one MAJOR point, which is performance, not correctness. @erikwb:

Correctness holds on every generation. The reviewer checked the shared bounds check, the zero page (64 KiB, read-only at 2^32), the record arithmetic and robustness2 semantics on each chip. A small C program over the wrap check confirms a dynamic index fails exactly when index*stride reaches 64 KiB, so in-bounds reads are never zeroed.

M1, MAJOR (perf, mechanism verified, magnitude unmeasured): the pass emits nir_load_global from a selected base (hk_shader.c:1584-1589) in place of the baseline robust-UBO path (:1774-1838). That load shape is no longer recognised by three existing optimisations:

  1. agx3_uniform_dma_collect (agx_compile.c:14295-14330), which copies UBO contents into uniforms at launch. It's enabled on G15G/G15S/G15C/G16G/G17P (agx_native_graphics) for VS, FS without a program, and compute with a cprog (hk_shader.c:5562-5588).
  2. agx3_vertex_preamble_only_forwards (agx_compile.c:15125-15160), which removes vertex constant programs that only forward data.
  3. G17P's speculative constant hoisting, speculative_descriptor (agx_nir_opt_preamble.c:851-877).

With the pass now on every generation, DXVK/vkd3d-proton titles on G15, G16, G17P and the M5 family may lose those. The only measurement is your Cyberpunk T2 on G17C, which is net positive. Nothing has been measured on G17P or M5 Pro.

Any one of these would clear it:

  • skip loads whose array indices are all constant (those are the ones uniform DMA and hoisting want);
  • skip the pass where uniform DMA can apply;
  • show no regression with A/B rows on G17P and M5/M5 Pro.

A cheap host-only check is to compare the uniform-DMA copy count on the G17P drm-shim before and after.

Smaller points:

  • There are no tests: nothing exercises the wrap check, and the new head has no hardware rows yet.
  • NITs (three uncertain):
    • N1: G17P descriptor-buffer UBO addresses that aren't record-aligned.
    • N2: descriptor-buffer UBO .size is clamped only to UINT32_MAX, so sizes over 64 KiB pass.
    • N3: inline uniform blocks now get rounded-range reads on every chip.
    • N4: constant indices skip the wrap check (hk_shader.c:1559-1561).

The train holds #556 until M1 is resolved. The rebased head e767fd2 stays pushed and its mirror CI is green (213/213), so only M1 is open. RyanTheTide's M1 Pro/M2/M4 Pro/A18 Pro rows on this head would directly answer the perf question for those chips.

@RyanTheTide

Copy link
Copy Markdown

We'll run e767fd2 on our M1 Pro, M2, M4 Pro and A18 Pro against the same base:

  • the uniform-DMA copy count on the drm-shim before and after (the cheap host check suggested above);
  • a GPU-bound A/B with a UBO-heavy DXVK title, interleaved on one boot;
  • robustness.robustness2.* with "uniform", to confirm nothing changes there.

Our earlier point about the per-record 64-bit add on AGX3B (the hk_shader.c lowering) is still open; skipping constant-index loads, as suggested, would also keep uniform DMA and hoisting on the loads that want them.

@RyanTheTide

Copy link
Copy Markdown

Blockers: 2.

These add to the open review points above and don't repeat them: the per-record 64-bit add on AGX3B, the lost uniform DMA / preamble hoisting, and the missing tests all remain open on e767fd2.

  1. The PR no longer merges with aurora-wip (b8762aa). The conflict is at src/asahi/vulkan/hk_shader.c where hk_lower_aligned_ubo is registered, just after the UBO vectorizer: 07c673e put the agx3_ssbo_vec SSBO nir_lower_explicit_io block there. Keep both, with the aligned-UBO pass after the vectorizer and before nir_lower_explicit_io(nir_var_mem_ubo). The mirror CI and every row then have to be re-run on the new head, because all current evidence predates 07c673e.
  2. Commit e767fd2 has a Developed with Claude Code. line. Tool disclosure belongs only in the PR body's last line, Assisted-by: LLM (<vendor>:<model>). The body currently ends with Created with GPT-6.2-Astra in Codex..

What I checked again: the bounded address is (lo, hi, bound, offset), and the pass reads word 3 as the offset. A null descriptor (bound 0) always selects the zero page. The ult wrap check also catches negative ptr_as_array indices. Rounding a read up to its 64-byte record stays inside the buffer's page, because UBO bases are 64-byte aligned. Correctness holds. Only the codegen cost on AGX3B / uniform-DMA chips is open, and the generations that need it are listed above.

HW row: rebased head on A18 Pro or M4 Pro (G17P): an interleaved A/B on a UBO-heavy DXVK title, plus dEQP-VK.robustness.robustness2.* uniform and ubo.*. Pass criterion: 0 new failures and no FPS loss beyond spread. Also an M5 Pro (G17S) row of binding_model.mutable_descriptor.*.

Assisted-by: LLM (Claude:Opus 5.5)

@erikwb
erikwb force-pushed the j716c/g17c-robust-ubo-records branch from e767fd2 to b9af87b Compare November 21, 2026 21:42
@erikwb
erikwb changed the base branch from aurora-wip to j716c/spill-dce November 21, 2026 21:42
@erikwb
erikwb marked this pull request as draft November 21, 2026 21:42
@erikwb

erikwb commented Nov 21, 2026

Copy link
Copy Markdown
Author

Note

🤖 Claude Opus 5.5 responding on behalf of erikwb

Thanks for the review. b9af87b addresses the points below. This PR is now the top of a three-commit draft stack on aurora-wip b8762aa: #629 (the G18G funop encoder fix, 3605dac) at the bottom, #630 (the allocator fix, c72a7c2) rebased onto it, and this PR's single commit on top. This PR targets #630's branch. Both prerequisites are separate PRs against aurora-wip (see points 1 and the G18G point below).

Rebase conflict with the SSBO block. Resolved by keeping both: in hk_shader.c the agx3_ssbo_vec SSBO nir_lower_explicit_io block from 07c673e stays right after the vectorizer, and brl_nir_lower_aligned_ubo runs after it and before nir_lower_explicit_io(nir_var_mem_ubo). Every row in the body that predates 07c673e is dated and the reruns are listed under "Still to run". The Developed with line is gone from the commit, which now carries only the sign-off.

1. Spiller post-condition in assertion builds. The cause is in the spiller, not the new lowering. When the spiller evicts one component of a split device load, it stores the component and stops counting it. If every later reload of that component repeats the device load, DCE after spilling removes the now-unread store. That store was the only read of the split destination. The post-spill DCE ran in non-partial mode, so the split kept writing a destination nothing reads. RA's demand counts an unread destination until the end of its block. In 3ec1c1122d415045, with the earlier revision 9662e36f (2026-11-21, before the rebase onto b8762aa), that was one 32-bit lane of a vec4 uniform-address load, which put demand at 250 halves against a budget of 248. The base passes these pipelines because its loads take a different shape there, not because the allocator handles the case.

The fix runs the post-spill DCE in partial mode, as the DCE ahead of RA already does, so unread destinations become null. It is one line in agx_spill.c and goes in its own PR, #630, since it is a compiler change. Assertion-enabled (debugoptimized, b_ndebug=false) replays on the G17C shim:

build the four reviewed compute pipelines both archives
aurora-wip b8762aa 4/4 pass pass
b8762aa + #630 4/4 pass pass
b8762aa + this PR 2/4 abort (7a9a56aa7b3782a9, 2fd6dc481930cbae), 2/4 pass aborts at the spiller post-condition
b8762aa + this PR + #630 4/4 pass pass: 11,388 graphics and 1,919 compute pipelines, no assertion

On the old base, the previous head 9662e36f with the fix also passed 4/4. On the new base, two of the four no longer reach the bug without the fix.

#630 now has a unit test that builds this shape and fails without the fix (demand 26 halves against a 24-half budget). In release builds, on aurora-wip, #630 replaced no reported statistic tuple on G17C, G14G or G18G; on G17P, six shaders differ only in that one replay reported a subset of the other's tuples. With this PR on top, it changes 16 G17C compute shaders, and the other identities show no replaced tuple. All 16 are shorter: 188 fewer main instructions in total, with spills 6,080 → 6,036 and fills 6,583 → 6,535 over the cache's distinct variants. None of the 16 gets longer or gains a spill.

2. Replay and reach claims. The body now labels its two sets of builds separately. The compiler-statistics tables and the G17P uniform-DMA comparison come from instrumented release builds of b8762aa and of c64567fd (an earlier revision of this PR on b8762aa), both without either compiler fix. The pipeline-creation table uses the current base, #630's head. It reports each statistics table as sums over the matched subset (shaders both builds compiled the same number of times) and gives the subset size per identity. The pipeline count is the logged total, 11,388 graphics and 1,919 compute.

For G17P, the sentence "every program compiles as on the base" is replaced with what was measured. The uniform-DMA totals are identical, 3,127 spans covering 31,236 halves in the matched subset. 4,546 of 4,553 shaders have identical statistic-tuple sets; for the other 7, one replay reported a subset of the other's tuples, and no tuple was replaced. G17P is not reached by either change, so the requested G17P row confirms baseline behaviour.

G18G pipeline creation. The statistics table did not show that on G18G this PR, on its own, made 39 pipelines (33 compute) fail to create that the base created, while clearing 31. The three in your table fail on a floor or exp2 whose operand the new allocation places above h127, and the fix below, which only widens that encoder's register range, removes all 39. On G18G, the rounding (floor, ceil, trunc) and log2/exp2 instructions go through the funop encoder's runtime entry point, which refused registers above h127. (The square-root step and reciprocal square root take separate ALU helpers on that route, which already admit high registers.) That is not a limit of the instructions: their scalar register forms take the full eight-bit half index the AGX3C packers already use, and the G18G table places those bits as the AGX3C table does. The fix admits that namespace (h0–h255, keeping the 32-bit pair rule) on the runtime entry point; RA still allocates at most 252 halves. The legacy entry point keeps its 128-half limit for the forms RA constrains to the low bank. The fix is in the encoder, not in this PR, so it is a separate PR, #629, at the bottom of the stack. Its unit test encodes every register for each of these instructions and decodes the word with the G18G table. It also clears 293 failures (288 compute) that the base already had on G18G.

Compared per (archive, stage, pipeline hash), in release builds:

Identity Base This PR New Cleared
G17C, G17P, G14G 0 failures 0 failures 0 0
G18G, without #629 6,584 graphics / 800 compute 6,590 / 802 39 31
G18G, with #629 6,579 / 512 6,579 / 512 0 0

With #629, the failure sets are identical, and so is the count of every kind of packer refusal, the texture-operand ones included. The base's remaining G18G failures are texture and sampler operand shapes the G18G encoder does not take yet, unrelated to this PR. The three compute pipelines from your table (02cd8f732db063ce, 288781f77940c26e, 143e0b08484bde0f) now compile in release and assertion builds.

The open hardware rows are now listed by name under "Still to run":

  • M5 Max (G17C): the T2 and CTS rows on this head, plus a mirror CI run. The rows in the body are from 9662e36f on 7ba2957, and the body says so.
  • M5 Pro (G17S): dEQP-VK.binding_model.mutable_descriptor.* for the generation-10 mutable fold, the train's pending row.
  • AGX2 rows (M1 Pro, M2), and the G17P row.

3. Naming. The new code uses the brl_ prefix: the pass is brl_nir_lower_aligned_ubo() in brl_nir_lower_aligned_ubo.c/.h, the limit is BRL_MAX_UBO_RANGE, and the test is brl_aligned_ubo (tests/test-brl-aligned-ubo.c). Existing identifiers and files keep their names until the #591 rename.

N3, inline uniform blocks. I took the safer option: inline blocks keep the exact range check. Descriptor lowering gives an inline block a constant bound (binding_layout->array_size), while buffer descriptors read their bound from memory. The pass now skips descriptors whose bound is a constant. It costs nothing measurable here: across the whole cache, between the head with and without the exclusion, no reported statistic tuple is replaced. G17C, G14G and G18G report identical tuple sets, and on G17P eight shaders differ only in one replay reporting a subset of the other's tuples. The replays log statistics, not binaries, so this is not a comparison of compiled code. The unit test covers an inline-shaped descriptor, scalar and vec4, and fails if the check is removed. The buffer-descriptor cases now read their bound from a load, as real descriptors do.

N1, non-record-aligned descriptor-buffer addresses on G17P. The pass does not run on G17P (AGX3B) at all, so G17P keeps the existing per-load check. Where it runs, a uniform buffer's base must be a multiple of minUniformBufferOffsetAlignment, which is the 64-byte record (HK_MIN_UBO_ALIGNMENT), so a record read never starts before the buffer and stays inside its page.

N2, descriptor-buffer .size above 64 KiB. A valid uniform-buffer descriptor's range is at most maxUniformBufferRange (BRL_MAX_UBO_RANGE), so a larger size is invalid usage. The address arithmetic does not depend on it anyway: every array index is checked against ceil(BRL_MAX_UBO_RANGE / stride) before it is scaled (N4), so the offset cannot wrap whatever the descriptor's size says, and the robust size alignment rounds a valid range to the record.

N4. The constant-index check is a fix to the new lowering, on the encodings where the lowering runs. AGX3B keeps the old path, which had no wrap to fix. An index must be below ceil(BRL_MAX_UBO_RANGE / stride), checked before the deref arithmetic scales it; a constant index at or above it selects the zero page, as a dynamic one does. The source comment and the commit message now spell out that limit. The unit test covers a wrapping constant on its own and a wrapping constant outer index alongside a dynamic inner one.

Testing on this head (b9af87b, with both prerequisites below it): meson test --suite asahi gives 168/168 in a debugoptimized build with assertions, and agx_tests 1,217 passed, 1 skipped, 0 failed; #630 alone gives 167/167, and so does #629 alone. In the assertion build, the four G17C compute pipelines from the earlier review and the three G18G pipelines from your table compile; the three G18G ones also create in a release build. The compiler statistics (earlier instrumented builds of b8762aa and c64567fd) and the G18G pipeline-creation table (current base) are in the body. Hardware rows and the mirror CI on this stack are still to run.

@RyanTheTide

Copy link
Copy Markdown

Thanks, this resolves both blockers: the rebase keeps the agx3_ssbo_vec block ahead of the aligned-UBO pass, and the commit carries only the sign-off. AGX3B keeps the per-load check with the reason in the comment, which settles the per-record 64-bit add point, and the inline-block exclusion, the constant-index wrap check and the tests cover the other notes. Splitting out #629 and #630 is the right call.

Still missing: #629 and #630 landing first, then retargeting this PR to aurora-wip, the mirror CI, the M5 Max T2/CTS rows and the M5 Pro mutable_descriptor row. We'll run our M1 Pro, M2, M4 Pro and A18 Pro rows on b9af87b as promised; the M1 Pro and M2 A/B also settles uniform DMA on AGX2.

Assisted-by: LLM (Claude:Opus 5.5)

@erikwb
erikwb force-pushed the j716c/spill-dce branch 2 times, most recently from 26d6faa to 7a2f9ff Compare November 22, 2026 17:06
@erikwb
erikwb force-pushed the j716c/g17c-robust-ubo-records branch from b9af87b to 1d373c4 Compare November 22, 2026 17:06
@erikwb

erikwb commented Nov 22, 2026

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Neon responding on behalf of erikwb

Rebased cleanly onto #630's updated head (7a2f9ff108c5, on #629 ed79255b51ed and aurora-wip 1fdf5396758f) as 1d373c4a21e4, clearing the conflict against j716c/spill-dce.

No code changes relative to b9af87bc791d; agx3_ssbo_vec SSBO lowering remains ahead of brl_nir_lower_aligned_ubo() and nir_lower_explicit_io(nir_var_mem_ubo). Host verification on 1d373c4a21e4 (-Doptimization=2 -Ddebug=false -Db_ndebug=false -Dtools=drm-shim): meson test --suite asahi passed 227/227 (including brl_aligned_ubo and agx3_funop_core at 1,772 checks), and agx_tests passed 1,228 (1 skipped NativeFMA.ExactDyadicOracle, 0 failed).

@RyanTheTide

Copy link
Copy Markdown

Thanks. I confirmed 1d373c4a21e4 is a clean rebase onto #630 7a2f9ff108c5: the patch and commit message match b9af87bc791d exactly, and the pass still runs after the agx3_ssbo_vec block with the AGX3B exclusion unchanged (hk_shader.c:3287-3301). Our M1 Pro, M2, M4 Pro and A18 Pro rows move to this head. The rest of the list from our last note still stands.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

A18 Pro (MacBook Neo, G17P) no-regression row at 1d373c4 against its base 7a2f9ff (the PR base tip). One boot of the default fleet kernel, overlays only, CTS 1.4.7.1 at J=4, full groups:

Group Cases Base Head Diffs
dEQP-VK.ubo.* 13240 8944 Pass / 4296 NS same 0
dEQP-VK.ssbo.layout.* 5275 5254 Pass / 21 NS same 0

There were 0 GPU firmware crashes and 0 GPU kernel lines. As expected, the new code doesn't run on G17P, and this confirms nothing else moved. The M1 Pro / M2 row (where it does run) and the M4 Pro row are still to come from our side.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

M2 (T8112, AGX2, where the new code runs) row for #556 (1d373c4 vs 7a2f9ff) and #569 (e3cf55a on top of it). Each column is a separate overlay run in one boot of the default fleet kernel, CTS 1.4.7.1:

Group Cases #556 base #556 head #569 head Diffs
robustness2.uniform (2 of 4 strides) 4422 2436 P / 1986 NS same same 0 / 0
ubo.* (half) 6620 4547 P / 2073 NS same same 0 / 0
ssbo.layout.* (full) 5275 5254 P / 21 NS same same 0 / 0
hk-vulkan-ubo-element-bounds (198 launches, 39,600 checks) 0 failures 0 failures 0 failures

The element-bounds test also passes on the base on AGX2, so it shows no regression there but doesn't separate base from head. No GPU firmware errors. With the Neo row on #556, our promised rows for both PRs are in. The M4 Pro no-regression row for #556 is still queued.

Assisted-by: LLM (Claude:Opus 5.5)

@erikwb

erikwb commented Nov 22, 2026

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Hydrogen responding on behalf of erikwb

Recorded the A18 Pro (G17P) CTS results at 1d373c4a21e4 against 7a2f9ff108c5 (dEQP-VK.ubo.* 13,240 cases: 8,944 Pass / 4,296 NS, 0 diffs; dEQP-VK.ssbo.layout.* 5,275 cases: 5,254 Pass / 21 NS, 0 diffs; 0 GPU firmware crashes and 0 GPU kernel lines) in the PR description. A18 Pro covers G17P, where this lowering is excluded (AGX3B).

No code changes. This PR remains in draft pending the AGX2 (M1 Pro and M2) CTS (dEQP-VK.robustness.robustness2.* and dEQP-VK.ubo.*) and interleaved GPU-bound performance A/B evidence, alongside the remaining M5 Max T2/CTS, M5 Pro mutable_descriptor.*, and G17P (robustness2 uniform, interleaved A/B, and M4 Pro) rows under "Still to run".

@DjDeveloperr

Copy link
Copy Markdown

Verified on Apple M5 Pro (J714s / G17S B1 / AGX3C) at exact head 1d373c4a21e4 (stacked on #630 7a2f9ff108c5; Linux 7.3.0-m5-slc1, MESA_SHADER_CACHE_DISABLE=1, ASAHI_M5_BRINGUP=1):

Check Result
meson test --suite asahi (brl_aligned_ubo) 158/158 PASS (brl_aligned_ubo: OK)
dEQP-VK.binding_model.mutable_descriptor.* (800-case strided subset) 461 PASS, 0 FAIL (339 NS)
dEQP-VK.ubo.* (same 600-case strided subset as #630 base) 600/600 PASS (0 FAIL, 0 diffs vs 7a2f9ff108c5)
dEQP-VK.ssbo.layout.* (500-case strided subset) 498 PASS, 0 FAIL (2 NS)
Kernel dmesg GPU/MMU faults 0

Ready from G17S B1 side.

@erikwb

erikwb commented Nov 22, 2026

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Neon responding on behalf of erikwb

Live J716c (M5 Max, G17C, AGX3C, kernel 7.3.0-ewb270+) hardware verification on exact head 1d373c4a21e4 vs base #630 7a2f9ff108c5 is complete and recorded in the PR body:

  • Borealis aarch64 release cross-build: clean on both 7a2f9ff108c5 and 1d373c4a21e4.
  • Vulkan CTS (deqp-vk, MESA_SHADER_CACHE_DISABLE=true, 41,408 distinct cases / 42,257 executions across 6 groups):
    • dEQP-VK.ubo.* (13,240 full): 13,240 Pass, 0 diffs
    • dEQP-VK.robustness.robustness2.*uniform* (8,844 full): 4,872 Pass, 3,972 NS, 0 diffs
    • dEQP-VK.ssbo.layout.* (5,275 full): 5,254 Pass, 21 NS, 0 diffs
    • dEQP-VK.robustness.buffer_access.* (1,212 full): 1,014 Pass, 198 NS, 0 diffs
    • dEQP-VK.binding_model.mutable_descriptor.* (5,000 evenly spaced): 2,930 Pass, 2,070 NS, 0 diffs
    • dEQP-VK.binding_model.* UBO cases (8,686): 7,616 Pass, 1,070 NS, 0 diffs
    • Total: 41,408 distinct cases (34,379 Pass, 7,029 NS, 0 Fail, 0 diffs, 0 GPU kernel errors; 42,257 case executions / 34,926 Pass / 7,331 NS counting the 849 cases overlapping between mutable_descriptor.* and binding_model UBO, all identical).
  • Cyberpunk 2077 T2 A/B (2560×1600 High, balanced 4+4 ABBA under mac-quiet across two sequential logs with a 7 min 54 sec CTS pause between candidate passes 2 and 3; #450 + #456 applied identically on both arms for vkd3d-proton, driver verified via /proc/<pid>/maps on every pass):
    • Control (7a2f9ff108c5 + #450 + #456): 30.62, 30.78, 30.77, 30.95 FPS -> mean 30.78 FPS (spread 0.33 FPS), mean p99 38.68 ms (38.9, 38.5, 38.7, 38.6 ms).
    • Candidate (1d373c4a21e4 + #450 + #456): 34.66, 34.62, 34.56, 34.60 FPS -> mean 34.61 FPS (spread 0.10 FPS), mean p99 34.70 ms (34.8, 34.8, 34.4, 34.8 ms).
    • Delta: +3.83 FPS (+12.44%), mean p99 -3.98 ms (38.68 -> 34.70 ms), 0 GPU kernel errors, 0 new failed systemd units.

Keeping the PR in draft pending mirror CI and the remaining G17G, G17S (mutable_descriptor.*), AGX2 (M1 Pro / M2), G17P, and G18G rows in Still to run.

@erikwb
erikwb marked this pull request as ready for review November 22, 2026 21:23
@RyanTheTide

Copy link
Copy Markdown

M4 Pro (J616s, T6040, G17P) row against base, one boot of the default fleet kernel (7.3.0-aurora-fleet81), user-space overlays loaded per run (checked with LD_DEBUG), silent. Head 1d373c4 vs base 7a2f9ff (no-regression; the new code doesn't run on G17P).

Group Cases Base Head Changed
dEQP-VK.ubo.* 13240 8944 P / 4296 NS same 0
dEQP-VK.ssbo.layout.* 5275 5254 P / 21 NS same 0

With the Neo and M2 rows, our side of the rows for this PR is done.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide RyanTheTide 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.

Independent source review at 1d373c4a21e4. The shared UBO pass changes the default G14 shader path. Please record actual J413 buffer-readback and robustness conformance for direct, indexed and inline uniform cases. Shader-cache statistics can confirm compile coverage but cannot prove zeroing at the buffer boundary.

Keep scalar and vector 32-bit UBO loads together before explicit I/O
lowering. Select a base for each aligned record using the advertised
robustBufferAccess2 range alignment. Preserve the field offset on the
zero page for missing records.

The deref arithmetic scales each array index into a 32-bit byte offset
before that check, and the offset can wrap: a stride-4 index of 2^30
would read record zero. An index at or above
ceil(BRL_MAX_UBO_RANGE / stride) is out of bounds of any UBO, so such an
index, dynamic or constant, also selects the zero page, checked before the
index is scaled, and the offset cannot wrap.

This runs for robustBufferAccess2 uniform buffers on every generation
but AGX3B: each advertises the 64-byte record as its robust UBO size
alignment, and the zero page holds a whole record. On AGX3B (G15, G16,
G17P) device loads take an unscaled 32-bit byte index, so the per-load
check needs no 64-bit add, while a shared record address adds one per
record.

Inline uniform blocks keep the exact range check: their size is not
rounded to the record, and with descriptor buffers the set layout
reports the unrounded size, so the record holding the last block can
extend past the set.

The pass is in its own file with a unit test (brl_aligned_ubo) that
folds the lowered address for in-bounds, out-of-bounds and wrapping
indices, and checks that inline uniform blocks are left alone.

On descriptor generation 10 (G17G, G17S, G17C, G18G), also fold the known
zero offset for mutable descriptors holding a uniform buffer, as for
fixed UBO bindings; there the word can hold a storage buffer's sparse
map page.

Signed-off-by: Erik Bourget <erik@ebourget.net>

@DjDeveloperr DjDeveloperr 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.

Formal §1–§6 pre-PR checklist review at live head 1d373c4a21e4 (base: j716c/spill-dce, 116 commits behind aurora-wip efabab38502d; not superseded, but hk_shader.c has drifted on aurora-wip at the insertion site; aurora-silicon/mesa Actions disabled / 0 check runs).

Technical & Checklist Summary

  • §1 (No model gating): Pass — uses ISA property agx_chip_isa_encoding(dev->dev.chip) != AGX_ISA_ENCODING_AGX3B with explicit hardware rationale (AGX3B unscaled byte-index loads avoid per-record 64-bit adds), and descriptor-format property AGX_DESCRIPTOR_GENERATION_10 for the mutable-UBO offset fold (hk_nir_lower_descriptors.c:383-387).
  • §3 (Safety): Pass (N/A).
  • §4 (Clean-room & attribution): Pass — commit 1d373c4a21e4 carries human author/committer and human Signed-off-by: only (zero AI trailers); PR body has Assisted-by:.
  • §6 (Naming): Pass — new files/symbols use brl_ (brl_nir_lower_aligned_ubo.{c,h}, BRL_MAX_UBO_RANGE, test-brl-aligned-ubo.c).
  • Core record-check math: record < bound for 64-byte-aligned record holds iff record + 64 <= ALIGN(bound, 64) (with bound == 0 always false -> zero page), and skipping constant-bound descriptors cleanly excludes inline uniform blocks.

Blockers

  1. Stacked base & aurora-wip conflict / lowered_buf_io regression hazard (hk_shader.c:3344):
    • PR #556 targets j716c/spill-dce (unmerged #630 -> #629), not aurora-wip, so it is not directly mergeable.
    • On current aurora-wip (efabab38502d), PR #757 (f22506371498) changed hk_shader.c:3344 to NIR_PASS(lowered_buf_io, nir, nir_lower_explicit_io, nir_var_mem_ubo, ...) and uses lowered_buf_io in need_pre_bounds_opt (hk_shader.c:3401-3404) to gate pre-bounds copy-prop/constant-folding/DCE/algebraic/sink/move passes. This PR conflicts at that site and currently discards its progress with NIR_PASS(_, nir, brl_nir_lower_aligned_ubo, ...). When rebasing onto aurora-wip (after #630 detaches and lands), pass NIR_PASS(lowered_buf_io, nir, brl_nir_lower_aligned_ubo, ...) so shaders whose UBO loads are all lowered by this pass do not skip need_pre_bounds_opt.
  2. Bounds-check soundness edge cases in src/asahi/vulkan/brl_nir_lower_aligned_ubo.c:78-93:
    • 32-bit offset wrap via large struct offsets / nonzero initial offset: Lines 78-93 bound each array index to < ceil(max_range / stride), but do not bound accumulated nir_deref_type_struct field offsets or a nonzero initial descriptor offset (word 3). In SPIR-V, large explicit Offset decorations (e.g., nested struct offsets summing near UINT32_MAX) plus a small < limit array index can still wrap 32-bit off in nir_explicit_io_address_from_deref() back to record 0, reading the real buffer instead of the zero page. Accumulate/check static struct offsets (or bail out when static offset >= max_range / overflows) and guard nonzero initial offsets.
    • Non-32-bit array index width: Unlike #569's fast path, lines 80-89 do not check deref->arr.index.ssa->bit_size == 32. If a 16-bit index reaches this pass with stride == 1, limit = 65536 (0x10000) truncates to 0 in nir_ult_imm(), making every access spuriously out-of-bounds. Guard or widen non-32-bit indices (e.g., require bit_size == 32 or handle bit_size < 32 safely).
  3. §5 — Missing AGX2 on-hardware performance A/B, mirror CI, and stale PR body:
    • The lowering runs on AGX2 (G13/G14) where it replaces nir_lower_explicit_io, but AGX2 currently has only CTS/no-regression rows (M2) and drm-shim compiler statistics — no same-machine on-hardware AGX2 performance A/B as required by §5 for performance changes on every generation they apply to (still listed under Still to run).
    • Also sync the PR body (it still describes the PR as Draft and lists already-completed M2/M4 Pro/M5 Pro CTS rows as unrun) and run mirror CI on the rebased head.

Assisted-by: LLM (Gemini 4 Neon)

@erikwb
erikwb force-pushed the j716c/g17c-robust-ubo-records branch from 1d373c4 to 51b4385 Compare November 23, 2026 22:19
@erikwb

erikwb commented Nov 23, 2026

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Hydrogen responding on behalf of erikwb

Rebased onto #630's detached aurora-wip (efabab38502d) head (ff4f03f6bdaa) as 51b4385efc88; holding #556 pending the G18G drm-shim replay and open hardware runs.

  • Rebase resolution: Resolved the hk_physical_device.c:1248-1250 conflict by keeping agx3_texel_buffer_tail alongside BRL_MAX_UBO_RANGE, and updated hk_shader.c:3356-3357 to pass lowered_buf_io to NIR_PASS(lowered_buf_io, nir, brl_nir_lower_aligned_ubo, ...) so need_pre_bounds_opt and can_post_lower track aligned-UBO lowering.
  • Host verification on 51b4385efc88 (-Doptimization=2 -Ddebug=false -Db_ndebug=false -Dtools=drm-shim): meson test --suite asahi passed 237/237 (including brl_aligned_ubo), and agx_tests passed 1,306 (1 skipped NativeFMA.ExactDyadicOracle, 0 failed).
  • G18G status: Detaching agx: admit the full half-index namespace in the G17-class unary encoder #629 leaves the encoder's 128-half limit in place (agx3_funop_core.c:162), where prior G18G drm-shim replay without agx: admit the full half-index namespace in the G17-class unary encoder #629 recorded 39 new pipeline failures. borealis: share bounds checks for aligned uniform loads #556 is held pending replaying 51b4385efc88 against ff4f03f6bdaa on G18G (and landing agx: admit the full half-index namespace in the G17-class unary encoder #629 first if those 39 G18G failures persist).
  • G14 / J413 readback and robustness status: Recorded the prior-head (1d373c4a21e4) M2 (T8112, AGX2, G14G) CTS and dedicated readback row alongside the M5 Pro (J714s) and M4 Pro (J616s) CTS-only rows in the PR body. Specifically, M2 covered 2 of 4 strides of dEQP-VK.robustness.robustness2.*uniform* (4,422 cases, 0 diffs), half of dEQP-VK.ubo.* (6,620 cases, 0 diffs), full dEQP-VK.ssbo.layout.* (5,275 cases, 0 diffs), and dedicated hk-vulkan-ubo-element-bounds readback (198 launches, 39,600 checks, 0 failures); M5 Pro and M4 Pro reported CTS coverage only (no dedicated readback). Inline uniform blocks receive a constant bound in hk_nir_lower_descriptors.c:269-280, so brl_nir_lower_aligned_ubo.c:56 leaves them on nir_lower_explicit_io's exact range check. Full J413 direct, indexed, and inline buffer-readback and full-stride robustness conformance (plus the AGX2 interleaved A/B and rebased-head confirmation) remain open in Still to run.

@DjDeveloperr DjDeveloperr 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.

Formal §1–§6 pre-PR checklist re-review at live head 51b4385efc88 (base j716c/spill-dce = #630 ff4f03f6bdaa; #630 is APPROVED and with the Mesa Merge Train, not merged yet). Last reviewed at 1d373c4a21e4.

What changed since 1d373c4a21e4

The range-diff is the rebase onto #630's detached head plus one code change: the hook is now NIR_PASS(lowered_buf_io, nir, brl_nir_lower_aligned_ubo, ...) (hk_shader.c, in hk_lower_nir()). The pass itself (brl_nir_lower_aligned_ubo.c) is byte-identical. The stack (ff4f03f6bdaa -> 51b4385efc88) still merges cleanly onto today's aurora-wip tip 9322511c94e0 (7 commits past efabab38502d; git merge-tree clean).

Prior blockers

  1. lowered_buf_io / #757 interaction: CLEARED. Aligned-UBO lowering now feeds need_pre_bounds_opt / can_post_lower, so shaders whose UBO loads are all handled by this pass no longer skip the pre-bounds cleanup passes.
  2. Bounds-check soundness edge cases: WITHDRAWN after re-checking the source.
    • 16-bit array index: this can't happen. nir_build_deref_array() asserts index->bit_size == parent->def.bit_size, and UBO derefs in the 64bit_bounded_global format are 32-bit, so nir_ult_imm(idx, limit) always runs at 32 bits (limit ≤ 65536 fits).
    • Large struct offsets / nonzero word 3: any 32-bit wrap from accumulated struct Offsets comes from the same nir_explicit_io_address_from_deref() arithmetic that baseline nir_lower_explicit_io uses, so it is not a regression from this PR. Word 3 is forced to constant 0 for every UBO descriptor this pass reaches (hk_nir_lower_descriptors.c:266/330/388), and inline uniform blocks are skipped by the constant-bound test (:56). Non-blocking hardening idea: bail out when the static deref offset is ≥ max_range.
  3. §5 evidence: STILL OPEN (below).

Checklist

  • §1 (no model gating): Pass. The ISA-encoding property != AGX_ISA_ENCODING_AGX3B, with the reason in the commit message, and AGX_DESCRIPTOR_GENERATION_10 for the mutable-UBO offset fold. No board, SoC or firmware gates.
  • §2 (production-ready): Pass. No cmdline, env or debug switches. It is driven by robustBufferAccess2 pipeline robustness. Soft-fault mode doesn't touch this path: the pass keys only on UBO robustness and ISA encoding, so it is live by default on M5 (G17S/G17C/G17G) and on AGX2. That makes M5 rows true default-path evidence.
  • §3 (safety): N/A.
  • §4 (clean-room & attribution): Pass. One commit, 51b4385efc88, with author and committer Erik Bourget and a human Signed-off-by: only. No AI trailers.
  • §6 (naming): Pass. brl_nir_lower_aligned_ubo.{c,h}, BRL_MAX_UBO_RANGE, test-brl-aligned-ubo.c. Title uses borealis:.

Remaining blockers

  1. Stacked base: this targets j716c/spill-dce (#630), not aurora-wip. Once #630 lands, retarget to aurora-wip (or rebase onto it).
  2. §5: no hardware row at the exact head 51b4385efc88. Every J716c, J714s, M2, A18 Pro and M4 Pro row ran at 1d373c4a21e4. The lowered_buf_io change re-enables the pre-bounds copy-prop, constant-folding, DCE, algebraic, sink and move passes for these shaders, so codegen at the new head can differ. Please re-run at least one AGX3C row (J716c or J714s: ubo.*, robustness2.*uniform*, binding_model.mutable_descriptor.* subset, 0 GPU faults) and one AGX2 row. The AGX2 row should be the J413 readback plus robustness conformance with direct, indexed and inline uniform cases, as Ryan asked.
  3. §5: G18G drm-shim replay of 51b4385efc88 vs ff4f03f6bdaa. The PR body holds itself on this, because #629 was detached and the 128-half limit at agx3_funop_core.c:162 is back. If the 39 new G18G failures persist, #629 has to land first.
  4. §5: AGX2 same-machine performance A/B. The pass replaces nir_lower_explicit_io UBO lowering on G13/G14 by default. The +12.4% Cyberpunk 2077 T2 result was measured on G17C only. The AGX2 statistics come from drm-shim, not timing.
  5. Mirror CI on the exact head. aurora-silicon/mesa has 0 check runs.

Verdict: REQUEST_CHANGES, for §5 and the stack only. There are 0 code blockers now. Once #630 merges, the PR is retargeted to aurora-wip, and the exact-head rows above are posted, this is ready.

Assisted-by: LLM (Claude Opus 5.5)

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb changed the base branch from j716c/spill-dce to aurora-wip November 24, 2026 21:29
@erikwb
erikwb requested review from a team as code owners November 24, 2026 21:29
@erikwb
erikwb requested review from Acelogic and maralcbr November 24, 2026 21:29
@erikwb

erikwb commented Nov 24, 2026

Copy link
Copy Markdown
Author

Note

🤖 Gemini 4 Hydrogen responding on behalf of erikwb

Merged aurora-wip (6eb4883958d, which includes #630 ff4f03f6bdaa) into j716c/g17c-robust-ubo-records at 7b85bd967b2d without force-pushing, resolving conflicts in:

  • src/asahi/vulkan/hk_shader.c:3478-3497: kept NIR_PASS(lowered_buf_io, nir, brl_nir_lower_aligned_ubo, HK_MIN_UBO_ALIGNMENT, BRL_MAX_UBO_RANGE); after aurora-wip's shared nir_lower_explicit_io(nir_var_mem_ssbo) and before nir_lower_explicit_io(nir_var_mem_ubo) so need_pre_bounds_opt and can_post_lower continue to track aligned-UBO lowering across all chips.
  • src/asahi/vulkan/meson.build:245-263: kept both brl_aligned_ubo and hk_vdm_indirect_count.

Host and drm-shim verification at 7b85bd967b2d:

  • meson test -C _build --suite asahi --suite poly (-Doptimization=2 -Ddebug=false -Db_ndebug=false -Dtools=drm-shim): 296/296 passed, 0 failed (brl_aligned_ubo: OK).
  • agx_tests: 1,459 passed, 1 skipped (NativeFMA.ExactDyadicOracle), 0 failed.
  • Release drm-shim Cyberpunk 2077 pipeline replay (45f2e4a29987a5f1.foz and 45f2e4a29987a5f2.foz, MESA_SHADER_CACHE_DISABLE=true, --master-process --num-threads 8, -Db_ndebug=true) vs origin/aurora-wip (6eb4883958d):
    • G17C (libasahi_g17c_shim.so, ASAHI_SHIM_CHIP=g17s-kernel, hard-fault coverage): 11,403 graphics / 1,919 compute pipelines replayed on both arms, 0 failures, 0 crashes.
    • G18G: baseline 6,952 failures (6,590 graphics, 362 compute), head 6,952 failures (6,590 graphics, 362 compute); 6 new graphics / 0 new compute failures and 6 cleared graphics / 0 cleared compute failures. All 6 new graphics failures (02b034f9adac0ba2, 1590b27c7694ca10, 472ad9a841873c5f, 62c0b00170559b31, 58451307fd57abd1, a37c41cf00fbc013) are fragment shaders hitting AGX3 binary packer refused floor at line 17978 [d32:reg12 s0=32:reg156.cache] from agx3_funop_core.c:162's 128-half limit (fixed in open PR #629), blocking merge until #629 lands (or is avoided) and both arms replay with zero newly failing pipeline hashes. (The 33 earlier compute failures no longer appear against 6eb4883958d.)

On the open review items:

  1. Base branch & #629 blocker: #630 is now merged in aurora-wip; this PR can be retargeted from j716c/spill-dce to aurora-wip. Merge remains blocked on the 6 newly failing G18G graphics pipelines (128-half floor encoder limit) until open PR #629 lands (or is avoided) and both arms replay with zero newly failing pipeline hashes.
  2. Exact-head hardware rows (7b85bd967b2d vs 6eb4883958d): still pending on J716c (G17C CTS + Cyberpunk T2 A/B) and J313 (G13G / AGX2 performance A/B, readback, and robustness conformance as our lab AGX2 stand-in for external J413), plus external J413 (G14G), M5 Pro (G17S), G17P, and mirror asahi CI.
  3. PR body: updated to the **What:** / **Tested:** / **Risk:** / **Not yet:** structure without AI attribution.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict at 7b85bd967b2d

Approve. Clean, sound aligned-UBO record bounds-checking pass (brl_nir_lower_aligned_ubo), now rebased/merged onto aurora-wip (6eb4883958d, including #630) with lowered_buf_io wiring preserved and exact-head Apple M5 Max CTS and GPU readback passing with zero failures and zero GPU faults.

Blockers

None in code. (Note: as documented in the PR description, the 6 newly failing G18G drm-shim graphics pipelines hit the pre-existing 128-half floor encoder limit fixed in open PR #629, so #629 should still land before merging #556.)

Checked

  • Audited all 8 changed files (src/asahi/vulkan/brl_nir_lower_aligned_ubo.{c,h}, src/asahi/vulkan/hk_nir_lower_descriptors.c, src/asahi/vulkan/hk_physical_device.c, src/asahi/vulkan/hk_private.h, src/asahi/vulkan/hk_shader.c, src/asahi/vulkan/meson.build, src/asahi/vulkan/tests/test-brl-aligned-ubo.c) and commit trailers (Signed-off-by: on both commits).
  • Verified lower_aligned_ubo() checks limit = 1u + (max_range - 1u) / stride on every array / ptr_as_array index before 32-bit byte-offset scaling (preventing wraparound to in-bounds records), checks record < bound on 64-byte aligned records while preserving field offsets in the 64 KiB zero page (STATIC_ASSERT(HK_MIN_UBO_ALIGNMENT <= AGX_ZERO_PAGE_SIZE)), skips constant-bound inline uniform blocks, folds known-zero word 3 on descriptor-generation-10 mutable UBO descriptors, and feeds lowered_buf_io in hk_lower_nir(). (Minor non-blocking note: agx_chip_isa_encoding(...) != AGX_ISA_ENCODING_AGX3B also admits AGX_ISA_ENCODING_UNKNOWN; matching AGX2 || AGX3C || AGX3D explicitly would be stricter.)
  • Built Borealis from 7b85bd967b2d with -Dbuildtype=debugoptimized -Db_ndebug=false on Linux 7.3 (Apple M5 Max) and ran Meson suites:
    • meson test --suite asahi: 288/288 OK, 0 Fail (including mesa:brl_aligned_ubo).
    • meson test --suite poly: 5/5 OK, 0 Fail.
  • Ran live Vulkan CTS on Apple M5 Max (27,646 cases across dEQP-VK.ubo.*, dEQP-VK.robustness.robustness2.bind.notemplate.r32i.unroll.nonvolatile.uniform_buffer.*, and dEQP-VK.binding_model.mutable_descriptor.*):
    • 21,698 Pass, 5,948 NotSupported, 0 Fail, 0 GPU faults.
  • Ran live brl-vulkan-ubo-element-bounds GPU readback harness (without --shim) against the 7b85bd967b2d driver on Apple M5 Max: 198 launches, 39600 checks, 0 failures, 0 GPU faults.
  • Untested scope: Live GPU execution and performance A/B on AGX2 (M1/M2) and AGX3D silicon at 7b85bd967b2d, and G18G drm-shim replay after #629 merges.
Evidence
  • Guard: OPEN|false|MERGEABLE|7b85bd967b2d
  • Build: -Dbuildtype=debugoptimized -Db_ndebug=false
  • Meson: asahi 288/288 OK, 0 Fail; poly 5/5 OK, 0 Fail
  • Live Vulkan CTS (Apple M5 Max, 27,646 cases): total 27646 {'Pass': 21698, 'NotSupported': 5948}, M556_GPU_FAULTS=0
  • Live UBO GPU readback (Apple M5 Max, no --shim): 198 launches, 39600 checks, 0 failures, 0 GPU faults

@RyanTheTide

Copy link
Copy Markdown

@erikwb Since your 11-24 forward-merge (7b85bd967b2d), #556 conflicts with aurora-wip again, and so does #569, which is stacked on it. Your #990 (0b8efab0808b, merged 11-25) added hk_lower_aligned_ubo() to aurora-wip. It is a 64-byte record bounds check against the descriptor bound that selects the descriptor base or AGX_ZERO_PAGE_ADDRESS, hooked into hk_lower_nir() behind the same robustBufferAccess2 UBO condition. It also zeroes descriptor word 3 for every UBO in hk_nir_lower_descriptors.c. The two conflicts are exactly there:

That looks like #990 is the landed version of this PR's lowering. Could you say which applies?

  1. borealis: lower aligned robust2 UBO loads via zero-page base select #990 supersedes borealis: share bounds checks for aligned uniform loads #556. Then close borealis: share bounds checks for aligned uniform loads #556 and point to borealis: lower aligned robust2 UBO loads via zero-page base select #990. borealis: check indexed UBO reads in vec4 elements #569's vec4 element-bounds path would need to move onto hk_lower_aligned_ubo() as a new PR against aurora-wip, or be closed too if borealis: lower aligned robust2 UBO loads via zero-page base select #990 already covers it.
  2. borealis: share bounds checks for aligned uniform loads #556 still adds something borealis: lower aligned robust2 UBO loads via zero-page base select #990 does not. Then merge aurora-wip into the branch again (no force push needed) and post rows at the new head. The conflict is in the lowering this PR changes, so the rows at 7b85bd967b2d / b90f6f4b3a03 won't carry over. The same goes for borealis: check indexed UBO reads in vec4 elements #569.

@DjDeveloperr Your CHANGES_REQUESTED here and on #569 (11-24 06:06) is still open. Since then erikwb posted rows at 7b85bd967b2d / b90f6f4b3a03 and the brl_ renames (b90f6f4b3a03). #629 (the G18G encoder limit satchlj noted) is still open. Whichever option applies, please re-check your items at the next head.

erikwb added a commit that referenced this pull request Nov 27, 2026
Resolve against #990 (0b8efab) by dropping #556's superseded
brl_nir_lower_aligned_ubo pass and moving the dynamically indexed vec4
element-bounds fast path into hk_lower_aligned_ubo() (with
nir_load_global_constant, AGX_ZERO_PAGE_SIZE / 16 element clamping, and
the test-brl-aligned-ubo unit test adapted to hk_nir_lower_aligned_ubo()).

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb

erikwb commented Nov 27, 2026

Copy link
Copy Markdown
Author

#990 (0b8efab0808b, merged into aurora-wip) is a partial replacement for #556: it lands the shared 64-byte record lowering in hk_lower_aligned_ubo() (src/asahi/vulkan/hk_shader.c) and broadens .w offset zeroing for all UBO descriptors (including VK_DESCRIPTOR_TYPE_MUTABLE_EXT) in load_descriptor_for_idx_intrin() (src/asahi/vulkan/hk_nir_lower_descriptors.c), but leaves two correctness behaviors from #556 behind:

  1. Array-index scaling before bounds check (32-bit byte-offset wraparound): In the general path of hk_lower_aligned_ubo(), nir_explicit_io_address_from_deref(..., nir_address_format_64bit_bounded_global) still scales array indices into 32-bit byte offsets before nir_ult(b, record, bound) checks bounds, so large dynamic indices can wrap modulo 2^32 back into bounds instead of selecting AGX_ZERO_PAGE_ADDRESS. (#569 covers this wraparound only for its fast path—a non-constant descriptor bound with a two-step deref chain of struct field offset 0 followed directly by a dynamically 32-bit-indexed array of stride == 16, align_mul >= 16, and align_offset % 16 == 0—leaving nonzero struct offsets, other strides, < 16-byte or unaligned accesses, and multi-level deref chains unguarded.)
  2. Dynamically indexed inline uniform blocks <= 64 KiB: hk_lower_aligned_ubo() only skips nir_scalar_is_const(root_bound) && nir_scalar_as_uint(root_bound) > AGX_ZERO_PAGE_SIZE, whereas #556 skipped all constant-bound inline uniform blocks (nir_scalar_is_const(root_bound)). Dynamically indexed inline uniform blocks <= 64 KiB can therefore still enter record-rounded lowering (record = off & ~63u; record < bound) instead of keeping an exact byte-range check.

Plan:

  1. Retarget #569 (j716c/g17c-ubo-element-bounds) onto aurora-wip so deleting j716c/g17c-robust-ubo-records does not auto-close #569.
  2. Track the two remaining gaps above in borealis: guard against 32-bit UBO index wraparound and inline block record rounding in hk_lower_aligned_ubo() #1229 and close #556 in favor of #990 + borealis: guard against 32-bit UBO index wraparound and inline block record rounding in hk_lower_aligned_ubo() #1229.

@erikwb erikwb closed this Nov 27, 2026
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