Recompiler: restore four-ballot lowering for pixel quad masks #3797
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3797"
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 CharlyRien on 2026-12-03T16:39:14Z.
Restores the direct DXIL pixel-shader quad ballot (
Lw::ballot_ps_quad) to the form it had before #3501. Follow-up to #3501.#3501 (
a50fa7ab) changedballot_ps_quadfrom fourWaveActiveBallot(one per quad member) to each lane shifting its quad's four predicate bits into place and OR-ing them across the wave withWaveActiveBit(Or). Two public reports on #3501 point at that function:e18e7b2(the commit beforea50fa7a) to 16.0256 ms ata50fa7a(13 pairs). On the complete #3501, restoring only the oldballot_ps_quadbody takes it from 17.9420 ms to 0.0814 ms (12 pairs; B slower in every pair, in both orders). The output changed too: between the two forms, 60/63/40 and 56/60/35 texels on targets 0/1/2 of two draws; the report notes that a console reference is needed to decide which is right. Hosta07ad1b1+ #3318, not this commit.493dbd3d+ #3528 + #3517 + 42 local commits, local switches listed there): with #2571's mask forms switched off, the GPU hung (DRED device state 3) in the same mesh + pixel-shader draw in 2 runs of 2; with the oldballot_ps_quadas well, no hang in 2 runs of 2 (0.66 and 1.41 presents/s in the world). With #2571's forms on and the #3501 body: 0.23 presents/s, the intro card never left in 358 s (1 run).We have not found why the
WaveActiveBitform is slow on the 4090 or hangs that draw on the 3090. There is one reason in the tree to prefer ballots in pixel shaders: the HLSL prelude'sballot_px_quad(recomp/emit.rs) uses only ballots and quad reads on purpose, because a helper lane gets the wave's result of a ballot butWaveActiveBitOrgave helper lanes another value on an RTX 5070 Ti (comment there, andgpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k, which prints it). On this 3090 that test prints:32 pixels next to a helper lane; its ballot right in 32, its bit-or in 0. #3501 did not change the HLSL path, so this also puts the two backends back on the same lowering.The restored body is the one of
a50fa7ab's parent, character for character; only its doc comment is new. The rest of #3501 (direct quad shuffles, predicate-derived lane bits) stays: the 4090 function-only control kept it too.What is in it
crates/xcl/src/gpu/dxil/lanes.rs,Lw::ballot_ps_quad: oneWaveActiveBallotper quad memberp; each quad's nibble of that ballot is OR-ed into bit4kand moved to4k + p. A wave64 program uses both words of the same ballots; a wave32 program in 64-lane hardware takes its half's word (as before #3501 and as HLSLballot_px_quad).direct_ps_non_vopc_carry_ballot_uses_quad_op: the fixture also readsVCC_LOas a word (so the test does not depend onv_cndmasktaking only its own bit), runs in wave32 and wave64, and checks four non-constantwaveActiveBallotand nowaveActiveBitin the DXIL. Onmainthese checks fail: itsballot_ps_quademitswaveActiveBitand no predicate ballot (read in the code; the test was not run onmain).No cache bump: the change is under
gpu/dxil, soXCL_DIRECT_DXIL_SOURCE_IDchanges on its own (every direct translation gets a new identity, all stages); the HLSL path'sXCL_TRANSLATOR_SOURCE_IDis unchanged.Tested
cargo build --workspaceandcargo test --workspace --no-run: okcargo test --workspace --no-fail-fast -- --test-threads=4: 3,016 passed, 2 failed (test_title_draws_with_a_root_signature_under_the_debug_layer,test_title_runs_under_the_debug_layer_with_dred), 56 ignored, over 45 test binaries. The same two debug-layer tests fail on this machine without this commit (maina815de93+ another one-commit recompiler branch: 3,020 passed, the same 2 failed);maina815de93itself was not run through the whole suite.SKIPPEDon this adapter: 25 lines: 22 "no wave64", 3 "no heap windows" or "noGPU_UPLOADheaps", the reasons this card always gives.XCL_REQUIRE_GPU=mesh: 17 of 17 passed. Direct path: the 8 tests ofgpu::dxil::lanes::ps_ballot_teststhat cover pixel masks, the changed one included;gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edgesneeds wave64 programs for all its cases and printsSKIPPED … no wave64on this card. HLSL path (unchanged, as controls): therecompps_masks,ballot_px_quad,rla, helper-lane and primitive-edge tests.ps_ballot_testsmodule by name (the changed test, 3 other CPU DXIL checks, the wave32 direct GPU edge test): passed, twice.Regression run
scripts/smoke.ps1, 60 s each, the same title, the same machine and driver, a fresh shader cache on both sides;mainfirst, then this head:Frames 523 / 495 (106 %), peak commit 15,764 / 15,974 MB (99 %), no device removal, no crash.
Not tested
main(with #2571's forms on), we have no run of this commit or of the old body alone in the world. One world run each on this machine (same driver, each side with its own prepared shader cache, 03/12):maina815de93reached the intro cinematic and lost the device at 233 s; this head reached the first scene after it and lost the device at 313 s. Both removals look the same (0x887a0005, DRED: device state 0, no breadcrumbs, no list in flight), so this commit does not remove it; neither side reached a stable world. One run per side shows no difference that can be credited to the commit.ballot_ps_quad. The function is covered here by the CPU DXIL test; the HLSLballot_px_quad, the same algorithm, has GPU tests that run on this card.WaveActiveBit(Or)and their selects.Overlap with #3455
#3455 (open) changes the caller
Lw::ballot_ps(quad reads lane by lane instead ofquadOp) and rewrites and renames the same test (direct_ps_non_vopc_carry_ballot_uses_quad_op); it does not change the body ofballot_ps_quad. A test merge of the twolanes.rs(#3455 at1895d9e8) conflicts only in that test; theballot_psandballot_ps_quadhunks merge cleanly. Whichever lands second rebases: if #3455 is first, the no-waveActiveBitcheck and the predicate-ballot count move into its test (withv_readfirstlaneits variants may have one more non-constant ballot, so the count would be checked against the form without it).AI use
Base:
maina815de93, one commit, no local switches.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T16:40:40Z.
Review of
f95100fc(code reading only, not a merge-check; draft) · no findingsIn short: The PR restores the direct-DXIL
Lw::ballot_ps_quadto its body from before #3501 (a50fa7ab): fourWaveActiveBallotcalls, one per quad member, instead of aWaveActiveBit(Or)of shifted bits. The reasons are two public reports on #3501: a 160× slower draw on an RTX 4090, and a GPU hang on a 3090. The body matchesa50fa7ab^character for character, the test now pins the form in wave32 and wave64, and the overlap with #3455 is described. Nothing blocks it.Checked and fine
ballot_ps_quadis identical to the one ina50fa7ab^, which I compared directly. Only its doc comment differs.p, the ballot of bitpover live lanes is spread across each quad's nibble (v | v>>1 | v>>2,& 0x1111_1111) and moved to bit4k + p. Any live lane of a quad, helper lanes included, gives the quad's bits. This matches the HLSL prelude'sballot_px_quad.gfx_half. Plain wave32 returns only the low word.WaveActiveBitOrgave helper lanes another value on an RTX 5070 Ti (gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k).VCC_LOas a word, so it does not depend onv_cndmasktaking only its own bit. It counts exactly four non-constantwaveActiveBallotcalls, so the entry EXEC ballot does not count, and it checks that there is nowaveActiveBit. Those checks fail onmain.gpu/dxil, whose sources are hashed intoXCL_DIRECT_DXIL_SOURCE_ID.ballot_psand rewrites the same test. The description says the two conflict only in that test, and that whichever lands second redoes it.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.