GPU: reduce work in texture refresh and readback #401

Closed
cat4blep wants to merge 1 commit from upstream-pr/401 into main
cat4blep commented 2026-11-24 02:56:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cat4blep on 2026-11-24T02:56:22Z.


Changes

  • Skip BLAKE3 for a bounded burst of full detiles after four consecutive hash changes in an unwatched texture. Run eight such refreshes before hashing again. Returning to write-watch invalidates the unwatched digest.
  • Reuse the diagnostics present probe's readback buffer across frames, under the existing presentation lock and fence.
  • Reuse one 64 KiB CPU buffer per submission for GPU copy-back. Merge the GPU's changed bytes with concurrent title edits using a vectorizable loop and preserve the existing write predicate.
  • Record consecutive dirty kernel pages that belong to one title page once per journal epoch, without an intermediate allocation.

Runtime context

An earlier local Windows run on an RTX 3060 Ti processed 12.7 MB of movie-texture data per frame. With the hash bypass, about 5.1 MB was hashed and 7.6 MB was detiled without hashing. That run also carried independent pacing and rendering changes, so these figures describe the hash workload in that build. Verification of this branch uses the tests below.

Verification

  • cargo test --locked --workspace --profile diag --features victory/diagnostics
  • cargo check --locked --workspace --profile diag
  • cargo xtask policy --staged
  • git diff --check
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573576584 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/401). Originally posted by [cat4blep](https://github.com/cat4blep) on 2026-11-24T02:56:22Z. --- ## Changes - Skip BLAKE3 for a bounded burst of full detiles after four consecutive hash changes in an unwatched texture. Run eight such refreshes before hashing again. Returning to write-watch invalidates the unwatched digest. - Reuse the diagnostics present probe's readback buffer across frames, under the existing presentation lock and fence. - Reuse one 64 KiB CPU buffer per submission for GPU copy-back. Merge the GPU's changed bytes with concurrent title edits using a vectorizable loop and preserve the existing write predicate. - Record consecutive dirty kernel pages that belong to one title page once per journal epoch, without an intermediate allocation. ## Runtime context An earlier local Windows run on an RTX 3060 Ti processed 12.7 MB of movie-texture data per frame. With the hash bypass, about 5.1 MB was hashed and 7.6 MB was detiled without hashing. That run also carried independent pacing and rendering changes, so these figures describe the hash workload in that build. Verification of this branch uses the tests below. ## Verification - `cargo test --locked --workspace --profile diag --features victory/diagnostics` - `cargo check --locked --workspace --profile diag` - `cargo xtask policy --staged` - `git diff --check`
mercuryVM commented 2026-11-24 06:52:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:19:08Z.

Review: APPROVED


Tested 0b5838d on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (268 passed, 0 failed).

  • merge_copy_back writes when h != old && t != h, the same condition as the loop it replaces. The new exhaustive test over 5×5×5 values checks that, and the "already merged" test checks that no write is issued then.
  • The copy-back scratch buffer is now PAGE bytes from the caller instead of a 64 KiB vec! per copy_back call. Pieces split on PAGE, so title[..n] always fits.
  • Texture hash bypass: a bypassed refresh still detiles the whole texture, so correctness doesn't depend on the hash. Only the skipped work changes. Clearing the unwatched digest when the texture goes back to being watched is the right invalidation.
  • Reusing the probe readback buffer is safe given the existing presentation lock and fence wait before black reads it.

Heads-up: this conflicts with #472 (texture.rs scratch buffer, shadow.rs growth) and #435/#440 (the copy-back loop in host.rs), which change the same lines. Whichever lands second needs a rebase. I have not merged it into our fork for that reason.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034584969 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/401#pullrequestreview-6034584969). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T06:19:08Z. **Review:** APPROVED --- Tested 0b5838d on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (268 passed, 0 failed). - `merge_copy_back` writes when `h != old && t != h`, the same condition as the loop it replaces. The new exhaustive test over 5×5×5 values checks that, and the "already merged" test checks that no write is issued then. - The copy-back scratch buffer is now `PAGE` bytes from the caller instead of a 64 KiB `vec!` per `copy_back` call. Pieces split on `PAGE`, so `title[..n]` always fits. - Texture hash bypass: a bypassed refresh still detiles the whole texture, so correctness doesn't depend on the hash. Only the skipped work changes. Clearing the unwatched digest when the texture goes back to being watched is the right invalidation. - Reusing the probe readback buffer is safe given the existing presentation lock and fence wait before `black` reads it. Heads-up: this conflicts with #472 (`texture.rs` scratch buffer, `shadow.rs` growth) and #435/#440 (the copy-back loop in `host.rs`), which change the same lines. Whichever lands second needs a rebase. I have not merged it into our fork for that reason. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 06:55:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:30:34Z.


Thanks @cat4blep for the GPU refresh/readback changes. I tested head 0b5838d4d2711021beca723254075f67a248d4c2 with:

cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1

Result: 49 passed, 0 failed, 1 ignored. The suite includes the bounded texture-refresh burst and interrupted-streak cases, copyback merge behavior, guarded-view checks, and the affected GPU unit modules. The ignored per-submission benchmark was not run, so this verifies correctness tests but provides no performance measurement; no title workload was run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122083699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/401#issuecomment-7122083699). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:30:34Z. --- Thanks @cat4blep for the GPU refresh/readback changes. I tested head `0b5838d4d2711021beca723254075f67a248d4c2` with: ``` cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 ``` Result: 49 passed, 0 failed, 1 ignored. The suite includes the bounded texture-refresh burst and interrupted-streak cases, copyback merge behavior, guarded-view checks, and the affected GPU unit modules. The ignored per-submission benchmark was not run, so this verifies correctness tests but provides no performance measurement; no title workload was run.
upstream-sync closed this pull request 2026-11-25 00:05:25 +00:00
Marvisak commented 2026-11-25 00:06:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:02:30Z.


Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Four unrelated micro-optimisations (skipping hashes in bursts, a reused probe buffer, a reused copy-back buffer, a tweak to watch::writes), each against code main replaced today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148071823 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/401#issuecomment-7148071823). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:02:30Z. --- Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Four unrelated micro-optimisations (skipping hashes in bursts, a reused probe buffer, a reused copy-back buffer, a tweak to watch::writes), each against code main replaced today. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!401
No description provided.