Skip to content

Direct DXIL: fold Countbits of constants (AMD folds Bfrev(Countbits(K)) wrong) - #2231

Draft
Diskuss wants to merge 1 commit into
xcl-dev:mainfrom
Diskuss:fuzz-1599-rdna4
Draft

Diskuss wants to merge 1 commit into
xcl-dev:mainfrom
Diskuss:fuzz-1599-rdna4

Conversation

@Diskuss

@Diskuss Diskuss commented Nov 25, 2026 •

Copy link
Copy Markdown

On the RX 9070 XT (RDNA4), the AMD driver (amdxc64) folds Bfrev(Countbits(K)) wrong when K is a constant. It gives bfrev(n) | n (n = countbits(K)): for K = 2 that is 0x80000001 instead of 0x80000000. This is the cause of fuzz seed 1599 (62 mismatches) and of fuzz_validate_and_gpu_3 failing on this card. Shader::bit_count now folds Countbits of a constant itself, so the driver never sees that pattern. The reduced HLSL repro and the analysis are in #2115 (comment).

Part of #2115

What is in it

  • crates/xcl/src/gpu/dxil/module.rs: Module::int_const, which reads the value of an integer constant.
  • crates/xcl/src/gpu/dxil/ops.rs: Shader::bit_count folds Countbits of a constant, masked to the operand's width.
  • crates/xcl/src/gpu/dxil/ops_tests.rs: new test bfrev_of_countbits_of_a_constant_matches_cpu, which compares the GPU result with the CPU.

Tested

  • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029; Ryzen 7 5700X3D; Windows 11 Pro 26300.9974; Rust 1.100.0 msvc; DXC 1.9.2602.17; debug build for the tests, release build for the smoke runs.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
    • this PR (3cf8ef7, on main 4d44186): 1182 passed, 3 failed, 46 ignored.
    • main 4d44186 on the same machine: 1180 passed, 4 failed, 46 ignored.
    • The difference: fuzz_validate_and_gpu_3 now passes, and the new test is counted.
    • The 3 failures also fail on main and are not touched here:
  • bfrev_of_countbits_of_a_constant_matches_cpu: passes.
  • Fuzz seed 1599: 0 mismatches (was 62).
  • SKIPPED tests:
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off).
    • 6 f16_programs_on_the_gpu/f32_programs_on_the_gpu per-lane cases (refused ops).
  • No device removal.

Regression run

main:

xcl-smoke v1
commit: 4d441866a42a0bca052044299f94ff1471a6523b
gpu: AMD Radeon RX 9070 XT
title: d5605821
seconds: 60
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 2
peak commit: 866 MB

This PR:

xcl-smoke v1
commit: 3cf8ef785d9a8df2ea03c73c1e6696d8e756e305
gpu: AMD Radeon RX 9070 XT
title: d5605821
seconds: 60
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0
device removals: 0
crashes: 2
peak commit: 866 MB

The title is The Matrix Awakens. On main and on this PR it dies the same way, about 1.5 to 3.5 s in: the title's CreateCommandSignature (DispatchIndirectMesh) fails, then it reads a null pointer (0xc0000005). That is fixed only in #1887. So this run shows no new crash and no device removal, but it never reaches a shader that this change affects.

Not tested

  • A retail title that reaches the changed code. The smoke title crashes before that (see above).
  • Constants that the driver derives itself are not folded here, e.g. Countbits(zext((in & 0) | 2)). The translator does not see those as constants.
  • Other AMD generations, newer drivers, and NVIDIA/Intel. The fold gives the same value on any GPU.

AI use

  • Claude Code (Claude Opus 5.5): code, tests and description; reviewed by Diskuss.

🤖 Generated with Claude Code

…)) wrong)

amdxc64 on RDNA4 folds Bfrev(Countbits(K)) for a constant K to
Bfrev(n) | n (0x80000001 for K = 2). Fold Countbits of constants in
bit_count so the driver never sees that pattern. Fixes fuzz seed 1599
on the RX 9070 XT (xcl-dev#2115).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant