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

Open
pug205gti6 wants to merge 1 commit from upstream-pr/509 into main
pug205gti6 commented 2026-11-25 01:54:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by pug205gti6 on 2026-11-25T01:54:39Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6595338965 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/509). Originally posted by [pug205gti6](https://github.com/pug205gti6) on 2026-11-25T01:54:39Z. --- …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.
Revens2 commented 2026-11-25 08:09:00 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Revens2 on 2026-11-25T07:35:59Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156041823 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/509#issuecomment-7156041823). Originally posted by [Revens2](https://github.com/Revens2) on 2026-11-25T07:35:59Z. --- 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.
xunbreakablex commented 2026-11-25 08:09:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by xunbreakablex on 2026-11-25T07:42:30Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156162453 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/509#issuecomment-7156162453). Originally posted by [xunbreakablex](https://github.com/xunbreakablex) on 2026-11-25T07:42:30Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/509:upstream-pr/509'
git switch 'upstream-pr/509'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/509'
git switch 'upstream-pr/509'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/509'
git switch 'upstream-pr/509'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/509'
git switch 'main'
git merge --squash 'upstream-pr/509'
git switch 'main'
git merge --ff-only 'upstream-pr/509'
git switch 'main'
git merge 'upstream-pr/509'
git push origin 'main'
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
fxceless/victory-fork!509
No description provided.