Skip to content

Direct DXIL: quad-read VGPR operands for 64-bit pixel-shader compares - #3405

Closed
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/direct-ps-cmp64-quad-ballot
Closed

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/direct-ps-cmp64-quad-ballot

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What changed

  • In crates/xcl/src/gpu/dxil/lower_wide.rs (Lw::valu64):
    • Added f64_pair and vopc64_cond helpers for 64-bit compares (u64, i64, f64, and class_f64).
    • In pixel shaders (self.is_pixel() && self.guard_override.is_none() && opn != "f"), lowered 64-bit v_cmp_* and v_cmpx_* by quad-reading VGPR operand dwords via dx.op.quadReadLaneAt, evaluating each quad member's predicate with its EXEC bit, and collecting the wave mask via ballot_ps_quad, matching 32-bit/16-bit compares in lower_valu::vopc and the HLSL path's quad_bits.
    • Short-circuited Dst::Null in pixel-shader 64-bit compares and avoided redundant quadReadLaneAt calls on SGPR / constant operands or on the constant upper dword of v_cmp_class_f64's 32-bit class mask.
  • Added CPU and GPU tests in crates/xcl/src/gpu/dxil/lower_wide.rs (mod cmp64_tests):
    • ps_cmp64_uses_quad_operand_reads_without_quad_op: translates and validates both wave32 and wave64 Direct DXIL pixel shaders containing a 64-bit v_readfirstlane_b32 + v_cmp_eq_u64 waterfall loop, v_cmp_gt_i64, v_cmp_lt_f64, v_cmp_class_f64 (both SGPR and VGPR class masks), Dst::Null, and v_cmpx_ne_u64, asserting zero dx.op.quadOp instructions and presence of dx.op.quadReadLaneAt.
    • gpu_ps_cmp64_waterfall_and_class_f64: capability-guarded real D3D12 GPU triangle draw verifying all 64 pixels (including diagonal edge quads with helper lanes) execute the Direct DXIL wave32 pixel shader and produce exact expected RGBA outputs.

Why

Previously, 64-bit pixel-shader compares (v_cmp_* / v_cmpx_* for u64, i64, f64, and class_f64) in lower_wide::valu64 bypassed the pixel-shader quad-operand ballot path and called write_mask -> ballot_ps, which emits dx.op.quadOp (QuadReadAcross*) on the compare predicate result. On AMD RDNA2/3/4 (amdxc64), quadOp on a value derived from WaveReadLaneAt (such as a 64-bit v_readfirstlane_b32 + v_cmp_eq_u64 descriptor/address waterfall loop in a pixel shader) crashes the driver compiler at PSO creation (the exact pattern already avoided for 32-bit compares in lower_valu::vopc). Quad-reading only the VGPR operands with dx.op.quadReadLaneAt and building the ballot with ballot_ps_quad eliminates dx.op.quadOp on the predicate while keeping helper lanes accurate across every 2x2 quad.

Tested

Hardware: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200), rustc 1.99.0, DXC 1.9.2609.5 (XCL_DXC_DIR).

  • cargo check --workspace --all-targets: passed (0 errors, 0 new warnings).
  • cargo test -p xcl --lib -- gpu::dxil::lower_wide::cmp64_tests:: --test-threads=1: 4 passed, 0 failed, 0 ignored.
  • cargo build --workspace and cargo test --workspace -- --test-threads=4: all workspace unit, e2e (D3D12 debug layer + DRED), and tiling tests passed (exit 0).
  • 150 s real-title smoke at PR head (2c93bbff567a8ca8403f052e7866e2a747595993):
xcl-smoke v1
commit: 2c93bbff567a8ca8403f052e7866e2a747595993
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34119 MB
  • Ancestor main baseline (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):
xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

Not tested

  • AMD RDNA2/3/4 hardware directly (tested on NVIDIA RTX 5070 Ti; the absence of dx.op.quadOp is verified by DXIL validation and disassembly for both wave32 and wave64).
  • Wave64 pixel-shader GPU draw execution (RTX 5070 Ti is wave32-only; wave64 translation, DXIL validation, and disassembly are verified on CPU).

AI use

Written and verified with an AI coding assistant (Antigravity); all code, tests, workspace runs, and smoke results were directly reviewed and executed on local hardware.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

Reviewed and tested at 2c93bbff.

Looks solid — clean quad-operand-read lowering for 64-bit PS compares (u64, i64, f64, class_f64) with good DXIL validation and GPU waterfall coverage. One tiny nit: when opn is "t" or "tru", both a_vgpr and b_vgpr are false, so the 4-iteration for p in 0..4 loop still evaluates vopc64_cond 4 times instead of short-circuiting to true.

Tested locally

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0, DXC 1.8.2502.11.
  • cargo test -p xcl --lib gpu::dxil::lower_wide::cmp64_tests:: -- --test-threads=1: 4 passed, 0 failed (including ps_cmp64_uses_quad_operand_reads_without_quad_op and gpu_ps_cmp64_waterfall_and_class_f64).

AI use

  • Antigravity (Gemini 4 Neon) assisted with code review and drafting; all builds and tests were executed locally on the hardware above.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: 2c93bbf
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (lower_wide.rs, +276/-28). Every 64-bit pixel-shader v_cmp/v_cmpx changes form on the default direct path. The PR is based 259 commits behind main (before ps_masks, f4ee8ac) and merges cleanly, but the new path doesn't follow main's ps_masks rules. Findings: (1) helper-lane bits can be lost (from reading). The new quad loop (lower_wide.rs ~903-923 in the merged tree) takes each quad member's bit from this lane's own copy of EXEC (lanebit_at(el, eh, lp)) and writes ballot_ps_quad(q) directly. After an earlier compare in a ps_masks local form, live lanes' copies of EXEC lack the helper lanes' bits, so the 64-bit mask drops them. After a v_cmpx or saveexec, helper lanes then stop and derivatives go wrong. Main's 32-bit path ORs in the lane's own bit for exactly this case (ballot_ps_local(own_bit), lower_valu.rs ~1369-1374) and calls note_own_bit, and main's current ballot_ps route for 64-bit compares keeps those bits, so this is a regression once merged. (2) Cost on the default path: up to 16 quadReadLaneAt and 4 compare evaluations per 64-bit compare (four f64 compares for _f64) versus 3 quadOp + 1 ballot on main, with ps_masks' cheaper forms never consulted even when only v_cndmask reads the mask. (3) The GPU test passes on NVIDIA either way and checks no output that depends on helper lanes, so it shows neither the AMD crash nor the helper-lane behaviour. (4) AI use says only "Antigravity", no model. Fine: f64 abs/neg are applied after the quad reads, the class mask reads only its low dword, constants and SGPRs aren't quad-read, Dst::Null returns early, and the tests still pass on main's ps_masks (64-bit compares bypass it), unlike #3429's. The PR's red CI (8 title_textures tests) was already red on its base.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (719c25a9): 1516 -> 1680 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17148 MB, 0 device removals, 0 crashes. Not shown here: whether the title's pixel shaders use 64-bit compares under a local-form EXEC.
verdict: not yet: once merged with main's ps_masks the new 64-bit path drops helper lanes' bits (finding 1; main's 32-bit path ORs in the own bit for this), and it skips ps_masks' cheaper forms
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 2c93bbff: 2 finding(s). 1 are inline. These are on lines outside the diff:

crates/xcl/src/gpu/dxil/lower_wide.rs:953: In the same valu64, v_mad_u64_u32 / v_mad_i64_i32 still write their carry through write_mask -> ballot_ps -> dx.op.quadOp, so 64-bit address math in a pixel shader can still put quadOp on a WaveReadLaneAt-derived predicate. In a PS waterfall (v_readfirstlane_b32 s0, v2 then v_mad_u64_u32 v[4:5], s[6:7], s0, v1, v[8:9]), the carry depends on s0 from WaveReadLaneAt, so ballot_ps emits QuadReadAcross* on it. That's the amdxc64 PSO-creation crash this PR describes, still reachable through the function it touches. The HLSL path applies quad_bits in its shared mask writer for every mask, which would be the equivalent fix here.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

// predicate result (AMD RDNA2/3/4 amdxc64 crashes on quadOp of values derived
// from WaveReadLaneAt, e.g. 64-bit v_readfirstlane waterfall loops with v_cmp_eq_u64).
if self.is_pixel() && self.guard_override.is_none() && opn != "f" {
if matches!(dst, Dst::Null) && matches!(ty, "f64" | "i64" | "u64") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain about this one: the pixel-shader Dst::Null short-circuit returns Ok before the predicate is checked. So v_cmp_<op>_u64 null, ... with an <op> that cmp64 doesn't support lowers silently to nothing in a pixel shader, but returns a "VOPC 64" error in every other stage, which hides an unhandled opcode in PS only. Checking the predicate before the short-circuit keeps the behaviour the same across stages.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing: predates main's ps_masks (f4ee8ac5), drops helper-lane bits under ps_masks, and has 0 safe checks; will re-open cleanly against ps_masks only if a title hits it.

@Kalmarv Kalmarv closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants