Textures picked by index: the recheck's fingerprint reads every mip of every slice #559

Open
github-bot wants to merge 1 commit from github-bot/gh-559 into main AGit
Owner

@⁠NickJBc on GitHub · 2026-11-25 02:14 UTC · original
NickJBc:recheck-every-mip → main · +202 −24 · 4 files · 1 commits · open

Follow-up to the known gap in a803c87 ("the fingerprint samples the start, middle and end of the memory, so a texture whose other parts arrive later is still missed").

The gap

The recheck compares a fingerprint of 16 KiB at the start, middle and end of a texture's memory. Each slice stores its mips smallest first, with mip 0 last, so:

  • For a plain 2D texture the three windows land on the tail and mip 0 only. Mips 1 and 2 (about a quarter of the bytes) and the mips between them are never read.
  • For an array or cube map the windows see two slices of six or more.

A mip or slice that arrives after the upload in one of those places is still missed.

The change

  • Layout::sample_ranges (victory-formats): one range at the start of each mip of each slice, with tail mips at their places in the tail block. Each range is 1 KiB, at most 64 per texture, spread evenly over slices and mips when there are more. Adjacent ranges are joined into one read.
  • victory-gpu: the ranges are worked out from the staging buffer's layout at upload and kept with the slot (Waiting::mips). They're read on top of the three existing windows, so the new fingerprint sees every change the old one saw.
  • Cost per look: a 4096² texture with all its mips takes 10 extra reads (12 KiB); a 512 cube map with 10 mips takes 40 reads (52 KiB).
  • Switch: VICTORY_HEAP_RECHECK_MIPS=0 reads the three windows alone, and the fingerprint is then identical to before.

Windows go at a mip's start, not its centre, because a tail mip may fill only the first part of its place in the tail block. A centred window missed mip 5 of a 2048² BC texture in the test below.

Checked

  • victory-formats tests on Linux, 27 passing, 3 of them new:
    • Every mip of every slice, tail mips included, has a range over bytes its elements are stored at. The bytes are found through Layout::offset, not through the mip offsets sample_ranges uses. The cases cover 2D BC and RGBA, cube, array, linear and a 4096×64 texture.
    • Ranges are ordered, apart, bounded and capped for every swizzle mode, XOR modes included.
    • Capped ranges spread over the slices of a 64-slice array.
  • The Windows target builds and passes clippy with and without diagnostics.

Not checked

Not run in the game yet, so it is unknown how many more stale textures this catches. The changed after its upload warning count, with and without VICTORY_HEAP_RECHECK_MIPS=0, would show it.

#555 also touches descriptor/host.rs and texture.rs (view-memory guards, a different path); they may need a small rebase against each other.

**@⁠NickJBc** on GitHub · 2026-11-25 02:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/559) `NickJBc:recheck-every-mip` → `main` · +202 −24 · 4 files · 1 commits · open Follow-up to the known gap in a803c87 ("the fingerprint samples the start, middle and end of the memory, so a texture whose other parts arrive later is still missed"). ## The gap The recheck compares a fingerprint of 16 KiB at the start, middle and end of a texture's memory. Each slice stores its mips smallest first, with mip 0 last, so: - For a plain 2D texture the three windows land on the tail and mip 0 only. Mips 1 and 2 (about a quarter of the bytes) and the mips between them are never read. - For an array or cube map the windows see two slices of six or more. A mip or slice that arrives after the upload in one of those places is still missed. ## The change - **`Layout::sample_ranges` (victory-formats):** one range at the start of each mip of each slice, with tail mips at their places in the tail block. Each range is 1 KiB, at most 64 per texture, spread evenly over slices and mips when there are more. Adjacent ranges are joined into one read. - **victory-gpu:** the ranges are worked out from the staging buffer's layout at upload and kept with the slot (`Waiting::mips`). They're read on top of the three existing windows, so **the new fingerprint sees every change the old one saw**. - **Cost per look:** a 4096² texture with all its mips takes 10 extra reads (12 KiB); a 512 cube map with 10 mips takes 40 reads (52 KiB). - **Switch:** `VICTORY_HEAP_RECHECK_MIPS=0` reads the three windows alone, and the fingerprint is then identical to before. Windows go at a mip's start, not its centre, because a tail mip may fill only the first part of its place in the tail block. A centred window missed mip 5 of a 2048² BC texture in the test below. ## Checked - victory-formats tests on Linux, 27 passing, 3 of them new: - Every mip of every slice, tail mips included, has a range over bytes its elements are stored at. The bytes are found through `Layout::offset`, not through the mip offsets `sample_ranges` uses. The cases cover 2D BC and RGBA, cube, array, linear and a 4096×64 texture. - Ranges are ordered, apart, bounded and capped for every swizzle mode, XOR modes included. - Capped ranges spread over the slices of a 64-slice array. - The Windows target builds and passes clippy with and without `diagnostics`. ## Not checked **Not run in the game yet**, so it is unknown how many more stale textures this catches. The `changed after its upload` warning count, with and without `VICTORY_HEAP_RECHECK_MIPS=0`, would show it. #555 also touches `descriptor/host.rs` and `texture.rs` (view-memory guards, a different path); they may need a small rebase against each other.
The recheck added in a803c87 compares a fingerprint of 16 KiB at the
start, middle and end of a texture's memory. Each slice stores its mips
smallest first with mip 0 last, so for a plain 2D texture those windows
land on the tail and mip 0 only: mips 1 and 2 (about a quarter of the
bytes) and every mip in between are never read. In an array or cube map
they see two slices of six or more. A mip or slice that arrived after the
upload there was still missed (the commit's own "known gap").

Layout::sample_ranges (victory-formats) gives one range at the start of
each mip of each slice, tail mips at their places in the tail block: 1 KiB
each, at most 64 per texture, spread evenly over slices and mips when
there are more, adjacent ranges joined into one read. The ranges are
worked out from the staging buffer's layout at upload, kept with the slot,
and read on top of the three windows, so the new fingerprint sees every
change the old one saw. A 4096-square texture with all its mips: 10 reads,
12 KiB more per look; a 512 cube map with 10 mips: 40 reads, 52 KiB.

VICTORY_HEAP_RECHECK_MIPS=0 keeps the three windows alone (the
fingerprint is then the same as before).

Checked: victory-formats tests on Linux, including a test that every mip
of every slice (tail mips too) has a range over bytes its elements are
stored at, found through Layout::offset rather than the mip offsets; the
Windows target builds and passes clippy with and without diagnostics.
Not yet run in the game.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YYNyBknqrxMVw1v7HYK6J4
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:20 +00:00
Author
Owner

@⁠Victorywillbeours222 on GitHub · 2026-11-25 13:44 UTC · original

A count of the gap this PR describes, from the game.

RTX 5080 16 GB, Ryzen 7 5800X, diag build of f85101b with its frame-rate switches, Series S profile. Two 10-minute runs through the prologue (the diner, the title card, the cell).

We read the textures picked by index whole as well (up to 8 MiB) at each recheck. We counted a change as "only between the windows" when the three 16 KiB windows matched but the whole did not:

run changes found at a recheck only between the three windows
f85101b + the switches 34,457 9,714 (28 %)
same, with #868's VICTORY_SKIP_WC_COMPARE=1 28,590 9,005 (31 %)
  • More than a quarter of what the title changes in these textures is invisible to the current fingerprint.
  • The case we saw on screen is the HUD's glyph cache. The cell's button prompts showed only a few of their letters until the whole texture was read.

The change we measured with is #956: a whole read up to a set size, and rechecks that go on past the fifth. It is meant to sit beside this PR, not replace it: your per-mip ranges for big textures, a whole read for small atlases. We're happy to rebase it onto this one if it goes in first.

Numbers only; no captures.

**@⁠Victorywillbeours222** on GitHub · 2026-11-25 13:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/559#issuecomment-7164220757) A count of the gap this PR describes, from the game. RTX 5080 16 GB, Ryzen 7 5800X, diag build of `f85101b` with its frame-rate switches, Series S profile. Two 10-minute runs through the prologue (the diner, the title card, the cell). We read the textures picked by index whole as well (up to 8 MiB) at each recheck. We counted a change as "only between the windows" when the three 16 KiB windows matched but the whole did not: | run | changes found at a recheck | only between the three windows | |---|---:|---:| | `f85101b` + the switches | 34,457 | 9,714 (28 %) | | same, with #868's `VICTORY_SKIP_WC_COMPARE=1` | 28,590 | 9,005 (31 %) | - More than a quarter of what the title changes in these textures is invisible to the current fingerprint. - The case we saw on screen is the HUD's glyph cache. The cell's button prompts showed only a few of their letters until the whole texture was read. The change we measured with is #956: a whole read up to a set size, and rechecks that go on past the fifth. It is meant to sit beside this PR, not replace it: your per-mip ranges for big textures, a whole read for small atlases. We're happy to rebase it onto this one if it goes in first. Numbers only; no captures.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.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/559/head:github-bot/gh-559'
git switch 'github-bot/gh-559'

Merge

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