Skip to content

dxil: lower 64-bit icmp via 32-bit dwords and guard MIMG heap indices - #1969

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:fix/amd-rdna4-icmp-and-oob
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:fix/amd-rdna4-icmp-and-oob

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes two RDNA4 / Tier-3 D3D12 shader correctness and stability issues across both Direct DXIL and HLSL backends: (1) lowers all 64-bit integer comparisons (v_cmp_*_{i64,u64}, v_cmpx_*_{i64,u64}, and v_mad_{u64_u32,i64_i32}) as exact 32-bit high/low dword comparisons instead of pack64 + icmp i64, avoiding driver miscompilation on shared-dword pairs; (2) clamps ResourceDescriptorHeap and SamplerDescriptorHeap indices and guards non-derivative MIMG descriptor-heap ops against invalid/out-of-bounds T# views and inactive lanes.

Part of #1269 and #1833.

What is in it

  • crates/xcl/src/gpu/dxil/lower_wide.rs, lower.rs, & crates/xcl/src/gpu/recomp/emit.rs: replace pack64 + icmp i64 across 64-bit v_cmp_* / v_cmpx_* (Lw::cmp64 in Direct DXIL and 32-bit dword comparisons in HLSL) and v_mad_{u64_u32,i64_i32} with 32-bit high/low dword comparisons (hi_cmp || (hi == hi && lo_cmp)) plus 32-bit carry/borrow arithmetic for s_addc_u32 / s_subb_u32 / s_lshl{1..4}_add_u32, eliminating Feature::Int64Ops and icmp i64 on 64-bit comparisons.
  • crates/xcl/src/gpu/dxil/lower_image.rs & crates/xcl/src/gpu/recomp/emit.rs: validate T# descriptors (valid_tsharp checking tw3[31:28] >= 8, tw1[7:0] == 0, and tw0 < VIEW_HEAP_MAX_SRV (2_097_151) to block null/unpatched/OOB T# indices and tw0 + 1 wraparound) and clamp dynamic SamplerDescriptorHeap indices with SAMPLER_HEAP_MASK (0x7FF); guard non-derivative MIMG ops (sample/gather explicit-LOD, get_resinfo, load/load_mip, mimg_msaa, store, atomic_* including moving HLSL atomic UAV handle inside the guard) on act && valid, while keeping PS implicit-LOD sample/get_lod quad-convergent via select(valid, tw0, 0).
  • Unit tests (dxil.dll 1.8 validated): gpu::dxil::lower_wide::cmp64_tests (cmp64_uses_32bit_dwords_no_i64_icmp, carry_ops_avoid_i64_icmp) and gpu::dxil::lower_image::heap_bounds_tests (mimg_view_and_sampler_heap_indices_are_guarded, ps_implicit_lod_sample_and_get_lod_validate).

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT (16191 MiB VRAM, RDNA4, native wave64), Windows 11 x64 (10.0.22631.0), rustc 1.99.1 (58cf8f9c3 2026-10-13), DXC 1.8.2502.11, rebased onto 80f4819 (5195e27).
  • cargo check --workspace --tests, cargo test -p xcl --lib cmp64_tests (2 passed, 0 failed), and cargo test -p xcl --lib heap_bounds_tests (2 passed, 0 failed; dxil.dll 1.8 validated).
  • Independent AMD RX 9070 XT verification on 5195e27 (@eizispark, driver 32.0.32015.16001, rustc 1.100.0): unfiltered cargo test --workspace --no-fail-fast -- --test-threads=4 passed 995 (2 pre-existing #1679 fuzz failures, 0 new failures, 45 ignored, 8 skipped); XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp -- --test-threads=4 passed 265/0/18; cmp64_tests, heap_bounds_tests, msaa_tests (5/5), ops_tests, graphics::tests, and native wave64 GPU tests all passed, plus a clean 60 s scripts/smoke.ps1 pair (1675/1675 frames, 0 device removals/crashes).

Regression run
60 s scripts/smoke.ps1 pair on AMD Radeon RX 9070 XT (Windows 11 x64, driver 32.0.32015.16001, release), contributed by @eizispark:

main:

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14861 MB

PR:

xcl-smoke v1
commit: 5195e27be9021c7c2515ef4c0b74cb8742773fc1
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 61 59
device removals: 0
crashes: 0
peak commit: 14916 MB

Not tested

  • NVIDIA / Intel GPUs, wave32-only adapters, extended retail gameplay past menus under XCL_DIRECT_DXIL=1 / XCL_SHADER_BACKEND=dxil, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity (Claude Opus 4.6) assisted with implementation and DXIL validation tests; the author reviewed the diff and test output.

@eizispark

Copy link
Copy Markdown

Hardware test report — commit 5195e27

Verified 5195e27be9021c7c2515ef4c0b74cb8742773fc1 (based on main 80f4819098e921f2e1ab371144d4832f68ffedd6, clean merge): pass (0 new failures vs main; all MIMG/MSAA and XCL_DIRECT_DXIL=1 gpu::recomp GPU tests pass under the new valid_tsharp and 32-bit cmp64 lowering).

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (RDNA4, native wave32 + wave64, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug tests + release smoke
  • Unfiltered cargo test --workspace --no-fail-fast -- --test-threads=4: 995 passed, 2 failed, 45 ignored (8 skipped) — 0 new failures:
    • gpu::dxil::lower_wide::cmp64_tests (cmp64_uses_32bit_dwords_no_i64_icmp, carry_ops_avoid_i64_icmp), gpu::dxil::lower_image::heap_bounds_tests (mimg_view_and_sampler_heap_indices_are_guarded, ps_implicit_lod_sample_and_get_lod_validate), gpu::dxil::msaa_tests (5/5 incl. gpu_direct_msaa_image_loads), gpu::dxil::ops_tests, gpu::dxil::graphics::tests, and native RDNA4 wave64 GPU tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, console_wave64_compute_through_the_pso_hook_dispatch_and_read_back) all passed with no synthetic T# descriptor rejected by valid_tsharp
    • The 2 remaining failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are the pre-existing #1679 synthetic dxil::Shader fuzz seeds (switch + WaveReadLaneFirst and Countbits.i64 → lshr/Bfrev, which do not go through lower_wide::cmp64)
    • 8 skipped: 6 gpu::recomp::lower_dxil::tests f16/f32 #1426-semantics sub-cases, shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (0x887A002D), and heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp -- --test-threads=4: 265 passed, 0 failed, 18 ignored (6 skipped)

Regression run
main (8e87fc7b62a87ea589ccb9ea6182f514016cf7db):

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14861 MB

PR (5195e27be9021c7c2515ef4c0b74cb8742773fc1):

xcl-smoke v1
commit: 5195e27be9021c7c2515ef4c0b74cb8742773fc1
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 61 59
device removals: 0
crashes: 0
peak commit: 14916 MB

Not tested

  • retail gameplay past the menus under XCL_DIRECT_DXIL=1 / XCL_SHADER_BACKEND=dxil, NVIDIA/Intel GPUs, Wine/vkd3d-proton

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) ran the workspace test suite and 60-second retail smoke check and formatted this report.

@raylitebull

Copy link
Copy Markdown
Member Author

@eizispark Thank you for the comprehensive RX 9070 XT verification (995 passed,

@DarkPanda69

Copy link
Copy Markdown

NVIDIA run (32-lane waves only), which this PR lists as not tested; the RX 9070 XT side is covered above.

Tested: pass, head 5195e27 applied on main 6567c5f, 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:

  • NVIDIA RTX 3060, driver 32.0.16.1088: 470 passed, 0 failed, 21 ignored. mimg_view_and_sampler_heap_indices_are_guarded, ps_implicit_lod_sample_and_get_lod_validate, cmp64_uses_32bit_dwords_no_i64_icmp and carry_ops_avoid_i64_icmp ok. The SKIPPED lines (no wave64, and the per-lane refusals) are the same as on main.
  • AMD RX 9070 XT, for comparison: 468 passed, 2 failed; the 2 are the fuzz seeds that fail the same way on main on that card.

Not tested: XCL_DIRECT_DXIL=1 title runs; Intel; Linux / Wine; the whole workspace suite.

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

@raylitebull
raylitebull merged commit 2e1c956 into xcl-dev:main Nov 25, 2026
2 of 3 checks passed
anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
)

Brings main to full parity with upstream/main (de36462):
- xcl-dev#1969: official upstream merge of 64-bit icmp 32-bit lowering and MIMG heap guards
- xcl-dev#1774: size-based commit headroom admission for big driver compiles and
  XCL_PIPELINE_MAX_KB cap for offline --pipelines precompile

Conflicts resolved by keeping HEAD's already-merged xcl-dev#1969 emit.rs (with heap_index),
combining xcl-dev#1996 + xcl-dev#1774 comments in real.rs, and combining xcl-dev#1871 + xcl-dev#1774 in shaders.rs.

Assisted-by: Antigravity (Gemini 4)
@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.

4 participants