Shaders: preserve first active lane reads across divergent switches #2182
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2192"
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 gloger2003 on 2026-11-25T08:41:29Z.
Part of #1833. Follow-up to #1679. On a Radeon RX 7800 XT, the direct DXIL read of the first active lane can return a value from a later divergent switch case. That case should see the value captured before the switch.
What is in it
Tested
cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-outputwith XCL_DXIL_CACHE pointing to a writable directory reported 1154 passed, 1 failed, 46 ignored. Runtime skips: 7 (gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu, gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, heap_window_out_of_memory_falls_back_to_the_switch_form). Seed 783 also produced mismatches on clean main. The HLSL mesh cache-only test passed separately on both revisions with a writable cache, after both had failed using the default directory in this environment.Regression run
Minecraft Preview, 90 seconds per build, 1x MSAA and
XCL_DIRECT_DXIL=all, with separate fresh caches. An earlier 30-second pair reached only 42 frames on main and ended before the candidate entered the title, so the comparison uses a longer matched run.Not tested
Other GPU drivers, retail world entry, and performance of workloads that use this operation more frequently.
AI use
OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode) investigated the mismatch, compared implementations, wrote the patch and regression test, ran validation, and drafted this description.
Imported from ivall/xcl. Originally posted by ettehn on 2026-11-25T09:16:26Z.
Windows software-adapter check on
1d8341a: all 500 DXIL modules for fuzz seeds 500–999 validated with DXC/DXIL 1.8.2502.11. WARP ran zero of the fixed-wave32 fuzz dispatches. I separately ran a four-thread synthetic shader, with no fixed wave size, through this PR’sShader::wave_read_lane_first. The call before the parity switch returned lane 0 on all four lanes. Calls partially active inside the switch returned lane 0 for even lanes and lane 1 for odd lanes, preserving the0x80000010payload. All 8 words matched. This covers the replacement’s behavior with different active lane sets on WARP. The AMD seed 722 reproduction and retail performance are outside this check.RDNA2 translation scope. I also translated ten synthetic compute entries on Windows with the patch and with only its
shader.rshunk reverted. All 20 modules validated. The 1D native wave32/wave64 cases were byte-identical, andV_READFIRSTLANE_B32continued to lower through the emulated EXEC mask andwaveReadLaneAt. The changed DXIL in this matrix was the prologue broadcast for 2D native groups and 1D split wave64: those cases changed even with no guestV_READFIRSTLANE_B32. Each replaced onewaveReadLaneFirstwith one additionalwaveIsFirstLanecall, a select, and onewaveActiveBitreduction in the emitted DXIL. This identifies production paths worth including in performance checks. It does not measure driver instructions or dispatch cost.Predicate reuse. The three lane-setup sites already compute
WaveIsFirstLanein the same active-lane set before broadcasting the atomic counter result. I factored the select/OR into a localwave_broadcast_first_i32(value, first)helper and passed that existing predicate at those sites. This reducedWaveIsFirstLanefrom two calls to one in all six affected variants of the matrix, retaining oneWaveActiveBitOR. The four native 1D variants remained byte-identical to PR head. All ten validated, and the WARP branch fixture still matched all eight words. This is an emitted-DXIL simplification, with no hardware timing claim.AI use — OpenAI Codex (GPT-6) wrote the local fixture and ran the checks.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T09:37:59Z.
Independent native Windows check of exact PR head
1d8341aba280c329e184a78869dc8d2327c81504against its parent568e7db7729c8fa6c8f0f4b32d798faaf11462bb. The final worktree is clean.Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M, driver
30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5.XCL_ADAPTER=6800M,XCL_REQUIRE_GPU=wave64,XCL_DIRECT_DXIL=1. Command:cargo test --locked -p xcl --lib -j 2 first_active_lane_value_survives_a_divergent_switch -- --test-threads=1 --show-output.PR head: The seed-722 regression passed 1/0/0, with no skip: the log says
validated 1, GPU-compared 1. The final clean-head repeat also passed 1/0/0 with the same GPU comparison.Test-only control: I kept the new seed-722 test and restored only
crates/xcl/src/gpu/dxil/shader.rsfrom parent568e7db, then rebuilt and ran the same command and adapter selection. It also passed 1/0/0,validated 1, GPU-compared 1. I restored the PR shader file before the final passing run.Scope: Seed 722 did not reproduce the parent behavior reported on the RX 7800 XT on this RX 6800M/driver. This run confirms that the focused test executes on this card, but it does not demonstrate a before/after correction here. I did not run the full workspace suite or a retail-title comparison on this PR.
AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran both variants, restored the clean PR head, checked the GPU comparison counts, and drafted this report.
Imported from ivall/xcl. Originally posted by cindertheblue on 2026-11-25T17:27:52Z.
Tested the head
1d8341aon a second RDNA3 card, where seed 722 reproduces. The fix works there: 722 fails without theshader.rschange and passes with it, andfuzz_validate_and_gpu_1moves on to seed 783.Tested
gfx1036), driver 32.0.21045.5002, on the same machine. Windows 11 Home 26200.9974, rustc 1.99.1, DXC 1.8.2502.11 (SDK 10.0.26100), debug, no local changes. "Control" is the head with onlycrates/xcl/src/gpu/dxil/shader.rsrestored from568e7db.first_active_lane_value_survives_a_divergent_switch(3 runs)debug_seed,FUZZ_SEED=722amd_reduced_seeds, both 722 shapes + full seed 722res[30] = 0x1, CPU 0x7fffffffamd_reduced_seeds, 1599 shapes + full seedSeed 722 doesn't reproduce on this iGPU, so the iGPU runs only show the new test runs there (
validated 1, GPU-compared 1).cargo test --workspace --no-fail-fast -- --test-threads=4, once each:main568e7dbXCL_DIRECT_DXIL=1Each tree had
cargo build --workspacefirst. The extra pass is the new test.fuzz_validate_and_gpu_1fails in every row, but on the RX 7600 XT it now stops at the next AMD seed, 783:res[64]with CPU0x7fffffff(wasseed 722: res[30] = 0x1, CPU 0x7fffffff). The wrong value changes between runs:0xchere,0x5d154f27in an earlier run. On the iGPU it stops at 540 on both trees. WithXCL_DIRECT_DXIL=1the other two failures are the same on both trees:gpu_image_get_resinfo_1d_array(#2046) andoffline_compute_pipeline_is_reused_by_a_second_process(#1674). The same 8SKIPPEDlines in all six runs.Not tested: a release build, a title or smoke run, NVIDIA, the cost of the extra wave reduction.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this comment from their output.
Imported from ivall/xcl. Originally posted by thiagocalile on 2026-11-25T19:35:19Z.
Independent Windows AMD Radeon RX 6600 (RDNA2, 8 GB VRAM, native wave64) verification of
main2898511+#1946(f906266) +#2192(1d8341a): all 1,364 workspace tests pass with 0 failures (down from 1 failure,gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, on unmodifiedmain2898511).Tested
32.0.21045.29003,XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust1.100.0(stable-x86_64-pc-windows-msvc), DXC1.8.2502.11.main(2898511af1c038a2ef809719e9b6f89e5675c422):XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 1,362 passed, 1 failed, 46 ignored (11skipped; failed:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1).#1946(f906266) +#2192(1d8341a) ontomain2898511:XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 1,364 passed, 0 failed, 46 ignored (11skipped).Regression run (
scripts/smoke.ps1 -Seconds 60, release builds,XCL_ADAPTER=radeon)main(2898511):main2898511+#1946(f906266) +#2192(1d8341a):Not tested:
#1946and#2192individually in isolation, NVIDIA/Intel GPUs, Linux/RADV, or world load past the 60 s smoke window.AI use: Antigravity (Gemini 4 Neon) ran the merge, workspace tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.
Imported from ivall/xcl. Originally posted by CharNoir on 2026-11-25T22:32:14Z.
Test report for
1d8341a("Shaders: preserve first active lane reads across divergent switches").Tested
<rustc --version>; debug (testprofile); DXC 1.8.2502.11 (Windows SDK 10.0.26100.0)cargo test -p xcl --lib fuzz_validate_and_gpu, on main and on this PR:_0_1_2_3e1d84b7res[30] = 0x1, CPU0x7fffffff)1d8341afuzz_validate_and_gpu_1now gets past it. The_3failure (seed 1599) is the Countbits/Bfrev constant-fold issue fixed by #2231 and is unrelated to this PR._1now stops at seed 783:res[64] = 0xffffffff, CPU0x7fffffff. It looks unrelated to this change:WaveReadLaneAton a constant) doesn't feed the failing output.IMax(i64 -5, i64 0x7FFFFFFFFFFFFFFB)(%40 = dx.op.binary.i64(37, %38, %33)), built entirely from constants.0x7FFFFFFF. The GPU returned0xFFFFFFFF, which is the unsigned max. This looks like another AMD driver constant-folding bug, this time in 64-bit IMax._1stops at seed 722 there first.e1d84b7:cargo test --workspace -- --test-threads=4: 1421 passed, 2 failed (the two fuzz tests above), 46 ignored. SKIPPED GPU tests: 6 f16/f32 per-lane refusals (#1426) and the heap_window test ("no heap windows").Not tested
fuzz_validate_and_gputests were run on it.scripts/smoke.ps1regression run on a real title.AI use
Imported from ivall/xcl. Originally posted by Granite900 on 2026-11-26T16:32:52Z.
Tested
1d8341abon an RX 9070 XT (RDNA4), Adrenalin 26.11.2, Windows 11, DXC 1.9.2609.5: seed 722 is fixed on RDNA4 too (first_active_lane_value_survives_a_divergent_switchpasses).On this PR alone,
fuzz_validate_and_gpu_1then fails on seed 783, which was hidden behind 722. That's a separate AMD i64 IMax fold that #1946 fixes. Combined with #2231 and #1946 onmain, all fuzz tests pass. Details and the table are in #2115.Not tested: full suite, retail titles. Report drafted with Claude (Claude Opus 5.5) from my runs.
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:43:34Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:34:08Z.
Triage (#1607) – head
1d8341aNo open or merged PR changes Shader::wave_read_lane_first (dxil/shader.rs). Main still emits waveReadLaneFirst there. For i32 the PR replaces it with WaveIsFirstLane + select + WaveActiveBitOr, which gives the same result. The WaveOps requirement still comes from the helpers it calls.
Note: the workaround is for AMD, but it applies on every vendor, and the seed-722 test only shows the bug on the RX 7800 XT.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.