Skip to content

Shaders: reverse the halves of an i64 Bfrev with shifts and masks on AMD - #2237

Open
oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:dxil-bfrev-i64-shifts
Open

oni-swr wants to merge 1 commit into
xcl-dev:mainfrom
oni-swr:dxil-bfrev-i64-shifts

Conversation

@oni-swr

@oni-swr oni-swr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2115. AMD's driver returns x | bfrev(x) for Bfrev.i32(trunc(mul i64)) when the product is the same on every lane. The i64 Bfrev lowering (reverse each 32-bit half, swap) goes through exactly that shape, so fuzz seed 817 read 0xfe53ffff where the CPU has 0x4a43fdeb. The halves are now reversed with five shift-and-mask steps. Reduced form: Bfrev.i64(mul i64 3, 5).

Seeds on the RX 7800 XT, main 568e7db plus this commit's base:

So fuzz_validate_and_gpu_1 here still fails on 722 until #2192 and #1946 are in.

What is in it

  • crates/xcl/src/gpu/dxil/ops.rs: bfrev32_shifts, used for both halves in the i64 case of Shader::bfrev. Bfrev.i32 on an i32 is unchanged.
  • crates/xcl/src/gpu/dxil/ops_tests.rs: bfrev_i64_of_a_uniform_product_matches_cpu (products 3*5 and the seed 817 constants). It fails without the change (low word 0xf000000f, expected 0) and passes with it.

Tested

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 26200; rustc 1.100.0; debug build; head a5af72b (rebased onto main 1a0bbe3).
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 1250 passed, 1 failed, 46 ignored. The failure is fuzz_validate_and_gpu_1, which stops at seed 722 (Shaders: preserve first active lane reads across divergent switches #2192); 783 (Direct DXIL: lower i64 min/max as compare/select #1946) is behind it. The other failures seen before the rebase (pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa, gpu_image_get_resinfo_past_last_level) are gone.
  • 7 SKIPPED lines (f16 / f32 per-lane forms refused, and heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows); not coverage.
  • bfrev_i64_of_a_uniform_product_matches_cpu fails without the change on this card (low word 0xf000000f, expected 0) and passes with it. debug_seed for 817: 64 mismatching results before, 0 after.

Regression run

Independent paired run on exact PR head a5af72bba1a0d25fbd59f37a6a952b33874ce734 vs main 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6 by @luckyteagirl (AMD Radeon RX 6800M, driver 30.0.13002.13003, Windows 11 26200, Rust 1.99.0 MSVC, 7 s each, fresh data/cache directories; see comment):

Main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7040 MB

PR head:

xcl-smoke v1
commit: a5af72bba1a0d25fbd59f37a6a952b33874ce734
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7048 MB

Not tested

  • Longer (>7 s) smoke runs or title dispatches exercising this bit-reversal form (the 7 s RX 6800M pair above reached the first frame only and did not observe a title dispatch of this form; no claim of runtime performance or world-load improvement).
  • RDNA2 / RDNA4, NVIDIA, other driver versions. The Bfrev.i32 behaviour is only shown on this card's driver.
  • Whether Bfrev.i32(trunc(mul i64)) outside the i64 lowering is hit by a real shader.

AI use
Claude Code (Claude Sonnet 5.5) reproduced the seeds, reduced them, wrote the change and the test, ran the suite and wrote this description; independent RX 6800M smoke blocks pasted from @luckyteagirl's comment.

🤖 Generated with Claude Code

AMD's driver returns x | bfrev(x) for Bfrev.i32(trunc(mul i64)) when the
product is the same on every lane. The i64 Bfrev lowering reverses each
32-bit half after a trunc / lshr of the i64 value, so a Bfrev of an i64
product hit it: fuzz seed 817 (xcl-dev#2115) read 0xfe53ffff for 0x4a43fdeb on an
RX 7800 XT. Reduced to Bfrev.i64(mul i64 3, 5).

The halves are now reversed with five shift-and-mask steps. The i64 case
is the only one that goes through trunc of an i64 value; Bfrev.i32 on a
plain i32 is unchanged. The new test fails without the change on the
RX 7800 XT (low word 0xf000000f, expected 0) and passes with it.

Part of xcl-dev#2115. Seed 783 is a separate driver bug (IMax.i64 after an i64
udiv); the compare / select lowering in xcl-dev#1946 fixes it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oni-swr
oni-swr force-pushed the dxil-bfrev-i64-shifts branch from 30d48e2 to a5af72b Compare November 25, 2026 12:03
@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent Windows/RX 6800M verification of exact PR head a5af72bba1a0d25fbd59f37a6a952b33874ce734, with a same-duration owned-title smoke comparison against main 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6.

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. The worktrees and Cargo targets were isolated. No game files were copied or attached.

Tested

  • XCL_ADAPTER=6800M XCL_REQUIRE_GPU=wave64 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 2 bfrev_i64_of_a_uniform_product_matches_cpu -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, no skip. The new fixture ran on native wave64.
  • cargo build --locked --workspace -j 2 and cargo build --locked --release --workspace -j 2 both passed on the exact PR head.
  • XCL_ADAPTER=6800M XCL_DIRECT_DXIL=1 cargo test --locked --workspace --no-fail-fast -j 2 -- --test-threads=4 --show-output: main 1012 passed, 169 failed, 26 ignored in the library; PR 1012 passed, 170 failed, 26 ignored. Both also failed the same offline_compute_pipeline_is_reused_by_a_second_process integration test. Both emitted 9 SKIPPED messages. The sole added library failure name was gpu::dxil::ops_tests::bfrev_i64_of_a_uniform_product_matches_cpu, at CreateComputePipelineState after device suspension 0x887A0005; it passed in the focused run. The broad suite is red on this driver, so this is not a clean full-suite result.

Regression run

Same owned title, seven seconds each, default translation mode, fresh separate data/cache directories. Both runs completed with no memory guard, crash or device removal. These are the exact xcl-smoke blocks:

Main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7040 MB

PR head:

xcl-smoke v1
commit: a5af72bba1a0d25fbd59f37a6a952b33874ce734
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7048 MB

Limits: An attempted 12-second PR run hit my external guard at 856 MB free system commit and was stopped before it emitted a smoke block; I excluded it from the comparison. The seven-second pair reached only the first frame, and no title dispatch of this bit-reversal form was observed. The synthetic fixture is the opcode check. The report does not establish a runtime performance or world-load improvement. If the PR head changes, its smoke block must be rerun for the new commit.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows builds and tests, monitored the owned-title smoke runs, compared the failure names and drafted this report. No game data was uploaded.

@oni-swr
oni-swr marked this pull request as ready for review November 25, 2026 13:23
@frenziedcoder

Copy link
Copy Markdown

NVIDIA test report for a5af72b: no new test failures (the 4 that fail also fail on 1a0bbe3), its own GPU test bfrev_i64_of_a_uniform_product_matches_cpu passes on NVIDIA too (the shift-and-mask reversal isn't vendor-gated, so it runs here as well), and a clean smoke pair on the retail title (1614 vs 1671 frames).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 621.40, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head a5af72bba1a0d25fbd59f37a6a952b33874ce734, no local changes.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 1247 passed, 4 failed, 46 ignored; the PR's own test bfrev_i64_of_a_uniform_product_matches_cpu and the existing int64_bit_ops_match_cpu pass. SKIPPED: gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (const_mask, wave64: no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (f16 packed, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 compares, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 conversions, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 rounding, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 three-source, wave64: no wave64), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (f32 transcendentals, wave64: no wave64), gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu (f64, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64), gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu (integer carries, wave64: no wave64), gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (mask_ff0_flbit, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll), uploads_start_from_each_subresources_state (no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))).
  • The 4 failures are fuzz_validate_and_gpu_0, fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_2, fuzz_validate_and_gpu_3 in gpu::dxil::fuzz_tests. They fail the same way on the base 1a0bbe3 here (0x8007000E from CreateComputePipelineState on seeds 70, 545, 1019 and 1507, the NVIDIA refusal @PHeitor1 reported on Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679), so this PR adds no failure. (Seed 1019's program is 3,208 bytes here against 3,020 on the base: the longer reversal.)

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (1a0bbe3, this PR's merge base with main):

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1671 (PresentX 1671)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14380 MB

this PR:

xcl-smoke v1
commit: a5af72bba1a0d25fbd59f37a6a952b33874ce734
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1614)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14607 MB

Not tested: this code in the title: it is on the opt-in direct-DXIL path (XCL_DIRECT_DXIL), which the smoke runs leave unset (default HLSL backend), so they show only that nothing else regressed; the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD, which the description and @luckyteagirl's run cover.

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

@fromthemoonx

Copy link
Copy Markdown

Second NVIDIA run (RTX 3060, 32-lane): passes at the head and merged onto current main, and the new test passes here without the fix too, so only AMD runs check it. This adds to frenziedcoder's RTX 5080 report:

result
cargo test --workspace --no-fail-fast -- --test-threads=4 at a5af72b 1251 passed, 0 failed, 46 ignored (the 4 failures on the 5080 do not show up on this card)
same, merged onto main 06c9f55 (no conflicts) 1266 passed, 0 failed, 46 ignored
bfrev_i64_of_a_uniform_product_matches_cpu, 10 runs 10 of 10 ok
that test with ops.rs from the base 1a0bbe3 (3 runs) ok 3 of 3: this driver does not have the x | bfrev(x) behaviour

SKIPPED: the same 24 lines at the head (no wave64, the refused per-lane f16/f32 forms). The merged tree has one more, dispatch_chain_native_wave64_builds_whole: no wave64, from 6c34370 on main.

Hardware: RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, DXC 1.9.2602.17.
Not tested: a title, a release build.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote 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