Shader tests: the split-LDS read-after-read test's UAV-load negative reads its load (fails on main since #2623) #4320

Merged
Lyrnc merged 1 commit from upstream-pr/4320 into main 2026-11-30 23:37:35 +00:00
Lyrnc commented 2026-11-30 18:51:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T18:51:26Z.


What fails

On main (84bd61e2), emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity fails at its neg_uav_load_between_reads case:

assertion `left == right` failed: neg_uav_load_between_reads mask=ALL pattern
  left: "BWBRRBWBR"
 right: "BWBRBRBWBR"

The five cases before it pass, and so does the same case with BARRIERS alone. The pattern checks need dxc.exe next to the validator, so the failure shows on machines with the Windows SDK's dxc. It has been reported as "fails on main too" in #4223 (RTX 3060), #4046 (RTX 3090), #3641, #3061 and #3064.

The test is wrong, not the pass

The case puts buffer_load_dword v8 between the two LDS reads, as a resource call that must keep the barrier between them. But nothing reads v8.

Since #2623 (dbdd6ada), Module::optimise drops dead instructions inside its fixed-point loop (so dead diamonds empty out for simplify_cfg). With ALL or DEFAULT:

  1. Round 1: merge sees the load (Effect::Reads, so the barrier state is reset) and keeps the middle barrier.
  2. drop_dead_insts then removes the load, because nothing uses it.
  3. Round 2: merge finds B R B R B with nothing between the reads and drops the middle barrier.

BARRIERS alone runs no DEAD, so the load stays and the barrier stays. That is why only the mask=ALL assertion fails. Before #2623, dead instructions went only after the last round, so the barrier stayed even though the load was gone.

Dropping that barrier is right. Once the unread load is gone, the case is the same as adjacent_rar, and the test expects BWBRRBWBR for that one. Two LDS reads with no write, atomic or other access between them cannot conflict. The barriers before the first read and after the second still order every write against them.

To check that against hardware, I ran the fixture on an RDNA2 GPU (Radeon iGPU, gfx1036, through a HIP kernel-body oracle). A barrier there is s_waitcnt lgkmcnt(0); s_barrier, the same as a group-sync with a group-shared fence. Every thread should get [t ^ 32, t, t + 25]:

case barriers (before W1, R1, R2, W2, R3) runs with a wrong row wrong rows
one wave64 (the console) none 0 / 20 0
two wave32 waves, as lowered (opt=0) all five 0 / 20 0
two wave32 waves, after the coalescing four, none between the reads 0 / 20 0
two wave32 waves, no barriers (control) none 20 / 20 1280 (all 64 every run)

So the console's order (one wave64, no barriers) gives what the test checks. Two 32-lane waves with the four barriers left after the coalescing (none between the reads) give the same result. The control shows the setup catches a missing barrier: with none, each wave reads the other's dwords before they are written. The oracle script is a short piece of plain GFX10 assembly. I can post it here if it's wanted.

The change (test only)

The negative now adds the loaded value into v6 before out[128 + t] is stored (v_add_nc_u32 v6, v8, v6). Thread t loads out[t], which is still 0 at that point: the test host's UAV is a fresh committed resource (zeroed), and only thread t writes out[t], after its load. So the expected outputs don't change. The load is now used under every mask, though, so the case tests what its comment says again: a UAV read between the reads keeps all five barriers.

No code outside the test changes.

How it was tested

RTX 5080 (the default adapter), Windows 11, Rust 1.98.1 (pinned), with the Windows SDK's dxc.exe next to the validator, so the pattern checks run.

  • Before (main): the test fails as shown above.
  • After: it passes, on the card and on WARP (both run in the test). Every case prints its patterns, and the last one is now neg_uav_load_between_reads: opt=0 BWBRBRBWBR -> BARRIERS BWBRBRBWBR, ALL BWBRBRBWBR. The other five cases print the same patterns as before.
  • Negative control: I made a local mutation, not part of this PR, where Effect::Reads calls no longer reset the barrier state in merge. With it, the fixed case fails (neg_uav_load_between_reads mask=BARRIERS pattern, BWBRRBWBR). Without the mutation it passes under all three masks.
  • cargo test -p victory-shader --lib -- emit::bitcode::opt --test-threads=1: 31 passed, 1 ignored, 0 failed. I stopped the full --lib run partway, so it didn't hold up a GPU benchmark here. By then 275 had passed and 3 had failed. Those 3 are the ones listed as failing on main in #3061 (barycentric_tests::first_half_values_render_on_hardware_and_warp, and rect::tests::rectangles_are_drawn_whole / the_rectangle_stage_is_a_geometry_shader), and they're nowhere near this change.
  • cargo clippy -p victory-shader --all-targets -- -D warnings, default and --all-features: one finding, the same as on main (field loop_caps is never read, emit/lower.rs:114, which #4296 deals with). Nothing new from the test change.
  • cargo xtask policy: one violation, the same as on main (victory-shader/src/native.rs, the hex run that #4223 removes).

Checked for overlap

  • I searched the open pull requests for this test, the lds barrier / read-after-read terms and opt.rs. Several PRs list this test as failing on main, and none changes it. #3106 (barrier state on Op::VolatileLoad) touches the same pass but not this test or the case.

AI use: Claude Code (an AI agent working for Lyrnc) did the analysis, the test change, the oracle runs and this text. The runs above are real runs on this machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5571647456 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4320). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-30T18:51:26Z. --- ## What fails On `main` (`84bd61e2`), `emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity` fails at its `neg_uav_load_between_reads` case: ``` assertion `left == right` failed: neg_uav_load_between_reads mask=ALL pattern left: "BWBRRBWBR" right: "BWBRBRBWBR" ``` The five cases before it pass, and so does the same case with `BARRIERS` alone. The pattern checks need `dxc.exe` next to the validator, so the failure shows on machines with the Windows SDK's dxc. It has been reported as "fails on main too" in #4223 (RTX 3060), #4046 (RTX 3090), #3641, #3061 and #3064. ## The test is wrong, not the pass The case puts `buffer_load_dword v8` between the two LDS reads, as a resource call that must keep the barrier between them. But nothing reads `v8`. Since #2623 (`dbdd6ada`), `Module::optimise` drops dead instructions inside its fixed-point loop (so dead diamonds empty out for `simplify_cfg`). With `ALL` or `DEFAULT`: 1. Round 1: `merge` sees the load (`Effect::Reads`, so the barrier state is reset) and keeps the middle barrier. 2. `drop_dead_insts` then removes the load, because nothing uses it. 3. Round 2: `merge` finds `B R B R B` with nothing between the reads and drops the middle barrier. `BARRIERS` alone runs no `DEAD`, so the load stays and the barrier stays. That is why only the `mask=ALL` assertion fails. Before #2623, dead instructions went only after the last round, so the barrier stayed even though the load was gone. Dropping that barrier is right. Once the unread load is gone, the case is the same as `adjacent_rar`, and the test expects `BWBRRBWBR` for that one. Two LDS reads with no write, atomic or other access between them cannot conflict. The barriers before the first read and after the second still order every write against them. To check that against hardware, I ran the fixture on an RDNA2 GPU (Radeon iGPU, gfx1036, through a HIP kernel-body oracle). A barrier there is `s_waitcnt lgkmcnt(0); s_barrier`, the same as a group-sync with a group-shared fence. Every thread should get `[t ^ 32, t, t + 25]`: | case | barriers (before W1, R1, R2, W2, R3) | runs with a wrong row | wrong rows | |---|---|---|---| | one wave64 (the console) | none | 0 / 20 | 0 | | two wave32 waves, as lowered (`opt=0`) | all five | 0 / 20 | 0 | | two wave32 waves, after the coalescing | four, none between the reads | 0 / 20 | 0 | | two wave32 waves, no barriers (control) | none | 20 / 20 | 1280 (all 64 every run) | So the console's order (one wave64, no barriers) gives what the test checks. Two 32-lane waves with the four barriers left after the coalescing (none between the reads) give the same result. The control shows the setup catches a missing barrier: with none, each wave reads the other's dwords before they are written. The oracle script is a short piece of plain GFX10 assembly. I can post it here if it's wanted. ## The change (test only) The negative now adds the loaded value into `v6` before `out[128 + t]` is stored (`v_add_nc_u32 v6, v8, v6`). Thread `t` loads `out[t]`, which is still 0 at that point: the test host's UAV is a fresh committed resource (zeroed), and only thread `t` writes `out[t]`, after its load. So the expected outputs don't change. The load is now used under every mask, though, so the case tests what its comment says again: a UAV read between the reads keeps all five barriers. No code outside the test changes. ## How it was tested RTX 5080 (the default adapter), Windows 11, Rust 1.98.1 (pinned), with the Windows SDK's `dxc.exe` next to the validator, so the pattern checks run. - Before (`main`): the test fails as shown above. - After: it passes, on the card and on WARP (both run in the test). Every case prints its patterns, and the last one is now `neg_uav_load_between_reads: opt=0 BWBRBRBWBR -> BARRIERS BWBRBRBWBR, ALL BWBRBRBWBR`. The other five cases print the same patterns as before. - Negative control: I made a local mutation, not part of this PR, where `Effect::Reads` calls no longer reset the barrier state in `merge`. With it, the fixed case fails (`neg_uav_load_between_reads mask=BARRIERS pattern`, `BWBRRBWBR`). Without the mutation it passes under all three masks. - `cargo test -p victory-shader --lib -- emit::bitcode::opt --test-threads=1`: 31 passed, 1 ignored, 0 failed. I stopped the full `--lib` run partway, so it didn't hold up a GPU benchmark here. By then 275 had passed and 3 had failed. Those 3 are the ones listed as failing on `main` in #3061 (`barycentric_tests::first_half_values_render_on_hardware_and_warp`, and `rect::tests::rectangles_are_drawn_whole` / `the_rectangle_stage_is_a_geometry_shader`), and they're nowhere near this change. - `cargo clippy -p victory-shader --all-targets -- -D warnings`, default and `--all-features`: one finding, the same as on `main` (`field loop_caps is never read`, `emit/lower.rs:114`, which #4296 deals with). Nothing new from the test change. - `cargo xtask policy`: one violation, the same as on `main` (`victory-shader/src/native.rs`, the hex run that #4223 removes). ## Checked for overlap - [x] I searched the open pull requests for this test, the `lds barrier` / read-after-read terms and `opt.rs`. Several PRs list this test as failing on `main`, and none changes it. #3106 (barrier state on `Op::VolatileLoad`) touches the same pass but not this test or the case. AI use: Claude Code (an AI agent working for Lyrnc) did the analysis, the test change, the oracle runs and this text. The runs above are real runs on this machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
babuakhil commented 2026-11-30 19:16:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by babuakhil on 2026-11-30T19:16:32Z.


This and #4327 fix the same failure of split_lds_wave32_read_after_read_barrier_coalescing_and_parity (neg_uav_load_between_reads mask=ALL), in two ways: this one makes the load used (v6 = v8 + v6 before the store), and #4327 keeps the dead load and expects ALL to drop the barrier. I ran both on Windows 11 with an RTX 3060 and the SDK's dxc (Rust 1.98.1, pinned), each applied on main (e1251c31); both cherry-pick cleanly.

main this PR #4327
the test, two runs each fails both: ALL gives BWBRRBWBR, expects BWBRBRBWBR passes both passes both
neg_uav_load_between_reads: opt=0 → BARRIERS → ALL — BWBRBRBWBR → BWBRBRBWBR → BWBRBRBWBR BWBRBRBWBR → BWBRBRBWBR → BWBRRBWBR

To see what each version of the test still guards, I made two throwaway changes to opt.rs (not part of either PR):

change to opt.rs this PR #4327
a bug: the Effect::Reads call arm of merge no longer runs barriers.reset(), so a resource read between two LDS reads stops keeping the barrier fails (mask=BARRIERS) fails (mask=BARRIERS)
no bug: drop_dead_insts taken out of optimise's rounds, so dead code goes only after the loop, as before #2623 passes fails (mask=ALL)

Both still catch the real bug. But #4327's ALL expectation is tied to when dead code is dropped rather than to the barrier rule, so it would fail on a harmless reordering of passes, and its ALL run no longer covers a live resource read between the reads. With this PR the case tests a live load in all three modes, and its value passes the hardware and WARP parity checks on the 3060.

So I'd take this one. #4327's analysis of why main fails is right; the difference is only which way the test is fixed.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7289124645 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4320#issuecomment-7289124645). Originally posted by [babuakhil](https://github.com/babuakhil) on 2026-11-30T19:16:32Z. --- This and #4327 fix the same failure of `split_lds_wave32_read_after_read_barrier_coalescing_and_parity` (`neg_uav_load_between_reads mask=ALL`), in two ways: this one makes the load used (`v6 = v8 + v6` before the store), and #4327 keeps the dead load and expects `ALL` to drop the barrier. I ran both on Windows 11 with an RTX 3060 and the SDK's `dxc` (Rust 1.98.1, pinned), each applied on `main` (`e1251c31`); both cherry-pick cleanly. | | `main` | this PR | #4327 | |---|---|---|---| | the test, two runs each | fails both: `ALL` gives `BWBRRBWBR`, expects `BWBRBRBWBR` | passes both | passes both | | `neg_uav_load_between_reads`: `opt=0` → `BARRIERS` → `ALL` | — | `BWBRBRBWBR` → `BWBRBRBWBR` → `BWBRBRBWBR` | `BWBRBRBWBR` → `BWBRBRBWBR` → `BWBRRBWBR` | To see what each version of the test still guards, I made two throwaway changes to `opt.rs` (not part of either PR): | change to `opt.rs` | this PR | #4327 | |---|---|---| | **a bug**: the `Effect::Reads` call arm of `merge` no longer runs `barriers.reset()`, so a resource read between two LDS reads stops keeping the barrier | fails (`mask=BARRIERS`) | fails (`mask=BARRIERS`) | | **no bug**: `drop_dead_insts` taken out of `optimise`'s rounds, so dead code goes only after the loop, as before #2623 | passes | **fails** (`mask=ALL`) | Both still catch the real bug. But #4327's `ALL` expectation is tied to *when* dead code is dropped rather than to the barrier rule, so it would fail on a harmless reordering of passes, and its `ALL` run no longer covers a live resource read between the reads. With this PR the case tests a live load in all three modes, and its value passes the hardware and WARP parity checks on the 3060. So I'd take this one. #4327's analysis of why `main` fails is right; the difference is only which way the test is fixed.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!4320
No description provided.