GPU: texture refreshes do not wait for the title-memory lock by default (mitigates the title's stop at world entry: 9 of 25 entries before, 0 of 15 with it) #137

Open
Impre-visible wants to merge 1 commit from upstream-pr/137 into main
Impre-visible commented 2026-11-25 14:11:02 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Impre-visible on 2026-11-25T13:45:31Z.


What

Makes VICTORY_TEXTURE_NO_WAIT the default (texture refreshes read through the kernel or retry at the next refresh instead of waiting for the title-memory lock); VICTORY_TEXTURE_NO_WAIT=0 restores the old waiting. One small test for the switch's parsing.

It is a mitigation, not a fix, for a stop at world entry that hit about one run in three on my machine (GTX 1660, Linux, Wine + vkd3d-proton 2576c0b).

The stop it mitigates

Symptom: a few frames into the world the title ends itself with its own unhandled access violation writing address 0, from a thread started directly by kernel32 (its watchdog). No Xid, no device removal. Possibly what #28 and #39 describe, but I cannot tell from here.

What I measured with stall dumps (state of our queues and locks plus every thread's stack at 12 s and 24 s without a present, and at the exception) in three such runs:

  • Our side is idle: nothing inside execute or present, the title-memory and guard locks free, no queue holding anything, all DirectStorage / pipeline / XAsync workers waiting for work.
  • The title's waits go straight to WaitForSingleObject / Sleep; no VIctory frame between title code and the wait.
  • The title's main thread waits for a job group. One or two of the title's job threads are not waiting: they spin in a hash-map lookup that only ends when the key is found.
  • The map is intact and current, but it does not hold the key: it holds the same pool slot one generation older. A call trace shows the title rebuilds that map once per frame, a few ms after the jobs that look things up, so each frame's lookups use the previous frame's map. In the stopped run the map was 7.35 s old.

So it is a race inside the title (a slot freed and reused within one frame), with a window of one frame of wall-clock time: 33 ms on the console, 6 to 8 s at world entry here. Nothing of ours writes that table. Disabling the title's watchdog cannot help: the lookup never ends, the title would hang instead.

Why this change

Of those 6.5 s entry frames, 1.0 to 1.9 s per frame were texture refreshes waiting for the title-memory lock (the waiting for title memory figure in the frame statistics). With this change that figure is 0.0 ms in the runs below. No work is skipped; a texture can show one frame late.

Measured

World entries on the same machine and tree, counted one run at a time:

title stops at world entry world entries
before 9 25
with this change 0 15

Fifteen entries in a row without that stop would happen by chance about once in 800 at the old rate (16 of 25 entries survived).

To be complete about those 15 runs: 13 were clean; one had a single 16 s frame in the steady scene (CPU side: 5.4 s preparing, 6.9 s copying back, 0.8 s on the card) and then went on; one ended with Xid 109 13 s after world entry. Neither is the stop described above (no spinning title job). Both happened on a tree that also carries #119; see the caveat I posted there for the Xid. I have no evidence that this change causes or prevents either.

Checks on this branch alone: Windows cargo check -p victory --features diagnostics clean; cargo test -p victory-shader --lib 170 passed, 2 ignored. The new test in victory-gpu compiles but I did not run it (that crate's tests need a Windows device).

Not tested / limits

  • It shortens the window; it does not close the race. Other long parts of the entry frames remain (write-watch queries 1 to 3 s, copies 0.7 to 3.8 s per frame).
  • Windows, AMD, and anything past the first playable scene.
  • The image: I saw no difference in the scene over these runs, but did not compare frames pixel by pixel.

No game files, addresses, strings or hashes in this PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Zettrox/ztrx:issue:6605908552 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/137). Originally posted by [Impre-visible](https://github.com/Impre-visible) on 2026-11-25T13:45:31Z. --- ## What Makes `VICTORY_TEXTURE_NO_WAIT` the default (texture refreshes read through the kernel or retry at the next refresh instead of waiting for the title-memory lock); `VICTORY_TEXTURE_NO_WAIT=0` restores the old waiting. One small test for the switch's parsing. It is a **mitigation**, not a fix, for a stop at world entry that hit about one run in three on my machine (GTX 1660, Linux, Wine + vkd3d-proton `2576c0b`). ## The stop it mitigates Symptom: a few frames into the world the title ends itself with its own unhandled access violation writing address 0, from a thread started directly by `kernel32` (its watchdog). No `Xid`, no device removal. Possibly what #28 and #39 describe, but I cannot tell from here. What I measured with stall dumps (state of our queues and locks plus every thread's stack at 12 s and 24 s without a present, and at the exception) in three such runs: - Our side is idle: nothing inside execute or present, the title-memory and guard locks free, no queue holding anything, all DirectStorage / pipeline / XAsync workers waiting for work. - The title's waits go straight to `WaitForSingleObject` / `Sleep`; no VIctory frame between title code and the wait. - The title's main thread waits for a job group. One or two of the title's job threads are not waiting: they spin in a hash-map lookup that only ends when the key is found. - The map is intact and current, but it does not hold the key: it holds the same pool slot one generation older. A call trace shows the title rebuilds that map once per frame, a few ms *after* the jobs that look things up, so each frame's lookups use the previous frame's map. In the stopped run the map was 7.35 s old. So it is a race inside the title (a slot freed and reused within one frame), with a window of one frame of wall-clock time: 33 ms on the console, 6 to 8 s at world entry here. Nothing of ours writes that table. Disabling the title's watchdog cannot help: the lookup never ends, the title would hang instead. ## Why this change Of those 6.5 s entry frames, 1.0 to 1.9 s per frame were texture refreshes waiting for the title-memory lock (the `waiting for title memory` figure in the frame statistics). With this change that figure is 0.0 ms in the runs below. No work is skipped; a texture can show one frame late. ## Measured World entries on the same machine and tree, counted one run at a time: | | title stops at world entry | world entries | |---|---|---| | before | 9 | 25 | | with this change | 0 | 15 | Fifteen entries in a row without that stop would happen by chance about once in 800 at the old rate (16 of 25 entries survived). To be complete about those 15 runs: 13 were clean; one had a single 16 s frame in the steady scene (CPU side: 5.4 s preparing, 6.9 s copying back, 0.8 s on the card) and then went on; one ended with `Xid 109` 13 s after world entry. Neither is the stop described above (no spinning title job). Both happened on a tree that also carries #119; see the caveat I posted there for the `Xid`. I have no evidence that this change causes or prevents either. Checks on this branch alone: Windows `cargo check -p victory --features diagnostics` clean; `cargo test -p victory-shader --lib` 170 passed, 2 ignored. The new test in `victory-gpu` compiles but I did not run it (that crate's tests need a Windows device). ## Not tested / limits - It shortens the window; it does not close the race. Other long parts of the entry frames remain (write-watch queries 1 to 3 s, copies 0.7 to 3.8 s per frame). - Windows, AMD, and anything past the first playable scene. - The image: I saw no difference in the scene over these runs, but did not compare frames pixel by pixel. No game files, addresses, strings or hashes in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ege-Mert commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Ege-Mert on 2026-11-25T14:41:03Z.


Windows 11, NVIDIA RTX 3060 Laptop 6 GB, Series S profile. The PR body lists Windows and NVIDIA as untested, so here is what running that way looks like on a small card — we have had the equivalent wait skipped for several days, which is the configuration this change makes the default.

With the card at its memory line, texture refreshes waited 4–12 s per world frame for title memory to hold still. With the wait skipped the texture pass fell to 25–170 ms per frame. That is a much longer wait than the 1.0–1.9 s reported in the PR body; I would put that down to a 6 GB card sitting at its line with textures churning, not to a difference in behaviour of the change itself.

On a later tree that also carries parallel texture checks and coalesced refreshes, the texture pass costs 24 ms a frame at full read rate, with a median frame of 876 ms against 1,263 ms when the wait is skipped on the same shaders. One run each, and the spread between identical runs on this machine is about ±25 %, so I would take the texture-pass time as the reportable part and not the frame times.

We have not counted world-entry stops, so nothing from us on the 9-of-25 to 0-of-15 figure either way.

Written with Claude Code (model claude-opus-5).

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165654113 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/137#issuecomment-7165654113). Originally posted by [Ege-Mert](https://github.com/Ege-Mert) on 2026-11-25T14:41:03Z. --- Windows 11, NVIDIA RTX 3060 Laptop 6 GB, Series S profile. The PR body lists Windows and NVIDIA as untested, so here is what running that way looks like on a small card — we have had the equivalent wait skipped for several days, which is the configuration this change makes the default. With the card at its memory line, texture refreshes waited 4–12 s per world frame for title memory to hold still. With the wait skipped the texture pass fell to 25–170 ms per frame. That is a much longer wait than the 1.0–1.9 s reported in the PR body; I would put that down to a 6 GB card sitting at its line with textures churning, not to a difference in behaviour of the change itself. On a later tree that also carries parallel texture checks and coalesced refreshes, the texture pass costs 24 ms a frame at full read rate, with a median frame of 876 ms against 1,263 ms when the wait is skipped on the same shaders. One run each, and the spread between identical runs on this machine is about ±25 %, so I would take the texture-pass time as the reportable part and not the frame times. We have not counted world-entry stops, so nothing from us on the 9-of-25 to 0-of-15 figure either way. Written with Claude Code (model claude-opus-5).
carlosmegino commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by carlosmegino on 2026-11-25T15:00:32Z.


Independent Windows validation of exact head 55fb82c90a056aae1767afb795ad010bb3c9af5b, in a clean isolated worktree. Windows 11, i7-8700K, RTX 5070 Ti 16 GB (driver 621.01), 32 GB RAM, pinned Rust 1.98.1.

Exact PR branch checks

  • Release and diagnostics builds: pass.
  • cargo test -p victory-gpu --locked -- --test-threads=1: 111 passed, 0 failed, 1 ignored, including the new switch-parsing test.
  • Workspace tests, serial: 497 passed / 0 failed / 7 ignored normally; 505 / 0 / 7 with all features.
  • Both workspace/all-targets Clippy configurations, with -D warnings: pass.
  • Asset policy: 170 files pass.
  • cargo fmt --all -- --check: fails with repository-wide formatting differences; it also failed on our original-main reference. No formatting changes were applied.

Separate opt-in runtime observation

The runtime trial used our previously preserved combined compatibility binary based on 90b529f (#56, #36, opt-in profiling/input diagnostics and the LDS-mode cache-key fix), with VICTORY_LDS_FLAGS=0 and VICTORY_TEXTURE_NO_WAIT=1. It exercises the existing path; it is not a runtime test of the exact PR executable or the changed default.

One requested 1,200-second run reached the deadline and was intentionally stopped by the harness (1,205.8 s including shutdown). No unhandled-exception/device-removal/panic message was found. All 717 detailed texture-meter windows reported 0.0 ms waiting for title memory; 494 windows reported kernel reads/deferred refreshes. The preceding waiting-mode control, using the same executable with LDS disabled, had positive waits in 226/234 texture windows and ended spontaneously with a guest breakpoint.

The runs used independent copies of the same frozen data seed, but cache conditioning and startup input timing differed. One deadline-limited survival does not establish a crash-rate reduction or the failure's mechanism. Visual output alternated between nearly blank and partial 3D images; interactive world entry and visual equivalence remain unverified. No FPS improvement is claimed.

The exported prefix contains 3,233 successful Present and 765 meter records; all 3,998 CSV/JSONL pairs match with no reported loss. Raw title logs, reports, captures and resources remain local.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166157749 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/137#issuecomment-7166157749). Originally posted by [carlosmegino](https://github.com/carlosmegino) on 2026-11-25T15:00:32Z. --- Independent Windows validation of exact head `55fb82c90a056aae1767afb795ad010bb3c9af5b`, in a clean isolated worktree. Windows 11, i7-8700K, RTX 5070 Ti 16 GB (driver 621.01), 32 GB RAM, pinned Rust 1.98.1. **Exact PR branch checks** - Release and diagnostics builds: pass. - `cargo test -p victory-gpu --locked -- --test-threads=1`: 111 passed, 0 failed, 1 ignored, including the new switch-parsing test. - Workspace tests, serial: 497 passed / 0 failed / 7 ignored normally; 505 / 0 / 7 with all features. - Both workspace/all-targets Clippy configurations, with `-D warnings`: pass. - Asset policy: 170 files pass. - `cargo fmt --all -- --check`: fails with repository-wide formatting differences; it also failed on our original-main reference. No formatting changes were applied. **Separate opt-in runtime observation** The runtime trial used our previously preserved combined compatibility binary based on `90b529f` (#56, #36, opt-in profiling/input diagnostics and the LDS-mode cache-key fix), with `VICTORY_LDS_FLAGS=0` and `VICTORY_TEXTURE_NO_WAIT=1`. It exercises the existing path; it is **not a runtime test of the exact PR executable or the changed default**. One requested 1,200-second run reached the deadline and was intentionally stopped by the harness (1,205.8 s including shutdown). No unhandled-exception/device-removal/panic message was found. All 717 detailed texture-meter windows reported 0.0 ms waiting for title memory; 494 windows reported kernel reads/deferred refreshes. The preceding waiting-mode control, using the same executable with LDS disabled, had positive waits in 226/234 texture windows and ended spontaneously with a guest breakpoint. The runs used independent copies of the same frozen data seed, but cache conditioning and startup input timing differed. One deadline-limited survival does not establish a crash-rate reduction or the failure's mechanism. Visual output alternated between nearly blank and partial 3D images; interactive world entry and visual equivalence remain unverified. No FPS improvement is claimed. The exported prefix contains 3,233 successful Present and 765 meter records; all 3,998 CSV/JSONL pairs match with no reported loss. Raw title logs, reports, captures and resources remain local.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/137:upstream-pr/137'
git switch 'upstream-pr/137'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/137'
git switch 'upstream-pr/137'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/137'
git switch 'upstream-pr/137'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/137'
git switch 'main'
git merge --squash 'upstream-pr/137'
git switch 'main'
git merge --ff-only 'upstream-pr/137'
git switch 'main'
git merge 'upstream-pr/137'
git push origin 'main'
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
Zettrox/ztrx!137
No description provided.