Repository navigation
GPU: hash a view-memory texture once more at its next check, and every check while it keeps changing - #460
Closed
xunbreakablex wants to merge 1 commit into
Closed
GPU: hash a view-memory texture once more at its next check, and every check while it keeps changing#460xunbreakablex wants to merge 1 commit into
xunbreakablex 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>
Author
|
Closing this one. I cannot follow this PR further, so closing it is cleaner than leaving it open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needs human attention: this overlaps #115, #159, #343, #438 and #456 (and the closed #58 and #63), which all try to fix the same intro flicker (textures written through another view of their pages are seen only by the hash every 8th frame). I could not tell from the threads which one you prefer to keep, so this is not a request to pick mine; it is the variant for which I have measured the cost, so that the choice can use numbers. If one of the others is merged, this can be closed.
The problem
On
maina texture in view memory is checked by its write guard, which does not see writes made through another view of the same physical pages (the Bink video planes are written that way), so the only thing that notices a change is a hash taken every 8th frame (HASH_EVERY). The planes are sampled in a ring of three, each checked every third frame, so the three host copies refresh on different frames and the picture jumps between three older frames.What this changes
After the hash finds a texture changed, it is hashed once more at its next check (not the next frame: a ring texture is checked every third frame, so a "next frame" check never sees the second change). Only if that second hash also finds a change is the texture "hot" and hashed at every check while it keeps changing, until 24 frames after the last change. A texture that streams in changes once and is not hashed any more. State per texture:
Last { hot_until, changed_at, verify }, withchanged,unchangedandhash_due. Onlycrates/victory-gpu/src/texture.rschanges (+100/-1).Measured
All on a diag build of
7b0f736plus this change (the commit here is the same change ona803c87; I have not run the game ona803c87), RTX 4070 12 GB, Ryzen 5 5600, driver 621.01, Windows 11 26300.VICTORY_CAPTUREframes, mean difference of consecutive frames divided by the mean difference of frames three apart: smooth scene 0.36; with the bug 7.5 (15 runs, 6.5-7.9); with this change 0.57 (2 runs). Counting the moving frame triples where frame n+1 looks more like n-1 than like n: 47-62% in 15 runs with the bug, 0.0% (95% interval 0.0-3.4%, 108 triples) in 2 runs with this change.cargo test -p victory-gpu --lib -- hot_texture_tests, no GPU).cargo check -p victory-gpu(also--features diagnostics) andcargo clippy -p victory-gpu --all-targets -- -D warnings(also--all-features): clean.Not measured
#58, #159, #343, #438, #456 and #115 themselves: I do not know their cost in the world, only the cost of my first variant. Other GPUs. The Linux/Proton reports in #39 mention a remaining jump of about one frame in 16 to 20 that this does not address.
AI-assisted (Claude); the runs were done on my machine.