Skip to content

GPU: reduce work in texture refresh and readback - #401

Closed
cat4blep wants to merge 1 commit into
Marvisak:mainfrom
cat4blep:victory-d2a4bae1
Closed

cat4blep wants to merge 1 commit into
Marvisak:mainfrom
cat4blep:victory-d2a4bae1

Conversation

@cat4blep

Copy link
Copy Markdown

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

@jeremygold02

Copy link
Copy Markdown
Contributor

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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Jarrrk pushed a commit to Jarrrk/VIctory that referenced this pull request Nov 24, 2026
…hashes

Per-frame copy-machinery churn is reduced: Shadow::copy_back reuses a
caller scratch buffer instead of allocating and zeroing 64 KiB on every
call, the diagnostics probe reuses its readback buffer, watch::writes
deduplicates kernel pages that fold into one title page, and unwatched
textures that change every frame skip their content hash for a short burst.

Ported from Marvisak/VIctory Marvisak#401.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Marvisak

Copy link
Copy Markdown
Owner

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.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants