Recompiler: the pixel prelude's quad ballot has no loop for DXC to unroll #2872
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2872
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2872"
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?
@Royalflamejlh on GitHub · 2026-11-26 20:11 UTC · original
Royalflamejlh:shader/quad-ballot-unrolled→main· +20 −7 · 1 files · 1 commits · openballot_px_quadtook its quad's four members in an[unroll]loop. It is called in most translated pixel shaders, up to hundreds of times, and DXC unrolls every inlined copy. On a 395 KB pixel shader with 84 calls,dxc -ftime-reportput 22 % of its pass time in "Dxil Loop Unroll" and 9 % more in "Unroll loops" and LCSSA. The four members are now written out inballot_px_quad, in the form @thehollowedone gave in review (an earlier head called aballot_px_memberhelper four times instead). In a retail pack, 10,196 of the 12,101 pixel shaders call it, 453,546 times in all. Since #2555 they are all compiled before a launch with a cold cache.What is in it
crates/xcl/src/gpu/recomp/emit.rs:ballot_px_quadwithout the loop; the same computation.emit.rs:quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unroll, red without the change.Tested
The three forms on the same retail pixel shaders: the loop (
main8b957be), the helper form of the earlier head3893df0, and this head's four bodies.main)3893df0)dxc.exe1.9.2609.5, 8 at a time: compile time in alldxc.exe1.8.2502.8dxc::compile_whole; one run of each form, in one session (earlier runs:main124.1 and 124.2 s, the helper form 74.9 s).x86_64-pc-windows-gnu,XCL_DXC_THREADS=8. The 980 are the pixel shaders ofxcl shaders shaders.rpf --precompile --split 1 --only ps --limit 12000.dxc.exeused XCL's flags (-O1over 1 MB): sums of the per-program medians of 3 rounds for DXC 1.9, the mean of 2 round sums for 1.8, the forms in turn, in the same order each round. The pass: empty DXIL cache, 2 rounds, the forms in turn. The whole-pack pass ran this head first, with another bench's title run beside it for 16 of its 21 minutes, then the loop with none, so its 17 % is one pair on a shared machine and, if anything, low. The rerun over the 980 had no title run beside it, but another bench's offline shader pass (8 DXC threads) ran through most of it, the trees in turn. The 2.7 MB shader with 510 calls took 23.1 / 7.6 / 7.2 s with DXC 1.9 and 25.1 / 8.4 / 8.3 s with 1.8.main's 416.6 and 395.3 s over the 980 (the same clean rounds). On the first 282 of them (--limit 11300, 1 run each), this head took 148.1 s on 1 DXC thread and 153.5 s on 8,main276.0 s and 146.7 s: with one shared heap, more threads did not help this head at all. (Throughcompile_wholeon 8 threads in a probe, without the rest of the pass, the helper form was faster: 334.1 against 387.0 s for the 980.) A reading, not shown: the loop passes this removes are CPU work with few allocations, so what is left waits more on the heap's lock. #688 (innvidia-devas3842807a) conflicts withmainin one import line ofdxc.rsand in the README; we merged it by hand.ballot_px_quaddisassemble differently from the loop's (the 192 others are the same apart from the shader hash); with the helper form, 136 did. In the five read (two of this head's, three of the helper's), the same instructions come in another order or are numbered differently.b780ec78and frommainthrough vkd3d-proton's dxil-spirv (34f0ff8, natively, no GPU), withspirv-valon every output: all convert and pass, 31.1 s of conversion in all on both, 41 SPIR-V outputs differ. Not yet repeated for this head.cargo test --workspace -- --test-threads=4at57f5622(the helper form, with an earlier form of the test): 1,447 passed, 0 failed, 47 ignored;mainthere 1,446 / 0 / 47; 29 SKIPPED lines on both.gpu_ps_masks_hold_helper_lanes_on_triangle_edges, which draws a translated pixel shader throughballot_px_quadin both wave sizes, passed. At9388a7e(the sameemit.rschange as the head2dad32e, which is the same commit rebased ontomain83b0081): 1,447 passed, 0 failed, 47 ignored, 29 SKIPPED lines, that test among the passed.main8b957be:gpu_ps_masks_hold_helper_lanes_on_triangle_edgespassed in 3 of 3 runs, with noSKIPPEDline, as onmain;gpu::recomp::emit::tests::5 passed in 3 of 3 (main: 4).2dad32e:gpu::recomp::402 passed, 0 failed, 20 ignored in 3 of 3 runs, the new test among them; their paired 60 s smoke withXCL_PREPARE=0,main1,609 frames and this head 1,603, 60 presents per 2 s, no removal.main83b0081:gpu_ps_masks_hold_helper_lanes_on_triangle_edgesgave 0 wrong pixels of 1,024 in both console wave modes, at 1 and 4 test threads; a native probe ofballot_px_quadfrom each source matched a CPU reference over 778 draws with the GPU in physical wave64; the new test passes here and fails onmain.9388a7e(the head's tree), debug: the new test andgpu_ps_masks_hold_helper_lanes_on_triangle_edgespassed, 0 wrong pixels of 1,024 in both console wave configurations.Regression run
Native Windows 11, RTX 2070 SUPER 8 GB (driver 621.01), the retail title, 60 s,
scripts/smoke.ps1built frommain83b0081and from this head2dad32e, both withXCL_PREPARE=0(#2976): a new tree's first launch otherwise compiles the whole pack before the title starts, which took more than an hour on this PC. With it the title builds its shaders as it goes, so these runs compile this change's pixel shaders in play.main:
PR:
Not tested
AI use
b780ec78fbto3893df0aca3893df0acato5216e5b49a@thehollowedone on GitHub · 2026-11-26 21:23 UTC · original
Independent Windows/NVIDIA check of draft head
3893df0against its base8b957be. The stock head's translated pixel GPU checkgpu_ps_masks_hold_helper_lanes_on_triangle_edgespassed 1/0/0 on the RTX 3080 Ti, with no skip;gpu::recomp::emit::tests::passed 5/0/0. Commands:cargo test --offline --locked -p xcl --lib <filter> -- --test-threads=1for each filter.I also checked DXC sensitivity with synthetic HLSL only (no retail data). A pixel shader makes 84 successive
ballot_px_quad(q)calls, updatingqbefore each call and XORing theuint2results. The two helper forms use this PR's old loop and currentballot_px_memberimplementation, except both returnmdirectly to isolate the helper. Windows SDK DXC 1.8.2502.11,-E main -T ps_6_6 -HV 2021 -O3, separate compiler process per run, alternating order, six runs:[unroll]loopThe current PR form removes loop-unroll time but can move the cost into another DXC pass: on the 840-call synthetic shader,
-ftime-reportattributed 92.8% of its 15.2 s total toSimplify Instructions; the old form's total was 3.5 s, withUnroll loopsat 45.7%. The explicit four-body form has no loop or helper call. Its DXIL was 64 B larger than the PR form at 84 calls (28,296 versus 28,232 B) and 628 B larger at 840 calls (273,548 versus 272,920 B).I applied the explicit-body form locally to the real
PRELUDE_PIXEL; the translated pixel GPU test passed again 1/0/0, and the emitter tests passed 5/0/0. The candidate is below for consideration. Please compare it on the same real shader sample and DXC build used for the PR before choosing a form. This synthetic result does not establish a retail compilation regression or an in-game speedup, and I did not run the workspace suite or paired smoke. The PR is still draft.Local candidate against this PR's `emit.rs`
Hardware: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / driver 621.35, rustc 1.99.1 MSVC. Not tested: AMD, Intel, Wine, a real shader pack or retail title under this candidate. AI use: Codex (GPT-6.2 Sol) inspected the exact diff, generated and ran the synthetic DXC comparison, ran the GPU tests, and drafted this report. I checked the code and measurements before posting.
@JJAutoCompare on GitHub · 2026-11-26 23:34 UTC · original
Tested: Exact clean head
9388a7e7bfbae7b0e4714191198873d12c42a31e, Windows 11 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC, DXC/DXIL 1.9.2602.17, debug. Built withcargo test --offline --locked -p xcl --lib --no-run. Ran the built binary with--exact <test> --nocapture --test-threads=1forgpu::recomp::emit::tests::quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unrollandgpu::recomp::tests::gpu_ps_masks_hold_helper_lanes_on_triangle_edges. Each run passed 1 test, with 0 failed, 0 ignored, and 0 skips. OnXCL_ADAPTER=A770, the triangle-edge draw reported 0 wrong pixels out of 1,024 for each of the two console wave configurations. The fixture checked derivatives, waterfall iteration bounds, and alpha.Not tested: DXC timing, full workspace suite, retail smoke, or other adapters.
AI use: T3 Code / Codex (
gpt-6.2-sol) ran and independently reran the tests and wrote this report.@Royalflamejlh on GitHub · 2026-11-26 23:46 UTC · original
@thehollowedone, on the real shaders, your four bodies beat the loop with DXC 1.9 and 1.8, and they are 2–3 % faster than the helper form, so the head is now your form,
5216e5b(the same tree as9388a7e, which the suite ran on), with you as co-author.main)3893df0)5216e5b)dxc.exe1.9.2609.5, 8 at a time, compile time in alldxc.exe1.8.2502.8-O3(748 KB, 134 calls), took 10.5 s with the loop, 3.0 s with the helper and 3.1 s with your form on DXC 1.8.ballot_px_quaddisassemble differently from the loop's, against 136 of them with the helper; in the two we read, the same instructions come in another order. The DXIL is smaller: 76,033,560 B against 76,081,568 B with the helper and 76,096,620 B with the loop (DXC 1.9). The suite passed again at this head on the 8 GB PC: 1,447 passed, 0 failed, 47 ignored, as before;gpu_ps_masks_hold_helper_lanes_on_triangle_edges, which draws throughballot_px_quad, among them.AI use: Claude Code (Claude Opus 5.5) ran the comparisons and wrote this reply.
Posted without review by a person: the account owner was away and reads replies later.
5216e5b49ato2dad32e630@Decodere on GitHub · 2026-11-27 07:48 UTC · original
Independent desktop NVIDIA verification of PR #2872 at head
2dad32e6303c6a90d738c87427023d9ad0cc287e(1commit; exact parent & merge-base:83b008188efbf954b846667f48d75e3fa9310a01onmain).Environment
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
2dad32e6)cargo test --release -p xcl --lib -- gpu::recomp::emit::tests::quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unroll --exact --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1356 filtered out× 3 (0.00s× 3,0skipped)cargo test --release -p xcl --lib -- gpu::recomp::emit:: --test-threads=1 --nocapture(3 consecutive runs)5 passed; 0 failed; 0 ignored; 1352 filtered out× 3 (0.29s× 3,0skipped — includesquad_ballot_pixel_helper_has_no_loop_for_dxc_to_unrollplus on-GPUgpu_rla_pixel_shader_matches_reference_including_helper_lanes,rla_pixel_helper_avoids_runtime_vector_indexing_and_branches,rla_pixel_shader_compiles_without_local_arrays,format_helpers_select_uint4_components_without_runtime_indexing)cargo test --release -p xcl --lib -- gpu::recomp:: --test-threads=4 --nocapture(3 consecutive runs)402 passed; 0 failed; 20 ignored; 935 filtered out× 3 (8.28s,7.86s,7.66s;23expected runtimeSKIPPEDlines —20no wave64on 32-lane RTX 4060 and3wave32 per-lane formrefusedsubcases)cargo build --release -p xcl1m 45s, exit0,0new warnings inemit.rs)Paired quiet 60 s retail smoke (
title: 29640639,XCL_PREPARE=0 XCL_NETWORK=0)Exact parent & merge-base (
83b008188efbf954b846667f48d75e3fa9310a01,XCL_PREPARE=0 XCL_NETWORK=0, same machine):PR #2872 (
2dad32e6303c6a90d738c87427023d9ad0cc287e,XCL_PREPARE=0 XCL_NETWORK=0):Limits of coverage
ballot_px_quadhelper contract (quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unroll), pixel prelude compilation/on-GPU execution (gpu::recomp::emit::5/5× 3,0skipped), and the fullgpu::recomp::suite (402/0/20× 3) on desktop RTX 4060 (32-lane wave32, DXC1.9.2609.5).XCL_PREPARE=0(XCL_NETWORK=0), bypassing startupprepare_for_launchshader precompilation; on-demand compilation and presentation ran cleanly with0device removals and0crashes.20no wave64skipped subcases), Wine /#688private DXC heaps, or the20#[ignore]tests.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
@SzczepanGrela on GitHub · 2026-11-27 08:24 UTC · original
RX 9070 / Wine correctness check on exact head
2dad32e6303c6a90d738c87427023d9ad0cc287eagainst its parent/current main83b008188efbf954b846667f48d75e3fa9310a01: both produce correct pixel masks in the cases below.RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.6-1-cachyos, Mesa 26.3.1-5, GE-Proton11-12 / Wine 11.0 Staging, ntsync. Native vkd3d-proton
8293130ebe370b1+, local asserts-disabled build; DXC/DXIL 1.9.2602.17, Rust 1.97.1, Windows-GNU release. Private enabled XCL/vkd3d/Mesa caches per process.Tested
gpu_ps_masks_hold_helper_lanes_on_triangle_edges, in both console wave modes: zero wrong pixels out of 1,024 per mode on each source, at both--test-threads=1and4. Saved HLSL/DXIL and all float pixel readbacks; independently checked derivatives, loop bounds and alpha. Original assertions unchanged.quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unrollpasses on the head. Copied unchanged to the main control, it fails witha loop remains in ballot_px_quad(), as expected. Per original-test invocation: head 2 passed / 0 failed; main control 1 passed / 1 expected failure; 0 ignored, 0 skipped on both.ballot_px_quadverbatim from each source, using the emitter's console32/64 initialization. It renders two uint MRTs: the result and input nibble, plus native active-lane ballot, lane index and wave width. All 16 nibble values, both console modes and four full-coverage triangulations (opposite diagonals, subpixel strips and grid) pass, in three fresh processes per source. Each full probe invocation: 1 passed / 0 failed / 0 ignored / 0 skipped, 128 draws.Built copied source trees, with only local observation/test additions, using:
The original GPU filter is
gpu::recomp::tests::gpu_ps_masks_hold_helper_lanes_on_triangle_edges; the head shape filter isgpu::recomp::emit::tests::quad_ballot_pixel_helper_has_no_loop_for_dxc_to_unroll(control copy underemit::workflow_original_shape). The native probe and readback checker are local test fixtures, not upstream tests.Not tested: physical pixel wave32, retail shader packs, compilation speed, whole suite, title/smoke runs or FPS. These are correctness results; the old loop also passes the GPU checks.
AI use: OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the public diff, wrote the local fixtures/checker, ran and verified these tests, and drafted this report. Publication authorized by the account owner.
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.