GPU: run the relay at stage 2 by default #187

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

@⁠cblomert on GitHub · 2026-11-24 22:20 UTC · original
cblomert:gpu/relay-default → main · +48 −11 · 4 files · 1 commits · draft

Turns the relay (VICTORY_RELAY) on at stage 2 by default. In the world it cut the frame from about 230 to 132 ms on an RTX 4090, and a 30-minute run with it had no error or crash. VICTORY_RELAY=0 turns it off, 1 selects the first stage.

What is in it

  • crates/victory-gpu/src/shadow.rs: relay_level() reads VICTORY_RELAY in one place (unset or any other value: 2; 1; 0: off); relay() uses it; unit test for the parsing.
  • crates/victory-gpu/src/host.rs: relay_exact() uses relay_level(); doc comments say what the default is.
  • crates/victory-gpu/src/resource.rs: buffer_data_reaches_the_host_texture checked that the title's list still held the texture after the submission. With the relay the submission takes the host list and the flight lets it go once the card has run it (execute_late → relay thread → land/recycle), which on a fast card is before the check: the test failed 2 runs in 3. The hold is now checked before the submission, where both paths keep it, and after it only when the submission is waited for (!host::late()). Letting it go after the fence is safe: the read-backs are done before, and the texture's state lives in HostTexture, not in the list.
  • README.md: the relay is no longer listed among the switches that are off by default.

Tested

  • RTX 4090 (driver 621.40), i9-13900K, 128 GB, Windows 11 Pro 26200, rustc 1.98.1, release build for the game runs.

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean. With --all-features: clean.

  • cargo test --workspace --locked --no-fail-fast: 495 passed, 2 failed, 7 ignored. The two failures are emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole ("Container part 'Pipeline State Validation' does not match"): they fail the same way on main (4e17478) without this change (issue #12; #61 addresses it). No GPU test skipped.

  • buffer_data_reaches_the_host_texture: 10 of 10 runs pass with the default; passes with VICTORY_RELAY=0.

  • The title, world reached (first mission), median of 36 samples of the window title between 6 and 9 minutes after the start, the Enter pressed 60 s in:

    ms/frame fps card busy
    relay off 230.2 (best 222, worst 255) 4.3 51 %
    VICTORY_RELAY=2 132.0 (best 126, worst 147) 7.6 79 %
    VICTORY_RELAY=2 VICTORY_WIDE_BACK=1 134.2 7.5

    (on main plus 21 open PRs of this repository merged locally; the relay code is the same as on main apart from #71.) Card busy from the frame line "the card's clock per frame".

  • 30 minutes with VICTORY_RELAY=2 in the world: no ERROR line, no panic, no crashes.log entry, private memory steady at 24-25 GB.

Not tested

  • AMD and Intel GPUs, cards with less VRAM, Windows 10, Linux/Proton.
  • Runs longer than 30 minutes, other parts of the game than the first mission.

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the test fix and this description, ran the builds, tests and game runs, and opened this PR at the account owner's request.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lj18ajyo1buNyoZcYjnZYC

**@⁠cblomert** on GitHub · 2026-11-24 22:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/187) `cblomert:gpu/relay-default` → `main` · +48 −11 · 4 files · 1 commits · draft Turns the relay (`VICTORY_RELAY`) on at stage 2 by default. In the world it cut the frame from about 230 to 132 ms on an RTX 4090, and a 30-minute run with it had no error or crash. `VICTORY_RELAY=0` turns it off, `1` selects the first stage. **What is in it** - `crates/victory-gpu/src/shadow.rs`: `relay_level()` reads `VICTORY_RELAY` in one place (unset or any other value: 2; `1`; `0`: off); `relay()` uses it; unit test for the parsing. - `crates/victory-gpu/src/host.rs`: `relay_exact()` uses `relay_level()`; doc comments say what the default is. - `crates/victory-gpu/src/resource.rs`: `buffer_data_reaches_the_host_texture` checked that the title's list still held the texture *after* the submission. With the relay the submission takes the host list and the flight lets it go once the card has run it (`execute_late` → relay thread → `land`/`recycle`), which on a fast card is before the check: the test failed 2 runs in 3. The hold is now checked before the submission, where both paths keep it, and after it only when the submission is waited for (`!host::late()`). Letting it go after the fence is safe: the read-backs are done before, and the texture's state lives in `HostTexture`, not in the list. - `README.md`: the relay is no longer listed among the switches that are off by default. **Tested** - RTX 4090 (driver 621.40), i9-13900K, 128 GB, Windows 11 Pro 26200, rustc 1.98.1, release build for the game runs. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. With `--all-features`: clean. - `cargo test --workspace --locked --no-fail-fast`: 495 passed, 2 failed, 7 ignored. The two failures are `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole` ("Container part 'Pipeline State Validation' does not match"): they fail the same way on `main` (4e17478) without this change (issue #12; #61 addresses it). No GPU test skipped. - `buffer_data_reaches_the_host_texture`: 10 of 10 runs pass with the default; passes with `VICTORY_RELAY=0`. - The title, world reached (first mission), median of 36 samples of the window title between 6 and 9 minutes after the start, the Enter pressed 60 s in: | | ms/frame | fps | card busy | |---|---|---|---| | relay off | 230.2 (best 222, worst 255) | 4.3 | 51 % | | `VICTORY_RELAY=2` | 132.0 (best 126, worst 147) | 7.6 | 79 % | | `VICTORY_RELAY=2 VICTORY_WIDE_BACK=1` | 134.2 | 7.5 | | (on `main` plus 21 open PRs of this repository merged locally; the relay code is the same as on `main` apart from #71.) Card busy from the frame line "the card's clock per frame". - 30 minutes with `VICTORY_RELAY=2` in the world: no `ERROR` line, no panic, no `crashes.log` entry, private memory steady at 24-25 GB. **Not tested** - AMD and Intel GPUs, cards with less VRAM, Windows 10, Linux/Proton. - Runs longer than 30 minutes, other parts of the game than the first mission. **AI use** - Claude Code with Claude Opus 5.5: wrote the change, the test fix and this description, ran the builds, tests and game runs, and opened this PR at the account owner's request. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Lj18ajyo1buNyoZcYjnZYC
The relay (VICTORY_RELAY) lands what shaders wrote on a thread of its own
while the submitting thread prepares the next submissions; stage 2 waits
only for the flights that declared memory a submission reads. It was off
unless switched on. In the world of the test title on an RTX 4090 the
frame went from about 230 to 132 ms with VICTORY_RELAY=2 (the card busy
about 79 % of the frame instead of 51 %), and a 30-minute run with it
had no error or crash at a steady 24-25 GB.

VICTORY_RELAY is now read in one place (shadow::relay_level): unset or
any other value means stage 2, `1` the first stage, `0` turns it off.

The test buffer_data_reaches_the_host_texture checked that the title's
list still held the texture after the submission. With the relay the
submission takes the host list and the flight lets it go once the card
has run it, which on a fast card can be before the check: the hold is
now checked before the submission, where both paths keep it, and after
it only when the submission is waited for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lj18ajyo1buNyoZcYjnZYC
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:49 +00:00
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-25 00:23 UTC · original

Thanks @⁠cblomert. I ran this on Linux (RTX 4080, Proton Experimental, 200 s per run at the prison cell window, nobody touching the pad). The tree was 2119b0e with this PR, #80, #343, #256, #95, #231 and #257. The speed-up holds here too: 250 to 275 ms per frame with the default stage 2, against 335 to 372 ms with VICTORY_RELAY=0.

Stage 2 changes the picture, though. The cell's left wall is not drawn in either of the two stage-2 runs, and the sky shows through where it should be. With VICTORY_RELAY=0 and the same binary it is there. Both kinds of run kept #80's texture upload inside the list, which brings the wall back otherwise (details on #80). I have not found the cause. One candidate is the in-flight staging overwrite that #141 and #272 deal with.

That is three runs in total, so take it as a lead rather than a proof. Still, it seems worth a check before stage 2 becomes the default.

**@⁠brunofgmag** on GitHub · 2026-11-25 00:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/187#issuecomment-7148464424) Thanks @⁠cblomert. I ran this on Linux (RTX 4080, Proton Experimental, 200 s per run at the prison cell window, nobody touching the pad). The tree was `2119b0e` with this PR, #80, #343, #256, #95, #231 and #257. The speed-up holds here too: 250 to 275 ms per frame with the default stage 2, against 335 to 372 ms with `VICTORY_RELAY=0`. Stage 2 changes the picture, though. The cell's left wall is not drawn in either of the two stage-2 runs, and the sky shows through where it should be. With `VICTORY_RELAY=0` and the same binary it is there. Both kinds of run kept #80's texture upload inside the list, which brings the wall back otherwise (details on #80). I have not found the cause. One candidate is the in-flight staging overwrite that #141 and #272 deal with. That is three runs in total, so take it as a lead rather than a proof. Still, it seems worth a check before stage 2 becomes the default.
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-25 00:28 UTC · original

A follow-up from one more run, same binary and same spot, with VICTORY_RELAY=1. The frame time is about the same as stage 2 (242 to 268 ms). The cell's left wall is drawn this time, but the window's chain-link fence is missing. That fence shows in every run without the relay that has #80's copy in the list.

Across the runs where the texture copy sits in the list, the result is:

  • relay off: wall and fence in all 3 runs;
  • stage 2: no wall in either of the 2 runs, fence there;
  • stage 1: wall there, no fence (1 run).

So each stage loses some texture the title writes, and which one looks like a matter of timing rather than something specific to stage 2. Fence and wall are scored over the last 8 captured frames of each run: the brightness of the left strip, and the edge density in the window.

**@⁠brunofgmag** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/187#issuecomment-7148553817) A follow-up from one more run, same binary and same spot, with `VICTORY_RELAY=1`. The frame time is about the same as stage 2 (242 to 268 ms). The cell's left wall is drawn this time, but the window's chain-link fence is missing. That fence shows in every run without the relay that has #80's copy in the list. Across the runs where the texture copy sits in the list, the result is: - relay off: wall and fence in all 3 runs; - stage 2: no wall in either of the 2 runs, fence there; - stage 1: wall there, no fence (1 run). So each stage loses some texture the title writes, and which one looks like a matter of timing rather than something specific to stage 2. Fence and wall are scored over the last 8 captured frames of each run: the brightness of the left strip, and the edge density in the window.
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-25 00:54 UTC · original

I checked whether the textures lost under the relay come from the staging overwrite that #141 (@⁠adritoyalser) and #272 (@⁠fffluffy-dev) deal with. In this scene they don't.

I ported #272's wait to #80's prelude model on the same tree. A list notes each staging buffer it or its prelude copies from, every staging buffer the submission read gets that submission's fence once it has gone out ahead, and a detile waits for that fence. With stage 2 and the copy kept in the list, that gave one run with wall and fence, one run with neither plus a stale block over the window, and one run that died at frame 16 with a breakpoint inside the title. With the wait switched off, the wall was missing again.

Then I tried the bluntest version: before any detile, wait for every submission that has gone out ahead. It costs up to 15 ms per frame. One run still had no wall, and the other had the wall but no fence.

So under the relay something other than the staging buffer drops a title texture, or the geometry that uses it. Which one goes missing changes from run to run. With the relay off, all three runs were clean.

**@⁠brunofgmag** on GitHub · 2026-11-25 00:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/187#issuecomment-7149013168) I checked whether the textures lost under the relay come from the staging overwrite that #141 (@⁠adritoyalser) and #272 (@⁠fffluffy-dev) deal with. In this scene they don't. I ported #272's wait to #80's prelude model on the same tree. A list notes each staging buffer it or its prelude copies from, every staging buffer the submission read gets that submission's fence once it has gone out ahead, and a detile waits for that fence. With stage 2 and the copy kept in the list, that gave one run with wall and fence, one run with neither plus a stale block over the window, and one run that died at frame 16 with a breakpoint inside the title. With the wait switched off, the wall was missing again. Then I tried the bluntest version: before any detile, wait for every submission that has gone out ahead. It costs up to 15 ms per frame. One run still had no wall, and the other had the wall but no fence. So under the relay something other than the staging buffer drops a title texture, or the geometry that uses it. Which one goes missing changes from run to run. With the relay off, all three runs were clean.
Author
Owner

@⁠larelgit on GitHub · 2026-11-25 02:31 UTC · original · edited 2026-11-25 02:55 UTC

Edit: corrected. My first version of this comment had two rows wrong: my run script set the switches as process environment variables and did not clear them between the runs of a series, so the run I listed as C also had VICTORY_RELAY=2 (its log shows the relay's lines), and the one I listed as D also had VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1. Both were really "all four switches". The tables below are per what each run actually had; the script is fixed.

Measurements from another machine, for the default-on question. RTX 5080 16 GB (driver 610.88), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 22631, diag build, rustc 1.98.1. Each run loads the autosaved checkpoint at the prison cell window and nobody touches the pad; frame time is the spacing of the recording per frame lines over 260-355 s of the run (median of 15-17 intervals), and the scene is judged from screenshots at 300 and 350 s.

Main at a803c87 (this PR not applied; the relay set by environment):

Switches Runs ms/frame Card busy Cell's left wall Window fence
none 1 343 58 % drawn drawn
VICTORY_RELAY=2 1 240 72 % missing missing
VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 2 187, 185 70-71 % drawn (both) drawn (both)

The relay alone reproduces what @⁠brunofgmag saw: the cell's left wall and the chain-link fence are gone in this scene. The spread within a run is small (none 336-345 ms, relay 234-247, all four 184-190).

Further runs on builds of a803c87 with one experimental change of mine each (unrelated to the relay), switched on only in the first run of each switch set below (182 and 192 ms), so the others take main's code paths:

Switches ms/frame Cell's left wall Window fence
VICTORY_RELAY=2 + card buffers (MIN_MB=1, MB=1024) 182 missing drawn
same 180 missing missing
VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 + card buffers, no relay 192 missing drawn
same 187 drawn missing
same 193 drawn drawn, blocky garbage along the bottom of the frame
same 189 missing drawn
same 193 drawn missing

So in this scene the loss is intermittent and not only the relay's: late wait 3 with the wide copy-back and card buffers, with no relay at all, lost the wall or the fence (or drew garbage) in each of 5 runs, while the two runs with all four switches together were intact. Those are small numbers, and one run of the default is not enough to say it never loses them; I can run more of any row if that helps.

Nothing else changed between the runs: same checkpoint, one run at a time, 360-400 s each, peak private 23-27 GB.

**@⁠larelgit** on GitHub · 2026-11-25 02:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/187#issuecomment-7150838888) · edited 2026-11-25 02:55 UTC **Edit:** corrected. My first version of this comment had two rows wrong: my run script set the switches as process environment variables and did not clear them between the runs of a series, so the run I listed as C also had `VICTORY_RELAY=2` (its log shows the relay's lines), and the one I listed as D also had `VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1`. Both were really "all four switches". The tables below are per what each run actually had; the script is fixed. Measurements from another machine, for the default-on question. RTX 5080 16 GB (driver 610.88), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 22631, diag build, rustc 1.98.1. Each run loads the autosaved checkpoint at the prison cell window and nobody touches the pad; frame time is the spacing of the `recording per frame` lines over 260-355 s of the run (median of 15-17 intervals), and the scene is judged from screenshots at 300 and 350 s. **Main at a803c87 (this PR not applied; the relay set by environment):** | Switches | Runs | ms/frame | Card busy | Cell's left wall | Window fence | |----------|-----:|---------:|----------:|------------------|--------------| | none | 1 | 343 | 58 % | drawn | drawn | | `VICTORY_RELAY=2` | 1 | 240 | 72 % | **missing** | **missing** | | `VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024` | 2 | 187, 185 | 70-71 % | drawn (both) | drawn (both) | The relay alone reproduces what @⁠brunofgmag saw: the cell's left wall and the chain-link fence are gone in this scene. The spread within a run is small (none 336-345 ms, relay 234-247, all four 184-190). **Further runs** on builds of a803c87 with one experimental change of mine each (unrelated to the relay), switched on only in the first run of each switch set below (182 and 192 ms), so the others take main's code paths: | Switches | ms/frame | Cell's left wall | Window fence | |----------|---------:|------------------|--------------| | `VICTORY_RELAY=2` + card buffers (`MIN_MB=1`, `MB=1024`) | 182 | **missing** | drawn | | same | 180 | **missing** | **missing** | | `VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1` + card buffers, no relay | 192 | **missing** | drawn | | same | 187 | drawn | **missing** | | same | 193 | drawn | drawn, blocky garbage along the bottom of the frame | | same | 189 | **missing** | drawn | | same | 193 | drawn | **missing** | So in this scene the loss is intermittent and not only the relay's: late wait 3 with the wide copy-back and card buffers, with no relay at all, lost the wall or the fence (or drew garbage) in each of 5 runs, while the two runs with all four switches together were intact. Those are small numbers, and one run of the default is not enough to say it never loses them; I can run more of any row if that helps. Nothing else changed between the runs: same checkpoint, one run at a time, 360-400 s each, peak private 23-27 GB.
Author
Owner

@⁠cblomert on GitHub · 2026-11-25 05:53 UTC · original

Thanks @⁠Flyander, @⁠brunofgmag and @⁠larelgit for the runs: three machines agree that the relay is faster and that the prison cell's wall or fence can go missing, and @⁠larelgit's late-wait-3 runs without the relay show the loss is not stage 2's alone. My measurements (RTX 4090) only covered frame time, not the picture, so I am turning this into a draft: stage 2 should not become the default while geometry can drop.

I'll look for what the sent-ahead path loses (late wait and relay both) and come back with matched captures and mesh-group counts before asking for a review again.

🤖 Generated with Claude Code

**@⁠cblomert** on GitHub · 2026-11-25 05:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/187#issuecomment-7154229341) Thanks @⁠Flyander, @⁠brunofgmag and @⁠larelgit for the runs: three machines agree that the relay is faster and that the prison cell's wall or fence can go missing, and @⁠larelgit's late-wait-3 runs without the relay show the loss is not stage 2's alone. My measurements (RTX 4090) only covered frame time, not the picture, so I am turning this into a draft: stage 2 should not become the default while geometry can drop. I'll look for what the sent-ahead path loses (late wait and relay both) and come back with matched captures and mesh-group counts before asking for a review again. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request has changes conflicting with the target branch.
  • README.md
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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