Repository navigation
GPU: hash a view-memory texture once more at its next check, and ever… - #509
pug205gti6 wants to merge 1 commit into
Conversation
…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>
|
Duplicate of #460: @xunbreakablex opened this patch 42 minutes earlier, and Please continue in #460 so the review history and any test data stay in one place. |
|
For whoever follows this: #460 is closed (not merged). I closed it because |
…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 ofLast(hot_until,changed_at,verify) and three small methods (changed,unchanged,hash_due); the turn test becomesturn || 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.