Recompiler: split wave64 half-local masks read their words from the first lane #3792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3792"
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-03T15:00:05Z.
Works around group 6 of the #3716 fuzzer (point 6 of https://github.com/xcl-dev/xcl/pull/3716#issuecomment-7358845851), discussed in #3758.
In the direct split form (a wave64 program run as two 32-lane hardware waves), a compare mask that is never read whole stays a half-local pair:
Lw::write_mask(gpu/dxil/lower.rs) builds it as(select(upper, 0, ballot), select(upper, ballot, 0))and the halves exchange nothing at the compare. On an RTX 3090 (drivers 616.56 and 621.47), NVIDIA's shader compiler reads the lower half's own word of that pair as 0 at a later branch on EXEC in some programs: 12 programs of group 6 give wrong words in every run. The same DXIL gives the reference words on WARP and in a CPU interpreter of it, and in that interpreter only zeroing that word reproduces the 3090's 128 wrong words in the shrunk program (#3758, second comment). The same shape written by hand in HLSL is right on the 3090 at DXC-O3,-O1and-Od, so only the DXIL the translator emits meets it.Both words of the pair are the same in the lanes that run the ballot together, so this change reads each of them once more with
WaveReadLaneFirst(Lw::read_pair_first):upperis the same in every lane of a hardware wave: each hardware wave is one 32-lane half, its lanes are a base that is a multiple of 32, read from the first lane, plus a rank below 32 (setup_lanes,setup_lanes_compute).So the read changes nothing in the program's meaning, and the halves exchange nothing more. It applies to every split entry (compute, mesh, the GS). It also stops the translator's select folds on the pair: a lane's bit of it used to fold back to the ballot word and is now a select of the two reads, so the DXIL grows a little (measured below).
Lw::ballotbuilds the same pair when there is no partner half (Partner::Missing: the other half's word is 0):upperis now the constant false there (setup_lanes_compute): the selects fold to(ballot, 0)and there is nothing to read.batch_ballotandmeet_atbuild the pair without a partner only in compute and mesh programs, so they fold too;upperis not a constant where the GS's EXEC is made, so that pair is read from the first lane too.It is not applied:
upperis a constant (apart, groups of 32 threads or fewer): no select;Dst::Null);This is not #3784's read: #3784 reads a mask word before a lane's bit test, and #3758's second comment notes that this does not fix these programs (the branch reads 0 too). This change reads the pair's words where they are made. The two commits touch different lines and merge without conflict.
With #3748 (every mask exchanged by default),
Lw::write_maskwould take the half-local branch for an SGPR destination only underXCL_X64_PRECISE_MASKS=1; by default only the GS-aloneLw::ballotpair would keep the read. The measurements here are ofmaina815de93's default, where the half-local analysis runs unlessXCL_X64_ALL_MASKSis set. Whichever of the two PRs lands second adapts the tests: the twogroup6CPU tests need the analysis on.What is in it
gpu/dxil/lower.rs:Lw::read_pair_first, called fromLw::write_mask's half-local branch; a test-only switch to show the old form (NO_PAIR_READ_FIRST_IN_TEST).gpu/dxil/lanes.rs:upperis the constant false in split compute / mesh groups of 32 threads or fewer;Lw::ballotreads its pair from the first lane when there is no partner half.gpu/dxil/kernel.rs: the translator thread takes that switch over, like the existing ones;translate_compute_as(test only), the compute twin oftranslate_full_as.gpu/dxil/lower.rs, tests (split_pair_tests), on group 6's shrunk program (seed 1000823 shrunk to 120 instructions, assembled by hand; 96 threads, 2 groups). The CPU tests translate in the plain form (not the compact one, whateverXCL_DIRECT_COMPACTsays) and skip withoutdxcompiler.dll, checked before translating (translation validates under test). The twogroup6CPU tests also skip whenXCL_X64_ALL_MASKSis set (no half-local pair then), and their "no half-local pair" messages name that premise:split_half_local_pairs_are_read_from_the_first_lane(CPU): in the split form each word of a half-local pair (a select between a ballot's word and 0) is read once from the first lane, nothing else uses the word, and the program uses each read; none is read without the change; the ballots, groupshared accesses and barriers are the same. The native wave64 form has no such pair and the same reads as before.split_groups_of_32_threads_or_fewer_have_no_pair_to_read(CPU): the same program in split groups of 32 and 20 threads has no such pair and no read more.split_gs_alone_reads_its_exec_pair_from_the_first_lane(CPU): the split form's GS alone reads its EXEC pair from the first lane, and only the reads use it.gpu_split_half_local_exec_branch(GPU): the program in the split form, every stored word checked (v1..v16 and s4..s15 of all 192 threads, 5,376 words; the expected words are the #3716 RDNA2 reference's for this program). It also runs the old form and prints its wrong words without asserting them, since other GPUs may compile it right. It skips without a GPU, a wave32 GPU or DXC, checked before translating.88a810f4, tests only, after Foniass's review): the GPU test's DXC check, and theXCL_X64_ALL_MASKSskip and messages above. The runtime code is the first commit's.No cache bump: the change is under
gpu/dxil, whose hash isXCL_DIRECT_DXIL_SOURCE_ID, so split-form direct translations get a new identity on their own; the HLSL path'sXCL_TRANSLATOR_SOURCE_IDis unchanged.Measured before this PR
RTX 3090, driver 621.47. These runs use a local probe, not this commit: the same read behind a variable, applied in the whole half-local branch (also with
apart,local_masksandDst::Null), on #37077b19e27d+ #3716d2293dcb. Only the split form was run.mainWaveReadLaneFirstof each word (this PR)WaveReadLaneFirstof the ballot, then the selectsballot & (upper - 1),ballot & (0 - upper)8,000 programs of the #3716 fuzzer (seeds 0–1999, 1000000–1001999, 2000000–2001999, 3000000–3001999), direct split form:
The other 188 are other issues: group 5 (#3779), group 1 and one signed zero (the same split as in #3784's description).
With this commit, on
maina815de93+ #3716de05c50e(whose generator changed, so the seed numbers above need not be the same programs) and the same fuzz probe, against the same tree without the commit, over the same 8,000 seeds: 203 programs differ from the reference without it, 193 with it; fixed: 10 (seeds 155, 358, 746, 824, 1869, 1000716, 1001176, 2000677, 2000986, 2001922); wrong only with it: 0.Over the same 8,000 programs, the direct split form's containers grow from 50,574,952 to 50,723,040 bytes (+0.29 %): 1,767 programs larger (at most +356 bytes), none smaller, 6,233 the same.
This is a workaround chosen from the shapes seen on one card with two drivers. It does not prove that other shapes do not meet the same driver bug.
Tested
88a810f4):cargo build --workspaceandcargo test --workspace --no-run: okcargo test --workspace --no-fail-fast -- --test-threads=4: 3,020 passed, 2 failed (the same two debug-layer tests as below), 56 ignored, over 45 test binaries;SKIPPED: the same 25 lines as below.XCL_REQUIRE_GPU=mesh: passed;gpu_split_half_local_exec_branch, 3 runs: 128 wrong words without the read each time, 0 with it. Release build: the four tests passed.01d941e1, the same runtime code), on the same machine:cargo build --workspaceandcargo test --workspace --no-run: ok01d941e1:cargo test --workspace --no-fail-fast -- --test-threads=4: 3,020 passed, 2 failed (test_title_draws_with_a_root_signature_under_the_debug_layer,test_title_runs_under_the_debug_layer_with_dred), 56 ignored, over 45 test binaries. The same two debug-layer tests fail on this machine without this commit (main16c2fd08+ another one-commit recompiler branch: 3,013 passed, the same 2 failed);maina815de93itself was not run through the whole suite.01d941e1:SKIPPEDon this adapter: 25 lines: 22 "no wave64", 3 "no heap windows" or "noGPU_UPLOADheaps", the reasons this card always gives.01d941e1: the four new tests by name withXCL_REQUIRE_GPU=mesh: passed, and passed again in the whole suite.gpu_split_half_local_exec_branch, 3 runs: the old form gave 128 wrong words each time (v1of group 0's first threads read 0, as in #3758), the new form 0. A release build of this head passed the four tests too.Regression run
scripts/smoke.ps1, 60 s each, the same title, the same machine and driver (621.47), a fresh shader cache on each side;mainfirst, then this head (88a810f4), then the first head (01d941e1, the same runtime code) for reference:This head: frames 1,642 / 495 (332 %), peak commit 15,878 / 15,974 MB (99 %), no device removal, no crash. This head changes only tests, so its runtime code is
01d941e1's; the higher frame count is not from it. A likely cause (not checked) is the driver's own shader cache, warm from the01d941e1run of the same DXIL.01d941e1: frames 532 / 495 (107 %), peak commit 15,926 / 15,974 MB (100 %), no device removal, no crash.Not tested
XCL_SPLIT_WAVE64=1would use it), Intel, other NVIDIA cards and drivers. Without this commit, @stijn-boer's run of the same probe onmaina815de93(RX 9060 XT, #3779 comment) already matched on all 12 G6 programs, so the miscompile is seen on NVIDIA only so far.Lw::local_masks,XCL_PER_LANE=1), and in the HLSL path'sxcl_x_ballot_local(recomp/emit.rs), which split programs take when the direct translator refuses them.upperof groups of 32 threads or fewer: covered by the CPU tests and by the existing split GPU tests of 32-thread groups in the whole suite; no fuzz program reaches the GS.WaveReadLaneFirstper half-local compare mask in split programs and stops some select folds; not measured beyond the smoke run.AI use
Base:
maina815de93, two commits (the change, then its test follow-up), no local switches.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:05:21Z.
Review of
01d941e1(code reading only, not a merge-check; draft) · 1 medium, 1 nitIn short: In the split wave64 form, this PR adds a
WaveReadLaneFirston each word of a half-local mask pair (Lw::write_mask, andLw::ballotwhen there is no partner half). It also makesupperthe constant false in split compute and mesh groups of 32 threads or fewer. Both words are uniform within each 32-lane hardware wave, so the read does not change what the program computes. Nothing blocks the PR. One medium point is how it interacts with #3748, and one nit is a GPU test that does not skip without DXC.Medium
Interaction with #3748.
write_masktakes the half-local branch only throughwhole_live(dxil/lower.rs~1081). On this base,whole_liveis filled wheneverXCL_X64_ALL_MASKSis unset (kernel.rs~873).x64_masks::precise_masks(), which is off by default. If it lands, thewrite_maskread here applies only withXCL_X64_PRECISE_MASKS=1, and by default only the GS-aloneballotpath keeps it.group6in 96-thread groups has no half-local pair, soassert!(pairs > 0, …)(~2884) andassert!(pairs96 > 0, …)(~2911) would fail.Whichever of the two lands second has to handle this. The tests should turn the precise analyses on (for example with #3748's test guard), and the description should say which default the measurements apply to.
Nit
gpu_split_half_local_exec_branch(lower.rs~2958) checks onlyrunner::adapter()andwave32_supported(). It then callstranslate, which validates under test and panics throughunwrap_or_else(|e| panic!(…))whendxcompiler.dllis missing. The CPU tests in the same module checkhave_dxc()first, and other GPU tests checkdxc::location()(for examplecompact_tests.rsgpu_compact_form_runs_as_the_plain_form). Add the same check, withskip_test("no DXC").Checked and fine
upperis uniform within each hardware wave in every split entry.setup_lanesandsetup_lanes_computebuild the lane as a base that is a multiple of 32, read withWaveReadLaneFirst, plus a rank below 32. So reading each word of the pair from the first active lane changes nothing.upper = falsefor split groups of 32 threads or fewer (lanes.rs~203) is correct: withtotal <= 32the base is always 0. Geometry always uses 64 threads, and Kernel usessetup_lanes, so neither is affected.read_pair_firstreturns the pair unchanged in four cases: whenupperis a constant, in the per-lane bridge (local_masks), and with the test switch on.const_u64handles thei1constant fromb(false).Partner::Missingwith a non-constantupperoccurs only in the GS.batch_ballotandmeet_atare used only in planned compute and mesh programs, whereupperis now constant whenever the partner is missing.live_execandexec_cachekey on the valuesballotreturns.NO_PAIR_READ_FIRST_IN_TESTis carried to the translator thread like the existing ones.upper(20 and 32 threads) and the GS-aloneballot. The branch targets in the hand-assembledgroup6program match their comments.build.rshashes every file undersrc/gpu/dxil.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-03T15:49:16Z.
Thanks for the review. Both points are in
88a810f4(a new commit, tests only):group6CPU tests now skip whenXCL_X64_ALL_MASKSis set (a failure underXCL_REQUIRE_GPU), and their "no half-local pair" messages say they needkernelto fillwhole_live. I did not add a test override for the analysis here: it would sit on the same lines #3748 changes. Whichever PR lands second switches these two tests to #3748's guard (PreciseForTest). The description now says that, with #3748, thewrite_maskread applies only underXCL_X64_PRECISE_MASKS=1, and that the measurements are ofmaina815de93's default.gpu_split_half_local_exec_branchnow checksdxc::location()with the adapter, before translating, and skips with "no DXC".New head on the RTX 3090 (621.47): whole suite 3,020 passed, 2 failed (the two known debug-layer tests), 56 ignored; the four tests by name passed; smoke: no device removal or crash, peak commit 15,878 / 15,974 MB (frames 1,642 / 495, but this head changes only tests: see the description). The description is updated.
AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and wrote this reply; checked and posted by me.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:50:50Z.
Follow-up review of
88a810f4, since01d941e1(code reading only, not a merge-check; draft) · 1 nitIn short: The new commit
88a810f4is test-only. The GPU test now skips without DXC, and the twogroup6CPU tests now skip whenXCL_X64_ALL_MASKSturns the half-local analysis off. The description now covers #3748: the measurements are ofmain's default, and whichever PR lands second adapts the tests. The first commit is unchanged. Nothing new found; one small point remains.Nit
half_local_masks()(lower.rs~2783) checks onlyXCL_X64_ALL_MASKS. #3748 turns the analysis off by default throughx64_masks::precise_masks(), with no environment variable set. If #3748 lands first, the two tests still run and fail onpairs > 0, now with a clearer message, not skip. That matches the description ("whichever lands second adapts the tests"), so this is only a note. Once #3748 is in,half_local_masks()should callprecise_masks(), or the tests should turn it on.Checked and fine
gpu_split_half_local_exec_branchnow checksdxc::location()and skips with "no DXC", after the GPU check, as the module's other GPU tests do.whole_livestops being filled by default.01d941e1is unchanged since the last review (range-diff=).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.