Stop re-zeroing the texture scratch buffer, and reuse the placed-texture set #63

Closed
github-bot wants to merge 1 commit from github-bot/gh-63 into main AGit
Owner

@⁠romainhedouin on GitHub · 2026-11-25 13:16 UTC · original
romainhedouin:perf/texture-refresh-no-zero-fill → main · +23 −10 · 2 files · 1 commits · closed without merging

Two small cuts in texture refresh:

  • Scratch buffer. Refreshing a texture whose memory is not write-watched copies it into a per-thread scratch buffer, after resize(size, 0). Every time a texture was bigger than the previous one, the extra part was zero-filled, then immediately overwritten by the copy (which writes every byte, zeros for unreadable pages). The buffer now keeps its length, as with_tiled_copy already does, so only a texture bigger than any before is zero-filled. The diagnostics mode that skips copies still hashes zeros.
  • placed_live. It rebuilt a set of every placed texture from PLACED_TEXTURES with one hash insert each, while PLACED_LIVE already holds exactly that set (both change together under the same lock). It now clones PLACED_LIVE.
Before After
Bytes zero-filled per refresh growth over the previous texture growth over the largest so far (≈0 in steady state)
Model benchmark, 8 textures/frame alternating 4 MiB / 64 KiB, 2,000 frames 20 GiB zeroed, 164 ms 4 MiB, 0.3 ms
placed_live, model benchmark, 20,000 placed textures 194 µs 4.7 µs

"Model benchmark" = the same logic copied into a standalone program and timed in release mode on a Mac, not in the game. Type-checked for Windows (cargo clippy --target x86_64-pc-windows-msvc, with and without --all-features, no new warnings); not run.

🤖 Generated with Claude Code

**@⁠romainhedouin** on GitHub · 2026-11-25 13:16 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/63) `romainhedouin:perf/texture-refresh-no-zero-fill` → `main` · +23 −10 · 2 files · 1 commits · closed without merging Two small cuts in texture refresh: - **Scratch buffer.** Refreshing a texture whose memory is not write-watched copies it into a per-thread scratch buffer, after `resize(size, 0)`. Every time a texture was bigger than the previous one, the extra part was zero-filled, then immediately overwritten by the copy (which writes every byte, zeros for unreadable pages). The buffer now keeps its length, as `with_tiled_copy` already does, so only a texture bigger than any before is zero-filled. The diagnostics mode that skips copies still hashes zeros. - **`placed_live`.** It rebuilt a set of every placed texture from `PLACED_TEXTURES` with one hash insert each, while `PLACED_LIVE` already holds exactly that set (both change together under the same lock). It now clones `PLACED_LIVE`. | | Before | After | |---|---|---| | Bytes zero-filled per refresh | growth over the previous texture | growth over the largest so far (≈0 in steady state) | | Model benchmark, 8 textures/frame alternating 4 MiB / 64 KiB, 2,000 frames | 20 GiB zeroed, 164 ms | 4 MiB, 0.3 ms | | `placed_live`, model benchmark, 20,000 placed textures | 194 µs | 4.7 µs | "Model benchmark" = the same logic copied into a standalone program and timed in release mode on a Mac, not in the game. Type-checked for Windows (`cargo clippy --target x86_64-pc-windows-msvc`, with and without `--all-features`, no new warnings); not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:49 +00:00
@ -336,1 +342,4 @@
crate::host::copy_mapped(tiled.as_mut_ptr(), self.memory, size, false);
// The diagnostics mode without copies writes nothing: it hashes zeros, as before.
#[cfg(feature = "diagnostics")]
if crate::copystat::mode() == 2 {
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:09 UTC · original

Could a diagnostics-mode regression test prefill the retained scratch buffer with nonzero bytes, run a no-copy refresh, and verify that the hash sees zeros? That explicit fill preserves the old behavior after scratch stops being resized to zero on every refresh. AI-assisted review; I checked the diagnostics-only zero-fill and scratch reuse path.

**@⁠gut0to** on GitHub · 2026-11-25 15:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/63#discussion_r4696898892) Could a diagnostics-mode regression test prefill the retained scratch buffer with nonzero bytes, run a no-copy refresh, and verify that the hash sees zeros? That explicit fill preserves the old behavior after scratch stops being resized to zero on every refresh. AI-assisted review; I checked the diagnostics-only zero-fill and scratch reuse path.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 15:09 UTC · original · reviewed

AI-assisted review: I checked the changed behavior and the associated test coverage.

**@⁠gut0to** on GitHub · 2026-11-25 15:09 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/63#pullrequestreview-6060186136) · **reviewed** AI-assisted review: I checked the changed behavior and the associated test coverage.
github-bot closed this pull request 2026-11-27 01:00:03 +00:00
Author
Owner

@⁠romainhedouin on GitHub · 2026-11-26 22:24 UTC · original

Closing: on a-publier the texture read buffer already only grows (with_read, texture.rs:433), and the placed-texture set this PR reused doesn't exist.

**@⁠romainhedouin** on GitHub · 2026-11-26 22:24 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/63#issuecomment-7204650646) Closing: on `a-publier` the texture read buffer already only grows (`with_read`, texture.rs:433), and the placed-texture set this PR reused doesn't exist.

Pull request closed

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