Skip to content

GPU: a texture that changed with no write seen is hashed at each check for a while - #159

Open
NuraadGit wants to merge 1 commit into
fxceless:mainfrom
NuraadGit:gpu/texture-unseen-writes
Open

NuraadGit wants to merge 1 commit into
fxceless:mainfrom
NuraadGit:gpu/texture-unseen-writes

Conversation

@NuraadGit

Copy link
Copy Markdown

What it fixes

On the loading/intro video the picture switched between older and newer frames, so the video strobed.

The video's frames are textures that the runtime writes through another view of their pages, so write watching never sees those writes. Such textures are only hashed every eighth frame, staggered by address. With a ring of three frame textures, a slot kept showing its old picture until its turn came round.

Change (crates/victory-gpu/src/texture.rs)

  • Last gets an unseen counter. If a texture's hash changed although no write to it was seen, it is hashed at each of its next 64 checks instead of waiting for its eighth-frame turn.
  • Once it has stayed the same for that long, it goes back to the eighth-frame turn. Textures whose writes are seen, and textures that don't change, behave exactly as before.
  • A diagnostics log line for the first such textures (n <= 8 or powers of two).
  • Unit test a_texture_that_changed_unseen_is_hashed_at_each_check.

Testing

RTX 2080 (8 GB, Windows 11), on this fork, warm shader cache:

  • Without the change: a script compares each captured intro frame with frames n-1, n-2 and n-3. It found 6 frames where n-2 or n-3 matched and n-1 didn't, i.e. old frames shown again.
  • With it: 0 such frames over the same capture window.
  • By eye: the video plays smoothly, and the world loads as before.
  • cargo test -p victory-gpu --lib passes; cargo clippy adds no warnings.

Cost: only textures that changed without a seen write get hashed more often, and only for 64 checks after each change.

AI-assisted (Claude Code). I reviewed and tested it.

…k for a while

Textures whose memory is written through another view of its pages (a
video's frames, written by the runtime) are never seen written, so they
were hashed only at every eighth frame, by address. A ring of three such
frame textures then showed its older pictures in turn: the loading video
strobed between old and new frames.

A texture whose hash changed though no write was seen is now hashed at
each of its next 64 checks; once it stays the same that long it goes back
to the eighth-frame turn.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T22:01:45.961513Z 6109393 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BitWuehler

Copy link
Copy Markdown

Tested on CachyOS Linux (Ryzen 7 9800X3D, RTX 5080 620.73.04, GE-Proton11-14, release build, Series X files) bundled on 4e17478 with #454, #127, #154, #95, #108, and #92:

  • victory-gpu (114/115 non-ignored pass under GE-Proton11-14; only the known vkd3d-proton CreatePipelineLibrary stub fails).
  • In a 353 s world run (41 world intervals, 0 crashes/device removals), the user visually noted the opening scene showed noticeably more cleanly compared to before #159 (alongside #95/#92/#108).
  • Together with #95 + #108 + #92, preparing: textures median dropped from 596.55 ms (892.66 ms mean) to 91.30 ms (122.55 ms mean; 10.5 ms in the final 5,426-draw frame), showing #159 did not introduce texture-path slowdowns in this Proton stack.

(AI-assisted build/log analysis.)

@Asenje

Asenje commented Nov 24, 2026

Copy link
Copy Markdown

Independent confirmation on RTX 3060 12 GB / i7-7700K, fork 4e17478 + an equivalent patch (hash a texture at every check for 60 frames after a change its guard did not see).

Capture of the intro (OBS, 60 fps, mean luma per frame; counting frames where n matches n-6 but not n-2/n-4, i.e. a 3-texture cycle):

  • without the change: 141 and 207 such frames in two runs (eagle/stars artwork cycling between pictures seconds apart)
  • with it: 0 in two runs; the zoom plays in order

The log names the ring: three textures changed unseen in the same frame (0xb4a800000, 0xb4ac00000, 0xb4b000000), then two more triples a few frames later, and three more (0xc90…) during the opening cutscene. No new warnings, no visible cost in the intro (6 draws/frame, 30 fps).

@clypeal6

Copy link
Copy Markdown

Tested on an RTX 4070 Laptop GPU (8 GB, driver 621.14, default TDR), i9-14900HX, Windows 11, Series X profile, diag build with --features diagnostics. #159 applied on top of 2119b0e (it applies cleanly; texture.rs is unchanged since its base 4e17478). Warm shader cache, debug layer off.

Jump-backs in the intro. Every presented frame from 300 to 850 was saved (VICTORY_CAPTURE_FRAMES), which covers the loading-screen transitions. A frame counts as a jump-back when it differs from frame n-1 but matches one of frames n-2…n-8, and that older frame itself differs from n-1 (mean absolute difference on a 64×36 grey thumbnail: ≤ 0.6 is a match, > 2 is a change).

Build Frames compared Picture changes Jump-backs
2119b0e (texture guard on) 551 321 246 (almost all n-3: the three-texture ring)
2119b0e + VICTORY_TEXTURE_GUARD=0 551 264 0
2119b0e + #159 551 227 0

The PR's log line fired as expected (a texture changed though no write to it was seen for 1920×1080 and 3840×2160 2D textures). By eye on the unpatched build, each loading-screen transition flickers between the old, a half-faded and the new picture for about half a second.

Cost, from runs without per-frame saving (saving every frame drops the intro to 5–7 fps, so those runs are not used here). The intro holds its 30 fps cap in all three, and reaches frames 512 and 1024 equally fast (about 18 s apart).

Build preparing: textures during the loading screens after them
guard on ~0.5 ms/frame ~0.5 ms
guard off ~3.5 ms ~3–4 ms (stays)
#159 ~6 ms ~0.5 ms

So #159 costs more than turning the guard off while the video plays (it hashes the 3840×2160 target each check), but drops back to the guarded cost once the video stops.

cargo test -p victory-gpu --lib (texture tests, including a_texture_that_changed_unseen_is_hashed_at_each_check): pass. No device removals or GPU errors in any run.

Not checked: whether it changes anything in the world; runs were 75–120 s.

AI-assisted (Claude Code): the runs, frame comparison and numbers were produced by Claude Code and checked against the logs.

@ryotdev

ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

I found one path that misses this PR’s unseen-write tracking on 6109393. When a remap is in progress and VICTORY_TEXTURE_NO_WAIT=1, refresh_unlocked stores the new hash directly. If the texture changed through an alias, the next check can still take the every-eighth-frame shortcut. #270 makes this path the default.

I put a one-file fix and synthetic regression directly on top of your head. The unlocked read now passes the same unwritten flag to Last::hashed as the ordinary path. The first snapshot and a reported write leave the counter at zero, a change without a reported write arms all 64 checks, and an unsuccessful kernel read preserves the last good state. Cherry-pickable commit

I reproduced the zero-counter failure on native Windows x64 and reran the same test after the fix. All four texture tests and the mapping synchronization test passed. The regression uses a synthetic 16-byte texture. AI-assisted.

VlREX added a commit to VlREX/victory-fork that referenced this pull request Nov 25, 2026
…uploads

Credit NuraadGit (fxceless#159), ryotdev (unlocked reads), adritoyalser (fxceless#80), arminkhaleghirod (fxceless#39/fxceless#63), and brunofgmag (geometry A/B). Preserve inline placement for correctness testing. Native validation pending.
burber added a commit to burber/victory-fork that referenced this pull request Nov 25, 2026
texture.rs: fxceless#159's unseen-write handling kept where both changes made the same fix
(victory-amd's `unguarded` / `unseen_write` left out); the rest of victory-amd's
texture changes (true-memory spans, lost views put back) kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants