Shaders: a folded program reads the joins of its lane masks (the particle light atlas ran to the loop limit) #2853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2853"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by wutzebaer on 2026-11-29T18:08:51Z.
What it changes
A folded wave64 compute program reads its EXEC pair as a number wherever the console reads a first lane (
s_cmp_lg_u32 E.lo, 0: which half holds the first lane). Where that pair came through a join that only a loop header's join reads, the join was not marked as read, and its incoming masks became zero without a word. That is the shortcutVICTORY_STRICT_JOINSnames infill_phis.From the second iteration on, the read then said "no lane in the lower half". It took the upper half's first lane, and with no lane there a stale value.
In
ptfx_CS_lightAtlas_Sprite(2561af9577c47289) the counter of the loop over the light mask's words is read that way. In every wave of 32 sprites or fewer:The host code showed it directly: the loop header's join of that mask had the ballot on the entry edge and the constant 0 on the back edge.
The change: in folded programs the joins of lane masks are read too, whatever the switch. A mask has a DXIL form, the ballot of its lanes. Other joins keep the shortcut, so nothing else changes.
Of the title's 26,084 programs, 18 come out otherwise, all folded:
ptx_prerender:ptfx_CS_lightAtlas_Sprite,_Trailshadowmask:CS_GenerateShadowMasks*,CS_TraceShadowRays_Fullwater_shading:CS_TransmissionVolumetrics*scattering_transmittance_system:CS_Gather,_ReferenceGpuParticleUpdate:CS_Update*ParticlesAll 26,084 still translate (
victory translate --listbefore and after, compared by the emitted hashes).How it was tested
VICTORY_GPU_TIMES: 45-68 ms of it in2561af9577c47289, the longest command about 80 ms); frame 78-112 ms.VICTORY_STRICT_JOINS=1on that one program the result is the same; the switch itself stays as it is.cargo testpassed for the crates it touches: yes (cargo test -p victory-shader --lib: 462 passed, 9 ignored, on the RTX 5090).cargo clippy -p victory-shader --all-targets -- -D warningsstops at four findings that are onmainalready and in lines this does not touch (lower/analysis.rs:6,lower/analysis.rs:467,lower.rs:594,native.rs:1655).No regression test is in this change. A folded program with a first-lane read in a loop whose EXEC pair passes a join before the back edge, run with lanes in the lower half only, would be one; I can add it if wanted.
Checked for overlap
emit/lower.rselsewhere.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cadfan on 2026-11-30T05:57:23Z.
Tested on an RTX 5080: this fixes the strip-club hang in the Delight robbery mission (#3623) here.
Setup: RTX 5080 16 GB (driver 621.24), Ryzen 7 7800X3D, 64 GB RAM, Windows 11 26200.
41adb551plus #3043 and #3487, Series X, DLSS Performance, DLSS frame generation 2x. Diagnostics build withVICTORY_D3D12_DRED=lightandVICTORY_CARD_METER_PIPELINES=1, same save both times.Before (without this PR): the card hung (0x887A0006) after 6.5 minutes in the club, before the stage. The card meter showed the light atlas growing until it did:
compute 2561af9577c47289compute cabb87599722e59aEach was one dispatch a frame. DRED put the stop in another list (command 599 of 998, with
compute 0452fc2d2e2fc4c3and9146291b38ea9ce1in flight between the same barriers), so the atlas looks like what drove the frame into the hang rather than the command that hung.After (this PR merged, nothing else changed): 24 minutes, the whole club scene including the dance, closed normally. Across 262 card-meter readings (256 frames each), neither
2561af9577c47289norcabb87599722e59awas ever among the largest pipelines. The card's time in the title's lists peaked at 58 ms. In the club it was 18-27 fps with "on the GPU" at 1-5 ms (median per minute), where the earlier release run sat at 4 fps with 185-234 ms.Release build too: same merge,
releaseprofile, translates and prepares cleanly (5,344 pipelines, 1 without a host pipeline, as before).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T06:11:31Z.
Checked this against a Radeon gfx1036 (RDNA 2) running the same kernels natively in wave64, and ran the folded form for main and for this PR on an RTX 5080 and on that Radeon through D3D12.
Setup
mainat41adb551with this PR's head (bd9ffc5) merged locally, no conflict. The victory-shader test binary was built from that merged tree (own tree and target directory).super::folded(the two-lanes-per-host-lane rewrite),dxil.dllvalidation, dispatched on the 5080 and on the Radeon (VICTORY_ADAPTER=radeon). Alsosuper::emitwith 32 host lanes (both cards) and 64 (Radeon).Cases
counter_loop/<lo20|all|up40>andcounter_loop2/*: a loop whose exit reads a VGPR counter throughv_readfirstlane_b32(s_cmp_lt_u32 s40, 7), with ans_and_saveexec_b64/s_cbranch_execz/s_or_b64 execif inside the loop (EXEC written in the loop, so the header joins the EXEC pair) and another if before the loop (the pair's entry value comes through a join). Lanes taking part: below 20 (lower half only, "32 or fewer"), all 64, or 40..51 (upper half only). An iteration guard stops it at 40 rounds. v10 = per-lane hits (1 in each lane taking part), v11 = rounds (7), v12 = the last counter read (7), v13 = the value from the if before the loop.counter_loop2restores EXEC inside both arms of each if (so the merges join two different EXEC values) and has no vector instruction between the loop's inner merge and its back edge, so that merge's EXEC reaches only the loop header's join (9 rounds, last counter 8).waterfall/<mixed|upper_only|sparse>: av_readfirstlane_b32waterfall (v_cmp_eq_u32,s_and_saveexec_b64,s_xor_b64 exec,s_cbranch_execnz) with a scalar counter read after the loop (5, 3, 5 rounds on the hardware).restore_exec/*,join_leader*/*,permute*,saveexec_forms.Results (values that differ from the gfx1036, out of 64 lanes x outputs)
counter_loop/lo20,/all,/up40counter_loop2/lo20,/all,/up40waterfall/mixedwaterfall/sparsewaterfall/upper_onlyOver 30 wave64 cases (27 in all five host forms, the three
counter_loop2in four) and the 24 wave32 cases (two host forms), this PR changed no value anywhere compared with main. The waterfall difference is the counter after the loop (the gfx1036 has 5 / 5 / 3 in every lane; the folded form gives each lane the round it left in, e.g. 4 in the even lanes ofmixed); #2265 makes those three exact in the folded form.Verdict: not reproduced, no regression. None of my loops shows the zeroed join on main: the folded form already gets the counter loops right on both cards, with the lanes in the lower half only (lanes 0..19, the "32 or fewer" case), in the upper half only, or all 64, and with or without a join of two EXEC values feeding the loop header. This PR changes no value in any case, so it is safe on this set, but I cannot confirm the fix from hand-written code. A loop shape that does fail on main (written by hand, not taken from a title) would let me measure it against the gfx1036.
Outside this PR: with
super::emit(both cards, 32 and 64 host lanes)counter_loop/lo20and/up40give v11 = 40 (the iteration guard) and v12 = 0 in the half with no lane taking part, where the hardware has 7 and 7 in every lane; main and this PR alike.AI use: Claude Code (Claude Opus 5.5) ran the oracle and host cases and wrote this comment.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by SergDi on 2026-11-30T06:32:33Z.
@Lyrnc, I have a synthetic loop that does reproduce the zeroed join on an RTX 4080. The test patch below contains no title data and no production fix.
The distinguishing shape keeps SCC live across the back edge: the loop header reads an EXEC-mask phi whose incoming value is another mask phi, read only by that header. Bounding initial EXEC with both a lower and an upper limit prevents upper-half lanes from accidentally making the broken version pass. The CPU test asserts that the intended phi chain survives folding.
Windows evidence: RTX 4080 16 GB, driver 610.88, pinned Rust 1.98.1. Actual test base was
f72cec7714aa6d6e274b761fb6fa40bfcf44243bplus this test; GREEN adds this PR'sbd9ffc513c7479393119abb816ebb133b46952dbdiff. These are not runs on current main or on the exact PR head.lane 0, first active lane's count, left 0 / right 4; hardware execution was recorded.[(32, 0)]on the back edge; restoring it passes.The GPU helper can return early without an adapter; check for
ran on the hardware device, not just a passing test. Strict Clippy still fails the same four baseline findings; no new diagnostics from this patch. I have not measured an in-game FPS benefit from this fix.AI assistance: Codex and Claude prepared/reviewed the synthetic tests; the reported Windows results were collected on the physical machine.
pr2853-test.patch
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wutzebaer on 2026-11-30T07:07:34Z.
Thanks for testing, all three.
@SergDi, I added your synthetic loop to this PR as
f080d07a(both tests, unchanged). Here on an RTX 5090 (driver 621.40), on the PR branch:lower.rsas before this PR) the CPU test fails witha 32-bit join takes zero over the back edge (the mask join left unread): [(32, 0)]; with the fix it passes.a_folded_first_lane_loop_counts_through_a_mask_join_on_its_back_edgeran on the hardware device and passes for all five masks in both folded forms.cargo test --locked --release -p victory-shader --lib: 465 passed, 0 failed, 9 ignored.@cadfan, good to know it also takes the light atlas out of the picture in the club; here it was the same pair of pipelines outdoors at night (
2561af9577c47289at 60-80 ms a dispatch before, gone from the card meter after).@Lyrnc, that matches what I saw: the zero only appears when the mask join on the back edge is read by nothing but the header's join, which is the shape SergDi's loop builds.
The CI run on the first commit failed without starting a job ("workflow file issue");
ci.ymlon this branch is the same as on main, and no run has started forf080d07ayet.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ramsody on 2026-11-30T12:05:26Z.
Tested on another RTX 5090, this time on Windows 10. With this PR,
2561af9577c47289no longer appears in the card meter rows, and neither of my two runs had a log line below 8 fps. The full report and three before/after logs are in #3933.Setup: RTX 5090 (driver 617.42), Core Ultra 7 270K Plus, 64 GB, Windows 10 22H2. v2026.11.29.05 (
41adb551) +f080d07a, merged with no conflicts. Series X, 2560x1440, frame generation and ray tracing off.2561af9577c47289Tests on this card: your new loop test passed with 10 runs on the hardware device. All 19
folded_tests passed, with none skipped.Windows 10 note: a plain
cargo testprintedno SM 6.6 hardware device; not runfor the GPU tests, but still reported them asok. To really run them, I used a copy of the test exe with the D3D12 SDK 614 exports added andD3D12\D3D12Core.dllbeside it.Limits: this was not a controlled route. I have not confirmed that the "after" runs include the same spot at the petrol station at night, so the whole FPS difference should not be credited to this PR. The game was stable, with no crashes or device-removed errors in the logs. I did not specifically check shadows, water, smoke or particles for visual changes, and I did not compare this PR with the other proposed fixes.
Thank you for finding and fixing this. I would like to see it, or another verified fix for this problem, in the next release.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-11-30T12:23:09Z.
I reran the checked-in mask-join regressions, using the same Windows WARP 1.0.22 runtime and DXIL validator on both sides. The baseline is current
41adb551with only the test commitf080d07aapplied ase40f1b8. The fixed build is GitHub's exact merge of this PR into41adb551,7ae8b24.[(32, 0)]I counted ten completed WARP dispatch confirmations on the fixed run and zero adapter skips. All 19
folded_tests also passed. The harness printsran on the hardware devicefor the forced software adapter too. I setVICTORY_WARP=1, which selects DXGI's software adapter in this harness.@Ramsody, your Windows 10 results in #3933 complement the synthetic check. If you can repeat the same petrol-station checkpoint at night with identical DLSS settings on .05 and this PR, that would give a route-matched measure of the FPS and GPU-wait changes.
AI-assisted with OpenAI Codex.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wutzebaer on 2026-12-01T10:09:59Z.
Closing this: both commits are in
mainnow, unchanged, through #3871 (b8f365adandf1e2a0cd), so there is nothing left for this PR to add. The conflict it shows is only the test file, which already holds the same tests.Thanks to everyone who tested it: cadfan for the club run, Lyrnc for the comparison against the Radeon running the kernels natively, SergDi for the synthetic loop, Ramsody for the Windows 10 runs and andrewpozdnakov7-jpg for the WARP check.
Pull request closed