Recompiler: split wave64 bit tests read the mask word from the first lane #3784
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3784"
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:35Z.
Works around #3779.
In the direct split form (a wave64 program run as two 32-lane hardware waves),
Lw::lanebit(gpu/dxil/lanes.rs) tests a lane's bit of a mask as(select(upper, hi, lo) >> lane31) & 1. On an RTX 3090 (drivers 616.56 and 621.47), and as others reported in #3779 on an RTX 3070 Laptop (621.40) and an RTX 3080, NVIDIA's shader compiler gets this test wrong in some programs: all 58 programs of the #3716 fuzzer's group 5 fail there. The same shape written as plain HLSL (the repro in #3779) fails with DXC-O3/-O1and passes with-Odand on WARP, so this looks like a driver compiler bug, not a translator bug. On an AMD RX 9060 XT, all 58 programs and the repro are right (also reported in #3779).In the split form the mask word is the same in every lane of a hardware wave, so this change reads it once more with
WaveReadLaneFirstbefore the shift:uppercomes from a base that is a multiple of 32, read from the first lane, plus a rank below 32 (setup_lanes,setup_lanes_compute);v_readfirstlane/v_readlaneresults come fromWaveReadLaneAttoo).So the read changes nothing in the program's meaning; it only changes the shape the driver compiles. It is not applied:
uppervaries within the wave;recomp::lower_dxil,Lw::local_masks), which passes a mask read lane by lane as a word holding only that lane's own bit;apart(each hardware wave runs its own console wave): theretidis the flattened group thread id, so TG_SIZE'stid / 64can differ inside one hardware wave of a group of more than 64 threads, and a scalar compare on it (uniform_compare) can give an EXEC word that differs by lane. I did not show that this cannot reachlanebit, soapartkeeps the old test.lanebit_at(a bit of another lane) is unchanged.What is in it
gpu/dxil/lanes.rs: the read inLw::lanebit, split form only, not withapart, not underlocal_masks; a test-only switch to show the old form (NO_READ_FIRST_IN_TEST).gpu/dxil/kernel.rs: the translator thread takes that test switch over, like the existing ones.gpu/dxil/lanes.rs, tests (split_lanebit_tests):split_lane_bits_test_the_mask_word_read_from_the_first_lane(CPU, needs DXC): translated in the plain form (not the compact one, whateverXCL_DIRECT_COMPACTsays); in the split form, the bit test behind v17's select (v4 or -1) shifts a word read from the first lane, and did not without the change; thev_bfe_i32and the groupshared accesses are the same with and without it; the native wave64 form's bit tests do not read from the first lane, with the same number ofWaveReadLaneFirst. It skips only when DXC is missing; a disassembly failure with DXC present fails it.gpu_split_lane_bit_of_an_exec_with_an_empty_half(GPU): #3779's program (group 5's smallest program, shrunk), assembled by hand, run in the split form (plain); every register checked. It also runs the old form and prints its wrong words, without asserting them, since other GPUs compile it right.split_bridge_lane_bits_test_each_lanes_own_word(CPU + GPU): a bridged carry-in from a bridged carry-out in the per-lane split form: no first-lane read in its DXIL, and the right sums on the GPU (same DXC handling).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
8,000 programs of the #3716 fuzzer (seeds 0–1999, 1000000–1001999, 2000000–2001999, 3000000–3001999), direct split form only, RTX 3090, driver 621.47. These runs use a local probe, not this commit: the same
WaveReadLaneFirstread behind a variable, applied in every form, on #3716's headd2293dcb(onmain5ad98adb). Only the split form was run.0xFFC00000, RTX 30900x7FFFFFFF), and the fuzzer atd2293dcbcompares that word bit for bit (its later headde05c50eaccepts any NaN made by float arithmetic).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
cargo build --workspaceandcargo test --workspace --no-run: okcargo test --workspace --no-fail-fast -- --test-threads=4: 3013 passed, 2 failed (the same two e2e debug-layer tests), 56 ignored, over 45 test binaries;main1c8b5514on the same machine: 2907 passed, 2 failed (two e2e debug-layer tests), 51 ignored.SKIPPEDon this adapter: 25, allno wave64(8 tests, plus 17 wave64 cases of the arithmetic / mask tests); the same 25 as onmain.XCL_REQUIRE_GPU=mesh: passed, and passed again in the whole suite.gpu_split_lane_bit_of_an_exec_with_an_empty_half, 3 runs: the old form gave 31 wrong words each time (v17 = 0xFFFFFFFF where the program wants its select's other value), the new form 0.Regression run
scripts/smoke.ps1, 60 s each, the same title, the same machine and driver (621.47), a fresh shader cache on both sides;mainfirst, then this head:Frames 510 / 488 (104 %), peak commit 16,268 / 16,164 MB (101 %), no device removal, no crash.
Not tested
XCL_SPLIT_WAVE64=1would use it), Intel, other NVIDIA cards and drivers.lanebitinrecomp/emit.rs), the shape of the plain-HLSL repro in #3779. In the #3716 fuzz (the same 8,000 seeds, RTX 3090, driver 616.56), the HLSL split form gave none of the 58 group 5 failures, so I left it out of this PR. A split program the direct translator rejects, or one with LDS underXCL_PER_LANE=1, takes that path. A follow-up can apply the same read there, but not forxcl_w32(a wave32 program in a 64-lane hardware wave, two console waves in one hardware wave).WaveReadLaneFirstper mask and block in split programs; not measured.Limits (unchanged by this PR)
AI use
Base:
main16c2fd08, one commit, no local switches.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T12:49:36Z.
Review of
b2a23955(code reading only, not a merge-check; draft) · 1 mediumIn short: The PR works around an NVIDIA driver miscompile (#3779). In the direct translator's split wave64 form,
Lw::lanebitreads the mask word once more withWaveReadLaneFirstbefore the shift, except underapart, in the per-lane bridge (local_masks) and outside the split form. The word is uniform in every hardware wave the read applies to, so program meaning does not change, and nothing blocks it. One gap: the HLSL fallback keeps the same bit test.Medium
The HLSL path's split form keeps the old bit test.
recomp/emit.rs~6909 still defineslanebitas((select(lane_id < 32u, lo, hi) >> (lane_id & 31u)) & 1u) != 0u. That is the shape of the plain-HLSL repro in #3779, which fails on NVIDIA at-O1/-O3.XCL_PER_LANE=1. So the workaround covers only the direct form.Fix: say so under Not tested and open a follow-up, or apply the same read there. If you do,
xcl_w32(a wave32 program in a 64-lane hardware wave) puts two console waves in one hardware wave, so the read must not apply in that case.Checked and fine
upperis uniform within each hardware wave of the split form.setup_lanes/setup_lanes_compute(lanes.rs~85-152) give each 32-lane hardware wave a base that is a multiple of 32, read withWaveReadLaneFirst, and the split form always compiles withWaveSize(32).tidprefix (module/split.rs~160, ~262-274), so their masks stay uniform.Lwonly throughIr::foreign, which setslocal_masks, and that path is excluded.write_maskpath in the direct split form gives(sel(upper, 0, w), sel(upper, w, 0))from a ballot, which is uniform per hardware wave.apartmatches the code: therelane31is the hardware lane index andupperis false.NO_READ_FIRST_IN_TESTexists only under#[cfg(test)]and reaches the translator thread like the other switches. The disassembly test compares against the form without the read, so it fails if the change is removed.build.rshashessrc/gpu/dxil, so no version bump is needed. About 30 runtime lines; the rest are tests. No duplicate.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 Gevroska on 2026-12-03T13:44:43Z.
If the workaround is extended to the HLSL fallback, I’d keep the
WaveReadLaneFirstguard specific to mask words known to be uniform within each hardware wave. I tested three mask producers on my RTX 3080 using the split-wave HLSL helpers fromb2a23955. Each form ran three times with fenced readback.The half-local ballot still supplied the same word throughout each 32-lane half, so broadcasting preserved every result. In the per-lane control, only lane 32 remained true after broadcast; the same 16 predicates disappeared in every trial.
This concerns a possible HLSL extension. The current PR changes direct DXIL. I haven’t reproduced the reported failure through stock XCL-emitted fallback HLSL, so I’d want that failing case before carrying the workaround over.
AI disclosure: OpenAI Codex GPT-6.2 Sol led the fixture work, and an independent Codex review checked the readbacks. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T15:06:22Z.
Thanks for the review, and thanks @Gevroska for the measurement.
XCL_PER_LANE=1) and thexcl_w32exception.Gevroska's table is a good reason not to carry the read over blindly: a broadcast is only safe on a word that is the same in every lane of the hardware wave. In the direct form,
upperand the mask words are (the review's checked points), and the read is skipped underlocal_masks, where each lane supplies its own bit. A follow-up for the HLSL path would need the same guard, plus thexcl_w32exception, and I'd want a failing XCL-emitted HLSL program first, as Gevroska says. I'll open one if the fuzz or a game program shows such a case.AI use: Claude Code (Claude Opus 5.5) checked the points against the code and the fuzz results and wrote this reply; checked and posted by me.
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.