Direct DXIL: quad-read VGPR operands for 64-bit pixel-shader compares #3405
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3405"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T13:53:41Z.
What changed
Lw::valu64):f64_pairandvopc64_condhelpers for 64-bit compares (u64,i64,f64, andclass_f64).self.is_pixel() && self.guard_override.is_none() && opn != "f"), lowered 64-bitv_cmp_*andv_cmpx_*by quad-reading VGPR operand dwords viadx.op.quadReadLaneAt, evaluating each quad member's predicate with itsEXECbit, and collecting the wave mask viaballot_ps_quad, matching 32-bit/16-bit compares inlower_valu::vopcand the HLSL path'squad_bits.Dst::Nullin pixel-shader 64-bit compares and avoided redundantquadReadLaneAtcalls on SGPR / constant operands or on the constant upper dword ofv_cmp_class_f64's 32-bit class mask.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-bitv_readfirstlane_b32+v_cmp_eq_u64waterfall loop,v_cmp_gt_i64,v_cmp_lt_f64,v_cmp_class_f64(both SGPR and VGPR class masks),Dst::Null, andv_cmpx_ne_u64, asserting zerodx.op.quadOpinstructions and presence ofdx.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_*foru64,i64,f64, andclass_f64) inlower_wide::valu64bypassed the pixel-shader quad-operand ballot path and calledwrite_mask->ballot_ps, which emitsdx.op.quadOp(QuadReadAcross*) on the compare predicate result. On AMD RDNA2/3/4 (amdxc64),quadOpon a value derived fromWaveReadLaneAt(such as a 64-bitv_readfirstlane_b32+v_cmp_eq_u64descriptor/address waterfall loop in a pixel shader) crashes the driver compiler at PSO creation (the exact pattern already avoided for 32-bit compares inlower_valu::vopc). Quad-reading only the VGPR operands withdx.op.quadReadLaneAtand building the ballot withballot_ps_quadeliminatesdx.op.quadOpon 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 --workspaceandcargo test --workspace -- --test-threads=4: all workspace unit, e2e (D3D12 debug layer + DRED), and tiling tests passed (exit 0).2c93bbff567a8ca8403f052e7866e2a747595993):mainbaseline (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):Not tested
dx.op.quadOpis verified by DXIL validation and disassembly for both wave32 and wave64).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.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-29T14:20:46Z.
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: whenopnis"t"or"tru", botha_vgprandb_vgprarefalse, so the 4-iterationfor p in 0..4loop still evaluatesvopc64_cond4 times instead of short-circuiting totrue.Tested locally
32.0.16.2140), AMD Ryzen 7 7800X3D,rustc 1.100.0, DXC1.8.2502.11.cargo test -p xcl --lib gpu::dxil::lower_wide::cmp64_tests:: -- --test-threads=1: 4 passed, 0 failed (includingps_cmp64_uses_quad_operand_reads_without_quad_opandgpu_ps_cmp64_waterfall_and_class_f64).AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:22:18Z.
merge-check
base:
d0832e614fhead:
2c93bbff56merge: 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_cmpxchanges form on the default direct path. The PR is based 259 commits behind main (beforeps_masks,f4ee8ac5) 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 writesballot_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 av_cmpxor 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 callsnote_own_bit, and main's currentballot_psroute for 64-bit compares keeps those bits, so this is a regression once merged. (2) Cost on the default path: up to 16quadReadLaneAtand 4 compare evaluations per 64-bit compare (four f64 compares for_f64) versus 3quadOp+ 1 ballot on main, with ps_masks' cheaper forms never consulted even when onlyv_cndmaskreads 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::Nullreturns 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
d0832e61vs 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:50Z.
Review: COMMENTED
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 samevalu64,v_mad_u64_u32/v_mad_i64_i32still write their carry throughwrite_mask->ballot_ps->dx.op.quadOp, so 64-bit address math in a pixel shader can still put quadOp on aWaveReadLaneAt-derived predicate. In a PS waterfall (v_readfirstlane_b32 s0, v2thenv_mad_u64_u32 v[4:5], s[6:7], s0, v1, v[8:9]), the carry depends on s0 from WaveReadLaneAt, soballot_psemits QuadReadAcross* on it. That's the amdxc64 PSO-creation crash this PR describes, still reachable through the function it touches. The HLSL path appliesquad_bitsin 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:19:51Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_wide.rs; line 873Not certain about this one: the pixel-shader
Dst::Nullshort-circuit returns Ok before the predicate is checked. Sov_cmp_<op>_u64 null, ...with an<op>thatcmp64doesn'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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:28Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:48Z.
Closing: predates
main'sps_masks(f4ee8ac5), drops helper-lane bits underps_masks, and has 0 safe checks; will re-open cleanly againstps_masksonly if a title hits it.Pull request closed