Skip to content

Shaders: preserve first active lane reads across divergent switches - #2192

Draft
gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/dxil-first-active-lane
Draft

gloger2003 wants to merge 1 commit into
xcl-dev:mainfrom
gloger2003:fix/dxil-first-active-lane

Conversation

@gloger2003

Copy link
Copy Markdown

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

  • For i32, keep the first active lane's bits and broadcast them with a bitwise OR reduction. Other types continue to use the existing intrinsic.
  • Add a standalone GPU regression for seed 722. The existing source hash invalidates cached DXIL.

Tested

  • Windows x64, Ryzen 7 5700X, Radeon RX 7800 XT. Clean main produced one wrong result for seed 722. The standalone test and a direct DXIL GPU divergence test both passed with the patch.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output with 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.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 7800 XT
title: c22a3829
seconds: 90
exit: 0x0
frames shown: 4847 (PresentX 4847)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3344 MB
xcl-smoke v1
commit: 1d8341aba280c329e184a78869dc8d2327c81504
gpu: AMD Radeon RX 7800 XT
title: c22a3829
seconds: 90
exit: 0x0
frames shown: 5256 (PresentX 5256)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3344 MB

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.

Broadcast the first active lane i32 value with a masked wave reduction. On the RX 7800 XT the original opcode returns a case-local value in fuzz seed 722. Pin that case in a standalone test.

Assisted-by: OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode)
@ettehn

ettehn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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’s Shader::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 the 0x80000010 payload. 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.rs hunk reverted. All 20 modules validated. The 1D native wave32/wave64 cases were byte-identical, and V_READFIRSTLANE_B32 continued to lower through the emulated EXEC mask and waveReadLaneAt. The changed DXIL in this matrix was the prologue broadcast for 2D native groups and 1D split wave64: those cases changed even with no guest V_READFIRSTLANE_B32. Each replaced one waveReadLaneFirst with one additional waveIsFirstLane call, a select, and one waveActiveBit reduction 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 WaveIsFirstLane in the same active-lane set before broadcasting the atomic counter result. I factored the select/OR into a local wave_broadcast_first_i32(value, first) helper and passed that existing predicate at those sites. This reduced WaveIsFirstLane from two calls to one in all six affected variants of the matrix, retaining one WaveActiveBit OR. 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.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows check of exact PR head 1d8341aba280c329e184a78869dc8d2327c81504 against its parent 568e7db7729c8fa6c8f0f4b32d798faaf11462bb. 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.rs from parent 568e7db, 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.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1860, xcl-dev#1913, xcl-dev#2192, xcl-dev#1946, xcl-dev#2237

Integrates XG CopyFromSubresource 7-arg ABI (xcl-dev#684), DirectStorage physical-page list re-read (xcl-dev#1405), vkd3d-proton in-place vtable patching with UnadoptGuard composition (xcl-dev#1395), single-back-edge Direct DXIL CFG (xcl-dev#1860), wave64 graphics Direct DXIL guard (xcl-dev#1913), and AMD RDNA2-4 DXIL fuzz fixes (xcl-dev#2192, xcl-dev#1946, xcl-dev#2237).
@cindertheblue

Copy link
Copy Markdown
Contributor

Tested the head 1d8341a on a second RDNA3 card, where seed 722 reproduces. The fix works there: 722 fails without the shader.rs change and passes with it, and fuzz_validate_and_gpu_1 moves on to seed 783.

Tested

  • AMD Radeon RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.31041.1004, and the Ryzen 5 9600X iGPU (RDNA2, 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 only crates/xcl/src/gpu/dxil/shader.rs restored from 568e7db.
RX 7600 XT, head RX 7600 XT, control iGPU, head iGPU, control
first_active_lane_value_survives_a_divergent_switch (3 runs) pass ×3 fail ×3 pass ×3 pass ×3
debug_seed, FUZZ_SEED=722 0 mismatching 1 mismatching 0 0
amd_reduced_seeds, both 722 shapes + full seed 722 PASS FAIL res[30] = 0x1, CPU 0x7fffffff PASS PASS
amd_reduced_seeds, 1599 shapes + full seed PASS PASS PASS PASS

Seed 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:
main 568e7db + this PR
RX 7600 XT 1153 passed, 1 failed, 46 ignored 1154 passed, 1 failed, 46 ignored
RX 7600 XT, XCL_DIRECT_DXIL=1 1151 passed, 3 failed, 46 ignored 1152 passed, 3 failed, 46 ignored
iGPU 1153 passed, 1 failed, 46 ignored 1154 passed, 1 failed, 46 ignored

Each tree had cargo build --workspace first. The extra pass is the new test. fuzz_validate_and_gpu_1 fails in every row, but on the RX 7600 XT it now stops at the next AMD seed, 783: res[64] with CPU 0x7fffffff (was seed 722: res[30] = 0x1, CPU 0x7fffffff). The wrong value changes between runs: 0xc here, 0x5d154f27 in an earlier run. On the iGPU it stops at 540 on both trees. With XCL_DIRECT_DXIL=1 the other two failures are the same on both trees: gpu_image_get_resinfo_1d_array (#2046) and offline_compute_pipeline_is_reused_by_a_second_process (#1674). The same 8 SKIPPED lines 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.

@thiagocalile

Copy link
Copy Markdown

Independent Windows AMD Radeon RX 6600 (RDNA2, 8 GB VRAM, native wave64) verification of main 2898511 + #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 unmodified main 2898511).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • Unmodified main (2898511af1c038a2ef809719e9b6f89e5675c422):
    • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 1,362 passed, 1 failed, 46 ignored (11 skipped; failed: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1).
  • Clean local merge of #1946 (f906266) + #2192 (1d8341a) onto main 2898511:
    • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 1,364 passed, 0 failed, 46 ignored (11 skipped).

Regression run (scripts/smoke.ps1 -Seconds 60, release builds, XCL_ADAPTER=radeon)

main (2898511):

xcl-smoke v1
commit: 2898511af1c038a2ef809719e9b6f89e5675c422
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1489)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 11934 MB

main 2898511 + #1946 (f906266) + #2192 (1d8341a):

xcl-smoke v1
commit: 48282949dc959da8eb78351b8f61a6bd80457500
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1453 (PresentX 1453)
presents per 2 s (last 3): 49 0 59
device removals: 0
crashes: 0
peak commit: 18345 MB

Not tested: #1946 and #2192 individually 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.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1946, xcl-dev#1803, xcl-dev#2297, xcl-dev#2320, xcl-dev#2333

Carries forward still-open high-value upstream PRs onto upstream/main (2898511)
+ our updated Wine PR stack (xcl-dev#867, xcl-dev#1395-successor, xcl-dev#871, xcl-dev#877, xcl-dev#1732).
Preserves UnadoptGuard in xcl-dev#2320 KickoffX reset_one.

Assisted-by: Antigravity (Gemini 4 Neon)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…1946, xcl-dev#1803, xcl-dev#2297, xcl-dev#2320, xcl-dev#2333

Carries forward still-open high-value upstream PRs onto upstream/main (2898511)
+ our updated Wine PR stack (xcl-dev#867, xcl-dev#1395-successor, xcl-dev#871, xcl-dev#877, xcl-dev#1732).
Preserves UnadoptGuard in xcl-dev#2320 KickoffX reset_one.

Assisted-by: Antigravity (Gemini 4 Neon)
@CharNoir

Copy link
Copy Markdown

Test report for 1d8341a ("Shaders: preserve first active lane reads across divergent switches").

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, 16 GB), Adrenalin 26.11.2; AMD Ryzen 5 7600; Windows 11 Pro 25H2 (build 26200.9974); Rust <rustc --version>; debug (test profile); 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:
Commit _0 _1 _2 _3
main e1d84b7 ok FAIL (seed 722: res[30] = 0x1, CPU 0x7fffffff) ok FAIL (seed 1599)
PR 1d8341a ok FAIL (seed 783, see below) ok FAIL (seed 1599, unchanged)
  • Seed 722 is fixed on RDNA4: fuzz_validate_and_gpu_1 now gets past it. The _3 failure (seed 1599) is the Countbits/Bfrev constant-fold issue fixed by Direct DXIL: fold Countbits of constants (AMD folds Bfrev(Countbits(K)) wrong) #2231 and is unrelated to this PR.
  • _1 now stops at seed 783: res[64] = 0xffffffff, CPU 0x7fffffff. It looks unrelated to this change:
    • The program has no switch, and its only wave op (WaveReadLaneAt on a constant) doesn't feed the failing output.
    • The failing output is the high word of IMax(i64 -5, i64 0x7FFFFFFFFFFFFFFB) (%40 = dx.op.binary.i64(37, %38, %33)), built entirely from constants.
    • Signed max gives a high word of 0x7FFFFFFF. The GPU returned 0xFFFFFFFF, which is the unsigned max. This looks like another AMD driver constant-folding bug, this time in 64-bit IMax.
    • It can't be checked on main, because _1 stops at seed 722 there first.
  • For reference, the full suite on main 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 (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426) and the heap_window test ("no heap windows").

Not tested

AI use

  • Claude (Claude Sonnet 5.5) assembled this report from the logs of the runs above. I ran the commands on the hardware named.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants