Skip to content

GPU: a marked page's copy-back reads the title's page into one buffer per thread - #3246

Open
lhnizdo wants to merge 1 commit into
Marvisak:mainfrom
lhnizdo:pr/marked-page-buffer
Open

lhnizdo wants to merge 1 commit into
Marvisak:mainfrom
lhnizdo:pr/marked-page-buffer

Conversation

@lhnizdo

@lhnizdo lhnizdo commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Shadow::copy_back_marked reads the title's bytes of every page shaders marked into a fresh vec![0u8; n], 64 KiB each. In the world that's thousands of pages per frame (about 12,700 on an RTX 2080 here), each allocation zero-filled and its pages faulted in again. The buffer is now one per thread, resized to the page's length. Every byte up to that length is read from the title before it's used, as before.

Measured: RTX 2080, Windows 10, a story save that loads into the world, warm caches, 5-minute runs. Reading the title's pages for marked copy-backs took 132 ms per frame before and 100 ms after (median over the last 12 frame reports). Most of what's left of the marked pages' cost is waiting for the guard lock, which this doesn't touch.

Test: shadow::tests::a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes. A whole page the shaders filled with 0xee goes back, then the copy's last page, held only in part, which a shader and the title both wrote. The second page keeps both writers' bytes and none of the first page's. The existing marked-page tests still pass.

AI-assisted (Claude Code); the runs were on my machine. No game data.

🤖 Generated with Claude Code

https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G

… per thread

`Shadow::copy_back_marked` read the title's bytes of each page shaders
marked into a fresh `vec![0u8; n]` of 64 KiB: thousands of pages a world
frame (about 12,700 on an RTX 2080), each allocation zero-filled and its
pages faulted in again. The buffer is now one per thread, resized to the
page's length; every byte up to it is read from the title before use.

RTX 2080, warm caches, in the world: reading the title's pages for
marked copy-backs 132 -> 100 ms a frame (median of 12 frame reports).

Test: shadow::tests::a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes
(a whole page the shaders filled goes back, then the copy's last page,
held in part, which a shader and the title both wrote: it keeps both
writers' bytes and none of the first page's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):

  • Reusing a thread-local Vec via std::mem::take / give_back avoids per-page 64 KiB allocations and page faults while remaining reentrancy-safe across
    ead_into / write_mapped.
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1 (RTX 5090): 11 passed, 0 failed (including �_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes).
  • VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib shadow::tests::a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes -- --test-threads=1 (WARP): 1 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

WARP verification of #3246 (test report only, no code changes)

Head c2e4507ce40ccdf1056ccf9c40e39f27bb8721ef, main 63bcca43c6a00a758510398fa43096ce7e4f7df0 (merge base = main).

Env: Windows 11, WARP only (adapter "Microsoft Basic Render Driver", d3d10warp.dll 10.0.26100.9818), VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0), cargo -j 4. No physical GPU used. Each test was run in its own process (<test> --exact), so one crashing test cannot hide the others. (With the old 10.0.19041 dxil.dll the validator tests crash with an access violation, on main too; unrelated to this PR.)

Commands (head, checked out detached):

  • cargo test -j 4 -p victory-gpu --features diagnostics --lib (the diagnostics feature is what makes VICTORY_D3D12_WARP take effect; without it the host tests would pick the physical adapter)
  • the new test: shadow::tests::a_partial_marked_page_after_a_whole_one_takes_none_of_its_bytes

Results:

  • New test: passes. Because it returns early when no host device is available, I also put a temporary panic! right after that early return and the test hit it, so on WARP it runs through to its assertions (probe reverted; not part of the PR).
  • victory-gpu lib on head: 248 tests, 247 passed, 1 ignored, 0 failed. On main: 247 tests, 246 passed, 1 ignored, 0 failed.
  • Control: main with only the PR's test added: the test also passes on main. It is a guard for the reused per-thread buffer (stale bytes must not leak into the next page), not a reproduction of a bug on main, so there is no failing control.

AI-assisted: verification by Claude Code (Claude Sonnet 5.5). Synthetic tests only; no game files, dumps, shader names or hashes.

Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 27, 2026
… the buffer path, a refresh by event that passes its check

Found by reading and closed, none seen in a run: a read of the kernel's
into title memory that outlives a check's re-arming of the block (a
finished ReadFile now counts the blocks under it written once more); a
title buffer copy made while no asking stood, whose written bits were
taken and nothing noted; a view a mapping dropped that a check's late
protection call left read-only and unknown, so that the title's write
there was an access violation nobody answered.

The refresh by event (VICTORY_REFRESH_EVENTS, still off): a mapping is
counted under the guards' lock, a copy with blocks not there is asked
once in 30 frames, and the check decides with the asking's locks held.
The check counted 0 in the prologue and at the open world's entry, where
it had counted 7 and 2. A landing can take the kernel's written bits of
the private memory it wrote (VICTORY_LAND_TAKEN, off; its check counted
0 as well). With both on, preparing falls from 40.6 to 36.4 ms a frame
in the first room and the copies read from 89 to 70 MB; the frame does
not move (67.8 against 66.6 ms), so they stay off.

A compute dispatch stands for its pipeline until it is made, where it
was dropped and never repeated (after fxceless/victory-fork pull request
Marvisak#1312). Title bytes under flights are read into one buffer a thread
(after Marvisak/VIctory pull request Marvisak#3246). The check of stale copies
(VICTORY_REFRESH_CHECK) discounts looks under a read the title has
submitted: its warnings at the world's entry were blocks DirectStorage
was still filling. Parts of the host moved to files of their own
(host.rs was at the repository's size cap).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@neonbyte1

Copy link
Copy Markdown

Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is main plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).

Measured on the base without #3341 (this PR is the alternative to its pooled buffer):

Frame Preparing Copy-back
control 399 ms 80 ms 47.8 ms
+ this PR 391 ms 79 ms 44.4 ms

About 3.4 ms off copy-back, the only one of the six copy-back/refresh PRs I measured that moved copy-back clearly. #3341 on the same kind of base made copy-back 5-7 ms slower in two independent pairs, so on this setup this PR is the better of the two. Its new shadow:: test passes under Wine.

AI-assisted (Claude); measured on my machine, no game data shared.

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.

4 participants