Skip to content

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

Open
cblomert wants to merge 1 commit into
fxceless:mainfrom
cblomert:gpu/relay-default
Open

cblomert wants to merge 1 commit into
fxceless:mainfrom
cblomert:gpu/relay-default

Conversation

@cblomert

Copy link
Copy Markdown

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 RTX 4070 Ti SUPER: prologue color vs. same-frame depth, plus a mesh PSV validation fix #12; Shaders: write every PSV0 semantic name again, as DXC does (fixes #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 GPU: use D3D12 COPY queue for relay card-copy fetches and parallelize CARD_COMPARE #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

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lj18ajyo1buNyoZcYjnZYC

@Flyander Flyander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the current PR #187 + #191 merge on an RTX 5070 Ti with VICTORY_RELAY unset: all 9 relay tests pass, and buffer_data_reaches_the_host_texture passes on the D3D12 device. That checks synchronization and a texture transfer, but it does not check rendered title frames.

Issue #168 reports a controlled, same-save RTX 4090 A/B on 4e17478: both default runs rendered the first room's walls; both VICTORY_RELAY=2 runs lost them, and the relay runs also requested roughly 20% fewer mesh groups. The issue predates #191, whose new alias/read-back waits may change the outcome.

Could you rerun the matched warm-cache capture on the current #187 + #191 candidate before making stage 2 the default, and attach the frame/matched mesh-group counts? The unit tests above cannot establish that visual output is intact.

@brunofgmag

brunofgmag commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants