GPU: detile only the subresources a texture's changed pages hold (fix ready on a fork) #915

Open
opened 2026-11-26 04:14:09 +00:00 by github-bot · 3 comments
Owner

@⁠talakasse on GitHub · 2026-11-24 14:04 UTC · original

Pull requests are limited to collaborators, so I'm posting this here. The fix is one commit on top of current main (ffe310e). I checked all 612 open PRs, and none of them touches this shortcut.

Branch: https://github.com/talakasse/VIctory/tree/gpu/partial-detile
Commit: github.com/talakasse/VIctory@af4fef4037

git fetch https://github.com/talakasse/VIctory.git gpu/partial-detile
git cherry-pick af4fef4

Related open PRs change the same refresh code in other ways: #143 (hash and detile from a kernel-read copy), #388 (detile into cached memory), #401 (skip hashing textures rewritten every frame), #641 (partially resident streamed textures). This one is orthogonal to them, but it will conflict textually with whichever merges first, and I can rebase it.

Problem

victory-gpu/src/texture.rs: "shortcut: a change detiles the whole texture, not the pages written." When one 64 KiB page of a title texture changed, the whole memory was read back (watched memory) or hashed as one, and then every mip and slice was detiled again. A streamed texture filling page by page paid that full cost at every submission that sampled it.

Change

  • Layout::extents(mip, slice) (victory-formats): the tiled byte ranges a subresource is detiled from. There is one range per depth slice or slab, merged. Tail mips get the part of the tail block they span.
  • Watched memory: after the first detiling, only the pages written since the last asking are read again into the kept copy.
  • Hashed memory: one hash per 64 KiB page instead of one for the whole texture.
  • Both: only the subresources whose extents overlap a changed page are detiled.
  • Unchanged: the first detiling is still whole, and so is every subresource's copy into the host texture.

Tests

  • extents_hold_what_a_subresource_detiles covers 9 layouts: tiled S/D at 256 B, 4 KiB and 64 KiB, linear, mip tails, arrays and 3D. It checks four things:
    • every element is inside its extents;
    • flipping every byte outside them leaves the detiled result unchanged;
    • ranges are sorted and disjoint;
    • a 2D mip outside the tail spans no more than its own blocks.
  • texture::tests: overlap, changed pages and page-to-range conversion.

Checked / not checked

  • cargo test -p victory-formats passes, run on macOS.
  • cargo clippy -p victory-formats -p victory-gpu --all-targets [--all-features] --target x86_64-pc-windows-msvc -- -D warnings is clean. Locally I needed blake3's pure feature, because there is no Windows C compiler here.
  • Not run on Windows, and not measured in the game. The texture::tests unit tests and the GPU path have not been executed. The gain depends on how much frame time goes into detiling.
  • Known edge: a page that is decommitted without being written can leave stale bytes in the kept copy. The existing code had the same gap, but a full re-read sometimes hid it.

🤖 Generated with Claude Code

**@⁠talakasse** on GitHub · 2026-11-24 14:04 UTC · [original](https://github.com/Marvisak/VIctory/issues/915) Pull requests are limited to collaborators, so I'm posting this here. The fix is one commit on top of current `main` (`ffe310e`). I checked all 612 open PRs, and none of them touches this shortcut. **Branch:** https://github.com/talakasse/VIctory/tree/gpu/partial-detile **Commit:** https://github.com/talakasse/VIctory/commit/af4fef40372e4e1bf75b1d1600c36656b4b3ad26 ``` git fetch https://github.com/talakasse/VIctory.git gpu/partial-detile git cherry-pick af4fef4 ``` Related open PRs change the same refresh code in other ways: #143 (hash and detile from a kernel-read copy), #388 (detile into cached memory), #401 (skip hashing textures rewritten every frame), #641 (partially resident streamed textures). This one is orthogonal to them, but it will conflict textually with whichever merges first, and I can rebase it. ## Problem `victory-gpu/src/texture.rs`: "shortcut: a change detiles the whole texture, not the pages written." When one 64 KiB page of a title texture changed, the whole memory was read back (watched memory) or hashed as one, and then every mip and slice was detiled again. A streamed texture filling page by page paid that full cost at every submission that sampled it. ## Change - **`Layout::extents(mip, slice)`** (`victory-formats`): the tiled byte ranges a subresource is detiled from. There is one range per depth slice or slab, merged. Tail mips get the part of the tail block they span. - **Watched memory**: after the first detiling, only the pages written since the last asking are read again into the kept copy. - **Hashed memory**: one hash per 64 KiB page instead of one for the whole texture. - **Both**: only the subresources whose extents overlap a changed page are detiled. - **Unchanged**: the first detiling is still whole, and so is every subresource's copy into the host texture. ## Tests - **`extents_hold_what_a_subresource_detiles`** covers 9 layouts: tiled S/D at 256 B, 4 KiB and 64 KiB, linear, mip tails, arrays and 3D. It checks four things: - every element is inside its extents; - flipping every byte outside them leaves the detiled result unchanged; - ranges are sorted and disjoint; - a 2D mip outside the tail spans no more than its own blocks. - **`texture::tests`**: overlap, changed pages and page-to-range conversion. ## Checked / not checked - `cargo test -p victory-formats` passes, run on macOS. - `cargo clippy -p victory-formats -p victory-gpu --all-targets [--all-features] --target x86_64-pc-windows-msvc -- -D warnings` is clean. Locally I needed blake3's `pure` feature, because there is no Windows C compiler here. - **Not run on Windows, and not measured in the game.** The `texture::tests` unit tests and the GPU path have not been executed. The gain depends on how much frame time goes into detiling. - **Known edge:** a page that is decommitted without being written can leave stale bytes in the kept copy. The existing code had the same gap, but a full re-read sometimes hid it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:09 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 14:12 UTC · original

Native Windows 10 MSVC check at af4fef4: victory-formats 24 passed, 4 ignored. GPU diagnostics 56 passed, 1 ignored, including all three new texture::tests.

A synthetic WARP fixture with two mips and two array slices exercised Staging::refresh_now on pre-touched memory. Changing one texel on one 64 KiB page updated the expected mip and slice in the mapped upload buffer. Both hash and write-watch paths left a marker in the unrelated subresource untouched. The write-watch path read 64 KiB out of 256 KiB, then read zero bytes on the unchanged refresh.

A separate control on this Windows host showed that the first read of newly committed, untouched pages can make all four 64 KiB blocks appear written, with either a CPU copy or the kernel read. This can make the initial follow-up copy larger. The fixture checked staging bytes without submitting a draw. AI-assisted.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 14:12 UTC · [original](https://github.com/Marvisak/VIctory/issues/915#issuecomment-7134019579) Native Windows 10 MSVC check at `af4fef4`: `victory-formats` 24 passed, 4 ignored. GPU diagnostics 56 passed, 1 ignored, including all three new `texture::tests`. A synthetic WARP fixture with two mips and two array slices exercised `Staging::refresh_now` on pre-touched memory. Changing one texel on one 64 KiB page updated the expected mip and slice in the mapped upload buffer. Both hash and write-watch paths left a marker in the unrelated subresource untouched. The write-watch path read 64 KiB out of 256 KiB, then read zero bytes on the unchanged refresh. A separate control on this Windows host showed that the first read of newly committed, untouched pages can make all four 64 KiB blocks appear written, with either a CPU copy or the kernel read. This can make the initial follow-up copy larger. The fixture checked staging bytes without submitting a draw. AI-assisted.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:45 UTC · original

@⁠talakasse your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto main ffe310e. Clippy (both runs) and cargo test --workspace pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/915#issuecomment-7142547563) @⁠talakasse your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:59 UTC · original

Automated triage for the maintainers.

main still has the shortcut noted at the top of crates/victory-gpu/src/texture.rs: a change detiles the whole texture, not the pages written. This change is carried by open PR #1135 (divyeshganta, "Fixes #915"); the bundle #1610 that also carried it was closed unmerged. If you would rather open your own PR from af4fef4, pull requests are open to everyone; otherwise review continues on #1135. Whether to take it is for the maintainers.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/915#issuecomment-7155372005) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T19:45:31Z at=2026-11-25T06:59:36Z --> Automated triage for the maintainers. `main` still has the shortcut noted at the top of `crates/victory-gpu/src/texture.rs`: a change detiles the whole texture, not the pages written. This change is carried by open PR #1135 (divyeshganta, "Fixes #915"); the bundle #1610 that also carried it was closed unmerged. If you would rather open your own PR from `af4fef4`, pull requests are open to everyone; otherwise review continues on #1135. Whether to take it is for the maintainers. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#915
No description provided.