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

Open
github-bot wants to merge 1 commit from github-bot/gh-159 into main AGit
Owner

@⁠NuraadGit on GitHub · 2026-11-24 21:59 UTC · original
NuraadGit:gpu/texture-unseen-writes → main · +81 −6 · 1 files · 1 commits · open

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.

**@⁠NuraadGit** on GitHub · 2026-11-24 21:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/159) `NuraadGit:gpu/texture-unseen-writes` → `main` · +81 −6 · 1 files · 1 commits · open ## 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.*
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:10 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 21:59 UTC · original · edited 2026-11-24 22:01 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 21:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/159#issuecomment-7145658736) · edited 2026-11-24 22:01 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6109393264af764ee99445b39bf30c2b88d29f99","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T22:01:45.961513Z">2026-11-24T22:01:45.961513Z</relative-time> | `6109393` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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. </details> </details>
Author
Owner

@⁠BitWuehler on GitHub · 2026-11-24 22:40 UTC · original

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.)

**@⁠BitWuehler** on GitHub · 2026-11-24 22:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/159#issuecomment-7146501516) 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.)*
Author
Owner

@⁠Asenje on GitHub · 2026-11-24 23:04 UTC · original

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).

**@⁠Asenje** on GitHub · 2026-11-24 23:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/159#issuecomment-7146981647) 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).
Author
Owner

@⁠clypeal6 on GitHub · 2026-11-24 23:05 UTC · original

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.

**@⁠clypeal6** on GitHub · 2026-11-24 23:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/159#issuecomment-7147001962) **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.*
Author
Owner

@⁠ryotdev on GitHub · 2026-11-24 23:39 UTC · original

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.

**@⁠ryotdev** on GitHub · 2026-11-24 23:39 UTC · [original](https://github.com/fxceless/victory-fork/pull/159#issuecomment-7147643592) 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](https://github.com/ryotdev/VIctory/commit/680c2f60629a7724befec1ee9bb72734cf675e7f) 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.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/159/head:github-bot/gh-159'
git switch 'github-bot/gh-159'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-159'
git switch 'github-bot/gh-159'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-159'
git switch 'github-bot/gh-159'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-159'
git switch 'main'
git merge --squash 'github-bot/gh-159'
git switch 'main'
git merge --ff-only 'github-bot/gh-159'
git switch 'main'
git merge 'github-bot/gh-159'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.