shader: take the loops lanes outside EXEC run wave-wide (distant-shadow LDS stack pops) #22

Manually merged
github merged 4 commits from github-bot/gh-22 into gh-pr/22/base 2026-12-01 08:27:33 +00:00 AGit
Owner

@⁠just-another-dude84 on GitHub · 2026-11-30 21:43 UTC · original
just-another-dude84:ds-stack-fix → main · +280 −8 · 5 files · 4 commits · merged 2026-12-01 08:24 UTC

What

In programs where scalar_splits already takes per-lane branches wave-wide, s_cbranch_vccz / s_cbranch_vccnz loops are now taken wave-wide too. This applies when the loop holds EXEC-guarded vector code and exits to unguarded vector code.

Why

CS_RTDistantShadowTrace32 (a1b20bc4) keeps its BVH traversal stack in lanes of v23 plus an overflow stack in LDS.

  • Since b33b3d1cd, the walker region runs wave-wide, so lanes outside EXEC also run the LDS pop loops (a1b2 0x16c0, 0x2750, and the other copies).
  • Those loops close on VCC and had stayed per lane. A lane outside EXEC never sees its exit, so it spins to the loop limit.
  • structure then assumed EXEC holds behind the loop, so the v_readfirstlane of the popped stack pointer and node pointer had no EXEC guard. It read lane 0's stale value.
  • Result: stack pointers up to ~486, past the console's 256-dword cap, and node pointers that are floats (0x43a00000) or wild addresses. This is the residue distshadow.md listed as open: "a +60 base of -FLT_MAX read as an instance".
  • Most of these reads land inside the title window and read zeros silently, so the past-the-window census undercounts them.

Scope

Of the 2,734 store compute programs, 12 change; there are no new failures and no fallbacks.

  • The walker family: a1b20bc4, e8c96235, and the CS_TraceShadowRays_* variants.
  • Three programs with the same loop shape that are not walkers: CS_ResolveVBuffer, CS_DefragHeap_ComputeRelocations and CS_MultipleScattering. I have not checked these one by one for a stale read.

If the wider form is refused, the plain form is used. This is counted through kept_per_lane.

TRANSLATOR_VERSION goes from 10 to 11.

Measurements

Setup: RX 6800 (RDNA2), RADV 26.3.1, prison save. Interleaved ABAB, 3 runs per arm, world 90-190 s, run medians. Only translate-dir differs between the arms (main 3a0b738 vs 086d949); the later commits produce identical DXIL.

run arm Execute #13 (ms) #15 (ms)
1 main 15.07 7.70
1 fix 14.70 7.76
2 main 15.23 7.86
2 fix 14.69 7.82
3 main 15.23 7.83
3 fix 14.67 7.69
  • Execute #13 is about 0.5 ms faster, because lanes no longer spin. #15 does not change.
  • Neither arm lost the device.
  • A debug count of all-zero node reads in a1b20bc4 went from about 6.7k per 150 presents at world +35-42 s to 0. The LDS pops had read slots up to 484. The count lives on a local branch and is not part of this PR.

Tests

cargo test -p victory-shader passes, including the new lane_loop_tests:

  • the pop's shape, lowered and emitted (wave votes, guarded first-lane read);
  • two negative cases that must stay per lane;
  • the choice between the wider and plain forms.

How this came up: device losses with the hardware node test

This started from the roadmap's "Hardware BVH node test", step 1: a local experiment that runs image_bvh64_intersect_ray on the card's own instruction instead of the emulation. It uses a small local Mesa patch, which is not part of this PR.

  • Execute #13 came in about 1.6 ms faster on the RX 6800. But 3 of 9 runs lost the device at world +36 s with GPU read permission faults (TCP), each at a different never-bound title address.
  • Making the descriptor wave-uniform did not help. umem's bind log showed the faulting pages, and everything within ±4 MiB, were never bound. So this was not a bind race.
  • The emulated path reads the same addresses, but an unbound page in the sparse window reads as zeros there, so it hides the bug. The card's node fetch faults on the same read instead.
  • A debug count of all-zero node reads in the emulated path (local branch) found the source: thousands of empty-node reads from a1b20bc4 at that same moment. Their descriptor bases were data such as 0x7878f8f800, and the bad pointers came only from the LDS pops, never from lane slots. That led to the stale v_readfirstlane fixed here.

So the change fixes the root cause behind those crashes. With it, the emulated path's all-zero node count in a1b20bc4 is 0.

The hardware arm has not been re-run with this fix yet. An unrelated truncated row in our local shader store held it up; the stack fix itself is not the cause. Results will follow on the roadmap item.

🤖 Generated with Claude Code

**@⁠just-another-dude84** on GitHub · 2026-11-30 21:43 UTC · [original](https://github.com/vktory6/VKtory/pull/22) `just-another-dude84:ds-stack-fix` → `main` · +280 −8 · 5 files · 4 commits · merged 2026-12-01 08:24 UTC ## What In programs where `scalar_splits` already takes per-lane branches wave-wide, `s_cbranch_vccz` / `s_cbranch_vccnz` loops are now taken wave-wide too. This applies when the loop holds EXEC-guarded vector code and exits to unguarded vector code. ## Why CS_RTDistantShadowTrace32 (a1b20bc4) keeps its BVH traversal stack in lanes of v23 plus an overflow stack in LDS. - Since b33b3d1cd, the walker region runs wave-wide, so lanes outside EXEC also run the LDS pop loops (a1b2 0x16c0, 0x2750, and the other copies). - Those loops close on VCC and had stayed per lane. A lane outside EXEC never sees its exit, so it spins to the loop limit. - `structure` then assumed EXEC holds behind the loop, so the `v_readfirstlane` of the popped stack pointer and node pointer had no EXEC guard. It read lane 0's stale value. - Result: stack pointers up to ~486, past the console's 256-dword cap, and node pointers that are floats (0x43a00000) or wild addresses. This is the residue `distshadow.md` listed as open: "a +60 base of -FLT_MAX read as an instance". - Most of these reads land inside the title window and read zeros silently, so the past-the-window census undercounts them. ## Scope Of the 2,734 store compute programs, 12 change; there are no new failures and no fallbacks. - The walker family: a1b20bc4, e8c96235, and the CS_TraceShadowRays_* variants. - Three programs with the same loop shape that are not walkers: CS_ResolveVBuffer, CS_DefragHeap_ComputeRelocations and CS_MultipleScattering. I have not checked these one by one for a stale read. If the wider form is refused, the plain form is used. This is counted through `kept_per_lane`. `TRANSLATOR_VERSION` goes from 10 to 11. ## Measurements Setup: RX 6800 (RDNA2), RADV 26.3.1, prison save. Interleaved ABAB, 3 runs per arm, world 90-190 s, run medians. Only `translate-dir` differs between the arms (main 3a0b738 vs 086d949); the later commits produce identical DXIL. | run | arm | Execute #13 (ms) | #15 (ms) | |---|---|---|---| | 1 | main | 15.07 | 7.70 | | 1 | fix | 14.70 | 7.76 | | 2 | main | 15.23 | 7.86 | | 2 | fix | 14.69 | 7.82 | | 3 | main | 15.23 | 7.83 | | 3 | fix | 14.67 | 7.69 | - Execute #13 is about 0.5 ms faster, because lanes no longer spin. #15 does not change. - Neither arm lost the device. - A debug count of all-zero node reads in a1b20bc4 went from about 6.7k per 150 presents at world +35-42 s to 0. The LDS pops had read slots up to 484. The count lives on a local branch and is not part of this PR. ## Tests `cargo test -p victory-shader` passes, including the new `lane_loop_tests`: - the pop's shape, lowered and emitted (wave votes, guarded first-lane read); - two negative cases that must stay per lane; - the choice between the wider and plain forms. ## How this came up: device losses with the hardware node test This started from the roadmap's "Hardware BVH node test", step 1: a local experiment that runs `image_bvh64_intersect_ray` on the card's own instruction instead of the emulation. It uses a small local Mesa patch, which is not part of this PR. - Execute #13 came in about 1.6 ms faster on the RX 6800. But 3 of 9 runs lost the device at world +36 s with GPU read permission faults (TCP), each at a different never-bound title address. - Making the descriptor wave-uniform did not help. umem's bind log showed the faulting pages, and everything within ±4 MiB, were never bound. So this was not a bind race. - The emulated path reads the same addresses, but an unbound page in the sparse window reads as zeros there, so it hides the bug. The card's node fetch faults on the same read instead. - A debug count of all-zero node reads in the emulated path (local branch) found the source: thousands of empty-node reads from a1b20bc4 at that same moment. Their descriptor bases were data such as 0x7878f8f800, and the bad pointers came only from the LDS pops, never from lane slots. That led to the stale `v_readfirstlane` fixed here. So the change fixes the root cause behind those crashes. With it, the emulated path's all-zero node count in a1b20bc4 is 0. The hardware arm has not been re-run with this fix yet. An unrelated truncated row in our local shader store held it up; the stack fix itself is not the cause. Results will follow on the roadmap item. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
scalar_splits takes the walker region wave-wide, so lanes outside EXEC (pixels
that need no shadow ray) run the pop loops of CS_RTDistantShadowTrace32
(a1b20bc4 0x16c0, 0x2750, ...). Their closing branches stayed per lane: in a
lane outside EXEC `vccz` loops back (`!(vcc & exec)`), so it spun to the loop
limit while the lanes in EXEC left, and behind the loop the structure derived
"EXEC holds in every lane that arrives" from the exit taken on `vcc & exec`.
The `v_readfirstlane_b32` of the popped stack pointer and node pointer got no
EXEC guard and took lane 0's stale value when lane 0 was outside EXEC (an
image_bvh_intersect_ray result: a float or node pointer). The console reads the
first lane of EXEC. Wild stack pointers (LDS slot 484) and float node pointers
followed.

lower::lane_loops names the per-lane loop branches with an EXEC-guarded block
once some branch is wave-wide; emit and widen take them wave-wide too, and fall
back (loudly) to the form without them where that is refused. a1b20bc4: 29 -> 37
wave-wide branches, the four pops. TRANSLATOR_VERSION 11.

Test: emit::lane_loop_tests (structure and lowering of the pop's shape).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lane_loop_tests: no assert on the pre-fix state; negative cases (exit to scalar code
only, no lane outside EXEC); emit's result checked (loop branches wave votes, the
first-lane read guarded, wider form chosen, kept_per_lane empty); the choice between
the forms tested (prefer_wider). When the wider form is refused and the plain form
is taken, kept_per_lane says so (counted by the renderer); when neither completes the
plain form's error is reported, as before the change. The DXIL of the 12 store
programs it changes is byte-identical to 086d949.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:44:58 +00:00
The wider form is the only one that reads the first lane of EXEC behind those loops; the plain form reads a stale
lane, and no program of the store needs it. A refusal of the wide form now goes the way it went before this change
(the per-lane form, counted in kept_per_lane). AGENTS.md rule 33.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot changed target branch from main to gh-pr/22/base 2026-12-01 08:27:30 +00:00
github manually merged commit e430113434 into gh-pr/22/base 2026-12-01 08:27:33 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 08:24 UTC · original

Merged, thanks! One commit of mine on top (e430113): the per-lane form without the lane loops (prefer_wider / LOOPS_KEPT) is gone. When the wider form is refused, the existing per-lane arm takes it and counts it (kept_per_lane). Keeping a second fallback form would only be code for a case we now count instead (rule 33).

Check on the reference system (RX 9070 XT): tests pass, and the house-scene validation run shows no new error. The run is slow (4.4 fps) because the translator change retranslates the store.

**@⁠vktory6** on GitHub · 2026-12-01 08:24 UTC · [original](https://github.com/vktory6/VKtory/pull/22#issuecomment-7305275592) Merged, thanks! One commit of mine on top (e430113): the per-lane form without the lane loops (`prefer_wider` / `LOOPS_KEPT`) is gone. When the wider form is refused, the existing per-lane arm takes it and counts it (`kept_per_lane`). Keeping a second fallback form would only be code for a case we now count instead (rule 33). Check on the reference system (RX 9070 XT): tests pass, and the house-scene validation run shows no new error. The run is slow (4.4 fps) because the translator change retranslates the store.
This discussion has been locked. Commenting is limited to contributors.
No description provided.