Skip to content

Direct DXIL: route pixel-shader v_cmp_class_f16 through quad-read ballot - #3429

Closed
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/ps-cmp-class-f16-quad-ballot
Closed

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/ps-cmp-class-f16-quad-ballot

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What is in it

Routes Direct DXIL pixel-shader V_CMP_CLASS_F16 and V_CMPX_CLASS_F16 through the shared VOPC quad-read operand ballot path instead of returning early via vopc_write (crates/xcl/src/gpu/dxil/lower_valu.rs):

  • For ty == "f16" with opn == "class", extracts the selected half and applies ABS/NEG to ua, then selects "f16_class" instead of calling vopc_write early.
  • In pixel shaders (Variant::Plain, no guard_override), V_CMP_CLASS_F16 / V_CMPX_CLASS_F16 now quad-read VGPR operands with dx.op.quadReadLaneAt.i32 (never dx.op.quadOp, matching #134) and short-circuit Dst::Null with zero quad reads.
  • Evaluates "f16_class" inside vopc_cond using fclass16(ua) shifted/masked against ub, keeping the non-PS path identical.
  • Adds unit disassembly tests (wave32 & wave64 V_CMP_CLASS_F16, V_CMPX_CLASS_F16, and VDST=125 null destination) and a real-GPU triangle-edge pixel-shader test (V_CMPX_CLASS_F16 + V_CMP_CLASS_F16 with NEG=1 + DPP quad derivatives) in crates/xcl/src/gpu/dxil/lanes.rs, guarded on runner::wave32_supported() and dxc::location().

Tested

  • Causal reproduction before the fix: direct_ps_cmp_class_f16_uses_quad_read_lane_at_not_quad_op failed on origin/main because V_CMP_CLASS_F16 / V_CMPX_CLASS_F16 emitted dx.op.quadOp.i32 instead of dx.op.quadReadLaneAt.i32.
  • Targeted tests after the fix (cargo test -p xcl --lib -- ps_ballot_tests:: cmp_class fclass): 15 passed, 0 failed (including both new V_CMP_CLASS_F16 / V_CMPX_CLASS_F16 unit and GPU triangle-edge tests).
  • Full workspace test run on NVIDIA GeForce RTX 5070 Ti (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: with DXC 1.9.2609.5): 41 test binaries, 2717 passed, 0 failed, 49 ignored, 9 filtered; 27 SKIPPED (22 no wave64 on RTX 5070 Ti, 3 per-lane #1426 refused, 2 no heap windows).

Regression run

Baseline (main ancestor 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

This PR (06c0be7d4610113b51f969bc189976b3209bc6e1):

xcl-smoke v1
commit: 06c0be7d4610113b51f969bc189976b3209bc6e1
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1872 (PresentX 1872)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 32993 MB

Not tested

  • Wave64 GPU execution of the new pixel-shader test (RTX 5070 Ti is wave32-only; wave64 translation + DXIL validation + disassembly assertions ran and passed).
  • AMD RDNA2/3/4 hardware PSO compilation (verified via DXIL disassembly asserting zero dx.op.quadOp and presence of dx.op.quadReadLaneAt.i32).
  • test_title_runs_and_game_folder_is_untouched and uma_driver::tests:: (skipped during the workspace run).

AI use

Used an AI coding assistant to locate the early vopc_write return in lower_valu.rs, write the fix and synthetic unit/GPU tests, and verify the workspace tests and smoke run.

@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
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: 06c0be7
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 1 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: gpu::dxil::lanes::ps_ballot_tests::direct_ps_cmp_class_f16_uses_quad_read_lane_at_not_quad_op (the PR's own new test; lanes.rs:1254, "wave64 false V_CMP_CLASS_F16: PS VOPC must quad-read VGPR operands via quadReadLaneAt"). It can't fail on main, where the test doesn't exist; it fails because main's ps_masks now gives this compare a form without quad reads (finding 1).
review: read the whole diff (lower_valu.rs, lanes.rs tests). It changes the default path: every pixel shader with a plain v_cmp_class_f16 / v_cmpx_class_f16 compiles differently. The claim about main is right: today that instruction leaves early through vopc_write -> write_mask -> ballot_ps, which emits quadOp (the AMD compiler crash of #134). Findings: (1) the PR is based 201 commits behind main, and main has since gained ps_masks (f4ee8ac), which gives a compare read only by v_cndmask a form with no quad reads. The PR now routes class_f16 through that too, so the new test's assertion that dx.op.quadReadLaneAt.i32 appears (the V_CMP(X)_CLASS_F16 + v_cndmask + exp cases) contradicts main's sibling test of the same shape with V_CMP_LT_F32, which asserts no quad reads. The test result above confirms it. A test whose mask is really read (e.g. by DPP under EXEC) would cover the quad-read path. (2) gpu_direct_ps_cmp_class_f16_preserves_helper_lanes… should also pass on main (main's quadOp ballot includes helper lanes too) and doesn't reproduce the AMD crash, so it adds coverage but isn't a regression test. (3) Not in the description: class_f16 now also gets the cheaper ps_masks forms (correct by the same reasoning as the other compares). (4) AI use names no tool or model; the subject uses dxil:, not a repo area. (5) #1980 edits the same class_f16 lines (OP_SEL[1] for the mask), so whichever merges second conflicts. Fine: abs/neg are applied before the quad reads (pure per-lane functions), vopc_cond ignores the modifiers for f16_class so they aren't applied twice, non-pixel shaders and SDWA/DPP variants get the same IR as before, and the HLSL path already sends class_f16 through QuadReadLaneAt.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (2256ccd9): 1516 -> 1677 frames shown (111 %; 60 presents per 2 s in both), peak commit 18133 -> 17057 MB, no device removal, no crash.
verdict: not yet: the PR's new test fails on the merge with current main (rebase onto main and test a compare whose mask is really read)
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 06c0be7d: 1 finding(s). These are on lines outside the diff:

crates/xcl/src/gpu/dxil/lower_valu.rs:1263: The fix only routes Plain, non-guarded f16 class compares onto the quadReadLaneAt path. Any PS VOPC that misses the gate (SDWA/DPP forms like v_cmp_class_f16_sdwa, or a set guard_override) still goes vopc_write -> write_mask -> ballot_ps and emits dx.op.quadOp. A pixel shader running such a compare on a value derived from v_readfirstlane still hits the #134 amdxc64 crash pattern on RDNA2/3/4. Changing ballot_ps (or write_mask in PS) to read across the quad with quadReadLaneAt would cover every VOPC at once instead of adding one opcode/type at a time.


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.

@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), fails merged with main, 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.

3 participants