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

Open
github-bot wants to merge 1 commit from github-bot/gh-458 into main AGit
Owner

@⁠KyleS98 on GitHub · 2026-11-27 22:48 UTC · original
KyleS98:waterfall-shape → main · +346 −1 · 1 files · 1 commits · draft

Draft. A dark tile-edged patch on a wall in the prologue's cell came in 3 of 5 runs with this and 1 of 10 without it: a fault that already exists, which this may or may not make more likely. Details in the comments; draft until that is known.

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** on GitHub · 2026-11-27 22:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458) `KyleS98:waterfall-shape` → `main` · +346 −1 · 1 files · 1 commits · draft > **Draft.** A dark tile-edged patch on a wall in the prologue's cell came in 3 of 5 runs with this and 1 of 10 without it: a fault that already exists, which this may or may not make more likely. Details in the comments; draft until that is known. ## 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.
The console compiler loops over a per-lane descriptor by reading the
first active lane's table offset, narrowing EXEC to the lanes with the
same one, loading that entry and dropping those lanes. `track` makes each
lane load its own entry when `Tracer::waterfall` proves the loop. In the
title's programs it mostly cannot: over all 25,760 programs it emits,
44,874 such loops were refused, 37,605 of them because the per-lane form
could not show that the compares select the access's lanes and 209
because it could not show that the retry keeps the lanes still waiting.
In a wave of 64 run as two host waves of 32, every pass of an unproven
loop exchanges the first lane's value and the mask between the halves:
four group barriers a pass.

`Tracer::waterfall_shape` proves the loop by its exact shape instead,
only where `waterfall` refused: one block that branches to itself, with
nothing in it but the first-lane reads, `v_cmpx_eq` of each with the
same lane value, the table loads, waits, accesses that only read, and
`s_andn2_wrexec` of a mask T with itself. T is shown to be EXEC on every
entry from the phis (a move of the loop's own entry EXEC from outside;
the same retry on the back edge), and the first-lane value is read
nowhere past the loop.

It proves 32,106 of the refused loops. The same programs are emitted as
before, and the DXIL validator gives the same results as before for all
of them.

Measured in the prologue's cell (RTX 3090 Ti, Series S profile, one run
each way unless said): where the card is the limit the frame gets 2.5 to
4 ms shorter. With the title's own upscaler (#68), 30.8 fps before and
33.3, 32.9 and 32.0 after; with DLSS Quality and FSR 3 frame generation,
27.0 rendered before and 30.8 after. On main alone without DLSS, where the
translated FSR 4 path keeps the preparing thread at 27 to 28 ms a frame,
28.5 before and 28.7 after. The costliest program of the frame,
vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized
(4.1 ms a frame in a timing run), has 27 such loops; its DXIL goes from
149 group barriers to 41.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 22:49:27 +00:00
Author
Owner

@⁠KyleS98 on GitHub · 2026-11-27 23:00 UTC · original

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** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458#issuecomment-7229798147) **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).
Author
Owner

@⁠KyleS98 on GitHub · 2026-11-27 23:35 UTC · original

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** on GitHub · 2026-11-27 23:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/458#issuecomment-7230257725) **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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/458/head:github-bot/gh-458'
git switch 'github-bot/gh-458'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-458'
git switch 'github-bot/gh-458'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-458'
git switch 'github-bot/gh-458'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-458'
git switch 'main'
git merge --squash 'github-bot/gh-458'
git switch 'main'
git merge --ff-only 'github-bot/gh-458'
git switch 'main'
git merge 'github-bot/gh-458'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.