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

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).
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.

4 participants