Recompiler: direct PS compares skip the per-quad mask where no helper bit is read #2561
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2571"
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-25T23:17:55Z.
Since #2083 every pixel-shader compare on the direct DXIL route rebuilds its quad's four bits: quad reads of its VGPR operands and four
WaveActiveBallotpasses. That is right for masks whose helper-lane bits are read, but it is used for every compare. On the 610 pixel shaders of title ea3b5e4d, it makes the DXIL 1.42× larger than before #2083 (median 1.36×). @MarcosMDev measured +28 % to +81 % driver time on an RTX 4060 in #2083, and found that a mask onlyv_cndmaskreads needs no ballot.This PR picks the cheapest form each compare's mask allows, from a forward dataflow analysis (
recomp/ps_masks.rs):x64_masks) takes the lane's own bit, as @MarcosMDev's variant in #2083 did;WaveActiveBallot(c) | own bit(the HLSL path'sballot_px_local): a mask that is read whole, but where nothing reads another lane's helper bit. In this form every lane's copy has the live lanes' bits and its own bit right. So EXEC predication,v_cndmaskand carry-ins stay exact in helper lanes, and so do the values they compute for later derivatives. The analysis refuses the form where something reads another lane's bit:s_cmp,s_wqm,s_bcnt…), SCC or VCCZ of the mask, or a scalar operand;ds_swizzle/bpermuteor permlane while EXEC carries the mask (they read the source lane's bit of the reader's EXEC);v_readfirstlaneunder it (waterfall loops);A register known to be a subset of the entry EXEC (the live-pixel mask a kill updates) has no helper bits, so it is exact whatever it was computed from;
cond ? EXEC : 0: a compare of scalar / constant operands;None of the new forms has a quad op, so #134's AMD constraint holds: the kept compares still quad-read their operands, never the predicate.
On the 610 PS (110,821 compares) the forms split as:
The main reasons a compare is kept (shares of the whole-read masks, first reason only):
s_cbranch_vcczon the mask: 20 %;s_andn2_wrexec/s_mov execchanges inside a branch on it: 7 %;v_readfirstlane: 4 %;Part of #156. Follows #2083.
What is in it
crates/xcl/src/gpu/recomp/ps_masks.rs: the analysis (forms), with unit tests.crates/xcl/src/gpu/dxil/lower_valu.rs,lanes.rs:Lw::vopctakes the chosen form;Lw::ballot_ps_local; kept compares OR in their own bit.kernel.rscomputes the forms for pixel shaders (not the split form),compact.rskeys blocks on them, andTRANSLATOR_VERSION10.lanes.rstest: #2083's standalonev_cmpread only byv_cndmasknow expects no quad reads.TRANSLATOR_VERSION10 is also taken by my wave64-split PR; whichever lands second rebases to 11.Tested
xcl shaders --direct --windows 4 --split 0 --validateon the 610 PS of title ea3b5e4d (DXC 1.9.2609): 0 errors, all validated on both sides.e44af706): main is ×1.415 in total, this PR ×1.109.dxc -dumpbin, function bodies) on 22 of them (the median and the largest growth under #2083, 20 random): 1,120,934 on main → 824,591 (×0.736); per program median ×0.79, best ×0.39. DXIL bytes on the same 22: 7.65 MB → 5.76 MB.CreateGraphicsPipelineState(driver shader cache off withShaderCacheControl) of each of the 22 PS with a pass-through VS, main and this PR alternating, two repeats (local harness, not in this PR):XCL_DIRECT_DXIL=all; VS and PS take the non-split direct form there): the 509 PS behind its cold graphics pipelines are 104.4 MiB of DXIL on main and 72.1 MiB here (−31 %), 16.62 M → 11.12 M instructions; VS unchanged; 0 failures.xcl shadersreporting patch (CLI only, not in this PR):ps_ballot_tests4 passed (with #2083'sgpu_direct_ps_masks_hold_helper_lanes_on_triangle_edges: ddx, ddy and a waterfall loop on triangle edges);XCL_DIRECT_DXIL=all,gpu_ps_: 8 passed;XCL_DIRECT_DXIL=all,gpu_wave64_ps: 2 passed; 0 failed, 0 skipped.cargo test --release --workspace --no-fail-fast -- --test-threads=4on the RTX 5070 Ti (XCL_DXC_DIR= DXC 1.9.2609): 1426 passed, 0 failed, 46 ignored.SKIPPED(15 tests): the wave64 cases (no wave64 on this GPU) oflower_dxil/lower/ kernel tests,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware; the f16 / f32-conversion per-lane cases (refused forms);heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).XCL_ADAPTER=nomatch): 1426 passed, 0 failed, 46 ignored. Two earlier runs of the lib binary ended in an access violation insidetls::tests, which this PR does not touch; those tests pass alone (15 of 15 runs).e1d84b7d,XCL_DIRECT_DXIL=all:ps_ballot_tests4/0/0,gpu_ps_8/0/0,gpu_wave64_ps2/0/0 on both, noSKIPPED;gpu::: 700 passed, 3 failed, 22 ignored here, 697/3/22 on main (the 3 more are the newps_maskstests). The same 3 fail on both (f64 / f16 rounding on that stack) and the same 13 tests printSKIPPEDon both.Regression run
main:PR head:
Not tested
gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edgesexits 0xc0000005 before a result on this head and on an earlier head (#2514,57853e01); the Windows Application Error events put all three crashes inside amdxc64.dll at the same offset (0x6b097b). So the crash is in the driver and not new here; it does not show whether this PR's shaders reach it more or less often. The new forms add no quad op (#134's constraint).ballot_pxfor every whole-live mask.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T23:28:49Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T00:46:47Z.
RX 6800M focused test report for #2571: the helper-lane pixel test starts, then the Windows test process exits with
0xc0000005 (STATUS_ACCESS_VIOLATION)before reporting a pass or failure. I reproduced this on the exact PR head and on an earlier XCL head, so I cannot attribute the crash to this PR.Setup: Windows 11 Home build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M (driver
30.0.13002.13003), Rust 1.99.0 MSVC, DXC/dxil1.9.2609.5.XCL_ADAPTER=6800M,XCL_REQUIRE_GPU=wave64,XCL_DIRECT_DXIL=1, withXCL_DXC_DIRset to the pinned DXC folder. Clean detached PR headad0ded91d9fac08d27631c8c09b2b83c9c923adf, isolated Cargo target.Tested:
cargo test --locked -p xcl --lib -j 1 gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edges -- --test-threads=1 --show-output, under a monitor that stops on low free system commit or physical memory. Compilation completed and the harness printedrunning 1 test, the exact fixture name, and the DXC version. It then exited0xc0000005beforeok,FAILED, or summary counts. The guard did not stop this run. A no-build direct rerun of the same test binary with--exact --test-threads=1 --nocapturereproduced the same exit. There was noSKIPPEDline in either run; neither produced a test result.Earlier-head control: The same exact test in a previously built clean #2514 binary (
57853e017054d715cd46cd3c07cb70e58eddddc8) also exited0xc0000005at the same point, with no test result. That head has the samelanes.rsas currentmain, but other compiler files differ, so this is not an exact-main baseline.Not tested: exact current
main, a title smoke pair, or the full suite. The first cold build attempt stopped at the memory guard before any test ran; it is not counted as a test result. No game files were used.AI use: Codex (GPT-6) and a Codex Luna subagent ran the guarded test and direct controls, verified commit and binary provenance, and wrote this report.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T01:14:34Z.
Follow-up to my RX 6800M report above: Windows Application Error (Event ID 1000) records all three focused-test process crashes in
amdxc64.dllversion30.0.13002.13003, with exception0xc0000005at the same fault offset0x00000000006b097b. Two events name the exact #2571 test binary underwork-pr2571/target; the third names the earlier-head control binary underwork-pr2444/target. Their recorded times were 16:43:25, 16:44:57, and 16:45:55 local on 2026-11-25.This localizes the observed access violation to the AMD shader-compiler module on this machine. The earlier-head control faulted at the same offset, so it still does not establish a regression from #2571. I have no call stack or shader compiler dump and did not rerun the test for this follow-up.
AI use: Codex (GPT-6) read the local Windows Application Error records and prepared this supplemental report.
Imported from ivall/xcl. Originally posted by rgroenewoudt on 2026-11-26T19:46:50Z.
Test report on AMD RDNA4 for
ad0ded91Tested
cargo test --workspace --no-fail-fast -- --test-threads=4onad0ded91: 1424 passed, 2 failed, 46 ignored.fuzz_validate_and_gpu_1(seed 722) andfuzz_validate_and_gpu_3(seed 1599), which also fail on main on this GPU (#2115).SKIPPED:f16_programs_on_the_gpu(4 cases) andf32_programs_on_the_gpu(2 cases), both refused per-lane forms, andheap_window_out_of_memory_falls_back_to_the_switch_form.gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edgesandgpu_ps_masks_hold_helper_lanes_on_triangle_edgespass on this GPU, with no crash inamdxc64.dll.XCL_DIRECT_DXIL=all,cargo test -p xcl --lib <filter>on this head and on its basee1d84b7d:ps_ballot_testsgpu_ps_gpu_wave64_psps_masks0 failed and no
SKIPPEDin any of them.Not tested
AI use
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T22:33:41Z.
Independent desktop NVIDIA (Wave32-only Ada) verification of PR #2571 at head
ad0ded91d9fac08d27631c8c09b2b83c9c923adf(1commit; exact parent & merge-base:e1d84b7d9153f86a97d2ec5d209d196046fc0bea, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), 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 (
ad0ded91)cargo test --release -p xcl --lib masks_read_lane_by_lane_or_restored_before_derivatives_take_the_cheap_forms -- --nocapture1 passed; 0 failed; 0 ignored; 1326 filtered out(0.00s)cargo test --release -p xcl --lib masks_read_across_lanes_keep_the_quad_form -- --nocapture1 passed; 0 failed; 0 ignored; 1326 filtered out(0.00s)cargo test --release -p xcl --lib a_kill_mask_of_live_lanes_stays_exact -- --nocapture1 passed; 0 failed; 0 ignored; 1326 filtered out(0.00s)cargo test --release -p xcl --lib gpu::recomp::ps_masks::(3 consecutive runs)3 passed; 0 failed; 0 ignored; 1324 filtered out× 3 (0.00s,0.00s,0.00s)cargo test --release -p xcl --lib gpu::dxil::183 passed; 0 failed; 3 ignored; 1141 filtered out(3.41s;dispatch_chain_native_wave64_builds_wholeself-skipped on Wave32-only RTX 4060)cargo test --release -p xcl --lib gpu::recomp::395 passed; 0 failed; 19 ignored; 913 filtered out(5.09s; Wave64-only and#1426-refused subcases self-skipped as expected)cargo build --release -p xcl --bin xcl1m 09s, exit0)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
e1d84b7d9153f86a97d2ec5d209d196046fc0bea, cached baseline on the same machine):PR #2571 (
ad0ded91d9fac08d27631c8c09b2b83c9c923adf):Runtime log observations (
xcl.log)9220log lines,0[ERROR]/ device-removal / panic lines.19618 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample13990 MB committed by the process; video memory 6116 MB local, 4651 MB non-local.Limits of coverage
ps_masks::, 3×) and fullgpu::dxil::/gpu::recomp::suites passed on RTX 4060 (with expected Wave64-only skips on Wave32-only Ada and existing#[ignore]dump/fuzz/benchmark tests left ignored).retail_ps_gallery/retail_shader_cost) or visual pixel-diff inspection was performed; the 60 s warm-cache retail smoke confirms clean runtime execution and zero regression ontitle: 29640639(frame-count delta vs. cached parent smoke reflects normal single-run startup variance, not this PR).AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T00:38:48Z.
Tested: Clean
ad0ded91d9fac08d27631c8c09b2b83c9c923adf, Windows 11 build 26200.9974, Ryzen 7 3800X, Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC, DXC/DXIL 1.9.2602.17, debug.cargo test --locked -p xcl --lib -j 2 --no-run, then exact test names with--test-threads=1 --nocapture. Eight CPU assertions and six Arc GPU fixtures passed, with zero failures, ignores or skips. The CPU fixtures checked lane-local compare and cross-lane helper reconstruction. HLSL and Direct DXIL triangle edge variants reported zero bad pixels out of 1,024 per draw. The helper ballot, mask and readfirstlane loops and the fourEXP VMsurvival cases also passed.Not tested: Base comparison, native wave64, full suite, retail smoke and performance.
AI use: T3 Code / Codex (
gpt-6.2-sol) ran and reran the fixtures and wrote this report.Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-29T13:09:43Z.
A possible wave32 gap in
ps_masks::forms(). I found it by reading the code; it is not measured in-game. Could you check it with a wave32 test on your side?Read (head
ad0ded91, and the same code rebased onto main7a649b0e):crates/xcl/src/gpu/recomp/ps_masks.rs:284:forms()takes its liveness fromx64_masks::whole_live_out(insts, false). That function always callswhole_live_out_for_width(.., wave64 = true)(x64_masks.rs:543-545).dxil/kernel.rs:758-759callsforms()for every pixel program that is not split. That includes console wave32 pixel shaders on any card.V_CMPwrites an SGPR pair. In wave32 it writes one SGPR. With the wave64 liveness, a compare intos20is treated as killings21as well.v_cmp → s21, thenv_cmp → s20, thens_bcnt1 s21. In the wave64 view, the first compare is dead at its site, so it getsForm::Own. But in wave32,s21is still live and is read whole bys_bcnt1, which then counts only the lane's own bit.ps_masks.rs(forms_of, l.457) all build wave64 programs.Deduced: in wave32 pixel shaders translated by the direct path, a compare whose destination is still read whole could get the per-lane form, giving wrong counts or ballots on helper-lane / triangle-edge pixels. I have not identified any affected program in a run.
Suggested: pass the wave width to
forms()and use the width-aware liveness (whole_live_out_for_width, currently private), plus one wave32 test with the sequence above.Context: we read this while rebasing a test tree onto main
7a649b0e(RTX 3090 24 GB, driver 616.56, Windows 11 22631). Nothing was built or run for this note.AI use: found by an independent code review run with Claude Code (Claude Opus 5.5), checked and posted by me.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-11-30T15:46:34Z.
Correction, December 1. The RTX 4090 world replay reproduces the drop from 0.716 to 0.186 fps across an interval containing #3503, #3501, #2123 and #2571. I previously attributed that whole drop to #2571 alone. The comparison does not establish that.
With #3318 applied throughout, the fast tree was
da19f00c+ #3318 (local mergedaab7202). Mergingf4ee8acinto that tree also brought its ancestors. The resulting tree (a07ad1b1) differs from the fast one in 14 files. The exact pre-#2571 control isf3bb6649+ #3318 (7ee8201f). Its seven-file diff to the slow tree is byte-identical to the patch forf4ee8ac. That control lost the device at 87.1 s withDXGI_ERROR_DEVICE_HUNG, before world entry, as in the two earlier attempts. The in-world cost of #2571 in isolation remains unknown.The two measured 600 s runs finished on driver 621.40. The 300-540 s windows covered 170 presents in 237.51 s and 44 in 236.12 s. Three mesh/pixel shader pairs accounted for 68.8% of the summed GPU intervals in the slow four-frame sample (
XCL_GPU_TIMES=4,200). For meshbf5a7665d0c6631awith PSaf68da74e05dbb3c, a fast repeat with the full ranking measured 18.34 ms/frame at 267 calls/frame. The slow tree measured 2364.53 ms/frame at 264 calls/frame. These timestamps cover the two-pass draw path, and the sampled frames can differ in geometry.I then added identical inner timestamps and GPU-side indirect argument readback to both trees. On the slow tree, the mesh/raster dispatch of this pair accounts for 2392 of its 2426 ms/frame across four frames. For draws executing 2 compute groups and 8 mesh groups with 2560×1440 color and depth surfaces, compute measured 0.0345 vs 0.0346 ms/draw. Mesh/raster measured 0.0408 vs 17.0510 ms/draw (188 fast and 209 slow draws). We have yet to measure emitted primitives and pixel-shader invocations, so the specific shader or coverage change responsible is still open.
The fast diagnostic replay finished its 360 s limit. The slow one read all four frames at 245.8 s, then lost the device at 322.2 s (
DXGI_ERROR_DEVICE_HUNG, DRED state 3, no breadcrumbs).Original November 30 measurements, with the tree label corrected below.
Setup
f5496479(without #3318 this card does not reach the world onmain), release.XCL_GFX_PSO_WAIT_MS=50 XCL_CS_PSO_WAIT_MS=200 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_COHERENT_HEAPS=sparse XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=3990 XCL_TWO_PASS_MB=3072.nvidia-smievery 5 s.Frames/s per minute, 300–540 s. The world arrives at 110–125 s in every tree, with the same 4,600–5,400 draws per present.
3a8745dc(#3497, before #3499)c9aa9f8a(#3499)da19f00c(#3502)5b3c9a4f(#3503)da19f00c+ #3318 + merge off4ee8acincluding its ancestors1183cd43(this PR's merge)d52ff48cd52ff48c+ #3528's commit49eb78ed52ff48c, reverting #3499 (e8a36664), reverting it and #2123 (898fa11), orXCL_SPLIT_INDIRECT_ROUNDS=1all stay at 0.18–0.27 frames/s. #3528 does remove the #3499 work: split slabs per present went from ~1,900 ond52ff48cto ~1,170 with it (~985 before #3499). The frame rate still does not move, which is why I put this here.d52ff48cconflicts with #3500 (kernel.rs,lower.rs), so I have no currentmainwithout it.Also seen while bisecting, gone on current
main. The merges of #3501 (20e806f3) and then #2123 (f3bb6649) hung the GPU before the world, in 2 of 2 runs each: 82–87 s,0x887a0006, DRED state 3, no breadcrumbs,nvlddmkm153. The #3503 merge before them did not, and this PR's merge after them does not.Not tested: AMD or other wave64 GPUs, isolated in-world frame time for this PR, or this PR on
mainwithout #3499.AI use: Claude Code (Claude Opus 5.5) built the trees, ran the bisection and the replays and wrote this report. The person running these tests checked it and asked for it to be posted.
December 1 update: Codex (GPT-6) checked the Git ancestry, ran the follow-up replays and drafted the correction.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-30T16:26:12Z.
Thank you @CharlyRien and @minimalhipster990 for catching both of these!
Opened #3535 to fix @CharlyRien's wave32 register-width bug in
ps_masks::forms()(threadingo.wave64intowhole_live_out_for_width,uses_for_width,writes,per_lane, andVCC/EXECmasks). On wave32 NVIDIA GPUs, 100% of non-split pixel shaders hitps_masks, so a wave32v_cmp -> sNwas wrongly killings(N+1)in both liveness and forward taint and could misclassify a live mask asForm::Own(no ballot).@minimalhipster990 — if you have a chance to test #3535 (stacked with #3528) on your RTX 4090 world replay, please let us know if that lifts the 0.75 -> 0.20 fps drop. If it still stays at ~0.20 fps with wave32 liveness fixed, the next suspect is
Form::LocalmakingEXECper-lane (non-uniform) acrossS_CBRANCH_EXECbranches/loops, and we can either gateForm::LocalonEXECor revert #2571 while isolating it.Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-01T12:23:31Z.
An RTX 3090 data point for the drop minimalhipster990 bisected to this PR on the 4090: we see the same thing, and on NVIDIA this PR seems to hide a GPU hang from #3501 rather than cause the slowdown on its own.
Stack: main
493dbd3d(has #3535) + #3528 (ba8592a4) + #3517 (0b4283d1) + 42 local commits of ours (memory-window, alias-copy and diagnostic switches; none touchesrecomp/ps_masks.rs,dxil/kernel.rs,lower.rs,lower_valu.rsorlanes.rs). Run settings as in our earlier reports (16 heap windows,XCL_SPARSE_WINDOWS=4,XCL_GPU_WAIT_TIMEOUT_MS=45000). Fresh shader preparation for each build, warm driver cache. Presents/s from world +20 s to +180 s, one setting per run.lw.ps_masksleft empty indxil/kernel.rs)ballot_ps_quadas before #3501 (4WaveActiveBallot, local switch indxil/lanes.rs)53e85fb1(before #3499, #3501 and #2571)What we read (not measured):
02202839) produces: the code #2571 added elsewhere (lower_valu.rs,lanes.rs,compact.rs) is skipped whenps_masksis empty. That parent already has #3501 (a50fa7ab), which turnedballot_ps_quadintoWaveActiveBit(Or)+QuadReadLaneAt.QuadReadLaneAtand from 6 to 44WaveActiveBit(Or), inside a loop capped at 65536 iterations; the loop exit takes one of those masks. The bodies are otherwise the same (same CFG, resource handles, discard).real.rsprints "DRED page fault at GPU VA 0x0" whenever the page-fault output is readable, even for a hang, so that line is misleading.What we deduce: on NVIDIA (wave64 split into two wave32 halves) the #3501
ballot_ps_quadlowering can hang this draw. #2571 replaces most of those compares with its forms, so the hang disappears, but the frame rate drops (0.23 here, against 0.66-1.41 with the #3501 lowering reverted instead). That would also match the 82-87 s DRED-3 hangs reported on the 4090 before this PR. We have not found which instruction hangs, nor checked AMD.The image in the two no-hang runs is not clean either (bald character and half-dark window, as on our earlier trees, see #505 / #3517), so this is a pace and hang result, not a rendering one.
Hardware: RTX 3090 24 GB (driver 616.56, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631. Not tested: AMD, main without our local commits.
AI use: Claude Code (Claude Opus 5.5) ran the builds, preparations and runs, read the logs and wrote this; Antigravity CLI (Gemini 4 Neon) compared the two DXIL dumps (read-only); checked and posted by me.