Skip to content

Recompiler: use wave32 register width in direct PS mask analysis - #3535

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/2571-ps-masks-wave32
Dec 1, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/2571-ps-masks-wave32

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the wave32 register-width bug in recomp::ps_masks introduced by #2571 (1183cd437), reported by @CharlyRien.

Root cause: ps_masks::forms() called x64_masks::whole_live_out(insts, false) and x64_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 writing sN was treated as killing s(N+1) in both liveness and forward taint. An earlier compare writing s(N+1) that is still read whole later (e.g. by s_bcnt1, s_and_saveexec_b32, or a branch/loop) could therefore be misclassified as Form::Own (no WaveActiveBallot) or have its taint prematurely cleared.

Fix:

  • Expose x64_masks::uses_for_width and x64_masks::whole_live_out_for_width.
  • Pass o.wave64 from dxil::kernel into ps_masks::forms(insts, o.wave64).
  • Thread wave64 through ps_masks (vcc_mask, exec_mask, writes, per_lane, subset_after, live_subsets, run) so wave32 compares and SAVEEXEC/WREXEC use single-SGPR widths.
  • Add wave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taint covering @CharlyRien's v_cmp -> s21, v_cmp -> s20, s_bcnt1 s21 sequence and s_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::Local on EXEC branches/loops is also involved).

Regression run

Baseline (main):

xcl-smoke v1
commit: 91244db94d2f402237c6a8e428dbe5da07673c48
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1514 (PresentX 1514)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15133 MB

PR head:

xcl-smoke v1
commit: 44eeb0c75acb0b1d55961fbee4c7f6f14e4cf028
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1708 (PresentX 1708)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 17453 MB

Tested

  • cargo test -q -p xcl --lib gpu::recomp::ps_masks::tests -- --test-threads=1 (4 passed, 0 failed, including the new wave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taint).
  • cargo test -q -p xcl --lib ps_ballot_tests -- --test-threads=1 on Windows 11 + RTX 5070 Ti (8 passed, 0 failed).
  • 60 s title smoke on RTX 5070 Ti (44eeb0c75 vs 91244db94): 1708 frames (61/60/60 per 2 s), 0 device removals, 0 crashes, 17453 MB peak commit.

Not tested

  • 600 s RTX 4090 Series X world replay to verify whether this lifts @minimalhipster990's 0.75 -> 0.20 fps drop.
  • Full cargo test --workspace locally (covered by CI).

AI use

  • Antigravity assisted with auditing ps_masks.rs / x64_masks.rs, implementing the width-aware fix and wave32 unit tests, running local tests and smoke, and writing this description.

PR xcl-dev#2571 (1183cd4) called x64_masks::whole_live_out(insts, false) and x64_masks::uses(d) inside ps_masks::forms(), both of which assume wave64 register pairs. On wave32 pixel shaders (all non-split PS on wave32 NVIDIA GPUs), a compare writing sN was treated as killing s(N+1) in both liveness and forward taint, allowing an earlier compare into s(N+1) that is still read whole (e.g. by s_bcnt1, s_and_saveexec_b32, or a branch/loop) to be misclassified as Form::Own (no ballot) or have its taint cleared.

Expose x64_masks::uses_for_width and x64_masks::whole_live_out_for_width, pass o.wave64 from dxil::kernel into ps_masks::forms(), and use single-SGPR widths for VCC/EXEC/per-lane/writes in wave32 mode. Reported by CharlyRien on xcl-dev#2571.
@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 30, 2026
@Aniseto

Aniseto commented Nov 30, 2026

Copy link
Copy Markdown

Ran the ps_masks module tests and the pixel-shader ballot tests at 44eeb0c7 on 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.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu::recomp::ps_masks::tests -- --test-threads=1
4 passed; 0 failed; 0 ignored; 2766 filtered out      (exit 0)

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib ps_ballot_tests -- --test-threads=1
8 passed; 0 failed; 0 ignored; 2762 filtered out      (exit 0)

Both counts match the description at this exact head: the four ps_masks tests, including the new wave32 neighbour-SGPR case, and the eight ps_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.

@vasanex

vasanex commented Nov 30, 2026

Copy link
Copy Markdown

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 44eeb0c75acb0b1d55961fbee4c7f6f14e4cf028 on main 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b, in a separate worktree. The PR is based on this main, so the merged tree (fb0db1e8cbfe2f3a36222f3d304c67cc4437696b) is the head's own tree. No XCL_* 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: ok
  • cargo test --workspace --no-fail-fast -- --test-threads=4
passed failed ignored SKIPPED lines
main with this PR 2886 1 51 25
main without it 2885 1 51 25
  • The same test fails in both runs: gpu::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. Tests: name the trailing VGPRs in the D16 resinfo kernel test #3513 is about this test.
  • The same tests are skipped in both runs: 22 lines for no wave64, 2 for no heap windows, and 1 because the driver cache could not be disabled. None of them is a ps_masks or ps_ballot_tests test.
  • The test this PR adds (wave32_compare_does_not_kill_neighbor_sgpr_in_liveness_or_taint), the other 3 ps_masks tests and the 8 ps_ballot_tests passed.
  • With the width ignored inside ps_masks::forms() (one added line that sets wave64 to true, removed afterwards), cargo test -p xcl --lib -- ps_masks::tests --test-threads=1 gives 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:

AI use: Claude Code (Claude Opus 5.5) ran the builds and tests, and wrote and posted this report.

@minimalhipster990

Copy link
Copy Markdown

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

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.

tree run frames/s
+ #3528 + this PR cache build 0.22 · 0.20 · 0.22 · 0.20 · 0.22
+ #3528 + this PR measured 0.19 over 240–350 s, then the device removal at 356 s
+ #3528 cache build 0.20 · 0.18 · 0.20 · 0.18 · 0.20
+ #3528 measured 0.23 · 0.22 · 0.23 · 0.22 · 0.22
for reference: c9aa9f8a (#3499 merged, #2571 not yet) measured 0.73 · 0.75 · 0.75 · 0.72 · 0.63

Device removal in the measured run with this PR

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.

@Gevroska

Copy link
Copy Markdown

I tested the adjacent-register case on my RTX 3080 (driver 32.0.16.1692) with the same 32×32 pixel shader test on parent 9dfbe3ea and PR head 44eeb0c7. The shader writes a compare mask to s21, runs a second compare, then exports the population count of s21 to the render target. The expected count is 32.

Second compare writes to Parent PR head
s20 (adjacent) All 1,024 pixels returned 1 All 1,024 returned 32
s18 (control) All 1,024 returned 32 All 1,024 returned 32

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.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 44eeb0c
merge: 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 -> s20 kills s21 in both liveness and taint, so an earlier compare into s21 that is read whole later is wrongly given Form::Own. The fix threads wave64 through vcc_mask / exec_mask / writes / per_lane / run, and every helper reduces to the old constants when wave64 is 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 d0832e6 vs 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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Following the RTX 4090 world replay, I found one confound in the proposed Form::Local isolation on head 44eeb0c7.

For every compare that keeps the quad form, lower_valu.rs ORs in the lane's own bit whenever ps_masks contains any cheap-form site. ballot_ps_local(own_bit, true) does not issue another WaveActiveBallot, but it does add lane-dependent shift/OR work. An Own or Uniform site is enough to keep that path active even if all Local sites are disabled. A retained compare can then feed S_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/Uniform enabled with Local disabled 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 a Local form 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.

@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 44eeb0c

1 similar comment
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 44eeb0c

@throny

throny commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: 44eeb0c
merge: 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)

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny
throny merged commit 7d86c5d into xcl-dev:main Dec 1, 2026
3 checks passed
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merged at the checked head after a combined trial of #3400, #3386, #3393 and #3535 on main d0832e61 (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).

@brainhay5

Copy link
Copy Markdown

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.

@minimalhipster990

Copy link
Copy Markdown

I ran the three variants suggested in the retained-compare discussion. Disabling Form::Local with 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.

Direct PS variant Result on the 4090
Empty form map Device hung before world entry at 98.1 and 90.0 s
Own + Uniform, Local disabled, retained OR off Device hung before world entry at 83.7 and 92.2 s
Same forms, original retained OR Both runs reached the world and finished 600 s. Measured run had 54 presents in 236.9 s
Unchanged stack 50 presents in 238.5 s in the measured repeat

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.

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) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants