Cut the 17 s world frames with asynchronous submission and a copy queue #2960

Open
github-bot wants to merge 10 commits from github-bot/gh-2960 into main AGit
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 01:33 UTC · original
ynnmuraii:perf-async-submit → main · +2953 −46 · 18 files · 10 commits · open

The world stalls for 17 s a frame here (RTX 4060 8 GB): the render thread waits inside submit and inside the fetch of what shaders wrote, so the intro cutscene never draws. With the three things below the same frames take 0.3-2 s and the prologue card renders.

Ported from fxceless/victory-fork, where they sit behind switches:

  • VICTORY_ASYNC_SUBMIT=1: submissions are prepared and sent by a thread of the layer. A profile in that fork had the render thread inside submit for 257 of 292 ms a frame.
  • VICTORY_QUEUE2=1: fetches of what shaders wrote go to a copy queue; the copy-back thread's wait fell from about 125 to 7 ms a frame there. Its queue2.rs comes over with the fix for a piece fetched beside a later flight: textures count their state moves so a fetch recorded before a later use is told from one recorded after it.
  • VICTORY_PIPELINE_WAIT_MS and VICTORY_PIPELINE_WORKERS already exist upstream; the numbers below use 24 and 4.

Measured on one machine (Ryzen 7 5700X, RTX 4060 8 GB, Windows 11 26200, Series X, 1080p, warm shader cache), same build, from the first-run screens into the intro cutscene:

switches frame at about 1 400 draws frame at about 2 500 draws prologue card
none 16.9 s 17 s not reached
async + queue2, no workers 17 s 17 s not reached
workers only 17 s 17 s not reached
async + queue2 + workers 0.5-1.0 s 0.3-2.0 s drawn

No device removal in any of the runs with the device layer's debug output on; the runs above are 10-15 minutes each. Above about 2 900 draws the frame still goes back to 8-17 s, so this does not make the title playable, it makes the cutscene visible. Halving neither the worker count nor doubling it (4 against 8 workers) moves those heavy frames; they are not worker-bound.

The three are opt-in; the last row was run as VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_PIPELINE_WAIT_MS=24 VICTORY_PIPELINE_WORKERS=4.

Two caveats from the fork's own notes: the async path assumes the title leaves its memory alone between submit and preparation (it does there, but nothing enforces it), and the copy queue brings reads back with an up-lane bit this port does not add.

**@⁠ynnmuraii** on GitHub · 2026-11-26 01:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960) `ynnmuraii:perf-async-submit` → `main` · +2953 −46 · 18 files · 10 commits · open The world stalls for 17 s a frame here (RTX 4060 8 GB): the render thread waits inside submit and inside the fetch of what shaders wrote, so the intro cutscene never draws. With the three things below the same frames take 0.3-2 s and the prologue card renders. Ported from `fxceless/victory-fork`, where they sit behind switches: - **`VICTORY_ASYNC_SUBMIT=1`**: submissions are prepared and sent by a thread of the layer. A profile in that fork had the render thread inside submit for 257 of 292 ms a frame. - **`VICTORY_QUEUE2=1`**: fetches of what shaders wrote go to a copy queue; the copy-back thread's wait fell from about 125 to 7 ms a frame there. Its `queue2.rs` comes over with the fix for a piece fetched beside a later flight: textures count their state moves so a fetch recorded before a later use is told from one recorded after it. - `VICTORY_PIPELINE_WAIT_MS` and `VICTORY_PIPELINE_WORKERS` already exist upstream; the numbers below use 24 and 4. Measured on one machine (Ryzen 7 5700X, RTX 4060 8 GB, Windows 11 26200, Series X, 1080p, warm shader cache), same build, from the first-run screens into the intro cutscene: | switches | frame at about 1 400 draws | frame at about 2 500 draws | prologue card | |---|---|---|---| | none | 16.9 s | 17 s | not reached | | async + queue2, no workers | 17 s | 17 s | not reached | | workers only | 17 s | 17 s | not reached | | async + queue2 + workers | 0.5-1.0 s | 0.3-2.0 s | drawn | No device removal in any of the runs with the device layer's debug output on; the runs above are 10-15 minutes each. Above about 2 900 draws the frame still goes back to 8-17 s, so this does not make the title playable, it makes the cutscene visible. Halving neither the worker count nor doubling it (4 against 8 workers) moves those heavy frames; they are not worker-bound. The three are opt-in; the last row was run as `VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_PIPELINE_WAIT_MS=24 VICTORY_PIPELINE_WORKERS=4`. Two caveats from the fork's own notes: the async path assumes the title leaves its memory alone between submit and preparation (it does there, but nothing enforces it), and the copy queue brings reads back with an up-lane bit this port does not add.
After its watchdog fires the title writes a marker through a null pointer
(`mov dword ptr [0], 0x4d8bd421`): the console maps a null page, the PC does
not, and no allocator places memory at zero. A 64 KiB page is reserved at
0x10000 and every such instruction in the mapped image has its absolute
operand rewritten to it, keeping the original offset (some sites use [4]).
The page is made writable for the patch, flushed, and restored.

Measured: runs stop dying at the point every earlier one did (~150 s in).
A watchdog path in the title ends with an unconditional `int3` after
writing its breadcrumb; on a console its own handler catches it. With none
attached, the breakpoint killed the run. Only a real 0xCC at the reported
address is stepped, so debugger breakpoints are untouched.

Measured: a run that died on the trap at ~150 s passes it and continues.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:41 +00:00
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 02:18 UTC · original

Fixed 1 and 2 in 2e72cc94: the SAFETY comment moved inside the if, and Lists::new closes the list CreateCommandList hands back open, so the first reset can run; cargo clippy --locked -p victory-gpu --tests -- -D warnings is clean here now.

On 3 and 4: both are real and I have no fix yet. For 3 the simplest reading is that the deferred copy is only safe while nothing later in the same batch writes the source; a version that records the copy inline when the texture is written again later in the batch would need the list to know what it has already written. For 4 the reports are consistent with what the reviewer says — the ordering contract is not enforced, so the numbers in the body come partly from a path that can race.

Measured after 1 and 2 on the RTX 4060: the reset path no longer breaks, no device removal in 12 minutes, but a frame at 3 135 draws still takes 16.7 s. The 0.5-2 s numbers are at 1 100-2 500 draws only.

**@⁠ynnmuraii** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7180677243) Fixed 1 and 2 in 2e72cc94: the SAFETY comment moved inside the `if`, and `Lists::new` closes the list `CreateCommandList` hands back open, so the first `reset` can run; `cargo clippy --locked -p victory-gpu --tests -- -D warnings` is clean here now. On 3 and 4: both are real and I have no fix yet. For 3 the simplest reading is that the deferred copy is only safe while nothing later in the same batch writes the source; a version that records the copy inline when the texture is written again later in the batch would need the list to know what it has already written. For 4 the reports are consistent with what the reviewer says — the ordering contract is not enforced, so the numbers in the body come partly from a path that can race. Measured after 1 and 2 on the RTX 4060: the reset path no longer breaks, no device removal in 12 minutes, but a frame at 3 135 draws still takes 16.7 s. The 0.5-2 s numbers are at 1 100-2 500 draws only.
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 02:23 UTC · original

3 addressed in the latest push: Host::defer_fetch now refuses a second read back of the same texture and subresource, so the duplicate is recorded in the list and only the first stays deferred. That covers the repeated fetch; the harder half of 3 remains — a later write to the source in the same batch still lands in the deferred copy, and the list would have to know what it has already written to catch it.

4 is still open. Current state: clippy clean, reset path fixed, no device removal over 15 minutes, frame time unchanged at 16.7 s on a 2 941-draw frame.

**@⁠ynnmuraii** on GitHub · 2026-11-26 02:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7180760406) 3 addressed in the latest push: `Host::defer_fetch` now refuses a second read back of the same texture and subresource, so the duplicate is recorded in the list and only the first stays deferred. That covers the repeated fetch; the harder half of 3 remains — a later write to the source in the same batch still lands in the deferred copy, and the list would have to know what it has already written to catch it. 4 is still open. Current state: clippy clean, reset path fixed, no device removal over 15 minutes, frame time unchanged at 16.7 s on a 2 941-draw frame.
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 02:28 UTC · original

4 addressed too: present now calls queue::before_sync() before it reads or moves any plane's state, so the submit thread has finished the lists that touch those textures before this thread mutates copy.state. Nothing is drained from the submit thread itself, so no deadlock.

That leaves the intentional part of 4 — execute/signal returning before the card has run — which is what the switch is for; the drain in present and the existing one in Host::execute are the fences around it.

Frame time again unchanged at 16.7 s on 3 289 draws; no device removal in any of the runs after the four fixes.

**@⁠ynnmuraii** on GitHub · 2026-11-26 02:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7180831931) 4 addressed too: `present` now calls `queue::before_sync()` before it reads or moves any plane's state, so the submit thread has finished the lists that touch those textures before this thread mutates `copy.state`. Nothing is drained from the submit thread itself, so no deadlock. That leaves the intentional part of 4 — `execute`/`signal` returning before the card has run — which is what the switch is for; the drain in `present` and the existing one in `Host::execute` are the fences around it. Frame time again unchanged at 16.7 s on 3 289 draws; no device removal in any of the runs after the four fixes.
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 03:26 UTC · original

Added the fork's relay on top (the flights thread, 1 406 lines), with the two crash fixes it needs to survive here at all: redirect_null_write for the title's null breadcrumb and the int3 step-over. Without them the port dies in 2-3 minutes with 0xC0000005 on a write to 0, then 0x80000003.

With both: 10 minutes, no device removal, no exception. Frame time on the RTX 4060 is unchanged though — 16 s on 3 157 draws, one outlier at 33 s. So the relay is a working option here, not a gain; on this card the wall is the per-draw preparation, not the submit or the copy-back path.

**@⁠ynnmuraii** on GitHub · 2026-11-26 03:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7181718927) Added the fork's relay on top (the flights thread, 1 406 lines), with the two crash fixes it needs to survive here at all: `redirect_null_write` for the title's null breadcrumb and the `int3` step-over. Without them the port dies in 2-3 minutes with `0xC0000005` on a write to 0, then `0x80000003`. With both: 10 minutes, no device removal, no exception. Frame time on the RTX 4060 is unchanged though — 16 s on 3 157 draws, one outlier at 33 s. So the relay is a working option here, not a gain; on this card the wall is the per-draw preparation, not the submit or the copy-back path.
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 03:55 UTC · original

Ported the fork's framelog too (9cd2b104, diagnostics builds only, VICTORY_FRAME_LOG=0 turns the lines off) so the long frames can be attributed instead of guessed at. First run with it on the RTX 4060:

long frame 3370 at 156.5 s: 16948 ms | render thread: ran 31 ms; in the present call 16897
  (lines and settling 16842, copy and show 39) | submit thread: preparing 28.8, waiting for the card 16815.4
  | copies 21.6 ms 57.7 MB | pipelines: 0 made, 0 loaded | 2569 draws

So the heavy frames are the card's own time, not our preparation and not pipeline creation: 0 pipelines made, 16.8 s of waiting for the card, 57 MB of copies. Lighter frames of the same scene settle at 1.3 s. My earlier "CPU preparation" guess in the comments above was wrong — that comes from the fork's own overlay on its own build.

The counters fx has that our tree cannot source (card clock, per-call list timings, remaps) are noted in the commit; the copy-back counter covers the relay landing path here.

**@⁠ynnmuraii** on GitHub · 2026-11-26 03:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7182146318) Ported the fork's `framelog` too (`9cd2b104`, diagnostics builds only, `VICTORY_FRAME_LOG=0` turns the lines off) so the long frames can be attributed instead of guessed at. First run with it on the RTX 4060: ``` long frame 3370 at 156.5 s: 16948 ms | render thread: ran 31 ms; in the present call 16897 (lines and settling 16842, copy and show 39) | submit thread: preparing 28.8, waiting for the card 16815.4 | copies 21.6 ms 57.7 MB | pipelines: 0 made, 0 loaded | 2569 draws ``` So the heavy frames are the card's own time, not our preparation and not pipeline creation: 0 pipelines made, 16.8 s of waiting for the card, 57 MB of copies. Lighter frames of the same scene settle at 1.3 s. My earlier "CPU preparation" guess in the comments above was wrong — that comes from the fork's own overlay on its own build. The counters fx has that our tree cannot source (card clock, per-call list timings, remaps) are noted in the commit; the copy-back counter covers the relay landing path here.
Author
Owner

@⁠ynnmuraii on GitHub · 2026-11-26 04:01 UTC · original

Baseline with the same frame log and no switches, for comparison: 16904 ms | render thread: ran 297 ms; in submit calls 16871.5. With the switches the same 16 s sits in waiting for the card on our submit thread (16815) instead, so the title's thread is out of it. Total frame time is unchanged because the present then waits for the presented frame anyway — which is what both reviewers said in other words.

**@⁠ynnmuraii** on GitHub · 2026-11-26 04:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7182229497) Baseline with the same frame log and no switches, for comparison: `16904 ms | render thread: ran 297 ms; in submit calls 16871.5`. With the switches the same 16 s sits in `waiting for the card` on our submit thread (16815) instead, so the title's thread is out of it. Total frame time is unchanged because the present then waits for the presented frame anyway — which is what both reviewers said in other words.
Author
Owner

@⁠walterwallaceson on GitHub · 2026-11-26 05:01 UTC · original

RTX 3070 8 GB, Windows 10: with the switches on, the world runs at about half the speed it does with them off. That held on two heads, a480378 and 9cd2b10, two runs each. This card never had the 17 s frames, so there was nothing for the switches to win here.

Setup: RTX 3070 8 GB, driver 621.14, Windows 10 22H2 (19045). main 63bcca4 + #463 (Agility runtime, needed on Windows 10) + #2626, then + this PR. Diag build, Enter scripted at 17, 30 and 60 s, nothing skipped, 15-minute runs. "On" means VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_PIPELINE_WAIT_MS=24 VICTORY_PIPELINE_WORKERS=4, as in your table. "Off" is the same binary with none of them set.

a480378 on a480378 off 9cd2b10 on 9cd2b10 off
end 15 min, no removal 15 min, no removal 15 min, no removal 15 min, no removal
world speed, last ~4 min 0.7 fps 1.5 fps 0.8 fps 1.8 fps
copies/frame, end 132 ms 86 ms 171 ms 37 ms
indirect dispatches dropped/frame, end 80 315 68 226
slow submissions 3, slowest 893 ms 2, slowest 356 ms 2, slowest 313 ms 2, slowest 583 ms

Without this PR, the same stack ran at 1.8 fps, so with the switches off the PR costs nothing here. The switches also log as on (VICTORY_ASYNC_SUBMIT=1, VICTORY_QUEUE2=1), and no run crashed or removed the device.

Since all four settings were set together, I can't yet say which one costs the speed. A natural next split is the two switches without the workers and wait. Fewer indirect dispatches dropped with them on could be a side effect of fewer frames, not a fix.

One unrelated thing: the branch commits victory.toml.off, which looks like a local config. It fails xtask's policy::tests::repository_passes_policy (file type not on the allowlist). I dropped it locally to test.

Not tested: a second run of each cell; the frame log for the steady state (on this card it records almost no long frames after the first minutes).

No game data attached. I'm testing with Claude's help, and Claude drafted this comment.

**@⁠walterwallaceson** on GitHub · 2026-11-26 05:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7183112381) **RTX 3070 8 GB, Windows 10: with the switches on, the world runs at about half the speed it does with them off. That held on two heads, `a480378` and `9cd2b10`, two runs each. This card never had the 17 s frames, so there was nothing for the switches to win here.** **Setup:** RTX 3070 8 GB, driver 621.14, Windows 10 22H2 (19045). `main` `63bcca4` + #463 (Agility runtime, needed on Windows 10) + #2626, then + this PR. Diag build, Enter scripted at 17, 30 and 60 s, nothing skipped, 15-minute runs. "On" means `VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_PIPELINE_WAIT_MS=24 VICTORY_PIPELINE_WORKERS=4`, as in your table. "Off" is the same binary with none of them set. | | `a480378` on | `a480378` off | `9cd2b10` on | `9cd2b10` off | |---|---|---|---|---| | end | 15 min, no removal | 15 min, no removal | 15 min, no removal | 15 min, no removal | | world speed, last ~4 min | 0.7 fps | 1.5 fps | 0.8 fps | 1.8 fps | | copies/frame, end | 132 ms | 86 ms | 171 ms | 37 ms | | indirect dispatches dropped/frame, end | 80 | 315 | 68 | 226 | | slow submissions | 3, slowest 893 ms | 2, slowest 356 ms | 2, slowest 313 ms | 2, slowest 583 ms | Without this PR, the same stack ran at 1.8 fps, so with the switches off the PR costs nothing here. The switches also log as on (`VICTORY_ASYNC_SUBMIT=1`, `VICTORY_QUEUE2=1`), and no run crashed or removed the device. Since all four settings were set together, I can't yet say which one costs the speed. A natural next split is the two switches without the workers and wait. Fewer indirect dispatches dropped with them on could be a side effect of fewer frames, not a fix. One unrelated thing: the branch commits `victory.toml.off`, which looks like a local config. It fails `xtask`'s `policy::tests::repository_passes_policy` (file type not on the allowlist). I dropped it locally to test. Not tested: a second run of each cell; the frame log for the steady state (on this card it records almost no long frames after the first minutes). No game data attached. I'm testing with Claude's help, and Claude drafted this comment.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:32 UTC · original

Automated triage for the maintainers.

Proposed close. The PR adds about 2,900 lines of opt-in submission/copy-queue/relay code ported from another fork. By its own measurements in the comments, it does not help. The heavy frames stay at about 16.7 s with the switches on, and the frame log puts that time in waiting for the GPU, not in our submit path. An independent RTX 3070 run found the world at roughly half speed with the switches on (0.8 vs 1.8 fps). The deferred copy also has a known unfixed race: a later write to the source in the same batch lands in the deferred copy (Host::defer_fetch in host.rs).

It also bundles unrelated, risky changes:

  • handler in victory-loader/src/crash.rs now steps over every int3 in title code. That hides the title's own watchdog stops instead of explaining them, and breakpoint_tests asserts nothing about it.
  • A null-write redirect, framelog hooks in victory-hle dstorage, and a committed local victory.toml.off holding personal paths. That file is not on the policy allowlist and fails repository_passes_policy.

CI: failing.

What would change this: a small PR with one change that a frame log shows lowering frame time on main, without the crash-handler, null-write and config changes. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7183582539) <!-- victory-triage v1 head=9cd2b104384af63bf952462b2a61c040732c0ba6 verdict=proposed-close at=2026-11-26T05:32:29Z --> Automated triage for the maintainers. **Proposed close.** The PR adds about 2,900 lines of opt-in submission/copy-queue/relay code ported from another fork. By its own measurements in the comments, it does not help. The heavy frames stay at about 16.7 s with the switches on, and the frame log puts that time in waiting for the GPU, not in our submit path. An independent RTX 3070 run found the world at roughly half speed with the switches on (0.8 vs 1.8 fps). The deferred copy also has a known unfixed race: a later write to the source in the same batch lands in the deferred copy (`Host::defer_fetch` in `host.rs`). It also bundles unrelated, risky changes: - `handler` in `victory-loader/src/crash.rs` now steps over every `int3` in title code. That hides the title's own watchdog stops instead of explaining them, and `breakpoint_tests` asserts nothing about it. - A null-write redirect, `framelog` hooks in `victory-hle` `dstorage`, and a committed local `victory.toml.off` holding personal paths. That file is not on the policy allowlist and fails `repository_passes_policy`. CI: failing. What would change this: a small PR with one change that a frame log shows lowering frame time on `main`, without the crash-handler, null-write and config changes. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠walterwallaceson on GitHub · 2026-11-26 06:20 UTC · original

Correction to my comment above: the "switches on halve the speed" result isn't solid. Since posting it, I found that frame rate on this RTX 3070 swings between roughly 0.7 and 1.8 fps from run to run of the same build. A control run of an earlier fast tree came out at 0.93 fps. My on/off runs alternated (on, off, on, off), and the "on" runs may simply have landed on slow turns. Please treat that table as not showing an effect either way until I can measure the run-to-run spread here. The stray victory.toml.off note still applies.

I'm testing with Claude's help, and Claude drafted this comment.

**@⁠walterwallaceson** on GitHub · 2026-11-26 06:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2960#issuecomment-7184335913) **Correction to my comment above: the "switches on halve the speed" result isn't solid.** Since posting it, I found that frame rate on this RTX 3070 swings between roughly 0.7 and 1.8 fps from run to run of the same build. A control run of an earlier fast tree came out at 0.93 fps. My on/off runs alternated (on, off, on, off), and the "on" runs may simply have landed on slow turns. Please treat that table as not showing an effect either way until I can measure the run-to-run spread here. The stray `victory.toml.off` note still applies. I'm testing with Claude's help, and Claude drafted this comment.
This pull request can be merged automatically.
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/2960/head:github-bot/gh-2960'
git switch 'github-bot/gh-2960'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2960'
git switch 'github-bot/gh-2960'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2960'
git switch 'github-bot/gh-2960'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2960'
git switch 'main'
git merge --squash 'github-bot/gh-2960'
git switch 'main'
git merge --ff-only 'github-bot/gh-2960'
git switch 'main'
git merge 'github-bot/gh-2960'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2960
No description provided.