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 from upstream-pr/460 into main
xunbreakablex commented 2026-11-25 01:12:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by xunbreakablex on 2026-11-25T01:12:33Z.


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 main a 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 }, with changed, unchanged and hash_due. Only crates/victory-gpu/src/texture.rs changes (+100/-1).

Measured

All on a diag build of 7b0f736 plus this change (the commit here is the same change on a803c87; I have not run the game on a803c87), RTX 4070 12 GB, Ryzen 5 5600, driver 621.01, Windows 11 26300.

  • Intro, from VICTORY_CAPTURE frames, 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.
  • The first variant I tried, hashing every changed texture at every check for 120 frames (the same idea as #343 as I read it), raised the texture preparation in the world from 13 ms to 160 ms per frame (median frame 394 → 607 ms, one run each), because streaming textures change once and were then hashed every frame for 120 frames. With this change: texture preparation 13-21 ms (it was 13 ms before any fix), median frame 336-343 ms (3 runs, warm shader cache, no capture), same number of dropped draws.
  • 3 unit tests for the state machine (cargo test -p victory-gpu --lib -- hot_texture_tests, no GPU).
  • cargo check -p victory-gpu (also --features diagnostics) and cargo 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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594820096 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/460). Originally posted by [xunbreakablex](https://github.com/xunbreakablex) on 2026-11-25T01:12:33Z. --- **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 `main` a 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 }`, with `changed`, `unchanged` and `hash_due`. Only `crates/victory-gpu/src/texture.rs` changes (+100/-1). ### Measured All on a diag build of `7b0f736` plus this change (the commit here is the same change on `a803c87`; I have not run the game on `a803c87`), RTX 4070 12 GB, Ryzen 5 5600, driver 621.01, Windows 11 26300. - Intro, from `VICTORY_CAPTURE` frames, 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. - The first variant I tried, hashing every changed texture at every check for 120 frames (the same idea as #343 as I read it), raised the texture preparation in the world from 13 ms to 160 ms per frame (median frame 394 → 607 ms, one run each), because streaming textures change once and were then hashed every frame for 120 frames. With this change: texture preparation 13-21 ms (it was 13 ms before any fix), median frame 336-343 ms (3 runs, warm shader cache, no capture), same number of dropped draws. - 3 unit tests for the state machine (`cargo test -p victory-gpu --lib -- hot_texture_tests`, no GPU). - `cargo check -p victory-gpu` (also `--features diagnostics`) and `cargo 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.
upstream-sync closed this pull request 2026-11-25 08:08:36 +00:00
xunbreakablex commented 2026-11-25 08:08:59 +00:00 (Migrated from github.com)

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


Closing this one. main now has 8dd30ab ("A write through one view of a page is seen at its other views"), which removes the cause this change worked around: the guard did not see writes made through another view of a texture's pages, so only the hash every 8th frame noticed them. I have not re-run the intro on the new main, so I cannot say whether the flicker is gone there; if it comes back, the cost numbers in the description (hashing every changed texture for 120 frames cost 13 → 160 ms a frame in the world, hash-once-more-then-hot cost 13-21 ms) may still be useful to whoever looks at it.

I cannot follow this PR further, so closing it is cleaner than leaving it open.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7155888873 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/460#issuecomment-7155888873). Originally posted by [xunbreakablex](https://github.com/xunbreakablex) on 2026-11-25T07:27:53Z. --- Closing this one. `main` now has `8dd30ab` ("A write through one view of a page is seen at its other views"), which removes the cause this change worked around: the guard did not see writes made through another view of a texture's pages, so only the hash every 8th frame noticed them. I have not re-run the intro on the new `main`, so I cannot say whether the flicker is gone there; if it comes back, the cost numbers in the description (hashing every changed texture for 120 frames cost 13 → 160 ms a frame in the world, hash-once-more-then-hot cost 13-21 ms) may still be useful to whoever looks at it. I cannot follow this PR further, so closing it is cleaner than leaving it open.

Pull request closed

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!460
No description provided.