victory-gpu: chain heap-worker passes and read textures ahead on threads while slots are left due (stacked on #1007) #1290

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

@⁠Exopus-0x65f7ad0 on GitHub · 2026-11-26 11:16 UTC · original
Exopus-0x65f7ad0:pr/heap-chain → main · +594 −19 · 12 files · 4 commits · open

Stacked on #1007 (heap worker). Only the last commit is new.

What

  • draw.rs: BACKLOG_LEFT records whether the last pass over textures picked by index left slots due. That is the case when the pass was handed a full 4096 slots, or stopped early on bytes, time or make_way.
  • heap_worker.rs: after a pass, if slots are left due and no newer heap is waiting, the worker hands itself the same heap again. Turn this off with VICTORY_HEAP_WORKER_CHAIN=0.
  • host.rs: refresh_textures_ahead reads textures on scoped threads, but only while the queue is behind. VICTORY_REFRESH_WIDE=<n> sets the thread count (default 4, clamped to 1-8); 0 or 1 keeps the old single-thread path. When the queue is not behind it stays sequential, so it does not compete with the submitting thread's copies.

Why

I profiled the opening cutscene on a 16 GB machine where texture reads page-fault heavily. The heap worker sat idle about half of each frame (112 of 220 ms) waiting for the next kick, while ~20k slots were still due. Those due slots read null or stale views and show up as black or red faces at shot changes.

With both changes, faces stay textured across the shot changes in my runs. Frame time is unchanged, since that machine is memory-bound anyway.

Tests

  • cargo test -p victory-gpu: 171 passed.
  • No new tests: the change is scheduling only, and both env switches restore the old behaviour.

🤖 Generated with Claude Code

**@⁠Exopus-0x65f7ad0** on GitHub · 2026-11-26 11:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/1290) `Exopus-0x65f7ad0:pr/heap-chain` → `main` · +594 −19 · 12 files · 4 commits · open Stacked on #1007 (heap worker). Only the last commit is new. ## What - `draw.rs`: `BACKLOG_LEFT` records whether the last pass over textures picked by index left slots due. That is the case when the pass was handed a full 4096 slots, or stopped early on bytes, time or `make_way`. - `heap_worker.rs`: after a pass, if slots are left due and no newer heap is waiting, the worker hands itself the same heap again. Turn this off with `VICTORY_HEAP_WORKER_CHAIN=0`. - `host.rs`: `refresh_textures_ahead` reads textures on scoped threads, but only while the queue is behind. `VICTORY_REFRESH_WIDE=<n>` sets the thread count (default 4, clamped to 1-8); `0` or `1` keeps the old single-thread path. When the queue is not behind it stays sequential, so it does not compete with the submitting thread's copies. ## Why I profiled the opening cutscene on a 16 GB machine where texture reads page-fault heavily. The heap worker sat idle about half of each frame (112 of 220 ms) waiting for the next kick, while ~20k slots were still due. Those due slots read null or stale views and show up as black or red faces at shot changes. With both changes, faces stay textured across the shot changes in my runs. Frame time is unchanged, since that machine is memory-bound anyway. ## Tests - `cargo test -p victory-gpu`: 171 passed. - No new tests: the change is scheduling only, and both env switches restore the old behaviour. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The pass over textures picked by index asks what of each due texture is mapped, makes the host
texture, makes a staging buffer and records the copy, on whichever thread of the title records the
frame's first shader that picks textures by index. With a backlog that is up to 250 ms of a frame,
and the threads waiting for that list wait with it.

With VICTORY_HEAP_WORKER=1 (needs VICTORY_LATE_WAIT) the pass runs on a thread of its own and the
recording thread only wakes it. Its uploads go into host lists of our own, which the next late
submission runs ahead of the title's lists; a texture's host slot is given its view at that
submission, not before; the title's texture and heap are held while the worker uses them; the
uploads before the decoration bake stay on the recording thread.

Off by default; the numbers go in the pull request.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
On WARP the second group's draws can win the budget; the test asserts what holds either way,
that the record that is no draw runs empty.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The heap worker ran one pass per kick and then idled until the next frame,
while thousands of slots were still due at a change of shot. When the last
pass left slots behind (BACKLOG_LEFT: handed a full 4096, or stopped on
bytes, time or making way), the worker now hands itself the same heap again
unless a newer one is already waiting (VICTORY_HEAP_WORKER_CHAIN=0: off).

While behind, refresh_textures_ahead also reads textures on scoped threads
(VICTORY_REFRESH_WIDE, 4 by default, 0/1: one thread as before), since each
read can wait on paged-out memory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:19:58 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/heap_worker.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/indirect.rs
  • crates/victory-gpu/src/resource.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/1290/head:github-bot/gh-1290'
git switch 'github-bot/gh-1290'

Merge

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