perf(gpu): a due index for the texture queue (VICTORY_TEXTURE_DUE_CURSOR) #107

Closed
github-bot wants to merge 0 commits from github-bot/gh-107 into main AGit
Owner

@⁠RicardoLocher on GitHub · 2026-12-01 13:42 UTC · original
RicardoLocher:perf/texture-due-cursor → main · +158 −4 · 2 files · 23 commits · closed without merging

A new CPU-side idea, not on the docs/WAVE13-FPS.md list. Gated, off by default.

The cost it removes

TextureQueue (crates/victory-gpu/src/descriptor/host.rs) holds every title slot whose texture view waits to be brought up to date. Its ll_due(frame) walked every slot it held to find the ones due at the frame:

for (&index, w) in self.slots.iter().filter(|(_, w)| w.due <= frame) { ... }

The map is keyed by slot, so it cannot range-query by due. This runs once per indexed-heap draw (heap_textures, draw.rs), i.e. on the submitting thread, which is the CPU-side bottleneck this project is chasing. The code's own comments size the queue at "some ten thousand slots" / "tens of thousands of such views". No switch gated the walk (only VICTORY_HEAP_TEXTURES=0 disables the whole pass).

What this does

With VICTORY_TEXTURE_DUE_CURSOR=1 the queue keeps a due index - slot -> due and due -> slots - kept in step with slots by a single reindex called at every mutation (insert/take_out/later/hold/room/partly/recheck, with written/changed going through insert). A pass then reads only the frames up to the current one. Off (default): the same walk as before, and reindex is a no-op so the off path pays nothing.

census still walks every slot: its waiting/partly-uploaded counts span the whole queue and the index cannot answer them (documented in the code).

Correctness

New test the_due_index_answers_what_the_walk_answers drives writes, re-arms (later), removals (done/remove), holds and room, partly and recheck, and asserts the index answers exactly what the walk answers at 9 frame values, and that both halves of the index stay in step with slots (every slot named once, at its due). in_order is unchanged; only the source of the Due multiset changes.

Verification

  • cargo build -p victory: clean.
  • cargo test -p victory-gpu --lib -- descriptor::host::tests: 43 passed (incl. the new one).
  • cargo clippy -p victory-gpu --all-targets: no new warnings (the two remaining draw.rs casts are pre-existing on main).
  • cargo xtask policy: asset policy 330 files ok. (xtask documented_switches_are_read fails identically on clean main for the VICTORY_NAME placeholder in README.md - pre-existing, not touched here.)

Not done yet (needs the bench)

No in-game A/B in this PR: it is off by default, so nothing changes unless the switch is set. Before any default change I'll run the same save/scene warm, FG off and on reported separately, and record native FPS and frames>50 ms with VICTORY_TEXTURE_DUE_CURSOR unset vs 1. Happy to post that as a follow-up if you'd like the switch on by default or exposed in the launcher.

**@⁠RicardoLocher** on GitHub · 2026-12-01 13:42 UTC · [original](https://github.com/eikkapine/justanxboxemulator/pull/107) `RicardoLocher:perf/texture-due-cursor` → `main` · +158 −4 · 2 files · 23 commits · closed without merging A new CPU-side idea, not on the docs/WAVE13-FPS.md list. Gated, off by default. ## The cost it removes TextureQueue (crates/victory-gpu/src/descriptor/host.rs) holds every title slot whose texture view waits to be brought up to date. Its ll_due(frame) walked **every** slot it held to find the ones due at the frame: ```rust for (&index, w) in self.slots.iter().filter(|(_, w)| w.due <= frame) { ... } ``` The map is keyed by slot, so it cannot range-query by `due`. This runs once per indexed-heap draw (heap_textures, draw.rs), i.e. on the submitting thread, which is the CPU-side bottleneck this project is chasing. The code's own comments size the queue at "some ten thousand slots" / "tens of thousands of such views". No switch gated the walk (only VICTORY_HEAP_TEXTURES=0 disables the whole pass). ## What this does With `VICTORY_TEXTURE_DUE_CURSOR=1` the queue keeps a due index - `slot -> due` and `due -> slots` - kept in step with `slots` by a single `reindex` called at every mutation (`insert`/`take_out`/`later`/`hold`/`room`/`partly`/`recheck`, with `written`/`changed` going through `insert`). A pass then reads only the frames up to the current one. Off (default): the same walk as before, and `reindex` is a no-op so the off path pays nothing. `census` still walks every slot: its waiting/partly-uploaded counts span the whole queue and the index cannot answer them (documented in the code). ## Correctness New test `the_due_index_answers_what_the_walk_answers` drives writes, re-arms (`later`), removals (`done`/`remove`), holds and `room`, `partly` and `recheck`, and asserts the index answers **exactly** what the walk answers at 9 frame values, and that both halves of the index stay in step with `slots` (every slot named once, at its `due`). `in_order` is unchanged; only the source of the `Due` multiset changes. ## Verification - `cargo build -p victory`: clean. - `cargo test -p victory-gpu --lib -- descriptor::host::tests`: 43 passed (incl. the new one). - `cargo clippy -p victory-gpu --all-targets`: no new warnings (the two remaining `draw.rs` casts are pre-existing on `main`). - `cargo xtask policy`: asset policy 330 files ok. (`xtask` `documented_switches_are_read` fails identically on clean `main` for the `VICTORY_NAME` placeholder in `README.md` - pre-existing, not touched here.) ## Not done yet (needs the bench) No in-game A/B in this PR: it is off by default, so nothing changes unless the switch is set. Before any default change I'll run the same save/scene warm, FG off and on reported separately, and record native FPS and frames>50 ms with `VICTORY_TEXTURE_DUE_CURSOR` unset vs `1`. Happy to post that as a follow-up if you'd like the switch on by default or exposed in the launcher.
The queue of textures picked by index walked every slot it held on each
pass (descriptor/host.rs all_due, called once per indexed-heap draw from
draw.rs heap_textures) to find the slots due at the frame: the code's own
comments put the queue at tens of thousands of views, and the walk is on
the submitting thread.

With VICTORY_TEXTURE_DUE_CURSOR=1 the queue keeps a due index (slot->due and
due->slots), kept in step with the slots by reindex at every mutation, so a
pass reads only the frames up to the current one. Off (default): the same
walk as before, and reindex is a no-op.

census still walks every slot: its waiting/partly counts span the whole
queue and the due index cannot answer them.

Adds a test that drives writes, re-arms, holds, room and removals and
asserts the index answers exactly what the walk answers, and that the two
halves of the index stay in step with the slots.

A/B on the CPU-bound city before any default change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:43:24 +00:00
github-bot closed this pull request 2026-12-01 19:52:11 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.