Recompiler: a PS export after leaving WQM tests no ballot word #3786

Open
CharlyRien wants to merge 2 commits from upstream-pr/3786 into main
CharlyRien commented 2026-12-03 12:41:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T12:41:45Z.


Fixes #3772.

A direct-DXIL pixel shader that saves its entry EXEC, widens EXEC with s_wqm, runs a loop whose exits depend on the lane, and exports under EXEC = wqm(entry) & entry tests each lane's bit of that EXEC by shifting the entry WaveActiveBallot(true) word by the lane index, after the loop. On an RTX 3090 (drivers 616.56 and 621.47) some live lanes find their bit at 0 there, and their pixels are left unwritten. The same DXIL is right on WARP (details and measurements in #3772), so this looks like a driver compiler bug; this change avoids the shape.

Lw::lanebit already answers "this lane's bit" from the predicate that made a mask when it is known (Lw::own_bits), without reading the mask word. This change adds one case: the lane's bit of x & entry, where entry is the saved entry EXEC and x a mask made from s_wqm of it (the guest leaving whole quad mode), is !IsHelperLane() && live_bit(x):

  • live_bit is the lane's bit of x assuming the lane is live: s_wqm of the entry EXEC and the entry EXEC are 1 in every live lane; a compare's or v_cmpx's mask is its condition and the live bit of the EXEC it ran under (recorded by Lw::note_ps_exec_cond); and / or / xor / select compose; anything else gives up and the word test stays.
  • a helper lane's bit of the entry EXEC is 0, so the result is the console's bit in every lane, helper or live. After leaving WQM, helper lanes are inactive as with the word test before: they write no VGPR and add no bit to compare or carry masks that other lanes read.

Nothing else changes: the mask words, the entry EXEC's own bit (true, as on main), every lane's view of other lanes' bits, and the code that runs in WQM. Only x & entry with x derived from s_wqm of the entry EXEC gets the new bit; other masks and-ed with the entry EXEC (for example s_andn2 / s_xor forms, or a mask narrowed on one path) keep the word test.

s_wqm widths: s_wqm_b64 of the entry EXEC in wave64, s_wqm_b32 or s_wqm_b64 of it in wave32 (the high word is 0). A wave64 program's s_wqm_b32 exec_lo, exec_lo is not matched and keeps the word test.

The saved masks of the programs in #3772 are read after a loop and a join; on-the-fly SSA leaves webs of phis there whose only outside input is one value (opt removes them after lowering, when the guard has been chosen already). Lw::trivial_phi_value resolves them for this check only. It gives up on a phi with no incoming value yet and past 64 phis.

Why not mark the entry EXEC's own bit !IsHelperLane() everywhere: tried on a local tree, it fixed the same programs but lost pixels in about 95 others on the 3090 (it masks helper lanes' VALU writes inside WQM, which quad neighbours read through derivatives and cross-lane reads). Here helpers stay active in WQM, as on main, and drop out only at the and that leaves it, as on the console.

What is in it

  • gpu/dxil/lanes.rs: the and case in own_bit (ps_exact_bit, ps_live_bit), note_ps_exec_cond, trivial_phi_value; gpu/dxil/module.rs: Module::is_phi.
  • gpu/dxil/lower_gfx.rs: setup_pixel records the entry EXEC words (Lw::ps_entry_exec); note_ps_entry_wqm.
  • A runtime switch back to main's translation, XCL_PS_WQM_EXIT_BIT=0 (gpu/dxil/kernel.rs, ps_wqm_exit_bit; unset or any other value: on). Off, Lw::ps_entry_exec stays unset, so every hook above returns before it records anything and the export guard tests the entry ballot word as on main. It is read once and logged when off. Since it changes direct pixel shaders' DXIL, it is part of the translated cache's identity (gpu/recomp/pso.rs, ps_wqm_exit_tagged, under XCL_DIRECT_DXIL=all routing) and one of the warm settings (shaders.rs, semantic_pipeline_setting), as #3591 does for XCL_PS_SKIP_RUN_THROUGH: a cache made one way is not loaded the other way. The tests' "without the change" runs use a test override of this switch (kernel::PS_WQM_EXIT_BIT_IN_TEST, like idioms::IDIOMS_IN_TEST), so they go through the same check. README: one line next to the GPU notes.
  • gpu/dxil/lower.rs: the fields; s_wqm_b32 / s_wqm_b64 record s_wqm of the entry EXEC; write_mask records compare conditions. gpu/dxil/lower_valu.rs: the same for local- and quad-form compares.
  • Tests, gpu/dxil/lanes.rs (ps_ballot_tests):
    • direct_ps_export_guard_of_the_entry_exec_tests_no_ballot_word (CPU): exec = wqm(entry) & entry, with and without a guest v_cmpx kill in WQM, wave32 and wave64: the discard condition reads no wave operation, and evaluated for the four (helper, compare) cases it discards exactly helper and killed lanes. Without the change the same condition reads the ballot (checked in the test).
    • direct_ps_export_guard_after_a_loop_and_a_join_tests_no_ballot_word (CPU): the same after a divergent loop and a join (save, loop, restore, join, and), the shape of the programs in #3772, with and without a kill before the save.
    • direct_ps_export_guard_keeps_the_word_test_where_wqm_of_the_entry_is_not_known (CPU): a saved mask narrowed on one path (a non-trivial phi), s_wqm after a v_cmpx, and a wave64 s_wqm_b32 exec_lo keep the word test.
    • gpu_direct_ps_export_after_a_divergent_loop_writes_every_pixel (GPU): save, s_wqm, a loop of one pass per pixel column plus one, restore, and, export, with and without a kill; every kept pixel gets the right pass count, no killed pixel is written. It also runs the translation without the change and prints its wrong pixels without asserting them, since other GPUs compile it right.
    • gpu_direct_ps_helper_lanes_stay_out_of_a_carry_after_leaving_wqm (GPU): after leaving WQM, a v_add_co carry-out compared against EXEC and selected back into EXEC must equal EXEC (a helper bit in the carry would make covered lanes export).
    • gpu_direct_ps_helper_lanes_keep_their_vgprs_after_leaving_wqm (GPU): a VGPR written after leaving WQM and read by a quad neighbour with ds_swizzle: a helper lane must keep its WQM-mode value.
  • Unit tests of the switch: ps_wqm_exit_bit_is_on_unless_switched_off (gpu/dxil/kernel.rs, parsing), translated_identity_tracks_the_ps_wqm_exit_switch (gpu/recomp/pso.rs), warm_settings_keep_the_ps_wqm_exit_switch (shaders.rs).

No cache bump: the change is under gpu/dxil, whose hash is XCL_DIRECT_DXIL_SOURCE_ID, so direct translations get a new identity on their own. Only pixel shaders' translations can change.

This does not depend on #3591: it changes neither execz skips nor the words, and the holes it fixes were there without #3591 too (#3772).

Size: about 735 changed lines, about 460 of them tests (the switch adds about 60). The three GPU tests (gpu_direct_ps_* and their helpers) cover the bug's shape and the two helper-lane cases a review found in an earlier version of this change; if you prefer a smaller PR, I can move them into a stacked Tests: PR.

Measured before this PR

On a local tree (main 817eb1fc + #3591 + local probes, XCL_PS_SKIP_RUN_THROUGH=1), RTX 3090, a local offline tool that draws one console program both ways (direct DXIL and HLSL) on 3 synthetic input sets:

  • a guard that gives the same bit at this and as this change (helper lanes out, live lanes in) turned the 17 programs of #3772 identical to the HLSL path (8,514 of 49,152 pixels were unwritten in each before); that version also changed the entry EXEC's bit everywhere, which this PR does not;
  • this commit, on the same tree and the same 119 programs, both sides swept in one job on driver 621.47: the 17 programs of #3772 are identical to the HLSL path (were 187,170 unwritten pixels in all); programs identical to HLSL 4 → 21; unwritten pixels in all 119: 3,282,856 → 3,095,686; no program gets worse. 20 programs get another direct DXIL, the 17 among them.
  • the switch, on the same tree and the same 119 programs, driver 621.47, one sweep each way: with XCL_PS_WQM_EXIT_BIT=0, all 119 programs get the base tree's direct DXIL size, and the 17 programs of #3772 have unwritten pixels again (identical to HLSL: 4, as the base; unwritten pixels in all 119: 3,282,789 against the base's 3,282,856; one of the 17 has 3,988 instead of 4,055, every other program the base's counts). With the switch unset, all 119 get the previous line's sizes and the same counts (identical 21, 3,095,686 unwritten).

Tested

  • RTX 3090 (driver 621.47), Ryzen 9 5950X, Windows 11 22631, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo build --workspace: ok
  • At this head (7740cd57): cargo test --workspace --no-fail-fast -- --test-threads=4: 3019 passed, 2 failed, 56 ignored. The two failures are the e2e debug-layer tests that fail on main too (main 16c2fd08 plus one unrelated commit on the same machine: 3013 passed, 2 failed, 56 ignored). At the first commit alone, two full-suite runs (that commit and an earlier version of it) also failed two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (counted twice: it re-runs itself as a child process), in its child case stale-compute: one two-pass state was still there after the test's 5 s wait (left: 1, right: 0, gpu_two_pass_cache_e2e.rs:584). It passed in this head's suite run, and alone or after the lib tests on this branch and on main (5 of 5). The change touches no two-pass or PSO release code; I read it as a timing-dependent test, not shown.
  • SKIPPED on this adapter: 25 lines: 22 no wave64 (expected on this card), 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1), 1 no GPU_UPLOAD heaps (Resizable BAR off).
  • The six new tests, the three unit tests of the switch and four existing PS mask tests by name with XCL_REQUIRE_GPU=mesh: passed. gpu_direct_ps_export_after_a_divergent_loop_writes_every_pixel, 3 runs: 0 of 1024 pixels wrong with the change, in wave32 and wave64, with and without a kill; 0 without it too (as at the first commit, 3 runs, 621.47: this small program does not trigger the driver bug, which so far shows in the retail programs of #3772 only).
  • ps_ballot_tests with XCL_PS_WQM_EXIT_BIT=0 in the environment (the tests that do not set the override then translate as main): 15 passed, 0 failed.
  • Release, the same named tests and the switch's unit tests, without the switch and with XCL_PS_WQM_EXIT_BIT=0: 18 of 18 passed both ways (ps_ballot_tests and the three unit tests), no SKIPPED line.

Regression run
scripts/smoke.ps1, 60 s, the retail title, same machine and driver (621.47), main 16c2fd08 then this head (switch unset):

xcl-smoke v1
commit: 16c2fd082ae2e96967a2ab553bc2e1032e491f70
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 488 (PresentX 488)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16164 MB
xcl-smoke v1
commit: 7740cd57b7993969e9cfa6cf343392d38c6cb957
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 544 (PresentX 544)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15679 MB

Frames 544 / 488 (111 %), peak commit 15,679 / 16,164 MB (97 %), no device removal, no crash. (The first commit alone, 95c5f6e8: 561 frames, 15,752 MB.)

Not tested

  • AMD, Intel, other NVIDIA cards and drivers: the change is on for every GPU and I have no other card. If it misbehaves on one, XCL_PS_WQM_EXIT_BIT=0 gives main's translation without a rebuild, and it is the first thing to try on a pixel regression after this PR.
  • IsHelperLane() in this position on drivers other than 621.47.
  • A wave64 program's s_wqm_b32 exec_lo, exec_lo and s_andn2 / s_xor forms of leaving WQM keep the word test (not fixed if a program uses them).
  • Frame time: the change removes word tests; not measured.

AI use

  • AI use: Claude Code (Claude Opus 5.5) found the cause with local probes, wrote the change, the switch, their tests and this description; checked and posted by me.

Base: main 16c2fd08, two commits (the workaround, then the switch), no local switches.

<!-- greyfinch-sync:ivall/xcl:issue:5626696249 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3786). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-03T12:41:45Z. --- Fixes #3772. A direct-DXIL pixel shader that saves its entry EXEC, widens EXEC with `s_wqm`, runs a loop whose exits depend on the lane, and exports under `EXEC = wqm(entry) & entry` tests each lane's bit of that EXEC by shifting the entry `WaveActiveBallot(true)` word by the lane index, after the loop. On an RTX 3090 (drivers 616.56 and 621.47) some live lanes find their bit at 0 there, and their pixels are left unwritten. The same DXIL is right on WARP (details and measurements in #3772), so this looks like a driver compiler bug; this change avoids the shape. `Lw::lanebit` already answers "this lane's bit" from the predicate that made a mask when it is known (`Lw::own_bits`), without reading the mask word. This change adds one case: the lane's bit of `x & entry`, where `entry` is the saved entry EXEC and `x` a mask made from `s_wqm` of it (the guest leaving whole quad mode), is `!IsHelperLane() && live_bit(x)`: - `live_bit` is the lane's bit of `x` assuming the lane is live: `s_wqm` of the entry EXEC and the entry EXEC are 1 in every live lane; a compare's or `v_cmpx`'s mask is its condition and the live bit of the EXEC it ran under (recorded by `Lw::note_ps_exec_cond`); `and` / `or` / `xor` / `select` compose; anything else gives up and the word test stays. - a helper lane's bit of the entry EXEC is 0, so the result is the console's bit in every lane, helper or live. After leaving WQM, helper lanes are inactive as with the word test before: they write no VGPR and add no bit to compare or carry masks that other lanes read. Nothing else changes: the mask words, the entry EXEC's own bit (`true`, as on `main`), every lane's view of other lanes' bits, and the code that runs in WQM. Only `x & entry` with `x` derived from `s_wqm` of the entry EXEC gets the new bit; other masks and-ed with the entry EXEC (for example `s_andn2` / `s_xor` forms, or a mask narrowed on one path) keep the word test. `s_wqm` widths: `s_wqm_b64` of the entry EXEC in wave64, `s_wqm_b32` or `s_wqm_b64` of it in wave32 (the high word is 0). A wave64 program's `s_wqm_b32 exec_lo, exec_lo` is not matched and keeps the word test. The saved masks of the programs in #3772 are read after a loop and a join; on-the-fly SSA leaves webs of phis there whose only outside input is one value (`opt` removes them after lowering, when the guard has been chosen already). `Lw::trivial_phi_value` resolves them for this check only. It gives up on a phi with no incoming value yet and past 64 phis. Why not mark the entry EXEC's own bit `!IsHelperLane()` everywhere: tried on a local tree, it fixed the same programs but lost pixels in about 95 others on the 3090 (it masks helper lanes' VALU writes inside WQM, which quad neighbours read through derivatives and cross-lane reads). Here helpers stay active in WQM, as on `main`, and drop out only at the `and` that leaves it, as on the console. **What is in it** - `gpu/dxil/lanes.rs`: the `and` case in `own_bit` (`ps_exact_bit`, `ps_live_bit`), `note_ps_exec_cond`, `trivial_phi_value`; `gpu/dxil/module.rs`: `Module::is_phi`. - `gpu/dxil/lower_gfx.rs`: `setup_pixel` records the entry EXEC words (`Lw::ps_entry_exec`); `note_ps_entry_wqm`. - A runtime switch back to `main`'s translation, `XCL_PS_WQM_EXIT_BIT=0` (`gpu/dxil/kernel.rs`, `ps_wqm_exit_bit`; unset or any other value: on). Off, `Lw::ps_entry_exec` stays unset, so every hook above returns before it records anything and the export guard tests the entry ballot word as on `main`. It is read once and logged when off. Since it changes direct pixel shaders' DXIL, it is part of the translated cache's identity (`gpu/recomp/pso.rs`, `ps_wqm_exit_tagged`, under `XCL_DIRECT_DXIL=all` routing) and one of the warm settings (`shaders.rs`, `semantic_pipeline_setting`), as #3591 does for `XCL_PS_SKIP_RUN_THROUGH`: a cache made one way is not loaded the other way. The tests' "without the change" runs use a test override of this switch (`kernel::PS_WQM_EXIT_BIT_IN_TEST`, like `idioms::IDIOMS_IN_TEST`), so they go through the same check. README: one line next to the GPU notes. - `gpu/dxil/lower.rs`: the fields; `s_wqm_b32` / `s_wqm_b64` record `s_wqm` of the entry EXEC; `write_mask` records compare conditions. `gpu/dxil/lower_valu.rs`: the same for local- and quad-form compares. - Tests, `gpu/dxil/lanes.rs` (`ps_ballot_tests`): - `direct_ps_export_guard_of_the_entry_exec_tests_no_ballot_word` (CPU): `exec = wqm(entry) & entry`, with and without a guest `v_cmpx` kill in WQM, wave32 and wave64: the discard condition reads no wave operation, and evaluated for the four (helper, compare) cases it discards exactly helper and killed lanes. Without the change the same condition reads the ballot (checked in the test). - `direct_ps_export_guard_after_a_loop_and_a_join_tests_no_ballot_word` (CPU): the same after a divergent loop and a join (save, loop, restore, join, `and`), the shape of the programs in #3772, with and without a kill before the save. - `direct_ps_export_guard_keeps_the_word_test_where_wqm_of_the_entry_is_not_known` (CPU): a saved mask narrowed on one path (a non-trivial phi), `s_wqm` after a `v_cmpx`, and a wave64 `s_wqm_b32 exec_lo` keep the word test. - `gpu_direct_ps_export_after_a_divergent_loop_writes_every_pixel` (GPU): save, `s_wqm`, a loop of one pass per pixel column plus one, restore, `and`, export, with and without a kill; every kept pixel gets the right pass count, no killed pixel is written. It also runs the translation without the change and prints its wrong pixels without asserting them, since other GPUs compile it right. - `gpu_direct_ps_helper_lanes_stay_out_of_a_carry_after_leaving_wqm` (GPU): after leaving WQM, a `v_add_co` carry-out compared against EXEC and selected back into EXEC must equal EXEC (a helper bit in the carry would make covered lanes export). - `gpu_direct_ps_helper_lanes_keep_their_vgprs_after_leaving_wqm` (GPU): a VGPR written after leaving WQM and read by a quad neighbour with `ds_swizzle`: a helper lane must keep its WQM-mode value. - Unit tests of the switch: `ps_wqm_exit_bit_is_on_unless_switched_off` (`gpu/dxil/kernel.rs`, parsing), `translated_identity_tracks_the_ps_wqm_exit_switch` (`gpu/recomp/pso.rs`), `warm_settings_keep_the_ps_wqm_exit_switch` (`shaders.rs`). No cache bump: the change is under `gpu/dxil`, whose hash is `XCL_DIRECT_DXIL_SOURCE_ID`, so direct translations get a new identity on their own. Only pixel shaders' translations can change. This does not depend on #3591: it changes neither `execz` skips nor the words, and the holes it fixes were there without #3591 too (#3772). Size: about 735 changed lines, about 460 of them tests (the switch adds about 60). The three GPU tests (`gpu_direct_ps_*` and their helpers) cover the bug's shape and the two helper-lane cases a review found in an earlier version of this change; if you prefer a smaller PR, I can move them into a stacked `Tests:` PR. **Measured before this PR** On a local tree (`main` 817eb1fc + #3591 + local probes, `XCL_PS_SKIP_RUN_THROUGH=1`), RTX 3090, a local offline tool that draws one console program both ways (direct DXIL and HLSL) on 3 synthetic input sets: - a guard that gives the same bit at this `and` as this change (helper lanes out, live lanes in) turned the 17 programs of #3772 identical to the HLSL path (8,514 of 49,152 pixels were unwritten in each before); that version also changed the entry EXEC's bit everywhere, which this PR does not; - this commit, on the same tree and the same 119 programs, both sides swept in one job on driver 621.47: the 17 programs of #3772 are identical to the HLSL path (were 187,170 unwritten pixels in all); programs identical to HLSL 4 → 21; unwritten pixels in all 119: 3,282,856 → 3,095,686; no program gets worse. 20 programs get another direct DXIL, the 17 among them. - the switch, on the same tree and the same 119 programs, driver 621.47, one sweep each way: with `XCL_PS_WQM_EXIT_BIT=0`, all 119 programs get the base tree's direct DXIL size, and the 17 programs of #3772 have unwritten pixels again (identical to HLSL: 4, as the base; unwritten pixels in all 119: 3,282,789 against the base's 3,282,856; one of the 17 has 3,988 instead of 4,055, every other program the base's counts). With the switch unset, all 119 get the previous line's sizes and the same counts (identical 21, 3,095,686 unwritten). **Tested** - RTX 3090 (driver 621.47), Ryzen 9 5950X, Windows 11 22631, Rust 1.100.0, debug, DXC 1.9.2602.17. - `cargo build --workspace`: ok - At this head (`7740cd57`): `cargo test --workspace --no-fail-fast -- --test-threads=4`: 3019 passed, 2 failed, 56 ignored. The two failures are the e2e debug-layer tests that fail on `main` too (`main` 16c2fd08 plus one unrelated commit on the same machine: 3013 passed, 2 failed, 56 ignored). At the first commit alone, two full-suite runs (that commit and an earlier version of it) also failed `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` (counted twice: it re-runs itself as a child process), in its child case `stale-compute`: one two-pass state was still there after the test's 5 s wait (`left: 1, right: 0`, `gpu_two_pass_cache_e2e.rs:584`). It passed in this head's suite run, and alone or after the lib tests on this branch and on `main` (5 of 5). The change touches no two-pass or PSO release code; I read it as a timing-dependent test, not shown. - `SKIPPED` on this adapter: 25 lines: 22 `no wave64` (expected on this card), 2 `no heap windows` (opt-in `XCL_HEAP_WINDOWS=1`), 1 `no GPU_UPLOAD heaps` (Resizable BAR off). - The six new tests, the three unit tests of the switch and four existing PS mask tests by name with `XCL_REQUIRE_GPU=mesh`: passed. `gpu_direct_ps_export_after_a_divergent_loop_writes_every_pixel`, 3 runs: 0 of 1024 pixels wrong with the change, in wave32 and wave64, with and without a kill; 0 without it too (as at the first commit, 3 runs, 621.47: this small program does not trigger the driver bug, which so far shows in the retail programs of #3772 only). - `ps_ballot_tests` with `XCL_PS_WQM_EXIT_BIT=0` in the environment (the tests that do not set the override then translate as `main`): 15 passed, 0 failed. - Release, the same named tests and the switch's unit tests, without the switch and with `XCL_PS_WQM_EXIT_BIT=0`: 18 of 18 passed both ways (`ps_ballot_tests` and the three unit tests), no `SKIPPED` line. **Regression run** `scripts/smoke.ps1`, 60 s, the retail title, same machine and driver (621.47), `main` 16c2fd08 then this head (switch unset): ``` xcl-smoke v1 commit: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 488 (PresentX 488) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16164 MB ``` ``` xcl-smoke v1 commit: 7740cd57b7993969e9cfa6cf343392d38c6cb957 gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 544 (PresentX 544) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15679 MB ``` Frames 544 / 488 (111 %), peak commit 15,679 / 16,164 MB (97 %), no device removal, no crash. (The first commit alone, 95c5f6e8: 561 frames, 15,752 MB.) **Not tested** - AMD, Intel, other NVIDIA cards and drivers: the change is on for every GPU and I have no other card. If it misbehaves on one, `XCL_PS_WQM_EXIT_BIT=0` gives `main`'s translation without a rebuild, and it is the first thing to try on a pixel regression after this PR. - `IsHelperLane()` in this position on drivers other than 621.47. - A wave64 program's `s_wqm_b32 exec_lo, exec_lo` and `s_andn2` / `s_xor` forms of leaving WQM keep the word test (not fixed if a program uses them). - Frame time: the change removes word tests; not measured. **AI use** - AI use: Claude Code (Claude Opus 5.5) found the cause with local probes, wrote the change, the switch, their tests and this description; checked and posted by me. Base: `main` `16c2fd08`, two commits (the workaround, then the switch), no local switches.
Foniass commented 2026-12-03 12:50:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T12:50:08Z.


Review of 95c5f6e8 (code reading only, not a merge-check; draft) · 2 medium

In short: This PR makes direct-DXIL pixel shaders compute a lane's bit of wqm(entry) & entry, the guest leaving whole quad mode, as !IsHelperLane() combined with the conditions that built the mask. The export no longer reads the entry ballot word, which sidesteps the RTX 3090 holes in #3772. I found no problem in the new lane-bit logic, the phi resolution or the tests. Two things to settle: the change is on for every vendor with only a test switch, and it is over the size target.

Medium

  1. On by default on every GPU, run on one NVIDIA card.

    • ps_exact_bit (dxil/lanes.rs ~340) changes every direct pixel shader that leaves WQM with s_and exec, exec, <saved entry>, on all vendors.
    • It puts the first IsHelperLane() into emitted DXIL: GfxIo::is_helper_lane (dxil/graphics.rs ~418) has no caller on main.
    • The only way back to main's translation is the test-only PS_ENTRY_EXEC_IN_TEST (dxil/lower_gfx.rs ~23). The workaround targets an NVIDIA driver problem, but all the evidence is from one RTX 3090 on drivers 616.56 and 621.47.

    Fix: run it on AMD (the suite plus a smoke run of the retail title), or add a runtime switch that gives main's translation, so a regression elsewhere can be checked without a rebuild.

  2. Size. 670 changed lines against the ~400 target, about 440 of them tests in lanes.rs (ps_ballot_tests). The description gives the reason. The three CPU tests fail without the change. The three GPU tests (gpu_direct_ps_*, ~1730-1860) and their helpers could go in a stacked Tests: PR if the maintainer wants it smaller.

Checked and fine
  • A helper lane's console bit of the entry EXEC is 0, so live_bit(x) & !IsHelperLane() is the console's bit in every lane. s_andn2 and s_not forms go through xor with all ones and still come out right. wqm() lowers to a mul, so bin_of never looks inside it.
  • note_ps_exec_cond is called before write64 / write32 in write_mask and in both PS compare forms in lower_valu.rs, so it records the EXEC the compare ran under. The batch_ballot path records nothing and keeps the word test.
  • trivial_phi_value: the SSA builder's phis have no operands until Ssa::seal, and a web with an empty phi gives up.
  • The conditions and masks returned through ps_exec_conds and trivial phi webs dominate the use.
  • Module::bin keeps operand order, so the lo / hi and pairs match in wave64.
  • Non-pixel shaders are unchanged: the new hooks return early while ps_entry_exec is None.
  • isHelperLane needs SM 6.6, and graphics kernels are built at 6.6.
  • The CPU tests check the guard reads a wave op without the change and none with it, and evaluate the discard for all four helper / kill cases.
  • build.rs hashes src/gpu/dxil, so no version bump is needed. Not a duplicate of #3591, #3785 or #3689.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7378909288 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3786#issuecomment-7378909288). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T12:50:08Z. --- **Review** of `95c5f6e8` (code reading only, not a merge-check; draft) · 2 medium **In short:** This PR makes direct-DXIL pixel shaders compute a lane's bit of `wqm(entry) & entry`, the guest leaving whole quad mode, as `!IsHelperLane()` combined with the conditions that built the mask. The export no longer reads the entry ballot word, which sidesteps the RTX 3090 holes in #3772. I found no problem in the new lane-bit logic, the phi resolution or the tests. Two things to settle: the change is on for every vendor with only a test switch, and it is over the size target. #### Medium 1. **On by default on every GPU, run on one NVIDIA card.** - `ps_exact_bit` (`dxil/lanes.rs` ~340) changes every direct pixel shader that leaves WQM with `s_and exec, exec, <saved entry>`, on all vendors. - It puts the first `IsHelperLane()` into emitted DXIL: `GfxIo::is_helper_lane` (`dxil/graphics.rs` ~418) has no caller on `main`. - The only way back to `main`'s translation is the test-only `PS_ENTRY_EXEC_IN_TEST` (`dxil/lower_gfx.rs` ~23). The workaround targets an NVIDIA driver problem, but all the evidence is from one RTX 3090 on drivers 616.56 and 621.47. Fix: run it on AMD (the suite plus a smoke run of the retail title), or add a runtime switch that gives `main`'s translation, so a regression elsewhere can be checked without a rebuild. 2. **Size.** 670 changed lines against the ~400 target, about 440 of them tests in `lanes.rs` (`ps_ballot_tests`). The description gives the reason. The three CPU tests fail without the change. The three GPU tests (`gpu_direct_ps_*`, ~1730-1860) and their helpers could go in a stacked `Tests:` PR if the maintainer wants it smaller. <details><summary>Checked and fine</summary> - A helper lane's console bit of the entry EXEC is 0, so `live_bit(x) & !IsHelperLane()` is the console's bit in every lane. `s_andn2` and `s_not` forms go through `xor` with all ones and still come out right. `wqm()` lowers to a `mul`, so `bin_of` never looks inside it. - `note_ps_exec_cond` is called before `write64` / `write32` in `write_mask` and in both PS compare forms in `lower_valu.rs`, so it records the EXEC the compare ran under. The `batch_ballot` path records nothing and keeps the word test. - `trivial_phi_value`: the SSA builder's phis have no operands until `Ssa::seal`, and a web with an empty phi gives up. - The conditions and masks returned through `ps_exec_conds` and trivial phi webs dominate the use. - `Module::bin` keeps operand order, so the lo / hi `and` pairs match in wave64. - Non-pixel shaders are unchanged: the new hooks return early while `ps_entry_exec` is `None`. - `isHelperLane` needs SM 6.6, and graphics kernels are built at 6.6. - The CPU tests check the guard reads a wave op without the change and none with it, and evaluate the discard for all four helper / kill cases. - `build.rs` hashes `src/gpu/dxil`, so no version bump is needed. Not a duplicate of #3591, #3785 or #3689. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
CharlyRien commented 2026-12-03 14:10:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T14:10:46Z.


Thanks for the review.

  1. On by default on every GPU. I have no AMD card, so I added a runtime switch in 7740cd57: XCL_PS_WQM_EXIT_BIT=0 gives main's translation without a rebuild. Off, Lw::ps_entry_exec stays unset, so every new hook returns before it records anything and the export guard tests the entry ballot word again. The default stays on.
    • It changes direct pixel shaders' DXIL, so it is part of the translated cache's identity (ps_wqm_exit_tagged in pso.rs) and one of the warm settings (semantic_pipeline_setting), as #3591 does for XCL_PS_SKIP_RUN_THROUGH. A cache made one way is not loaded the other way.
    • The test-only PS_ENTRY_EXEC_IN_TEST is now an override of the same switch (kernel::PS_WQM_EXIT_BIT_IN_TEST, like IDIOMS_IN_TEST). The CPU tests' "without the change" checks go through the same check. There are new unit tests for the parsing, the cache identity and the warm key.
    • RTX 3090, 621.47: ps_ballot_tests with XCL_PS_WQM_EXIT_BIT=0 in the environment: 15 of 15 passed. On the 119 retail programs of the earlier sweep, with the switch off, all 119 get the base tree's DXIL size, and the 17 programs of #3772 lose pixels again as on the base (one of them by 3,988 pixels instead of 4,055 in the base run). With it unset, all 119 match the first commit's sizes and pixel counts.
    • The description lists AMD under Not tested, with the switch as the way back. The README has one line next to the GPU notes.
  2. Size. It is now about 735 lines, about 460 of them tests. I left it in one piece for now. If you or the maintainer prefer, I'll move the three gpu_direct_ps_* tests and their helpers into a stacked Tests: PR.

Suite at the new head: 3019 passed, 2 failed (the two e2e debug-layer tests that fail on main too), 56 ignored. Smoke on the new head: 544 frames against main's 488, peak commit 15,679 MB (main 16,164 MB), no device removal, no crash. The description has both blocks.

AI use: Claude Code (Claude Opus 5.5) wrote the switch, its tests and this reply; checked and posted by me.

<!-- greyfinch-sync:ivall/xcl:comment:7381018452 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3786#issuecomment-7381018452). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-03T14:10:46Z. --- Thanks for the review. 1. **On by default on every GPU.** I have no AMD card, so I added a runtime switch in `7740cd57`: `XCL_PS_WQM_EXIT_BIT=0` gives `main`'s translation without a rebuild. Off, `Lw::ps_entry_exec` stays unset, so every new hook returns before it records anything and the export guard tests the entry ballot word again. The default stays on. - It changes direct pixel shaders' DXIL, so it is part of the translated cache's identity (`ps_wqm_exit_tagged` in `pso.rs`) and one of the warm settings (`semantic_pipeline_setting`), as #3591 does for `XCL_PS_SKIP_RUN_THROUGH`. A cache made one way is not loaded the other way. - The test-only `PS_ENTRY_EXEC_IN_TEST` is now an override of the same switch (`kernel::PS_WQM_EXIT_BIT_IN_TEST`, like `IDIOMS_IN_TEST`). The CPU tests' "without the change" checks go through the same check. There are new unit tests for the parsing, the cache identity and the warm key. - RTX 3090, 621.47: `ps_ballot_tests` with `XCL_PS_WQM_EXIT_BIT=0` in the environment: 15 of 15 passed. On the 119 retail programs of the earlier sweep, with the switch off, all 119 get the base tree's DXIL size, and the 17 programs of #3772 lose pixels again as on the base (one of them by 3,988 pixels instead of 4,055 in the base run). With it unset, all 119 match the first commit's sizes and pixel counts. - The description lists AMD under Not tested, with the switch as the way back. The README has one line next to the GPU notes. 2. **Size.** It is now about 735 lines, about 460 of them tests. I left it in one piece for now. If you or the maintainer prefer, I'll move the three `gpu_direct_ps_*` tests and their helpers into a stacked `Tests:` PR. Suite at the new head: 3019 passed, 2 failed (the two e2e debug-layer tests that fail on `main` too), 56 ignored. Smoke on the new head: 544 frames against `main`'s 488, peak commit 15,679 MB (`main` 16,164 MB), no device removal, no crash. The description has both blocks. AI use: Claude Code (Claude Opus 5.5) wrote the switch, its tests and this reply; checked and posted by me.
Foniass commented 2026-12-03 14:12:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:12:33Z.


Follow-up review of 7740cd57, since 95c5f6e8 (code reading only, not a merge-check; draft) · 1 medium

In short: The new commit 7740cd57 adds a runtime switch: XCL_PS_WQM_EXIT_BIT=0 gives main's translation of direct pixel shaders. It is part of the translated cache's identity and of the warm settings, which fixes the main earlier point. The first commit is unchanged. Only the size remains, and the description gives its reason.

Medium

  1. Size (still open). Now +730/-5, against the ~400 target. About 440 of those lines are the tests in lanes.rs (ps_ballot_tests), and the description says why. The three GPU tests (gpu_direct_ps_*) and their helpers could still go in a stacked Tests: PR if the maintainer wants it smaller.
Checked and fine
  • Earlier finding fixed: the change had only a test switch. Now ps_wqm_exit_bit (kernel.rs ~115) reads XCL_PS_WQM_EXIT_BIT once and logs when it is off. note_ps_entry_exec returns early when the switch is off, so ps_entry_exec stays None and every new hook returns before it records anything, as on main. The Not tested section names the switch as the first thing to try on a pixel regression.
  • The cache tag is applied only under Backend::DirectAll, and that is the only routing in which direct_graphics translates a pixel shader (pso.rs ~829-836). Translated entries made with and without the switch do not mix. semantic_pipeline_setting lists the switch, so warm caches are kept apart too. The new tests cover both.
  • The test override moved to kernel::PS_WQM_EXIT_BIT_IN_TEST (Option<bool>). It is copied to the translator thread in translate_entry_with, and the old lower_gfx::PS_ENTRY_EXEC_IN_TEST has no remaining users. translate_ps_entry_exec resets it to None before it unwraps the result, so a failed translation does not leak the override into later tests on that thread.
  • ps_wqm_exit_bit_for turns the workaround off only for 0 (trimmed). Unset, empty or any other value leaves it on, as documented.
  • Tested gives the whole suite on 7740cd57 (3019 passed, 2 failed, 56 ignored). The two failures are the e2e debug-layer tests, which fail on main too. It also gives ps_ballot_tests with the switch off.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7381066926 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3786#issuecomment-7381066926). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T14:12:33Z. --- **Follow-up review** of `7740cd57`, since `95c5f6e8` (code reading only, not a merge-check; draft) · 1 medium **In short:** The new commit `7740cd57` adds a runtime switch: `XCL_PS_WQM_EXIT_BIT=0` gives `main`'s translation of direct pixel shaders. It is part of the translated cache's identity and of the warm settings, which fixes the main earlier point. The first commit is unchanged. Only the size remains, and the description gives its reason. #### Medium 1. **Size (still open).** Now +730/-5, against the ~400 target. About 440 of those lines are the tests in `lanes.rs` (`ps_ballot_tests`), and the description says why. The three GPU tests (`gpu_direct_ps_*`) and their helpers could still go in a stacked `Tests:` PR if the maintainer wants it smaller. <details><summary>Checked and fine</summary> - Earlier finding fixed: the change had only a test switch. Now `ps_wqm_exit_bit` (`kernel.rs` ~115) reads `XCL_PS_WQM_EXIT_BIT` once and logs when it is off. `note_ps_entry_exec` returns early when the switch is off, so `ps_entry_exec` stays `None` and every new hook returns before it records anything, as on `main`. The **Not tested** section names the switch as the first thing to try on a pixel regression. - The cache tag is applied only under `Backend::DirectAll`, and that is the only routing in which `direct_graphics` translates a pixel shader (`pso.rs` ~829-836). Translated entries made with and without the switch do not mix. `semantic_pipeline_setting` lists the switch, so warm caches are kept apart too. The new tests cover both. - The test override moved to `kernel::PS_WQM_EXIT_BIT_IN_TEST` (`Option<bool>`). It is copied to the translator thread in `translate_entry_with`, and the old `lower_gfx::PS_ENTRY_EXEC_IN_TEST` has no remaining users. `translate_ps_entry_exec` resets it to `None` before it unwraps the result, so a failed translation does not leak the override into later tests on that thread. - `ps_wqm_exit_bit_for` turns the workaround off only for `0` (trimmed). Unset, empty or any other value leaves it on, as documented. - **Tested** gives the whole suite on `7740cd57` (3019 passed, 2 failed, 56 ignored). The two failures are the e2e debug-layer tests, which fail on `main` too. It also gives `ps_ballot_tests` with the switch off. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3786:upstream-pr/3786'
git switch 'upstream-pr/3786'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3786'
git switch 'upstream-pr/3786'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3786'
git switch 'upstream-pr/3786'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3786'
git switch 'main'
git merge --squash 'upstream-pr/3786'
git switch 'main'
git merge --ff-only 'upstream-pr/3786'
git switch 'main'
git merge 'upstream-pr/3786'
git push origin 'main'
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
xcl-dev/xcl!3786
No description provided.