GPU: hash a view-memory texture once more at its next check, and ever… #509

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

@⁠pug205gti6 on GitHub · 2026-11-25 01:54 UTC · original
pug205gti6:pr/460-gpu-hash-texture → main · +100 −1 · 1 files · 1 commits · open

…y check while it keeps changing

Why: the title's Bink 2 video planes live in view memory. They are written through the CPU view of their pages and sampled through the GPU view, and they cycle through a ring of three textures, so each texture is sampled (and checked) only every third frame. The guard on view memory sees writes made through the texture's own view but not a write to the same pages through another view, and what it cannot see was found only by a hash taken every eighth frame (HASH_EVERY), by the texture's address. Each plane therefore showed up to seven frames late, and the intro's picture jumped between three older frames.

What: a texture whose hash found it changed is hashed once more at its next check. If it changed again it is hot: it is hashed at every check while it keeps changing, and for 24 frames after its last change (HOT_FRAMES). A texture that streams in changes once, is found as it was at the extra look, and is not hashed on. The state is three fields of Last (hot_until, changed_at, verify) and three small methods (changed, unchanged, hash_due); the turn test becomes turn || last.hash_due(frame).

Why the next check and not the next frame: a ring texture is checked every third frame, so "changed again" cannot mean "changed in the next frame"; the extra look counts for VERIFY_FRAMES (24) frames after the change.

Measured on frames of the intro: the ratio of the mean difference between consecutive frames to that between frames three apart was 7.5 with the bug and is 0.57 now (a smooth scene: 0.36). In the world the cost is as before (textures 12.9 ms against 13.2 ms, median frame 336 ms against 394 ms). Hashing every check (VICTORY_TEXTURE_GUARD=0) fixes the intro too but cost 160 ms a frame in the world in an earlier attempt, and a 120-frame hot window made the world's texture work 160 ms. Three unit tests (no GPU) cover the state machine: a texture changing at every check goes hot, one that changed once does not, a hot one cools down.

**@⁠pug205gti6** on GitHub · 2026-11-25 01:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/509) `pug205gti6:pr/460-gpu-hash-texture` → `main` · +100 −1 · 1 files · 1 commits · open …y check while it keeps changing Why: the title's Bink 2 video planes live in view memory. They are written through the CPU view of their pages and sampled through the GPU view, and they cycle through a ring of three textures, so each texture is sampled (and checked) only every third frame. The guard on view memory sees writes made through the texture's own view but not a write to the same pages through another view, and what it cannot see was found only by a hash taken every eighth frame (`HASH_EVERY`), by the texture's address. Each plane therefore showed up to seven frames late, and the intro's picture jumped between three older frames. What: a texture whose hash found it changed is hashed once more at its next check. If it changed again it is hot: it is hashed at every check while it keeps changing, and for 24 frames after its last change (`HOT_FRAMES`). A texture that streams in changes once, is found as it was at the extra look, and is not hashed on. The state is three fields of `Last` (`hot_until`, `changed_at`, `verify`) and three small methods (`changed`, `unchanged`, `hash_due`); the turn test becomes `turn || last.hash_due(frame)`. Why the next check and not the next frame: a ring texture is checked every third frame, so "changed again" cannot mean "changed in the next frame"; the extra look counts for `VERIFY_FRAMES` (24) frames after the change. Measured on frames of the intro: the ratio of the mean difference between consecutive frames to that between frames three apart was 7.5 with the bug and is 0.57 now (a smooth scene: 0.36). In the world the cost is as before (textures 12.9 ms against 13.2 ms, median frame 336 ms against 394 ms). Hashing every check (VICTORY_TEXTURE_GUARD=0) fixes the intro too but cost 160 ms a frame in the world in an earlier attempt, and a 120-frame hot window made the world's texture work 160 ms. Three unit tests (no GPU) cover the state machine: a texture changing at every check goes hot, one that changed once does not, a hot one cools down.
Why: the title's Bink 2 video planes live in view memory. They are written
through the CPU view of their pages and sampled through the GPU view, and
they cycle through a ring of three textures, so each texture is sampled
(and checked) only every third frame. The guard on view memory sees writes
made through the texture's own view but not a write to the same pages
through another view, and what it cannot see was found only by a hash taken
every eighth frame (`HASH_EVERY`), by the texture's address. Each plane
therefore showed up to seven frames late, and the intro's picture jumped
between three older frames.

What: a texture whose hash found it changed is hashed once more at its next
check. If it changed again it is hot: it is hashed at every check while it
keeps changing, and for 24 frames after its last change (`HOT_FRAMES`). A
texture that streams in changes once, is found as it was at the extra look,
and is not hashed on. The state is three fields of `Last` (`hot_until`,
`changed_at`, `verify`) and three small methods (`changed`, `unchanged`,
`hash_due`); the turn test becomes `turn || last.hash_due(frame)`.

Why the next check and not the next frame: a ring texture is checked every
third frame, so "changed again" cannot mean "changed in the next frame";
the extra look counts for `VERIFY_FRAMES` (24) frames after the change.

Measured on frames of the intro: the ratio of the mean difference between
consecutive frames to that between frames three apart was 7.5 with the bug
and is 0.57 now (a smooth scene: 0.36). In the world the cost is as before
(textures 12.9 ms against 13.2 ms, median frame 336 ms against 394 ms).
Hashing every check (VICTORY_TEXTURE_GUARD=0) fixes the intro too but cost
160 ms a frame in the world in an earlier attempt, and a 120-frame hot
window made the world's texture work 160 ms. Three unit tests (no GPU)
cover the state machine: a texture changing at every check goes hot, one
that changed once does not, a hot one cools down.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:45:00 +00:00
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 07:35 UTC · original

Duplicate of #460: @⁠xunbreakablex opened this patch 42 minutes earlier, and gh pr diff returns the same bytes for both (+100/-1 on 1 file(s), same title).

Please continue in #460 so the review history and any test data stay in one place.
Thanks.

**@⁠Revens2** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/509#issuecomment-7156041823) Duplicate of #460: @⁠xunbreakablex opened this patch 42 minutes earlier, and `gh pr diff` returns the same bytes for both (+100/-1 on 1 file(s), same title). Please continue in #460 so the review history and any test data stay in one place. Thanks.
Author
Owner

@⁠xunbreakablex on GitHub · 2026-11-25 07:42 UTC · original

For whoever follows this: #460 is closed (not merged). I closed it because main now has 8dd30ab ("A write through one view of a page is seen at its other views"), which removes the cause both patches worked around, so the hash-twice-then-hot change may no longer be needed. I have not re-run the intro on the new main to check, and I cannot follow either PR further. The cost numbers in #460's description (the first variant, 120 frames hot, cost 13 → 160 ms a frame in the world; this variant 13-21 ms) can be reused if the flicker comes back.

**@⁠xunbreakablex** on GitHub · 2026-11-25 07:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/509#issuecomment-7156162453) For whoever follows this: #460 is closed (not merged). I closed it because `main` now has `8dd30ab` ("A write through one view of a page is seen at its other views"), which removes the cause both patches worked around, so the hash-twice-then-hot change may no longer be needed. I have not re-run the intro on the new `main` to check, and I cannot follow either PR further. The cost numbers in #460's description (the first variant, 120 frames hot, cost 13 → 160 ms a frame in the world; this variant 13-21 ms) can be reused if the flicker comes back.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.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/509/head:github-bot/gh-509'
git switch 'github-bot/gh-509'

Merge

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