Skip to content

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

Open
pug205gti6 wants to merge 1 commit into
fxceless:mainfrom
pug205gti6:pr/460-gpu-hash-texture
Open

pug205gti6 wants to merge 1 commit into
fxceless:mainfrom
pug205gti6:pr/460-gpu-hash-texture

Conversation

@pug205gti6

Copy link
Copy Markdown

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

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

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.

3 participants