Shaders: the console's waterfall over a first-lane table offset is proven by its shape where the per-lane form can't follow it (a decal pass: 149 group barriers to 41; frames 2.5 to 4 ms shorter where the card is the limit) #458

Merged
KyleS98 merged 1 commit from upstream-pr/458 into main 2026-11-28 19:39:39 +00:00
KyleS98 commented 2026-11-27 22:48:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KyleS98 on 2026-11-27T22:48:16Z.


Out of draft since 28 November. It was in draft for a day because a dark tile-edged patch on a wall in the prologue's cell came in 3 of 5 runs with this. That fault already exists: over a later night of runs it came in 2 of 14 without the change and 4 of 28 with it. The counts, and the card's time by command with and without (27.6 to 24.4 ms a frame), are in the comments.

What

The console compiler loops over a per-lane descriptor like this (wave64 shown):

s_mov_b64 s[8:9], exec           ; save EXEC
s_mov_b64 s[32:33], exec         ; T: lanes still to serve
loop:
  v_readfirstlane_b32 s0, v11    ; first waiting lane's table offset
  v_cmpx_eq_u32 exec, s0, v11    ; EXEC = lanes with that offset
  s_load_dwordx4 s[0:3], s[6:7], s0
  buffer_load_format_x v18, v12, s[0:3], 0 idxen
  s_andn2_wrexec_b64 s[32:33], s[32:33]   ; EXEC = T = T & ~EXEC
  s_cbranch_execnz loop
s_mov_b64 exec, s[8:9]

resource::track turns such a loop into one per-lane load (non-uniform handle) when Tracer::waterfall proves it, but on the title's programs it mostly can't. Unproven, the loop stays a loop. On a host with 32-lane waves, a console wave of 64 runs as two host waves, and every pass of the loop exchanges the first lane's value and the masks between the halves: four group barriers a pass.

This adds Tracer::waterfall_shape, tried only where waterfall refused a table-offset loop. It proves the loop by its exact shape:

  • One block that branches to itself (s_cbranch_execnz), containing nothing but:
    • the first-lane reads, each of a lane value set before the loop;
    • v_cmpx_eq_u32/_i32 of each read with that same lane value, without modifiers;
    • the table loads, s_waitcnt and s_nop;
    • accesses that only read (buffer_load_*, image_load*, image_sample*, image_gather*), under the compares' EXEC;
    • s_andn2_wrexec of a mask T with itself.
  • T is EXEC on every entry to the loop, shown from the phis: from outside, T is a s_mov of the very EXEC value the loop is entered with; on the back edge, both are what the one s_andn2_wrexec wrote.
  • The first-lane value is read nowhere past the loop (made the lane's own, it would differ there).

Anything else in the loop, a store or atomic, another compare, or T not coming from EXEC means no proof, and the loop stays as it is now.

How much it finds

victory translate over the title's 25,760 programs that are emitted, with a temporary print of each refusal (not in this PR):

table-offset waterfall loops
refused by waterfall: compares not shown to select the access's lanes 37,605
refused: retry not shown to keep the waiting lanes 209
refused: split over blocks or nested 6,006
refused: read outside a loop 1,055
of those, proven by their shape 32,106 (31,897 + 209)

The same programs are emitted as without it (14,259 / 2,736 / 8,765), and translate --validate gives the same results as without it for all of them (the 27 + 92 that fail validation fail the same way on main).

Measured

RTX 3090 Ti (driver 616.92), Ryzen 9 9950X3D, Windows 11, victory play, standing in the prologue's cell (4,300 to 4,700 draws a frame), medians of the 5-second frame lines over the last two thirds of a 9-minute run, one build without and one with this commit each time. The first row is main and this PR alone; the other two are my branch, which also has #67, #68 and #69 and main merged:

configuration without with
main 0cef07e alone, --series-s --dlss off --no-framegen-ready 28.5 fps (35.1 ms) 28.7 fps (34.9 ms)
with #68 (the title's own upscaler on Series S), same switches 30.8 fps (32.5 ms) 33.3, 32.9 and 32.0 fps in three runs (30.0 to 31.3 ms)
--series-s --dlss quality --framegen 2 --fg-type fsr (#68 steps aside here) 27.0 rendered, F3 FG: 52.8 30.8 rendered, F3 FG: 62.2

It helps only where the card is the limit. On main alone without DLSS, the Series S profile runs the title's FSR 4 path through the translator, and the thread preparing submissions takes 27 to 28 ms a frame, so the card's savings don't show (28.5 → 28.7). With the title's own upscaler (#68), or with DLSS and frame generation, the card is the limit and the frame gets 2.5 to 4 ms shorter.

A VICTORY_GPU_TIMING=1 run had one program at 4.1 ms of the card's ~27 ms a frame: vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized. It has 27 of these loops. Its DXIL goes from 149 group barriers, 32 WaveReadLaneFirst and 34 WaveActiveBallot to 41, 5 and 7.

The picture in the cell and the opening cutscene looks the same in screenshots: hair, the print on the shirt, the walls, the window, the poster.

Tests

  • 5 new tests in resource.rs:
    • the wave64 form of the existing table-offset test (proven by waterfall as it is);
    • waterfall_shape accepting the console's loop in wave32 and wave64;
    • refusals: other work in the loop, a compare against another lane value, T not from EXEC, the first-lane value read after the loop.
  • cargo test -p victory-shader: 294 passed.
  • cargo test --workspace: everything passes except the two indirect::tests that fail on main too (#67 fixes them).
  • cargo clippy -p victory-shader --all-targets with and without --all-features: no messages.
  • rustfmt --check on resource.rs: the same 9 differences as on main, none in the new code.

Not done

  • I did not find why waterfall's per-lane form fails on these loops. In a synthetic wave64 copy of the existing test it succeeds; in the title's programs these loops sit inside per-lane branches, and the solver cannot relate T and EXEC around the loop there. The shape check sidesteps that rather than fixing it.
  • Upstream VIctory's resource.rs has moved on since this tree took it; I have not checked whether its current proof accepts these loops. Marvisak/VIctory#1253 is related (table loads before the loop), but a different case.

AI-assisted (Claude Code, Claude Opus 5.5); runs on my machine; no game data in the change or the tests.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5534085613 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-27T22:48:16Z. --- > **Out of draft since 28 November.** It was in draft for a day because a dark tile-edged patch on a wall in the prologue's cell came in 3 of 5 runs with this. That fault already exists: over a later night of runs it came in 2 of 14 without the change and 4 of 28 with it. The counts, and the card's time by command with and without (27.6 to 24.4 ms a frame), are in the comments. ## What The console compiler loops over a per-lane descriptor like this (wave64 shown): ``` s_mov_b64 s[8:9], exec ; save EXEC s_mov_b64 s[32:33], exec ; T: lanes still to serve loop: v_readfirstlane_b32 s0, v11 ; first waiting lane's table offset v_cmpx_eq_u32 exec, s0, v11 ; EXEC = lanes with that offset s_load_dwordx4 s[0:3], s[6:7], s0 buffer_load_format_x v18, v12, s[0:3], 0 idxen s_andn2_wrexec_b64 s[32:33], s[32:33] ; EXEC = T = T & ~EXEC s_cbranch_execnz loop s_mov_b64 exec, s[8:9] ``` `resource::track` turns such a loop into one per-lane load (non-uniform handle) when `Tracer::waterfall` proves it, but on the title's programs it mostly can't. Unproven, the loop stays a loop. On a host with 32-lane waves, a console wave of 64 runs as two host waves, and every pass of the loop exchanges the first lane's value and the masks between the halves: **four group barriers a pass**. This adds `Tracer::waterfall_shape`, tried only where `waterfall` refused a table-offset loop. It proves the loop by its exact shape: - **One block that branches to itself** (`s_cbranch_execnz`), containing nothing but: - the first-lane reads, each of a lane value set before the loop; - `v_cmpx_eq_u32`/`_i32` of each read with that same lane value, without modifiers; - the table loads, `s_waitcnt` and `s_nop`; - accesses that only read (`buffer_load_*`, `image_load*`, `image_sample*`, `image_gather*`), under the compares' EXEC; - `s_andn2_wrexec` of a mask T with itself. - **T is EXEC on every entry to the loop**, shown from the phis: from outside, T is a `s_mov` of the very EXEC value the loop is entered with; on the back edge, both are what the one `s_andn2_wrexec` wrote. - **The first-lane value is read nowhere past the loop** (made the lane's own, it would differ there). Anything else in the loop, a store or atomic, another compare, or T not coming from EXEC means no proof, and the loop stays as it is now. ## How much it finds `victory translate` over the title's 25,760 programs that are emitted, with a temporary print of each refusal (not in this PR): | table-offset waterfall loops | | |---|---| | refused by `waterfall`: compares not shown to select the access's lanes | 37,605 | | refused: retry not shown to keep the waiting lanes | 209 | | refused: split over blocks or nested | 6,006 | | refused: read outside a loop | 1,055 | | **of those, proven by their shape** | **32,106** (31,897 + 209) | The same programs are emitted as without it (14,259 / 2,736 / 8,765), and `translate --validate` gives the same results as without it for all of them (the 27 + 92 that fail validation fail the same way on `main`). ## Measured RTX 3090 Ti (driver 616.92), Ryzen 9 9950X3D, Windows 11, `victory play`, standing in the prologue's cell (4,300 to 4,700 draws a frame), medians of the 5-second frame lines over the last two thirds of a 9-minute run, one build without and one with this commit each time. The first row is `main` and this PR alone; the other two are my branch, which also has #67, #68 and #69 and `main` merged: | configuration | without | with | |---|---|---| | `main` `0cef07e` alone, `--series-s --dlss off --no-framegen-ready` | 28.5 fps (35.1 ms) | 28.7 fps (34.9 ms) | | with #68 (the title's own upscaler on Series S), same switches | 30.8 fps (32.5 ms) | 33.3, 32.9 and 32.0 fps in three runs (30.0 to 31.3 ms) | | `--series-s --dlss quality --framegen 2 --fg-type fsr` (#68 steps aside here) | 27.0 rendered, F3 `FG: 52.8` | 30.8 rendered, F3 `FG: 62.2` | **It helps only where the card is the limit.** On `main` alone without DLSS, the Series S profile runs the title's FSR 4 path through the translator, and the thread preparing submissions takes 27 to 28 ms a frame, so the card's savings don't show (28.5 → 28.7). With the title's own upscaler (#68), or with DLSS and frame generation, the card is the limit and the frame gets 2.5 to 4 ms shorter. A `VICTORY_GPU_TIMING=1` run had one program at 4.1 ms of the card's ~27 ms a frame: `vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized`. It has 27 of these loops. Its DXIL goes from 149 group barriers, 32 `WaveReadLaneFirst` and 34 `WaveActiveBallot` to 41, 5 and 7. The picture in the cell and the opening cutscene looks the same in screenshots: hair, the print on the shirt, the walls, the window, the poster. ## Tests - 5 new tests in `resource.rs`: - the wave64 form of the existing table-offset test (proven by `waterfall` as it is); - `waterfall_shape` accepting the console's loop in wave32 and wave64; - refusals: other work in the loop, a compare against another lane value, T not from EXEC, the first-lane value read after the loop. - `cargo test -p victory-shader`: 294 passed. - `cargo test --workspace`: everything passes except the two `indirect::tests` that fail on `main` too (#67 fixes them). - `cargo clippy -p victory-shader --all-targets` with and without `--all-features`: no messages. - `rustfmt --check` on `resource.rs`: the same 9 differences as on `main`, none in the new code. ## Not done - I did not find why `waterfall`'s per-lane form fails on these loops. In a synthetic wave64 copy of the existing test it succeeds; in the title's programs these loops sit inside per-lane branches, and the solver cannot relate T and EXEC around the loop there. The shape check sidesteps that rather than fixing it. - Upstream VIctory's `resource.rs` has moved on since this tree took it; I have not checked whether its current proof accepts these loops. Marvisak/VIctory#1253 is related (table loads before the loop), but a different case. AI-assisted (Claude Code, Claude Opus 5.5); runs on my machine; no game data in the change or the tests.
KyleS98 commented 2026-11-27 23:00:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KyleS98 on 2026-11-27T23:00:39Z.


Don't merge this yet: it changes the picture. I found it after opening the PR, and I'm putting it in draft.

With this commit, the wall to the left of the character in the prologue's cell shows a dark patch with stair-stepped, tile-aligned edges. It comes in some runs and not in others. Measured as the mean brightness of that wall area over the last 12 screenshots of each 9-minute run (the same values in all 12, so it holds for the whole run):

runs with the patch
without this commit (main, and my branch with #67, #68 and #69, with and without DLSS / FSR 3) 0 of 7 (wall about 64)
with it 3 of 5 (wall about 40), including main + this PR alone

The edges look like the work of an 8x8-tile classification. That fits the shader this mostly speeds up (CS_ProjDecalReduceClassification_Scalarized), but I haven't shown that it's that one. Two explanations I can see, not yet told apart:

  1. a loop that the shape check accepts but that is not a plain waterfall, so the per-lane form computes something else; or
  2. the translation is right, and the loops finishing much sooner expose a missing wait between passes, which would explain why it comes in some runs only.

I'll come back with which one it is, or close this. The measurements in the description stand for the frame rate, not for the picture.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229798147 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458#issuecomment-7229798147). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-27T23:00:39Z. --- **Don't merge this yet: it changes the picture.** I found it after opening the PR, and I'm putting it in draft. With this commit, the wall to the left of the character in the prologue's cell shows a dark patch with stair-stepped, tile-aligned edges. It comes in some runs and not in others. Measured as the mean brightness of that wall area over the last 12 screenshots of each 9-minute run (the same values in all 12, so it holds for the whole run): | | runs with the patch | |---|---| | without this commit (`main`, and my branch with #67, #68 and #69, with and without DLSS / FSR 3) | 0 of 7 (wall about 64) | | with it | 3 of 5 (wall about 40), including `main` + this PR alone | The edges look like the work of an 8x8-tile classification. That fits the shader this mostly speeds up (`CS_ProjDecalReduceClassification_Scalarized`), but I haven't shown that it's that one. Two explanations I can see, not yet told apart: 1. a loop that the shape check accepts but that is not a plain waterfall, so the per-lane form computes something else; or 2. the translation is right, and the loops finishing much sooner expose a missing wait between passes, which would explain why it comes in some runs only. I'll come back with which one it is, or close this. The measurements in the description stand for the frame rate, not for the picture. AI-assisted (Claude Code, Claude Opus 5.5).
KyleS98 commented 2026-11-27 23:35:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KyleS98 on 2026-11-27T23:35:29Z.


Correction to my comment above: the dark patch also appears without this PR. A later run of my branch without this commit (--series-s --dlss quality, DLSS frame generation at 6x) shows the same tile-edged patch on the same wall, wall brightness about 40 against about 64, for the whole run.

So it is a fault that already exists and shows up in some runs, not one this PR creates. Counted over every run where that wall is visible:

runs with the patch
without this commit 1 of 10
with it 3 of 5

That may mean this PR makes it more likely (faster passes, a different order somewhere), or it may be chance: with this few runs I can't tell (p ≈ 0.08). I'm keeping this in draft until I have enough runs to say which, and until I know more about the patch itself. As it stands, "this PR breaks the picture" was too strong, and I'm saying so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7230257725 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458#issuecomment-7230257725). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-27T23:35:29Z. --- **Correction to my comment above: the dark patch also appears without this PR.** A later run of my branch *without* this commit (`--series-s --dlss quality`, DLSS frame generation at 6x) shows the same tile-edged patch on the same wall, wall brightness about 40 against about 64, for the whole run. So it is a fault that already exists and shows up in some runs, not one this PR creates. Counted over every run where that wall is visible: | | runs with the patch | |---|---| | without this commit | 1 of 10 | | with it | 3 of 5 | That may mean this PR makes it more likely (faster passes, a different order somewhere), or it may be chance: with this few runs I can't tell (p ≈ 0.08). I'm keeping this in draft until I have enough runs to say which, and until I know more about the patch itself. As it stands, "this PR breaks the picture" was too strong, and I'm saying so here. AI-assisted (Claude Code, Claude Opus 5.5).
KyleS98 commented 2026-11-28 11:03:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KyleS98 on 2026-11-28T11:03:25Z.


More runs, and the timing this change was missing. Same PC as before (RTX 3090 Ti, driver 616.92, Ryzen 9 9950X3D, Windows 11), Series S profile, the prologue's cell, hands off, 4 to 5 minutes each, 28 November. The branch here is still dad477d; the runs were made with this commit cherry-picked onto a4d05e7 (it applies cleanly).

The dark wall patch does not follow this change. Over one night of runs, counting the patch by the brightness of that wall in each run's last screenshots:

runs with the patch
without this commit 14 2
with this commit 28 4

Both one run in seven. The runs differ in other switches (they were made for something else: thread and lock work), so this is a count over a mixed set, not a controlled pair; what it shows is that the patch turns up at the same rate either way, as the single run without the commit already suggested. One thing that did seem to bring it more often, and has nothing to do with this PR: VICTORY_JOIN_PARTS=16 VICTORY_JOIN_LISTS=96, 3 runs of 5.

What it saves on the card, from a timing run on diagnostics builds (VICTORY_GPU_TIMING=1, each command timed on its own, per frame):

without with
all of the title's commands 27.6 ms 24.4 ms
indirect executions (3,910) 14.7 ms 11.5 ms
dispatches (2,542) 9.2 ms 9.2 ms
vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized (1f1fbd86759b3da2) 3.5 ms not among the 40 dearest (under 0.11 ms)

That one program's translation goes from 149 group barriers to 40 (counted in the DXIL with dxc -dumpbin). The two programs that still carry hundreds are cascadeshadows_classify:CS_WriteRasterClassificationResults and CS_CalcRasterClassificationListCounts (418 and 428 barriers, 0.28 and 0.24 ms a frame here); their loops are not of the shape this checks.

Frame rate, the pair of builds from before, three runs each, DLSS off: 31.0, 31.0, 31.0 without and 31.3, 32.2, 32.5 with; the wall right in all six. How much of the 3 ms shows as frames depends on whether the card or the preparing thread is the limit on a given PC.

With that I am taking it out of draft. I know pull requests are on hold; no hurry from my side.

AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7238297700 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458#issuecomment-7238297700). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-28T11:03:25Z. --- More runs, and the timing this change was missing. Same PC as before (RTX 3090 Ti, driver 616.92, Ryzen 9 9950X3D, Windows 11), Series S profile, the prologue's cell, hands off, 4 to 5 minutes each, 28 November. The branch here is still `dad477d`; the runs were made with this commit cherry-picked onto a4d05e7 (it applies cleanly). **The dark wall patch does not follow this change.** Over one night of runs, counting the patch by the brightness of that wall in each run's last screenshots: | | runs | with the patch | |---|---:|---:| | without this commit | 14 | 2 | | with this commit | 28 | 4 | Both one run in seven. The runs differ in other switches (they were made for something else: thread and lock work), so this is a count over a mixed set, not a controlled pair; what it shows is that the patch turns up at the same rate either way, as the single run without the commit already suggested. One thing that did seem to bring it more often, and has nothing to do with this PR: `VICTORY_JOIN_PARTS=16 VICTORY_JOIN_LISTS=96`, 3 runs of 5. **What it saves on the card**, from a timing run on diagnostics builds (`VICTORY_GPU_TIMING=1`, each command timed on its own, per frame): | | without | with | |---|---:|---:| | all of the title's commands | 27.6 ms | 24.4 ms | | indirect executions (3,910) | 14.7 ms | 11.5 ms | | dispatches (2,542) | 9.2 ms | 9.2 ms | | `vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized` (1f1fbd86759b3da2) | 3.5 ms | not among the 40 dearest (under 0.11 ms) | That one program's translation goes from 149 group barriers to 40 (counted in the DXIL with `dxc -dumpbin`). The two programs that still carry hundreds are `cascadeshadows_classify:CS_WriteRasterClassificationResults` and `CS_CalcRasterClassificationListCounts` (418 and 428 barriers, 0.28 and 0.24 ms a frame here); their loops are not of the shape this checks. **Frame rate**, the pair of builds from before, three runs each, DLSS off: 31.0, 31.0, 31.0 without and 31.3, 32.2, 32.5 with; the wall right in all six. How much of the 3 ms shows as frames depends on whether the card or the preparing thread is the limit on a given PC. With that I am taking it out of draft. I know pull requests are on hold; no hurry from my side. AI-assisted (Claude Code, Claude Fable 5.2).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!458
No description provided.