Skip to content

Texture guard: see writes through every view of its pages (boot video glitch) - #115

Open
Spexivus wants to merge 1 commit into
fxceless:mainfrom
Spexivus:texture-guard-views
Open

Spexivus wants to merge 1 commit into
fxceless:mainfrom
Spexivus:texture-guard-views

Conversation

@Spexivus

Copy link
Copy Markdown

Before: the texture guard made the 64 KiB blocks of one view read-only and learned of writes only at that address: a fault there, watch::writing, or a mapping. Physical pages can be mapped at several addresses, though, and a write through another view of the same pages, or the runtime's own write into physical pages (write_physical, DirectStorage page destinations), never faults at the guarded address. The guard then reported the texture unwritten, so it was hashed only on its turn every eighth frame and kept showing stale contents in between.

After: a write to the pages is seen whichever way it arrives.

  • watch.rs: the guard makes every view of the guarded physical pages read-only. A fault at any of them, or writing, opens and marks all of them written. New title_memory_written(section, offset, len) lets the runtime report its own writes into physical pages, and a view newly mapped over guarded pages makes their guards check again.
  • inplace.rs: an index from (section, 64 KiB offset) to every view showing it, kept by title_memory_view / views_gone, with views_between, pages_of and views_of_section to look it up.
  • xmem.rs: write_physical reports each run it writes; PageWindow::written() reports the window. dstorage.rs calls it after filling a page destination.
  • texture.rs: with diagnostics, a one-time warning when a hash finds a change the guard did not report, naming the texture, so any write path still missed shows up.

Unchanged: HASH_EVERY, and memory that is not written costs the same as before (no faults, no hash). The hash stays as the net under the guard.

Tests: three new ones in watch.rs (a write through another view, a view mapped beside a guarded one, a runtime write into physical pages). cargo test -p victory-gpu --features diagnostics 120 passed, victory-hle 95 passed, clippy clean with and without diagnostics.

The guard protected one view of a texture's physical pages and heard only of faults there, so a write through another view of the same pages, or the runtime's own write into them (write_physical, DirectStorage page destinations), went unseen and the texture kept stale contents until its eighth-frame hash. The guard now protects every view of its pages, and the runtime reports its own writes.
@thiagolima0

Copy link
Copy Markdown

Confirmed on AMD: this fixes the boot video stutter on an RX 6600M.

Setup: AMD Radeon RX 6600M (8 GB, 32-lane waves), driver 32.0.21045.16010, Windows 11 26200, default TDR. Own 1.0.2.1 copy, Series X profile, cargo build --profile diag -p victory --features diagnostics. Tree: 4e17478 + #24, #23, #9, #40, #25, #38, then this PR merged on top (no conflicts). Hashes and counts only, nothing from the game attached.

What it looked like before: the boot video played visibly jerky, and the present timing did not explain it. With VICTORY_LOG=victory_gpu::frame=debug, presents during the video arrive steadily (0-2 intervals over 45 ms per 5 s, nearly all 33-37 ms). The problem is the content. I saved 24 consecutive frames during the video (VICTORY_KEYS=25:Enter,27:Enter VICTORY_CAPTURE_FRAMES=760,...,783) and hashed the PNGs:

distinct frames of 24 frames equal to the one 3 before
without this PR 6 18
with this PR 24 0

Without it, the video's three frame buffers cycle: frames 761-770 show the same three images in turn (A B C A B C ...). Only one buffer gets new content every 8-9 frames (one new image at 771, another at 779). That fits the every-eighth-frame hash you describe: the picture jumps back and forth between stale frames. With the PR every frame is new, and the a texture's hash found a change its guard did not report warning did not fire in the run.

Tests: cargo test -p victory-gpu -p victory-hle --lib on this card: 115 + 95 passed, 1 ignored.

Unrelated, from the same runs, in case it helps someone else: the 1.0-1.5 s freezes on the black screen before the first logo are a title worker making about 54,000 one-page XMemMapPhysicalPages calls while the main thread polls with SleepEx. About 0.5 s of that is ours (VirtualFree placeholder split + MapViewOfFile3 ≈ 6.8 µs per call, commit ≈ 1.6 µs). The rest is the title's own page-list comparison. They happen before anything is drawn, so they are not visible as stutter.

AI-assisted (Claude Code); hashes, counts and log lines only.

@ryotdev

ryotdev commented Nov 24, 2026 •

Copy link
Copy Markdown

Confirmed the boot-video fix on an NVIDIA RTX 5070 (driver 610.88), Ryzen 7 7800X3D, Windows, native D3D12, Series X profile. I compared 4e17478 with #115 (2ef19e0, also cleanly applied to 2119b0e, whose source tree matches 4e17478). Both runs used the same saved setup, separately copied warm caches and identical inputs.

I captured three bursts of 18 consecutive frames in the animated startup video, starting at host frames 390, 470 and 555. Both sides showed the moving intro in all three bursts. I hashed the decoded RGB pixels. A return means frame N matches N−3 with at least one different image in between.

Distinct images per 18-frame burst Returns at lag 3 per 15 comparisons
Main 5, 5, 5 12, 13, 13
With #115 18, 18, 18 0, 0, 0

I also ran the Windows shared-page regressions against main as negative controls: the write-through-another-view and newly-mapped-alias tests both failed with an empty dirty-page result on main and passed with #115. All 33 focused watch, XMem and DirectStorage tests passed with the change. These captures measure frame content, so I’m reporting the reversal fix separately from frame pacing or gameplay FPS. AI-assisted testing.

World checkpoint follow-up. This revision also exited in two runs shortly after entering the prison scene on my RTX 5070. Windows exit code was 0x80000003 in both, without a reported GPU device loss. The last captured frames were 40 and 24 frames past the first 500-draw frame. One used joined rehash runs with descriptor statistics, the other the normal direct-queue play profile. I reran main with the latter profile and the same saved checkpoint and reached +150 frames. Earlier main comparisons reached +500. I haven't isolated which change accounts for the exits. The intro result above stands; I would keep later gameplay stability a separate check. The narrower patch from #63 applied to 4e17478 also gave 18 distinct frames in each of the three intro bursts and zero three-frame returns. With that patch, the same checkpoint reached +500 frames on the standard direct-queue play profile.

@joroyt

joroyt commented Nov 24, 2026

Copy link
Copy Markdown

A defect in this PR's protect, with a fix and a failing test: Spexivus#1 (one commit on top of 2ef19e0, +49/-1 in watch.rs).

What is wrong. protect makes the other views of the pages read-only through protect_here, which also notes them clean. The host copies at those other addresses have not taken the pages, so their next check reports nothing written and they keep the bytes from before the write. It needs two host copies of one physical page to show, which the video's textures do not have and the world does: the pages I looked at were shown at five or six title addresses, each with a host copy of its own.

The fix. The other views are made read-only and noted protected, not clean; guard already reports such a block written at its view's next check.

Test. a_write_is_reported_at_every_checked_view fails on 2ef19e0 (left: Some([]) at the second view's first check) and passes with the fix; the other ten watch:: tests pass in both.

Measured on an RTX 5070 (driver 32.0.16.2124, Windows 11, diag build, 2119b0e + #156, VICTORY_BVH_BUILDER=1), with a local diagnostic that compares each range a submission declares as written with title memory right after its refresh:

tree copies that differ from title memory after their refresh
without this PR windows: 13-29 pieces of 64 KiB a second that stay different while the title's bytes do not change; title buffers: 948 pieces (44 MB)
with this PR (2ef19e0) windows: none. Title buffers: 747-870 pieces (34-40 MB) in every run, the copy all zeros and title memory all 0xff; the blocks are mapped views, PAGE_READONLY, noted copied
with this PR and the fix 0 pieces, 2 of 2 runs

So this PR also matters outside textures: without it the copies of the memory the structure builder works in go stale within a second.

It does not fix #16: the title still crashes 5-15 s after the builder starts with both changes (2 of 2 runs, +0x4f38ba5 / +0x8f92a reading 0xffffffffffffffff).

Not tested: AMD, Intel, Windows 10, the boot video with the fix on top.

AI use: Claude (Anthropic) in OpenCode, on my machine with my own copy of the title; no game data attached.

@SantannaCarlos

Copy link
Copy Markdown
Contributor

Measured in the title with joroyt's Spexivus#1 (0bcc069) on top, and one problem this PR brings that needs fixing before it can go in.

RTX 4070, 2119b0e + this PR (+ 0bcc069 where noted), default mode (no relay, no late wait, no loop limit), a save that loads into the cell, diag build, 15-minute runs. A local diagnostic compares pages the guard reports clean with title memory and counts a page as stale when it still differs at three checks in a row (details on #62).

Tree Runs First room at the window Stale clean pages Of them on pages with several views Frame
2119b0e 2 missing in both (sky beside the frame) 2,598 in one run all ~430 ms
+ this PR 1 (title stopped at 136 s) 88 in 136 s 87 preparation ~1.7 s
+ this PR + 0bcc069 3 drawn in both runs that reached it (walls, posters, chain-link) 0–6 per run 0 ~440 ms

So with 0bcc069 the copies over aliased pages stop going stale, and the room comes back.

The problem: the title stops itself in 2 of the 4 runs with this PR (one without 0bcc069 at 136 s, one with it at 176 s): int3 at +0x23d8f03. In both, the line right before is
dstorage: request failed: copying options=0x0 ... destination_size=1600 ... hr=0x800706f8
(ERROR_INVALID_USER_BUFFER: the kernel read into the destination met a read-only page), and in one also a destination's physical pages could not be written. Without this PR: no request failure and no stop in either run.

Why it happens more with this PR: kernel_will_write opens the destination (and with this PR its other views) before the read, but nothing stops a guard check on another thread from protecting those blocks again before the kernel writes them. With every view of guarded pages protected, a raw DirectStorage destination is now often one of them. A fix is to have kernel_will_write hold the blocks open until the read is done (a value whose drop lets them be guarded again, the blocks reported written meanwhile), and the same for ReadFile/fread in files.rs and the page-destination path. I'm writing that on top of 0bcc069 with a test that reproduces the failure and will post it here.

oz-stanislav-zhukov added a commit to oz-stanislav-zhukov/victory-fork that referenced this pull request Nov 25, 2026
…ess#206 reverted)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oz-stanislav-zhukov

Copy link
Copy Markdown

Same stop as @SantannaCarlos describes, on another setup, and it comes fast with the speed switches.

Setup: RTX 5060 Ti 16 GB (driver 621.24), i7-14700KF, Windows 10 22H2 (#22 for the Agility SDK), release build, Series X. Tree 4e17478 + #22 + #58 + this PR (2ef19e0) + #410 + #51 (one run also + #206). VICTORY_SHADER_OPT=0 VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1 VICTORY_RELAY=1 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024.

tree runs result
with this PR (+ #206) 1 0xc0000005 at +0x541f03f reading 0x2ee5028a92f at world entry (~frame 1736, ~1 min after launch)
with this PR (without #206) 1 int3 at +0x23d8f03, ~1.5 min after launch
without this PR (same tree otherwise) 1 reaches the cell, no stop, ~3 fps

Before both stops the log has dstorage: a destination's physical pages could not be written ... its request fails (several, len=12288/16384, pages=1), and before the int3 also dstorage: request failed: copying ... destination_size=17232 ... hr=0x800706f8. So the access violation looks like the same failed read, the title using the unwritten bytes as a pointer instead of stopping.

With VICTORY_LATE_WAIT=3 + VICTORY_RELAY=1 it came in the first minute or two in every run, which may help test the hold-open fix. Happy to run it here once it is posted.

AI-assisted (Claude Code, Claude Opus 5.5); numbers from local logs, no game data attached.

oz-stanislav-zhukov added a commit to oz-stanislav-zhukov/victory-fork that referenced this pull request Nov 25, 2026
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.

6 participants