Recompiler: use wave32 register width in direct PS mask analysis #3535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3535"
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-30T16:26:10Z.
Summary
Fixes the wave32 register-width bug in
recomp::ps_masksintroduced by #2571 (1183cd437), reported by @CharlyRien.Root cause:
ps_masks::forms()calledx64_masks::whole_live_out(insts, false)andx64_masks::uses(d), both of which assume wave64 register pairs (wave64 = true). On wave32 pixel shaders (every non-split pixel shader on wave32 NVIDIA GPUs), a compare writingsNwas treated as killings(N+1)in both liveness and forward taint. An earlier compare writings(N+1)that is still read whole later (e.g. bys_bcnt1,s_and_saveexec_b32, or a branch/loop) could therefore be misclassified asForm::Own(noWaveActiveBallot) or have its taint prematurely cleared.Fix:
x64_masks::uses_for_widthandx64_masks::whole_live_out_for_width.o.wave64fromdxil::kernelintops_masks::forms(insts, o.wave64).wave64throughps_masks(vcc_mask,exec_mask,writes,per_lane,subset_after,live_subsets,run) so wave32 compares andSAVEEXEC/WREXECuse single-SGPR widths.wave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taintcovering @CharlyRien'sv_cmp -> s21,v_cmp -> s20,s_bcnt1 s21sequence ands_and_saveexec_b32.Also a candidate fix for @minimalhipster990's RTX 4090 wave32 world FPS regression reported on #2571 (needs RTX 4090 world re-test to confirm whether this accounts for all of the drop or whether
Form::LocalonEXECbranches/loops is also involved).Regression run
Baseline (
main):PR head:
Tested
cargo test -q -p xcl --lib gpu::recomp::ps_masks::tests -- --test-threads=1(4 passed, 0 failed, including the newwave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taint).cargo test -q -p xcl --lib ps_ballot_tests -- --test-threads=1on Windows 11 + RTX 5070 Ti (8 passed, 0 failed).44eeb0c75vs91244db94): 1708 frames (61/60/60 per 2 s), 0 device removals, 0 crashes, 17453 MB peak commit.Not tested
cargo test --workspacelocally (covered by CI).AI use
ps_masks.rs/x64_masks.rs, implementing the width-aware fix and wave32 unit tests, running local tests and smoke, and writing this description.Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-30T16:57:06Z.
Ran the
ps_masksmodule tests and the pixel-shader ballot tests at44eeb0c7on an NVIDIA Blackwell desktop part with 16 GB of VRAM; this is a second host for these tests.Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, DXC 1.9.2609.5, debug build,
XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.Both counts match the description at this exact head: the four
ps_maskstests, including the new wave32 neighbour-SGPR case, and the eightps_ballot_tests. This adapter is wave32 only with 16 GB of VRAM and driver 621.40, so the wave32 width path is the one exercised here.Not tested: the full workspace suite, native wave64 hosts, AMD and Intel GPUs, Wine, release profile, the RTX 4090 world re-test mentioned in the description, title and paired smoke runs, game data.
AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Imported from ivall/xcl. Originally posted by vasanex on 2026-11-30T17:56:49Z.
Unattended test report. Posted automatically by an AI agent on the account owner's instruction. The owner has not read or checked it. It is not a code review and not a
merge-check.Tested tree: head
44eeb0c75acb0b1d55961fbee4c7f6f14e4cf028onmain9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b, in a separate worktree. The PR is based on thismain, so the merged tree (fb0db1e8cbfe2f3a36222f3d304c67cc4437696b) is the head's own tree. NoXCL_*variables were set.Hardware and tools: NVIDIA GeForce RTX 3080 10 GB (32-lane waves only), driver 621.40, AMD Ryzen 9 7950X, Windows 11 Pro build 26200, rustc 1.100.0, debug build.
Results
cargo build --workspace: okcargo test --workspace --no-fail-fast -- --test-threads=4SKIPPEDlinesmainwith this PRmainwithout itgpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16("2D D16 resinfo clobbered v2/v3"). Run alone (cargo test -p xcl --lib -- gpu_direct_image_get_resinfo_d16 --test-threads=1), it fails in 3 of 3 runs with this PR and in 3 of 3 without it. #3513 is about this test.ps_masksorps_ballot_teststest.wave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taint), the other 3ps_maskstests and the 8ps_ballot_testspassed.ps_masks::forms()(one added line that setswave64to true, removed afterwards),cargo test -p xcl --lib -- ps_masks::tests --test-threads=1gives 3 passed and 1 failed. The failing test is the new one, at its first assertion.Outcome: no new test failure with this PR on this wave32-only card.
Not tested:
kernel.rson its own, and the DXIL of a title's pixel shaders before and afterXCL_HEAP_WINDOWS=1, wave64 and AMDAI use: Claude Code (Claude Opus 5.5) ran the builds and tests, and wrote and posted this report.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-11-30T19:51:30Z.
RTX 4090 world replay of this PR stacked with #3528, as asked on #2571: the world stays at ~0.2 frames/s, the same as without this PR. The PR's code does run (301 of 1,714 pixel shaders come out smaller), but the frame rate does not move. One of the two runs with it lost the device (
0x887a0006) at 356 s.Setup
mainff0c364b+ #3318f5496479(without it this card does not reach the world onmain) + #352849eb78ef, with and without this PR's head44eeb0c7. All clean merges, release.nvidia-smievery 5 s.Frames/s per minute, 300–540 s. The world arrives at 117–143 s in all four runs, with 4,500–5,500 draws per present; the GPU is at 100 % and 105–120 W in all of them.
c9aa9f8a(#3499 merged, #2571 not yet)293b2225…with it,1d4ad792…without). Of the 1,714 pixel shaders translated in both measured runs, 301 come out smaller with this PR (75.10 → 73.31 MB in all) and none larger; the 1,113 compute and 528 vertex shaders keep their sizes.Form::Localgated onEXEC, or #2571 reverted) as soon as there is a commit for it. A revert of #2571 on currentmainconflicts with #3500 (kernel.rs,lower.rs), so I have no tree without it.Device removal in the measured run with this PR
0x887a0006, DRED device state 3, no breadcrumbs, no page fault reported. System commit was at 60.0 of 63.4 GB.xcl-pso-wholeworker finished #3528's whole forms one after another, about one every 10 s, with no hang. The last one, for record6e8798cd…(447,152 B DXIL), finished at 353.8 s, about 3 s before the removal. The same whole form also finished at 435.0 s in the measured run without this PR, and at 328.4 s in a run ofd52ff48c+ #3528 yesterday, with no hang either time.ff0c364b, 2 yesterday ond52ff48c). One event is not enough to say whether this PR plays a part. It looks like the hangs throny reported on #3528 (0x887a0006, no breadcrumbs), though throny's came earlier (141–151 s) and had a DRED page fault at VA 0.Not tested: a second measured run with this PR, this PR without #3528, the change Zippp69 suggested for #3528, AMD or other wave64 GPUs, a GPU profile.
AI use: Claude Code (Claude Opus 5.5) built the trees, ran the replays, compared the shader caches and wrote this report. The person running these tests checked it and asked for it to be posted.
Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-30T23:02:55Z.
I tested the adjacent-register case on my RTX 3080 (driver
32.0.16.1692) with the same 32×32 pixel shader test on parent9dfbe3eaand PR head44eeb0c7. The shader writes a compare mask tos21, runs a second compare, then exports the population count ofs21to the render target. The expected count is 32.s20(adjacent)s18(control)Pixel coordinates and alpha also matched on both builds. This confirms the fix reaches the rendered pixels on Ampere. I didn’t measure retail-game frame time in this test.
AI disclosure — Codex GPT-6.2 Sol wrote and ran the test. A separate GPT-6.2 Sol agent checked the fixture and GPU readbacks. GPT-6.2 Astra drafted this comment.
I reviewed and approved this comment before posting.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:03:32Z.
merge-check
base:
d0832e614fhead:
44eeb0c75amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 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 (ps_masks.rs, x64_masks.rs, kernel.rs). The bug is real on main: in a wave32 pixel shader,
v_cmp -> s20kills s21 in both liveness and taint, so an earlier compare into s21 that is read whole later is wrongly givenForm::Own. The fix threadswave64throughvcc_mask/exec_mask/writes/per_lane/run, and every helper reduces to the old constants whenwave64is true, so wave64 output is unchanged. The new test fails on main's logic (liveness-only fix gives [Local, Own], not [None, Own]). The kernel.rs change invalidates the direct DXIL cache as it should. Editing x64_masks.rs also invalidates the HLSL translation cache though HLSL output doesn't change (one recompile). Description: AI use names the tool but not the model (CONTRIBUTING asks for the exact model), and the full suite was left to CI, which has no GPU; this run covers the suite on a GPU.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (40997e6b): 1516 -> 1457 frames shown (96 %, the title presents at 60 per 2 s in both), peak commit 18133 -> 16746 MB, no device removal, no crash.verdict: safe to merge
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 thehollowedone on 2026-12-01T03:40:00Z.
Following the RTX 4090 world replay, I found one confound in the proposed
Form::Localisolation on head44eeb0c7.For every compare that keeps the quad form,
lower_valu.rsORs in the lane's own bit wheneverps_maskscontains any cheap-form site.ballot_ps_local(own_bit, true)does not issue anotherWaveActiveBallot, but it does add lane-dependent shift/OR work. AnOwnorUniformsite is enough to keep that path active even if allLocalsites are disabled. A retained compare can then feedS_CBRANCH_VCCZ, which reads the mask directly.To isolate the world-frame cost, I suggest three otherwise matched wave32 builds: an empty PS form map (the original quad path);
Own/Uniformenabled withLocaldisabled and the retained-compare own-bit OR off; and the same forms with that OR on. Compare generated DXIL and driver/GPU time, then replay the same world segment with isolated caches. If the OR is implicated, check helper-lane and VCCZ/EXEC parity before narrowing its guard; it can be needed when aLocalform has changed EXEC. This is a source-derived experiment, not evidence that the OR causes the RTX 4090 regression.AI use: Codex (GPT-6.2 Sol) checked the current source and public reports; Codex (GPT-6.2 Astra) independently traced the retained-compare path.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T06:40:17Z.
merge-check claim
head:
44eeb0c75aImported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T06:49:36Z.
merge-check claim
head:
44eeb0c75aImported from ivall/xcl. Originally posted by throny on 2026-12-01T06:55:38Z.
merge-check
base:
d0832e614fhead:
44eeb0c75amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; failing: none (25 SKIPPED lines, all GPU tests on this adapter, e.g. no wave64)
review: Read the whole diff (kernel.rs, ps_masks.rs, x64_masks.rs). The pixel-shader mask analysis took wave64 pairs for VCC/EXEC and compare destinations; it now takes the wave width through forms() and uses the width-aware uses helper (exposed from x64_masks), so a wave32 compare no longer kills the neighbouring SGPR in liveness and taint. Wave64 behaviour is unchanged (the existing tests call it with wave64 = true). The new test reproduces the reported pattern for wave32 and checks the forms. Note: this is translator source, so every tester re-translates shaders; no GPU wave32 shader run was done here, only the unit tests.
performance: can change which wave32 pixel shaders get the Local/Own forms (shader code, not frame time by itself); not measured on a title; reasoned only.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report (the diff review is Sonnet's)
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T07:00:35Z.
Merged at the checked head after a combined trial of #3400, #3386, #3393 and #3535 on
maind0832e61(RTX 4080 16 GB,cargo test --workspace --no-fail-fast -- --test-threads=4: 2896 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks: Foniass and ours.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T11:48:15Z.
merge-check claim withdrawn
Our automated merge-check loop claimed this PR and then stopped before posting a check — two loops were running at once and both are now shut down. No check from us is coming, so this claim is void and the head is free for someone else to take.
AI use: an agent posted this withdrawal.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-12-01T11:58:41Z.
I ran the three variants suggested in the retained-compare discussion. Disabling
Form::Localwith the original own-bit OR gave 0.228 fps, against 0.210 fps for the unchanged stack. The three most expensive pixel shaders in this replay are guest wave64 programs running on a wave32 RTX 4090, so I applied each variant to both guest widths.Same Series X save and scripted input on driver 621.40. Release builds on
ff0c364b+ #3318 + #3528 (49eb78ef) + #3535 (44eeb0c7), private XCL caches, same GPU profiler settings. FPS is over 300–540 s. The slowest mesh/PS pair averaged 12.47 ms per two-pass call with Local disabled and 12.62 ms on the unchanged stack. Disabling Local did not restore the historical ~0.75 fps. The OR-off runs ended before the GPU sample, so its in-world timing and helper-lane correctness remain open.AI use: Codex (GPT-6) prepared the diagnostic variants, ran the replays, checked shader widths and drafted this update.