Recompiler: a PS export after leaving WQM tests no ballot word #3786
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3786"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 underEXEC = wqm(entry) & entrytests each lane's bit of that EXEC by shifting the entryWaveActiveBallot(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::lanebitalready 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 ofx & entry, whereentryis the saved entry EXEC andxa mask made froms_wqmof it (the guest leaving whole quad mode), is!IsHelperLane() && live_bit(x):live_bitis the lane's bit ofxassuming the lane is live:s_wqmof the entry EXEC and the entry EXEC are 1 in every live lane; a compare's orv_cmpx's mask is its condition and the live bit of the EXEC it ran under (recorded byLw::note_ps_exec_cond);and/or/xor/selectcompose; anything else gives up and the word test stays.Nothing else changes: the mask words, the entry EXEC's own bit (
true, as onmain), every lane's view of other lanes' bits, and the code that runs in WQM. Onlyx & entrywithxderived froms_wqmof the entry EXEC gets the new bit; other masks and-ed with the entry EXEC (for examples_andn2/s_xorforms, or a mask narrowed on one path) keep the word test.s_wqmwidths:s_wqm_b64of the entry EXEC in wave64,s_wqm_b32ors_wqm_b64of it in wave32 (the high word is 0). A wave64 program'ss_wqm_b32 exec_lo, exec_lois 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 (
optremoves them after lowering, when the guard has been chosen already).Lw::trivial_phi_valueresolves 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 onmain, and drop out only at theandthat leaves it, as on the console.What is in it
gpu/dxil/lanes.rs: theandcase inown_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_pixelrecords the entry EXEC words (Lw::ps_entry_exec);note_ps_entry_wqm.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_execstays unset, so every hook above returns before it records anything and the export guard tests the entry ballot word as onmain. 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, underXCL_DIRECT_DXIL=allrouting) and one of the warm settings (shaders.rs,semantic_pipeline_setting), as #3591 does forXCL_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, likeidioms::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_b64records_wqmof the entry EXEC;write_maskrecords compare conditions.gpu/dxil/lower_valu.rs: the same for local- and quad-form compares.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 guestv_cmpxkill 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_wqmafter av_cmpx, and a wave64s_wqm_b32 exec_lokeep 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, av_add_cocarry-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 withds_swizzle: a helper lane must keep its WQM-mode value.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 isXCL_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
execzskips 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 stackedTests:PR.Measured before this PR
On a local tree (
main817eb1fc+ #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:andas 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;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
cargo build --workspace: ok7740cd57):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 onmaintoo (main16c2fd08plus 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 failedtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(counted twice: it re-runs itself as a child process), in its child casestale-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 onmain(5 of 5). The change touches no two-pass or PSO release code; I read it as a timing-dependent test, not shown.SKIPPEDon this adapter: 25 lines: 22no wave64(expected on this card), 2no heap windows(opt-inXCL_HEAP_WINDOWS=1), 1no GPU_UPLOAD heaps(Resizable BAR off).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_testswithXCL_PS_WQM_EXIT_BIT=0in the environment (the tests that do not set the override then translate asmain): 15 passed, 0 failed.XCL_PS_WQM_EXIT_BIT=0: 18 of 18 passed both ways (ps_ballot_testsand the three unit tests), noSKIPPEDline.Regression run
scripts/smoke.ps1, 60 s, the retail title, same machine and driver (621.47),main16c2fd08then this head (switch unset):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
XCL_PS_WQM_EXIT_BIT=0givesmain'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.s_wqm_b32 exec_lo, exec_loands_andn2/s_xorforms of leaving WQM keep the word test (not fixed if a program uses them).AI use
Base:
main16c2fd08, two commits (the workaround, then the switch), no local switches.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 mediumIn 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
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 withs_and exec, exec, <saved entry>, on all vendors.IsHelperLane()into emitted DXIL:GfxIo::is_helper_lane(dxil/graphics.rs~418) has no caller onmain.main's translation is the test-onlyPS_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.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 stackedTests:PR if the maintainer wants it smaller.Checked and fine
live_bit(x) & !IsHelperLane()is the console's bit in every lane.s_andn2ands_notforms go throughxorwith all ones and still come out right.wqm()lowers to amul, sobin_ofnever looks inside it.note_ps_exec_condis called beforewrite64/write32inwrite_maskand in both PS compare forms inlower_valu.rs, so it records the EXEC the compare ran under. Thebatch_ballotpath records nothing and keeps the word test.trivial_phi_value: the SSA builder's phis have no operands untilSsa::seal, and a web with an empty phi gives up.ps_exec_condsand trivial phi webs dominate the use.Module::binkeeps operand order, so the lo / hiandpairs match in wave64.ps_entry_execisNone.isHelperLaneneeds SM 6.6, and graphics kernels are built at 6.6.build.rshashessrc/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.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T14:10:46Z.
Thanks for the review.
7740cd57:XCL_PS_WQM_EXIT_BIT=0givesmain's translation without a rebuild. Off,Lw::ps_entry_execstays unset, so every new hook returns before it records anything and the export guard tests the entry ballot word again. The default stays on.ps_wqm_exit_taggedinpso.rs) and one of the warm settings (semantic_pipeline_setting), as #3591 does forXCL_PS_SKIP_RUN_THROUGH. A cache made one way is not loaded the other way.PS_ENTRY_EXEC_IN_TESTis now an override of the same switch (kernel::PS_WQM_EXIT_BIT_IN_TEST, likeIDIOMS_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.ps_ballot_testswithXCL_PS_WQM_EXIT_BIT=0in 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.gpu_direct_ps_*tests and their helpers into a stackedTests:PR.Suite at the new head: 3019 passed, 2 failed (the two e2e debug-layer tests that fail on
maintoo), 56 ignored. Smoke on the new head: 544 frames againstmain's 488, peak commit 15,679 MB (main16,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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:12:33Z.
Follow-up review of
7740cd57, since95c5f6e8(code reading only, not a merge-check; draft) · 1 mediumIn short: The new commit
7740cd57adds a runtime switch:XCL_PS_WQM_EXIT_BIT=0givesmain'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
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 stackedTests:PR if the maintainer wants it smaller.Checked and fine
ps_wqm_exit_bit(kernel.rs~115) readsXCL_PS_WQM_EXIT_BITonce and logs when it is off.note_ps_entry_execreturns early when the switch is off, sops_entry_execstaysNoneand every new hook returns before it records anything, as onmain. The Not tested section names the switch as the first thing to try on a pixel regression.Backend::DirectAll, and that is the only routing in whichdirect_graphicstranslates a pixel shader (pso.rs~829-836). Translated entries made with and without the switch do not mix.semantic_pipeline_settinglists the switch, so warm caches are kept apart too. The new tests cover both.kernel::PS_WQM_EXIT_BIT_IN_TEST(Option<bool>). It is copied to the translator thread intranslate_entry_with, and the oldlower_gfx::PS_ENTRY_EXEC_IN_TESThas no remaining users.translate_ps_entry_execresets it toNonebefore it unwraps the result, so a failed translation does not leak the override into later tests on that thread.ps_wqm_exit_bit_forturns the workaround off only for0(trimmed). Unset, empty or any other value leaves it on, as documented.7740cd57(3019 passed, 2 failed, 56 ignored). The two failures are the e2e debug-layer tests, which fail onmaintoo. It also givesps_ballot_testswith the switch off.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.