GPU: cut cold launch to the first screen from 49 s to 21 s #2427

Open
github-bot wants to merge 4 commits from github-bot/gh-2427 into main AGit
Owner

@⁠imjustprism on GitHub · 2026-11-25 13:20 UTC · original
imjustprism:perf/startup-load → main · +1403 −107 · 9 files · 4 commits · open

the black screen before the first screen was almost all waiting, on the drive and on the host making thousands of tiny buffers. with the game folder on a hard drive a cold launch showed the first screen after 49 s; it is 21 s now.

launch to first screen main this branch change
cold, file cache purged 48.8, 49.5 s 21.0, 21.3, 21.3 s 2.3x
launched again, files still cached 37.0, 47.5 s 5.5, 5.5, 5.5 s about 7x
bytes read up to the first screen 1102 MB 1102 MB same
cpu time by the end of a cold run 29 to 32 s about 18.5 s
private bytes at the first screen 13.87 to 13.88 GB 13.87 to 13.92 GB

what each change is worth, from builds of this branch with one of them turned off:

build cold launched again
this branch 21.0, 21.3, 21.3 s 5.5, 5.5, 5.5 s
dstorage files opened for synchronous reads 27.3, 27.5, 27.5 s 5.5, 5.5, 5.8 s
small buffers committed one by one not measured 7.0, 7.0, 7.0 s

release builds of this branch's tree and of main at 940d32f, rx 9070 xt, game folder on a 7200 rpm drive that was idle before each run, each exe under a name the driver had not seen and warmed once first. cold means the file cache was purged for every file of the game folder before the run. the first screen is the first window capture with content, looked for every 250 ms, so times are good to a quarter second. three runs each; main's third cold run is left out because the capture missed the screen. main launched again varies and i do not know why.

packs go through the host file cache. the title opens its packs unbuffered, which is right on the console and costs here: every read went to the drive, windows kept nothing and read nothing ahead. CreateFileW now drops FILE_FLAG_NO_BUFFERING when the access is exactly GENERIC_READ and the open is not overlapped. an open that can write keeps the flag, and so does an overlapped one, because the host's ReadFileScatter needs it. nothing the title can see changes: same handle kind, same results, same sizes. a later launch then reads the packs from memory, and a cold one gets the cache manager's read-ahead on the sequential stretches.

dstorage reads are overlapped. a file was opened for synchronous reads, so the kernel ran one read of a file at a time however many workers were waiting on it. files are now opened with FILE_FLAG_OVERLAPPED and a worker reads at an offset with its own event, cancelling and draining the read if it has to give up, so reads of one file run at once and the drive's queue stays full. that is the 27 s to 21 s row. along with it: a submitted read wakes one worker instead of all of them, a worker keeps its source and intermediate buffers between requests (up to 1 MiB each) instead of allocating them per request, and a queue created when no worker could be started fails with E_OUTOFMEMORY instead of being a queue that never completes. this is the dstorage half of #234 written against current main; the xmem half of #234 is not here, and neither is the scheduling change of #1457.

small shared buffers share heaps. Host::shared_buffer made a committed resource per buffer, a kernel allocation each, and a title makes thousands of buffers of a few hundred bytes while it loads. a buffer of up to 64 KiB now takes a slot in a 16 MiB heap (crates/victory-gpu/src/placed.rs). a slot is free again when the host reports its buffer destroyed (ID3DDestructionNotifier), and a heap no buffer is left in is released, one per tick of the frame meter, as long as a heap's worth of free slots stays without it. a placed buffer is zeroed over its width only, so the copy of a title buffer asks for whole slots: a root descriptor's read past the title buffer's end stays inside that copy, as it did before. that is the 7.0 s to 5.5 s row.

what is left of the 21 s is drive time: the drive is busy for nearly all of it. warming the file cache from a list of an earlier launch's reads is the next idea and would be its own pull request.

what this does not show: only the way to the first screen was measured, no world scene. one machine, one amd card, a hard drive; on an ssd the unbuffered reads were never the problem, so expect less. in the measured launches the pool grew to 16 heaps holding about 4,000 buffers and no heap ran empty, so the release on the meter tick never ran there: tests cover what it does, nothing here says what it costs on the present thread.

the gate is green on each of the three commits, with the gpu tests on the rx 9070 xt. the new tests cover which opens lose the flag (wide, read-only, not overlapped) and which keep it, a read at an offset that leaves the handle's file pointer alone, a read whose wait fails having ended before the call returns, reads of one file queued together each getting their own bytes, which wakes a submit and a finish make, the buffers a worker keeps and frees, the scheduler without a worker, and the pool's slots, heaps and release rules.

refs #234
refs #280

**@⁠imjustprism** on GitHub · 2026-11-25 13:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427) `imjustprism:perf/startup-load` → `main` · +1403 −107 · 9 files · 4 commits · open the black screen before the first screen was almost all waiting, on the drive and on the host making thousands of tiny buffers. with the game folder on a hard drive a cold launch showed the first screen after 49 s; it is 21 s now. | launch to first screen | main | this branch | change | |---|---|---|---| | cold, file cache purged | 48.8, 49.5 s | 21.0, 21.3, 21.3 s | 2.3x | | launched again, files still cached | 37.0, 47.5 s | 5.5, 5.5, 5.5 s | about 7x | | bytes read up to the first screen | 1102 MB | 1102 MB | same | | cpu time by the end of a cold run | 29 to 32 s | about 18.5 s | | | private bytes at the first screen | 13.87 to 13.88 GB | 13.87 to 13.92 GB | | what each change is worth, from builds of this branch with one of them turned off: | build | cold | launched again | |---|---|---| | this branch | 21.0, 21.3, 21.3 s | 5.5, 5.5, 5.5 s | | dstorage files opened for synchronous reads | 27.3, 27.5, 27.5 s | 5.5, 5.5, 5.8 s | | small buffers committed one by one | not measured | 7.0, 7.0, 7.0 s | release builds of this branch's tree and of main at 940d32f, rx 9070 xt, game folder on a 7200 rpm drive that was idle before each run, each exe under a name the driver had not seen and warmed once first. cold means the file cache was purged for every file of the game folder before the run. the first screen is the first window capture with content, looked for every 250 ms, so times are good to a quarter second. three runs each; main's third cold run is left out because the capture missed the screen. main launched again varies and i do not know why. packs go through the host file cache. the title opens its packs unbuffered, which is right on the console and costs here: every read went to the drive, windows kept nothing and read nothing ahead. `CreateFileW` now drops `FILE_FLAG_NO_BUFFERING` when the access is exactly `GENERIC_READ` and the open is not overlapped. an open that can write keeps the flag, and so does an overlapped one, because the host's `ReadFileScatter` needs it. nothing the title can see changes: same handle kind, same results, same sizes. a later launch then reads the packs from memory, and a cold one gets the cache manager's read-ahead on the sequential stretches. dstorage reads are overlapped. a file was opened for synchronous reads, so the kernel ran one read of a file at a time however many workers were waiting on it. files are now opened with `FILE_FLAG_OVERLAPPED` and a worker reads at an offset with its own event, cancelling and draining the read if it has to give up, so reads of one file run at once and the drive's queue stays full. that is the 27 s to 21 s row. along with it: a submitted read wakes one worker instead of all of them, a worker keeps its source and intermediate buffers between requests (up to 1 MiB each) instead of allocating them per request, and a queue created when no worker could be started fails with `E_OUTOFMEMORY` instead of being a queue that never completes. this is the dstorage half of #234 written against current main; the xmem half of #234 is not here, and neither is the scheduling change of #1457. small shared buffers share heaps. `Host::shared_buffer` made a committed resource per buffer, a kernel allocation each, and a title makes thousands of buffers of a few hundred bytes while it loads. a buffer of up to 64 KiB now takes a slot in a 16 MiB heap (`crates/victory-gpu/src/placed.rs`). a slot is free again when the host reports its buffer destroyed (`ID3DDestructionNotifier`), and a heap no buffer is left in is released, one per tick of the frame meter, as long as a heap's worth of free slots stays without it. a placed buffer is zeroed over its width only, so the copy of a title buffer asks for whole slots: a root descriptor's read past the title buffer's end stays inside that copy, as it did before. that is the 7.0 s to 5.5 s row. what is left of the 21 s is drive time: the drive is busy for nearly all of it. warming the file cache from a list of an earlier launch's reads is the next idea and would be its own pull request. what this does not show: only the way to the first screen was measured, no world scene. one machine, one amd card, a hard drive; on an ssd the unbuffered reads were never the problem, so expect less. in the measured launches the pool grew to 16 heaps holding about 4,000 buffers and no heap ran empty, so the release on the meter tick never ran there: tests cover what it does, nothing here says what it costs on the present thread. the gate is green on each of the three commits, with the gpu tests on the rx 9070 xt. the new tests cover which opens lose the flag (wide, read-only, not overlapped) and which keep it, a read at an offset that leaves the handle's file pointer alone, a read whose wait fails having ended before the call returns, reads of one file queued together each getting their own bytes, which wakes a submit and a finish make, the buffers a worker keeps and frees, the scheduler without a worker, and the pool's slots, heaps and release rules. refs #234 refs #280
a shared buffer of up to 64 KiB takes a slot in a 16 MiB heap instead of
a committed allocation of its own. a slot is free again when the host
reports the buffer destroyed. on the frame meter's tick one heap no
buffer is left in goes back, while a heap's worth of slots stays free
without it.
a read no longer holds its file's position: requests of one file run at
once on overlapped handles. each submitted read wakes one worker, a
worker reuses its source and intermediate buffers up to 1 MiB, and a
queue made with no worker running fails instead of never completing.
a finish wakes every worker only when it frees staging that a start
waited for.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:28 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:33 UTC · original · edited 2026-11-26 00:20 UTC

Automated triage for the maintainers.

Needs work. The head is unchanged since the last triage. The PR still combines a pooled heap for small shared buffers (crates/victory-gpu/src/small_buffers.rs, Host::shared_buffer, slot rounding in shadow::find), dropping FILE_FLAG_NO_BUFFERING in files::CreateFileW, and two DirectStorage scheduling changes in dstorage.rs, about 1,400 lines in all.

On your reply: thank you for splitting the commits cleanly. Separate pull requests are still the better route. Each part touches a different subsystem with its own risks: GPU address reuse in the pool, title-visible file-open behaviour, and DirectStorage, which overlaps the open #1457 and #234. Separate PRs let each one be reviewed, merged or reverted on its own, and let the DirectStorage part be weighed against those two PRs. Please also add a timing for the CreateFileW buffering change by itself (it has no row of its own yet). If the maintainer says per-commit review here is fine, that overrides this. CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427#issuecomment-7167017278) · edited 2026-11-26 00:20 UTC <!-- victory-triage v1 head=9a8a397d3a01ca41e70b88fed20eba29638e3de6 verdict=needs-work at=2026-11-26T00:20:59Z --> Automated triage for the maintainers. **Needs work.** The head is unchanged since the last triage. The PR still combines a pooled heap for small shared buffers (`crates/victory-gpu/src/small_buffers.rs`, `Host::shared_buffer`, slot rounding in `shadow::find`), dropping `FILE_FLAG_NO_BUFFERING` in `files::CreateFileW`, and two DirectStorage scheduling changes in `dstorage.rs`, about 1,400 lines in all. On your reply: thank you for splitting the commits cleanly. Separate pull requests are still the better route. Each part touches a different subsystem with its own risks: GPU address reuse in the pool, title-visible file-open behaviour, and DirectStorage, which overlaps the open #1457 and #234. Separate PRs let each one be reviewed, merged or reverted on its own, and let the DirectStorage part be weighed against those two PRs. Please also add a timing for the `CreateFileW` buffering change by itself (it has no row of its own yet). If the maintainer says per-commit review here is fine, that overrides this. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:03 UTC · original

Read all three parts end to end. The wake/lock discipline is right (submit_and_wake drops the lanes lock before notifying; finish reports whether a starved start can retry; start lets zero-staging reads bypass the staging cap), read_at correctly keeps out/overlapped alive through a failed wait by spinning on Internal with CancelIoEx, and the pool's slot lifecycle closes every race I could construct: take_or_add handles two racing heap-creators, give only touches bits under the leaf lock, destroyed can't fire while slots is held (nothing drops a resource inside the lock), and spare's 2×HEAP_SLOTS hysteresis stops heap churn. The dropped_flags gate is exactly as conservative as it should be (access == GENERIC_READ, non-overlapped, CreateFileW only).

Two narrow edges, neither blocking:

  1. create_placed's RegisterDestructionCallback failure path drops the buffer and place gives the slot back immediately. The runtime defers a placed resource's teardown, so a fast re-take of that slot could try CreatePlacedResource over a resource the runtime is still destroying → create fails → pool closes → committed fallback. Self-healing, but a short delay or marking the slot free only after a tick would avoid the corner.
  2. starved only clears on a staging-holding finish. A run of zero-staging finishes leaves it set, so the next staging-freeing finish does a redundant notify_all. Over-wake only, but a take(&mut self.starved) on a refused→non-refused transition would keep it tighter.

The measurement methodology in the body (per-change attribution, cache purging, driver-name variation) is a model for how perf PRs here should be written up.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427#issuecomment-7168937209) Read all three parts end to end. The wake/lock discipline is right (`submit_and_wake` drops the lanes lock before notifying; `finish` reports whether a starved start can retry; `start` lets zero-staging reads bypass the staging cap), `read_at` correctly keeps `out`/`overlapped` alive through a failed wait by spinning on `Internal` with `CancelIoEx`, and the pool's slot lifecycle closes every race I could construct: `take_or_add` handles two racing heap-creators, `give` only touches bits under the leaf lock, `destroyed` can't fire while `slots` is held (nothing drops a resource inside the lock), and `spare`'s 2×HEAP_SLOTS hysteresis stops heap churn. The `dropped_flags` gate is exactly as conservative as it should be (`access == GENERIC_READ`, non-overlapped, CreateFileW only). Two narrow edges, neither blocking: 1. `create_placed`'s `RegisterDestructionCallback` failure path drops the buffer and `place` gives the slot back immediately. The runtime defers a placed resource's teardown, so a fast re-`take` of that slot could try `CreatePlacedResource` over a resource the runtime is still destroying → create fails → pool closes → committed fallback. Self-healing, but a short delay or marking the slot free only after a tick would avoid the corner. 2. `starved` only clears on a *staging-holding* finish. A run of zero-staging finishes leaves it set, so the next staging-freeing finish does a redundant `notify_all`. Over-wake only, but a `take(&mut self.starved)` on a refused→non-refused transition would keep it tighter. The measurement methodology in the body (per-change attribution, cache purging, driver-name variation) is a model for how perf PRs here should be written up.
Author
Owner

@⁠imjustprism on GitHub · 2026-11-25 20:32 UTC · original

@⁠Marvisak triage asks to split this into three pull requests. the branch is
already one commit per part, rebased on 13f91ca, gate green on each commit:

  • dc08afa small shared buffers in pooled heaps (victory-gpu only)
  • 79fd6c2 packs through the host file cache (files.rs)
  • 5530edd and 9a8a397 dstorage: reads without staging, overlapped reads
    (dstorage.rs)

do you want three pull requests, or is reviewing it per commit here fine?
happy to split, i just don't want to open three more if one is easier for
you. the pool commit shares no file with #1457 or #234, the file cache commit
only victory-hle's Cargo.toml. the dstorage commits are the ones that overlap
them.

timings i have per part are in the second table above: dstorage overlap
27.3 s to 21 s cold, pool 7.0 s to 5.5 s launched again. the file cache part
has no row of its own.

**@⁠imjustprism** on GitHub · 2026-11-25 20:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427#issuecomment-7173835419) @⁠Marvisak triage asks to split this into three pull requests. the branch is already one commit per part, rebased on 13f91ca, gate green on each commit: - dc08afa small shared buffers in pooled heaps (victory-gpu only) - 79fd6c2 packs through the host file cache (files.rs) - 5530edd and 9a8a397 dstorage: reads without staging, overlapped reads (dstorage.rs) do you want three pull requests, or is reviewing it per commit here fine? happy to split, i just don't want to open three more if one is easier for you. the pool commit shares no file with #1457 or #234, the file cache commit only victory-hle's Cargo.toml. the dstorage commits are the ones that overlap them. timings i have per part are in the second table above: dstorage overlap 27.3 s to 21 s cold, pool 7.0 s to 5.5 s launched again. the file cache part has no row of its own.
github-bot changed title from cut cold launch to the first screen from 49 s to 21 s to GPU: cut cold launch to the first screen from 49 s to 21 s 2026-11-26 09:03:15 +00:00
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 14:06 UTC · original · approved these changes

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090:

  • DirectStorage scheduling/buffer reuse, file I/O improvements, and placed buffer handling build cleanly and pass all targeted tests.
  • cargo test -p victory-hle dstorage::: 26/26 passed.
  • cargo test -p victory-hle files::: passed.
  • cargo test -p victory-gpu shadow::: 4/4 passed.
  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 184 files ok.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 14:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427#pullrequestreview-6059088645) · **approved these changes** Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090: - DirectStorage scheduling/buffer reuse, file I/O improvements, and placed buffer handling build cleanly and pass all targeted tests. - `cargo test -p victory-hle dstorage::`: 26/26 passed. - `cargo test -p victory-hle files::`: passed. - `cargo test -p victory-gpu shadow::`: 4/4 passed. - `cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 184 files ok. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 14:11 UTC · original · reviewed

Cold launch 49 s -> 21 s (+1366, docs+gpu+hle). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Big win if the numbers hold; too large for an approve without hardware repro, but the direction (parallel/lazy init) is sound. Needs hardware validation.

**@⁠catminou4** on GitHub · 2026-11-25 14:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2427#pullrequestreview-6059174475) · **reviewed** Cold launch 49 s -> 21 s (+1366, docs+gpu+hle). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Big win if the numbers hold; too large for an approve without hardware repro, but the direction (parallel/lazy init) is sound. Needs hardware validation.
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/2427/head:github-bot/gh-2427'
git switch 'github-bot/gh-2427'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2427'
git switch 'github-bot/gh-2427'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2427'
git switch 'github-bot/gh-2427'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2427'
git switch 'main'
git merge --squash 'github-bot/gh-2427'
git switch 'main'
git merge --ff-only 'github-bot/gh-2427'
git switch 'main'
git merge 'github-bot/gh-2427'
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!2427
No description provided.