Skip to content

Direct DXIL: translate ds_permute_b32 as the HLSL path does - #2228

Open
NWProgramming00 wants to merge 3 commits into
xcl-dev:mainfrom
NWProgramming00:dxil/ds-permute
Open

NWProgramming00 wants to merge 3 commits into
xcl-dev:mainfrom
NWProgramming00:dxil/ds-permute

Conversation

@NWProgramming00

@NWProgramming00 NWProgramming00 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2222. 06d8dea is #2222's commit 22133f3, rebased onto e120925; the patch is the same. This PR's commits are 9f2cacc (the lowering) and 1aa9794 (the refusal fix from review).

#2222 translates ds_permute_b32 in the HLSL path. The direct DXIL translator (XCL_DIRECT_DXIL) still refused it. This PR lowers it there the same way, so the two backends agree and match the RDNA2 measurements on #2222:

  • Each active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of its own 32-lane half, so it never crosses the halves.
  • Of several senders, the highest lane wins.
  • An active lane that nobody sends to gets 0.

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs: ds_permute_b32 in Lw::ds. Each receiver reads the 32 senders of its half in lane order (the loop is unrolled) through read_lane_half, as ds_swizzle_b32 does, so the split form needs no exchange. A wave64 VS / PS that may run in 32-lane waves refuses it, as in the HLSL path.
  • crates/xcl/src/gpu/dxil/kernel.rs, lower.rs and crates/xcl/src/gpu/recomp/pso.rs (1aa9794): before that commit the refusal could not fire. It tested split, which Lw::new clears for a VS / PS, and direct_graphics passed split: false.
    • Lw now keeps the requested split of a VS / PS in gfx_split.
    • direct_graphics passes split_wave64, as the HLSL path does.
    • The refusal tests gfx_split.
    • Found by @upipibi in review.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_ds_permute_b32 and a new gpu_ds_permute_b32_direct share one body. The new test runs the same five cases through the direct translator whatever XCL_DIRECT_DXIL says, in wave32, native wave64 and split wave64.
  • crates/xcl/src/gpu/recomp/tests.rs: ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist runs translate_pixel and translate_vertex with and without split. It fails with the old condition.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB (wave32; wave64 as two halves) and an AMD Radeon RDNA2 iGPU (gfx1036, native wave64, XCL_ADAPTER=radeon). Rust 1.100 MSVC, release.
  • xcl against the hardware (on 03d0ba8; the lowering itself is unchanged since): the 26 RDNA2 code blocks from Recompiler: translate ds_permute_b32 as RDNA2 runs it #2222 ran through the direct translator (runner::direct_kernel_full) on each adapter and were compared bit for bit with the gfx1036's own results. They give 26/26 equal on the RTX 5070 Ti and 26/26 equal on the Radeon.
  • The ds_permute tests: 5 passed on each adapter (ds_permute filter).
    • With the half bit dropped, gpu_ds_permute_b32_direct fails on both adapters, and with the offset dropped it fails too (checked on 03d0ba8).
    • With 1aa9794's condition put back to the old one, the new refusal test fails.
  • The whole suite: cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4, with and without XCL_DIRECT_DXIL=all, against base e120925 on the same machine:
Adapter Mode base e120925 this PR (1aa9794)
RTX 5070 Ti default 1438 passed, 4 failed, 47 ignored 1443 passed, 4 failed, 47 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1438 passed, 4 failed, 47 ignored 1443 passed, 4 failed, 47 ignored
Radeon gfx1036 default 1441 passed, 1 failed, 47 ignored 1446 passed, 1 failed, 47 ignored
Radeon gfx1036 XCL_DIRECT_DXIL=all 1441 passed, 1 failed, 47 ignored 1446 passed, 1 failed, 47 ignored

The +5 are the ds_permute tests: three from #2222 and two here. The failing tests are the same on base and PR, and both are tracked: fuzz_validate_and_gpu_0..3 on NVIDIA (#1905) and fuzz_validate_and_gpu_1 on RDNA2 (#2115, #2170).

Regression run
Base (main e120925), NVIDIA GeForce RTX 5070 Ti:

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 826 (PresentX 826)
presents per 2 s (last 3): 0 2 13
device removals: 0
crashes: 0
peak commit: 17376 MB

This PR (1aa9794), same card:

xcl-smoke v1
commit: 1aa97946e97e71e5baca0a62d088e552d0214ad5
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 851 (PresentX 852)
presents per 2 s (last 3): 29 31 31
device removals: 0
crashes: 0
peak commit: 16583 MB

The base is e120925, the main commit just before #2555. Since #2555, a run first prepares the whole shader pack, which takes about 5 hours from an empty cache here. The stack merges cleanly into current main 8b957be.

Not tested

  • A title run, and a retail program that uses ds_permute_b32.
  • RDNA3 / RDNA4 and Intel.
  • A wave64 VS / PS through the direct translator on a GPU with 64-lane waves (translated, not run).

AI use

  • Claude Code (Claude Opus 5.5) did the work: it wrote the lowering and the test change, ran the hardware comparison and the suites, and wrote this description.

🤖 Generated with Claude Code

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent RDNA2 check on exact, clean PR head 03d0ba8bd7e7d3079a227565bce8b07b2f5051c7.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC, debug; DXC/DXIL 1.9.2609.5. XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64.

I ran cargo test --locked -p xcl --lib -j 2 ds_permute -- --test-threads=1 --show-output twice with separate environment settings:

XCL_DIRECT_DXIL Passed Failed Ignored Explicit SKIPPED
1 4 0 0 0
0 4 0 0 0

Both runs include gpu_ds_permute_b32 and the new gpu_ds_permute_b32_direct; the latter explicitly takes the direct translator regardless of the environment setting. The reference-model and graphics-refusal tests passed too. This extends the reported RDNA2 test coverage from the author's gfx1036 iGPU to a discrete RX 6800M on an older driver. It is focused test evidence only: I did not repeat the full workspace suite, a hardware ISA measurement, or a retail smoke comparison for this head.

AI assistance: OpenAI Codex (GPT-6; exact variant not exposed) ran the commands, checked the logs and head revision, and drafted this report. No game data was used or attached.

@NWProgramming00
NWProgramming00 marked this pull request as ready for review November 25, 2026 14:19
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 03d0ba8bd7e7d3079a227565bce8b07b2f5051c7 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1156 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • All 4 PR tests passed (no skips): gpu::recomp::tests::ds_permute_reference_matches_rdna2_values, ds_permute_b32_refused_where_upper_lanes_do_not_exist, gpu_ds_permute_b32, and gpu_ds_permute_b32_direct.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 03d0ba8bd7e7d3079a227565bce8b07b2f5051c7
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1527 (PresentX 1527)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16330 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • Wave32-only GPUs (NVIDIA/Intel); D3D12 debug layer.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Found by reading the code at 03d0ba8b. I did not run it.

Thanks for the direct-path lowering. The permute itself matches the HLSL lowering in #2222 as far as I can trace it: same sender set, highest sender wins, 0 for an active lane nobody sends to, inactive receivers keep their old value. One question about the refusal:

crates/xcl/src/gpu/dxil/lower_mem.rs:2042

if self.wave64 && self.split && self.gfx.as_ref().is_some_and(|g| g.vs.is_some() || g.ps.is_some()) {

I don't see any path where this condition can be true:

  • self.gfx is set only in setup_vertex / setup_pixel (lower_gfx.rs:152, :251, plus the restore at :285). Those are called only for Entry::Vertex / Entry::Pixel (kernel.rs:211, :217).
  • For those entries, Lw::new clears split at kernel.rs:438 (let split = split && !gfx;) and stores it at kernel.rs:458. Nothing assigns split after that. translate_on_this_thread does the same at kernel.rs:170.
  • direct_graphics passes split: false anyway (recomp/pso.rs:767). The one caller that passes split_wave64 (pso.rs:987) is the GS compute pass (Entry::Geometry), which has no gfx context.

So with XCL_DIRECT_DXIL on a 32-lane-only GPU, the direct path lowers a wave64 VS / PS that uses ds_permute_b32, while the HLSL path refuses it (recomp/emit.rs:4405, which tests opt.split_wave64 and Mode::Vertex | Mode::Pixel). That doesn't match the description's "refuses it, as in the HLSL path". It also explains why the "Not tested" list has "A wave64 VS / PS without the refusal": the refusal can't fire.

By reading only, I can't say whether the direct output is actually wrong there. Its lanes are the real host lanes 0..31, and the direct translator has no upper_lanes model, so this may just be a mismatch between the two backends rather than a wrong value. Either way, the check at :2042 looks like dead code. Was the intent to test the requested split (o.wave64 && o.split before kernel.rs:438 clears it), or to drop the check and change the description? A CPU test like #2222's ds_permute_b32_refused_where_upper_lanes_do_not_exist, run through kernel::translate_vertex / translate_pixel with split: true, would settle it.

NWProgramming00 and others added 3 commits November 26, 2026 23:58
Each active lane sends DATA0 to lane ((ADDR + offset) >> 2) & 31 of its own
32-lane half, in wave64 too; of several senders the highest lane wins, an
active lane nobody sends to gets 0, inactive lanes take no part. Each
receiver looks at the 32 senders of its half (rla_half_fn, as ds_swizzle),
so the split wave64 form needs no exchange. A wave64 VS / PS that may run in
32-lane waves still refuses it: upper_lanes does not model its writes to
lanes 32..63.

The model was measured on an RDNA2 gfx1036 in native wave64 and wave32
(26 cases: collisions, partial EXEC, high address bits, cross-half
addresses), and matches the measurements reported on xcl-dev#925. The emitted
code follows xcl-dev#925 by @maximecmb, which was closed unmerged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The direct translator refused ds_permute_b32. It now lowers it as the
HLSL path (xcl-dev#2222) and RDNA2 hardware do: each active lane sends DATA0 to
lane ((ADDR + offset) >> 2) & 31 of its own 32-lane half; of several
senders the highest wins, an active lane nobody sends to gets 0. Each
receiver reads the 32 senders of its half in lane order (unrolled)
through read_lane_half, so the split form needs no exchange. A wave64
VS / PS that may run in 32-lane waves still refuses it.

gpu_ds_permute_b32 runs its cases through the direct translator too
(gpu_ds_permute_b32_direct), whatever XCL_DIRECT_DXIL says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The refusal tested `split`, which Lw::new clears for a VS / PS, and
direct_graphics passed split: false anyway, so a wave64 VS / PS that
may run in 32-lane waves was lowered where the HLSL path refuses it.
Lw keeps the requested split of a VS / PS in gfx_split, direct_graphics
passes split_wave64 as the HLSL path does, and the refusal tests
gfx_split.

ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist runs
translate_pixel / translate_vertex with and without split; it fails
with the old condition. Found by upipibi in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NWProgramming00

Copy link
Copy Markdown
Contributor Author

@upipibi you are right, thanks. The check could not fire: Lw::new clears split for a VS / PS, and direct_graphics passed split: false anyway. So the direct path lowered what the HLSL path refuses.

Fixed in 1aa9794:

  • Lw keeps the requested split of a VS / PS in gfx_split.
  • direct_graphics now passes split_wave64, as the HLSL path does.
  • The refusal tests gfx_split.
  • ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist runs translate_pixel / translate_vertex with and without split, as you suggested. It fails with the old condition and passes with the fix.

I rebased the stack onto e120925 for a fast smoke run (see the description). The full suite and the smoke pair are in the description.

AI use: Claude Code (Claude Opus 5.5) checked the trace, wrote the fix and the test, ran the suite and the smoke pair, and wrote this.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@NWProgramming00 thanks, 1aa9794 looks right to me by reading. gfx_split is now wave64 && split_wave64 for a VS / PS, which is the HLSL path's condition at emit.rs:4405. direct_graphics passes the split through, and translate_on_this_thread still clears split for graphics, so nothing else changes for a VS / PS. I also ran it on our card:

Tested head 1aa97946e97e71e5baca0a62d088e552d0214ad5, merge-base e120925e3abc9956a8b9bae631969d32e8ccd43c, RTX 3070 (Ampere) driver 616.56, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09)

Debug profile (not release), no game files. cargo build --workspace and cargo test -p xcl --lib --no-run built clean on head. XCL_DIRECT_DXIL was not set: the PR says gpu_ds_permute_b32_direct runs the direct translator whatever it says.

1. The five ds_permute tests on head, --test-threads=1, three runs (ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist, ds_permute_b32_refused_where_upper_lanes_do_not_exist, ds_permute_reference_matches_rdna2_values, gpu_ds_permute_b32, gpu_ds_permute_b32_direct):

  • run 1: 5 passed, 0 failed, 0 ignored
  • run 2: 5 passed, 0 failed, 0 ignored
  • run 3: 5 passed, 0 failed, 0 ignored

2. Negative control. Parent 9f2cacc163ecac52bb91c0b8fe3aa5bc9510932d (1aa9794^) with only the new test from 1aa9794 added to recomp/tests.rs: 0 passed, 1 failed.
ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist panicked at crates\xcl\src\gpu\recomp\tests.rs:8526:5: PS: "". So translate_pixel with split: true returned no error (the refusal did not fire), which is the bug the commit fixes.

3. cargo test -p xcl --lib -- --test-threads=4, same env:

  • head: 1320 passed, 0 failed, 27 ignored
  • merge-base: 1315 passed, 0 failed, 27 ignored (5 fewer tests: the stack's new tests are not there)

Skips (25 SKIPPED lines, identical on head and merge-base):

  • 21 "no wave64": this GPU has no native wave64, so the native-wave64 cases skip.
  • 3 "refused (unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))": f16 per-lane form, unrelated to this PR.
  • 1 pso_measurement_compiles_an_exact_synthetic_record: needs Windows Developer Mode to disable the driver cache.

Not tested: retail title; AMD wave64 hardware.

AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@JJAutoCompare

Copy link
Copy Markdown

Tested: Clean 1aa97946e97e71e5baca0a62d088e552d0214ad5, Windows 11 build 26200, Ryzen 7 3800X, Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug. cargo test --locked -p xcl --lib -j 2 --no-run, then ds_permute --skip gpu_ds_permute_b32 --test-threads=1 --nocapture and each exact test gpu::recomp::tests::{gpu_ds_permute_b32,gpu_ds_permute_b32_direct} on the resulting binary. Three CPU and two Arc tests passed, with zero failures, ignores or skips. A standalone replay of the fixture captured identical HLSL and direct DXIL readbacks for 160 wave32 and 320 split-wave64 register values, including collisions and inactive lanes.

Not tested: Retail smoke, full workspace suite, and native wave64 hardware.

AI use: T3 Code / Codex (gpt-6.2-sol) ran and reran the checks and wrote this report.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA (Wave32-only Ada) verification of PR #2228 at head 1aa97946e97e71e5baca0a62d088e552d0214ad5 (3 commits 06d8dea4 -> 9f2cacc1 -> 1aa97946; exact merge-base: e120925e3abc9956a8b9bae631969d32e8ccd43c, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (1aa97946)

Command Result
cargo test --release -p xcl --lib ds_permute_reference_matches_rdna2_values -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1346 filtered out × 3 (0.00s × 3)
cargo test --release -p xcl --lib gpu_ds_permute_b32 -- --nocapture (3 consecutive runs; executes both gpu_ds_permute_b32 and gpu_ds_permute_b32_direct) 2 passed; 0 failed; 0 ignored; 1345 filtered out × 3 (0.31s, 0.24s, 0.23s, 0 skipped; live on RTX 4060 + DXC 1.9.2609.5)
cargo test --release -p xcl --lib gpu_ds_permute_b32_direct -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1346 filtered out × 3 (0.19s, 0.19s, 0.21s, 0 skipped)
cargo test --release -p xcl --lib ds_permute_b32_refused_where_upper_lanes_do_not_exist -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1346 filtered out × 3 (0.00s × 3)
cargo test --release -p xcl --lib ds_permute_b32_direct_refused_where_upper_lanes_do_not_exist -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1346 filtered out × 3 (0.01s × 3)
cargo test --release -p xcl --lib gpu::dxil:: -- --test-threads=4 (3 consecutive runs) 184 passed; 0 failed; 3 ignored; 1160 filtered out × 3 (4.03s, 4.39s, 4.15s; 183 executed + 1 expected Wave32-only skip dispatch_chain_native_wave64_builds_whole: no wave64)
cargo test --release -p xcl --lib gpu::recomp::pso:: (3 consecutive runs) 27 passed; 0 failed; 1 ignored; 1319 filtered out × 3 (0.08s × 3, 0 skipped)
cargo build --release -p xcl Clean build (1m 14s, exit 0, 0 new warnings)

Paired quiet 60 s retail smoke (title: 29640639)

Exact merge-base (e120925e3abc9956a8b9bae631969d32e8ccd43c, cached baseline on the same machine):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13979 MB

PR #2228 (1aa97946e97e71e5baca0a62d088e552d0214ad5):

xcl-smoke v1
commit: 1aa97946e97e71e5baca0a62d088e552d0214ad5
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1606 (PresentX 1606)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13975 MB

Runtime log observations (xcl.log)

  • 9221 log lines, 0 [ERROR] / device-removal / panic lines.
  • Final draw/memory telemetry in log: 19585 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 13975 MB committed by the process; video memory 6115 MB local, 4651 MB non-local.

Limits of coverage

  • Both HLSL (gpu_ds_permute_b32) and direct DXIL (gpu_ds_permute_b32_direct) ds_permute_b32 lowering matched the RDNA2 reference live on desktop Wave32-only RTX 4060 (3/3, 0 skipped), alongside both VS/PS upper-lane refusal tests (3/3), gpu::dxil:: (183 executed + 1 expected no wave64 skip × 3), and gpu::recomp::pso:: (27/0/1 × 3).
  • Native Wave64 GPU execution is not available on this Wave32-only NVIDIA RTX 4060 (dispatch_chain_native_wave64_builds_whole skipped as expected), and the warm-cache 60 s retail smoke on title: 29640639 confirms zero runtime regression rather than exercising a retail shader using ds_permute_b32.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

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