Skip to content

Recompiler: lower 32-bit VALU add/sub with carry without i64 in direct DXIL - #2565

Open
ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-valu-carry-32bit
Open

ramon-victor wants to merge 1 commit into
xcl-dev:mainfrom
ramon-victor:opt/dxil-valu-carry-32bit

Conversation

@ramon-victor

Copy link
Copy Markdown
Contributor

Part of #1269.

Problem

In crates/xcl/src/gpu/dxil/lower_valu.rs, v_add_co_ci_u32, v_sub_co_ci_u32, and v_subrev_co_ci_u32 widened all three 32-bit operands (x, y, cin) to i64 via zext64, performed 64-bit add/sub, unpacked the 64-bit result (unpack64), and tested hi != 0 for carry/borrow out.

Every shader using 64-bit VALU address arithmetic (v_add_co_u32 + v_add_co_ci_u32) was therefore forced to emit i64 instructions and declare Feature::Int64Ops even when no 64-bit integer operations were otherwise needed, and opt.rs could not fold or dead-code-eliminate the i64 carry-out path (because 64-bit instructions are preserved to keep Int64Ops consistent).

Fix

  • Lower v_add_co_ci_u32, v_sub_co_ci_u32, and v_subrev_co_ci_u32 in crates/xcl/src/gpu/dxil/lower_valu.rs using pure 32-bit carry/borrow arithmetic matching s_addc_u32 / s_subb_u32 in lower.rs:
    • Add: t0 = x + y, t = t0 + cin, carry = (t0 < x) | (t < t0).
    • Sub / Subrev: t0 = x - y, t = t0 - cin, borrow = (x < y) | (t0 < cin).
  • Add lower_valu::valu_carry_tests::valu_carry_ops_avoid_i64_and_match_gpu verifying DXIL validation, disassembly (zero 64-Bit integer shader flag and zero zext i32), and wave32 RTX 3070 GPU parity across 32 boundary (x, y, cin) triples for all three opcodes (checking both 32-bit VDST outputs and all 32 carry/borrow-out mask bits).

Measured impact

573-program retail direct-DXIL validation sweep (dxil.dll 1.8.2502.11):

  • Baseline (6d12f58): 573/573 validated (val_fail=0), 51,117,488 total DXIL bytes (p50=22,865 us, p95=408,132 us).
  • This PR (97376ee): 573/573 validated (val_fail=0), 51,110,868 total DXIL bytes (-6,620 B / -0.013%; p50=20,462 us, p95=403,273 us).

Tested

  • Targeted IR disassembly + 32-lane boundary GPU parity test (cargo test --lib -p xcl valu_carry): 1 passed, 0 failed.
  • Full workspace (.\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11): 1424 passed, 0 failed, 46 ignored.
  • 573-shader direct DXIL dxil.dll validation sweep: 573/573 passed, 0 failures.
  • Release build (cargo build --release -p xcl) and 60 s retail smoke run (see below).

Not tested

  • Wave64-only GPU paths (the RTX 3070 runs wave32; wave64 GPU tests skipped automatically on this adapter).

Regression run

Main (f087b99):

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB

This PR (97376ee):

xcl-smoke v1
commit: 97376ee13636653cf6d1853dd330fe0290285cab
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14004 MB

AI use

  • Antigravity (Gemini 4 Neon): implementation, IR & 32-lane GPU parity test, 573-shader DXIL sweep, and PR drafting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

@DarkPanda69

Copy link
Copy Markdown

Wave64 run (listed as untested; the wave64 GPU tests skipped on the RTX 3070) on an AMD RX 9070 XT, plus an RTX 3060: the new test passes, and nothing else changes in the direct-DXIL GPU suite.

Head 97376ee applied on main 08db802, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, card chosen with XCL_ADAPTER:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010) 704 passed, 2 failed, 6 SKIPPED 705 passed, 2 failed, 6 SKIPPED
RTX 3060 (32.0.16.1088) 706 passed, 0 failed, 24 SKIPPED 707 passed, 0 failed, 24 SKIPPED

On both cards, the only result change against main is the new valu_carry_ops_avoid_i64_and_match_gpu (ok), with no new skips. That test translates with wave64: false, so its own GPU run is wave32. On the RTX 3060, 21 wave64 cases skip, among them the suite's integer carries, wave64 case. On the RX 9070 XT, 18 of them ran with this PR applied, integer carries, wave64 included, and still pass; the other 3 are per-lane forms refused on both cards. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on main.

Not tested: Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.
Targeted run of valu_carry_ops_avoid_i64_and_match_gpu (name sits outside the gpu_ filter): passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Integrates upstream amd-dev 9f02a3b (BVH null/OOB guard), b67375b (scratch
SADDR 0x7F), 4ae5668/xcl-dev#2565 (32-bit VALU add/sub carry without i64), plus
open PRs xcl-dev#2559 (bfm/ffbh_i), xcl-dev#2557 (known_nonzero_bits folding), xcl-dev#2552
(f16-to-f32 fold), xcl-dev#2568 (integer min/max range opt), and xcl-dev#2580 (empty DXC
blob null slice).

Assisted-by: 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.

4 participants