Skip to content

GPU: hash a guarded texture at every check while it keeps changing (#269) - #343

Open
PAYS0 wants to merge 2 commits into
fxceless:mainfrom
PAYS0:fix/texture-guard-recent-changes
Open

PAYS0 wants to merge 2 commits into
fxceless:mainfrom
PAYS0:fix/texture-guard-recent-changes

Conversation

@PAYS0

@PAYS0 PAYS0 commented Nov 24, 2026

Copy link
Copy Markdown

Fixes #269.

Problem

With VICTORY_TEXTURE_GUARD on (the default), a texture in view memory that the guard saw no write to is hashed only every eighth frame (HASH_EVERY, by address so textures take turns). The code already notes that a write through another view is not seen by the guard. The startup screens and intro are evidently written that way, so they were shown up to eight frames stale: repeated frames, jumping and flicker. #269 bisected it to this switch alone, and four more people in that thread confirmed VICTORY_TEXTURE_GUARD=0 removes it.

Fix

  • Last gains changed: the frame a hash last found the texture's memory changed. A new Last::rehash sets it, and every hashing path uses it (partly mapped, through the copy, in place, and the unlocked read).
  • The guard's skip decision moves into guard_skips. For RECENTLY_CHANGED (16, two turns) frames after a change, a texture is not skipped.
  • A texture that keeps changing (a video, an animated screen) is therefore hashed at every check, as with the guard off. One that stops goes back to taking turns, so still textures, which are where the guard's ~51 ms/frame saving came from, keep it.
  • Nothing changes for textures with a write-watch, for writes the guard does see, or with VICTORY_TEXTURE_GUARD=0.

Testing

  • New unit tests guard_tests::a_still_texture_takes_its_turn and guard_tests::a_changing_texture_is_hashed_at_every_frame, including frame counter wrap-around.
  • cargo test -p victory-gpu on Windows 11 at this commit: 112 passed, 0 failed (1 ignored benchmark). No clippy warnings in texture.rs, with or without --features diagnostics.
  • Not yet checked in the game. Could someone from Startup screens and intro flicker / show repeated frames – caused by VICTORY_TEXTURE_GUARD #269 confirm the startup screens and intro are smooth with the guard left on, and say whether the frame time in the world moves? VICTORY_TEXTURE_GUARD=0 stays the workaround until then.

Developed with Claude Code on Claude Opus 5.5.

🤖 Generated with Claude Code

…xceless#269)

A guarded texture in view memory that the guard saw no write to was
hashed every eighth frame only. A texture the title rewrites through
another view (the startup screens, video frames) changes where the guard
cannot see it, so it was shown up to eight frames stale: repeated frames
and flicker at startup and in the intro, gone with
VICTORY_TEXTURE_GUARD=0.

Each hash that finds a texture changed now notes the frame (`Last::rehash`,
used by every hashing path), and for 16 frames after that the guard does
not skip the texture. One that keeps changing is hashed at every check;
one that stops goes back to taking turns, so still textures keep the
guard's saving. The skip decision is a function (`guard_skips`) with unit
tests.

Not yet checked in the game: the change is to when a texture is hashed,
not to what is read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@avt0m4t48

Copy link
Copy Markdown

I checked 366ccb7 against 2119b0e with the exact refresh functions, real BLAKE3, and one synthetic 64 KiB file mapped at two addresses. The harness passed 6/6 on main and 8/8 on this branch with the guard both enabled and disabled. Requiring the branch's cadence on main failed.

Synthetic checks with the guard enabled Main This PR
One texture changing every check from cold 35 stale / 39 7 stale / 39, all before the first changed digest
Three rotating textures after first discovery 63 stale / 72 0 stale / 72
Original contents return at every scheduled hash 21 stale / 24 21 stale / 24
A newly read static texture 4 hashes / 32 18 hashes / 32

The discovery interval depends on when that slot is checked. With a slot used every third host frame, eight checks can take 24 host frames. If the old image is present at every scheduled hash, neither version enters the hot window. This is a useful control for a follow-up capture, especially given that #115 has intro results from AMD and NVIDIA using direct alias-write tracking.

Both models returned to the normal cadence once the texture settled. The harness mocked Windows guard, remap and detile operations. Game output and frame time still need a native run. Verified with Codex assistance.

Review on fxceless#343 found that a newly read static texture was hashed at every
check for its first 16 frames (18 hashes in 32 frames against 4 on main),
because its first hash counted as a change.

`Last::rehash` now notes the frame only when an earlier hash differs. A
texture just read takes turns as before; one that changes enters the
every-check window at its first changed hash. New test
`only_a_second_differing_hash_is_a_change`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PAYS0

PAYS0 commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks for running this. Pushed a follow-up (c4dc17e): a texture's first hash no longer opens the every-frame window, so a newly read static texture is back to main's cadence; one that changes enters it at its first changed digest. The "original contents at every scheduled hash" case is unchanged, as you say; only seeing the writes catches it, which is what #115 does at the source. This PR is meant to complement that: the hash net under the guard reacts within a frame, instead of up to eight, for any write path the guard still misses. Happy to rebase on #115 or close this if the maintainer prefers.

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.

Startup screens and intro flicker / show repeated frames – caused by VICTORY_TEXTURE_GUARD

2 participants