Skip to content

Direct DXIL: skip SDWA VSRC1 before S1-selected operand read - #2068

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-dxil-sdwa-vsrc1
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-dxil-sdwa-vsrc1

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes Lw::sources in crates/xcl/src/gpu/dxil/lower_valu.rs so SDWA VSRC1 operands are skipped during the initial operand-read loop before the SDWA arm selects the real operand using S1 (bringing direct DXIL into parity with merged HLSL PR #191). Part of #1269.

Previously, Lw::sources skipped SRC0 for non-plain variants (SDWA / DPP) but did not skip VSRC1 for Variant::Sdwa. On any SDWA VOP2 or VOPC instruction, the initial loop called self.read -> self.vreg(vsrc1) on the raw 8-bit VSRC1 encoding before the SDWA arm overwrote u[1]. When S1 == 1 (scalar SGPR or inline constant such as 242 = 1.0f or 138 = 10), that inserted bogus VGPRs (v242, v138, v4) into self.init.touched and inflated Lw::top_vgpr(), causing v_movrel* / v_swaprel_b32 select chains in the same shader to emit hundreds of unnecessary select instructions.

What is in it

  • crates/xcl/src/gpu/dxil/lower_valu.rs:
    • In Lw::sources, skip o.field == Some("VSRC1") when d.variant == Variant::Sdwa (matching recomp/emit.rs after Recompiler: wave32 src_vccz / src_execz and SDWA f16 inline constants #191), while keeping implicit operands (o.field == None, e.g., VCC on V_CNDMASK_B32 / V_ADD_CO_CI_U32) and VDST read normally.
    • Add sdwa_tests::direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr verifying via translate_compute + DXIL disassembly that SDWA S1 == 1 V_ADD_F32 (VSRC1=242), V_CMP_LT_U32 (VSRC1=138), and V_ADD_NC_U32 (VSRC1=4) do not inflate top_vgpr() with bogus VGPRs, plus sdwa_tests::gpu_direct_sdwa_scalar_vsrc1 (guarded by runner::wave32_supported() == Ok(true) so non-wave32 adapters like WARP skip cleanly while DXIL validation still runs on CPU) verifying HLSL and direct DXIL runtime parity on the GPU across scalar SGPR and inline-constant VSRC1 operands.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 (8 GB, 32-lane waves, driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0 (0ef1bc386), DXC 1.9.2609.5 (01b62ad4), release build.
  • Pre-fix reproduction: confirmed direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr fails before the fix (v_add_f32_sdwa_inline_242: bogus VGPR v242 polluted top_vgpr() in direct DXIL, emitting >1000 SSA instructions for a 5-instruction compute shader).
  • Targeted post-fix runs:
    • cargo test --release -p xcl --lib gpu::dxil::lower_valu::sdwa_tests -- --nocapture (RTX 4060): 2 passed, 0 failed, 0 ignored, 0 skipped (DXIL disassembly + HLSL/direct DXIL wave32 GPU parity).
    • XCL_ADAPTER="Microsoft Basic Render Driver" cargo test --release -p xcl --lib gpu::dxil::lower_valu::sdwa_tests -- --nocapture (WARP): 2 passed, 0 failed, 0 ignored (gpu_direct_sdwa_scalar_vsrc1 skips cleanly after DXIL validation without attempting a wave32 PSO on 4-lane WARP).
  • cargo build --release --workspace + cargo test --release --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored across 21 test binaries.
  • SKIPPED GPU/runtime tests on this adapter (25 lines on stderr; D3D12 debug-layer tests also skip without d3d12SDKLayers.dll):
    • 20 no wave64 subcases across gpu::recomp::lower::tests (4), gpu::recomp::lower_dxil::tests (14), and gpu::recomp::tests (2)
    • 3 intentional per-lane #1426 refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32) in gpu::recomp::lower_dxil::tests
    • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)
    • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows

Regression run
scripts/smoke.ps1 on main (cbc296ab65a2661a61e3e2da109134bcd5319f60) and on this PR's head commit (b6bf898254cd059c64999b962fde7f136c710ee9):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1577 (PresentX 1577)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14514 MB
xcl-smoke v1
commit: b6bf898254cd059c64999b962fde7f136c710ee9
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1597 (PresentX 1597)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14521 MB

Not tested

AI use

  • Google Antigravity (Gemini 4 Neon) — audited Lw::sources against HLSL #191, implemented the SDWA VSRC1 guard, DXIL disassembly and GPU parity regression tests (including the wave32_supported() WARP guard), and PR description; all tests and paired 60s smoke runs were executed and verified locally on RTX 4060 and WARP.

In `Lw::sources` (`dxil/lower_valu.rs`), the initial operand loop
skipped `SRC0` for non-plain variants but did not skip `VSRC1` for
`Variant::Sdwa` (unlike HLSL `recomp/emit.rs` after merged PR xcl-dev#191).
Before the SDWA match arm replaced `u[1]` using `S1` + `VSRC1`, the
initial loop called `self.read` -> `self.vreg(vsrc1)` on the raw 8-bit
`VSRC1` encoding. When `S1 == 1` (scalar SGPR or inline constant such as
`242` = `1.0f` or `138` = `10`), that polluted `self.init.touched` with
bogus VGPRs (`v242`, `v138`, `v4`) and inflated `top_vgpr()`, bloating
any `v_movrel*` / `v_swaprel_b32` select chains in the shader.

Skip `VSRC1` for `Variant::Sdwa` in the initial operand loop (parity
with `xcl-dev#191`) and add DXIL disassembly + RTX 4060 GPU regression tests.

Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the fix-1269-dxil-sdwa-vsrc1 branch from 4398ee3 to b6bf898 Compare November 25, 2026 03:00
@Decodere

Copy link
Copy Markdown
Contributor Author

Fixed the Build and test (Windows, no GPU) failure in gpu_direct_sdwa_scalar_vsrc1 (CreateComputePipelineState (0x80070057) on 4-lane WARP) at b6bf8982 by guarding GPU execution with runner::wave32_supported() == Ok(true) instead of runner::adapter().

Re-verified locally (release): sdwa_tests passes 2/2 on RTX 4060 (0 skips) and 2/2 on XCL_ADAPTER="Microsoft Basic Render Driver" (CPU DXIL validation runs; GPU dispatch skips cleanly), full workspace 1,156 passed, 0 failed, 46 ignored, and paired 60 s scripts/smoke.ps1 (1,577 -> 1,597 frames, 0 crashes/removals). Ready for CI!

AI use: Google Antigravity (Gemini 4 Neon).

@JJAutoCompare

Copy link
Copy Markdown

PR #2068 — Intel Arc A770 compatibility test

Tested GitHub PR xcl-dev/xcl #2068 at b6bf898254cd059c64999b962fde7f136c710ee9 in the assigned clean checkout. The original observed head was 4398ee3b1bfd7e1391eb33743c40b3156d010686. The force-push retained the SDWA VSRC1 fixtures and added a wave32 guard for GPU execution.

Tested

  • Windows 11 Enterprise Evaluation 25H2, build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175.
  • Rust 1.100.0 (0ef1bc386), x86_64-pc-windows-msvc, Cargo 1.100.0 (3acc79c0c), DXC and DXIL 1.9.2609.5.
  • Cargo test profile, CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, XCL_ADAPTER=A770.
  • CARGO_TARGET_DIR=L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target, TEMP and TMP set to L:/XclTooling/pr2068, and XCL_DXC_DIR=C:/Users/ljensen/AppData/Local/XclTooling/dxc-1.9.2609/bin/x64.
& 'C:/Users/ljensen/.cargo/bin/cargo.exe' +stable-x86_64-pc-windows-msvc test -p xcl --lib --no-run --jobs 2 --message-format=json
$testExe = 'L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe' # Cargo compiler-artifact executable
& $testExe --exact gpu::dxil::lower_valu::sdwa_tests::direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr --nocapture
# GPU retry in a separate PowerShell process
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force
$gpu = 'gpu::dxil::lower_valu::sdwa_tests::gpu_direct_sdwa_scalar_vsrc1'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { & $testExe --exact $gpu --nocapture }

The initial GPU invocation stopped at PowerShell script loading. The wrapper ran on retry with RemoteSigned scoped to the retry process.

Exact fixture Passed Failed Ignored Skipped Time
direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr 1 0 0 0 0.02 s
gpu_direct_sdwa_scalar_vsrc1 1 0 0 0 0.22 s

Cargo prebuilt the test binary outside the GPU mutex in 1 min 08 s. Each exact invocation filtered out 1,125 tests. The GPU wrapper printed lock acquisition and release, and the invoked test exited 0. The enclosing PowerShell command returned 1 because its post-run check looked for the Write-Host lock marker in the Tee-Object file. The marker appeared in the console output. The separate exit log and captured harness results verified both passes and zero SKIPPED markers.

  • CPU fixture. gpu::dxil::kernel::translate_compute emitted direct DXIL for three cases. DXC/DXIL validated and disassembled the output, and the test checked that the relative-register selection chains omitted the unintended VGPR indices.
  • GPU fixture. The direct path called runner::direct_kernel_full → gpu::dxil::kernel::translate_full and validated that DXIL. The HLSL path called recomp::translate in kernel mode, then compiled main as cs_6_6 through DXC. In that execution, runner::run_with_statics dispatched both binaries on the selected A770. Readback on each path verified the floating-point inline constant, the scalar-register byte, the inline-integer comparison mask in VCC, and the scalar comparison mask in s8. Both arithmetic results were checked for every lane of the 32-lane wave.

At the post-run check (2026-11-25 03:05 UTC), GitHub still displayed the PR as open and git ls-remote returned the tested SHA. The public conversation contained the author's wave32 guard update and had no Intel Arc result.

Not tested

Coverage was limited to the isolated wave32 fixture and the three CPU DXIL cases on this exact PR commit. Retail titles, whole-workspace tests, other adapters, WARP, wave64, the D3D12 debug layer, and production PSO backend selection were outside the run.

Evidence

Logs in this directory share prefix pr2068-b6bf898-20261125T030127318Z. The build log and Cargo JSON record the prebuild and artifact, and the CPU and GPU retry logs record the individual harness totals.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the tests, checked the PR head and fixture paths, and wrote this report.

@JoaoPauluu

Copy link
Copy Markdown

A run with vkd3d-proton as the host D3D12. The DXIL goes through dxil-spirv and then the NVIDIA Vulkan driver, a different compiler from a native-Windows run: this PR's 2 new tests pass.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from Linux: docs/linux.md, scripts/linux and Wine start-up checks for vkd3d-proton and DXVK (#154, #241) #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. b6bf898 as it is (merge base with main cbc296a), no uncommitted changes. The lib test binary runs under Wine, one test per process.
    • direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr: ok, not skipped
    • gpu_direct_sdwa_scalar_vsrc1: ok, not skipped

Not tested

  • the whole suite on this head, a retail title, native Windows, AMD.

AI use

  • Claude Code (Claude Opus 5.5) built the commit, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DarkPanda69

Copy link
Copy Markdown

Native-wave64 AMD run on Windows, which this PR lists as not tested (the reports above are Intel and NVIDIA).

Tested: pass, head b6bf898 applied on its base main cbc296a, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17. cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 586 passed, 2 failed, 22 ignored. gpu_direct_sdwa_scalar_vsrc1 ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, the same as on main cbc296a without this PR on this card.
  • NVIDIA RTX 3060, driver 32.0.16.1088: 588 passed, 0 failed, 22 ignored.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@Parakeet-Wheat

Copy link
Copy Markdown

NVIDIA RTX 3070 on native Windows, head b6bf898 on its base cbc296a (current main): the DXIL-disassembly test fails without the fix and passes with it, the GPU test passes either way, the whole suite passes, and the smoke pair is within the limits. This adds the fail-before run, the whole-suite counts and the smoke pair to the test runs above.

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), Ryzen 5 5600X, 32 GB, Windows 11 26300, Rust 1.95.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11, retail 1.0.2.1. Head b6bf898 (one commit on main cbc296a), checked out clean. Tests in the debug profile, smoke in release.
  • cargo test -p xcl --lib sdwa_tests -- --nocapture --test-threads=1:
    • on cbc296a with the PR's lower_valu.rs but its Lw::sources hunk (the fix) reverted: 1 failed, 1 passed. direct_sdwa_scalar_vsrc1_does_not_touch_bogus_vgpr fails at its first case, v_add_f32_sdwa_inline_242: bogus VGPR v242 polluted top_vgpr() in direct DXIL. gpu_direct_sdwa_scalar_vsrc1 passes there too: on this card the bogus VGPR does not change the lane results, so only the disassembly test tells the two apart;
    • on b6bf898: 2 passed, 0 failed, not skipped.
  • .\scripts\test.ps1 (cargo build --workspace, then cargo test --workspace -- --test-threads=4) on b6bf898: 1156 passed, 0 failed, 46 ignored, exit 0. SKIPPED, 25: 20 × no wave64, 3 × per-lane form refused (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16: "its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"), 1 × no heap windows, 1 × cannot disable the driver cache (Windows Developer Mode required).

Regression run (scripts/smoke.ps1 -Game <folder> -Seconds 60, the same title, back to back, menus, no input; unedited). main cbc296a:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1455 (PresentX 1455)
presents per 2 s (last 3): 60 51 10
device removals: 0
crashes: 0
peak commit: 18612 MB

PR head b6bf898:

xcl-smoke v1
commit: b6bf898254cd059c64999b962fde7f136c710ee9
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1498 (PresentX 1499)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17941 MB

That is 103 % of main's frames and 96 % of its peak commit. One run each; the 60 51 10 tail of main's run (against 60 61 60 on the head) is not something I repeated.

Not tested

  • Native wave64 (the 20 no wave64 skips above), AMD, a world run (the smoke stays in the menus, so it does not show whether the title reaches an SDWA instruction with S1 == 1), the tests on game data (XCL_SAMPLE_* not set).

AI use

  • Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. The account owner has not reviewed it.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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.

6 participants