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

Manually merged
github merged 1 commit from gh-pr/1969/head into gh-pr/1969/base 2026-11-26 05:12:05 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-25 00:06 UTC · original
raylitebull:fix/amd-rdna4-icmp-and-oob → main · +465 −215 · 4 files · 1 commits · merged 2026-11-25 00:53 UTC

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.
**@⁠raylitebull** on GitHub · 2026-11-25 00:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1969) `raylitebull:fix/amd-rdna4-icmp-and-oob` → `main` · +465 −215 · 4 files · 1 commits · merged 2026-11-25 00:53 UTC 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:03 +00:00
github manually merged commit 5195e27be9 into gh-pr/1969/base 2026-11-26 05:12:05 +00:00
Author
Owner

@⁠eizispark on GitHub · 2026-11-25 00:14 UTC · original

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.
**@⁠eizispark** on GitHub · 2026-11-25 00:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1969#issuecomment-7148296924) ### 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.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 00:18 UTC · original

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

**@⁠raylitebull** on GitHub · 2026-11-25 00:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/1969#issuecomment-7148370806) @⁠eizispark Thank you for the comprehensive RX 9070 XT verification (995 passed,
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 00:47 UTC · original

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.

**@⁠DarkPanda69** on GitHub · 2026-11-25 00:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1969#issuecomment-7148885752) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 03:09 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 03:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/1969#issuecomment-7151641708) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.