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

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

@⁠lhnizdo on GitHub · 2026-11-26 14:25 UTC · original
lhnizdo:pr/marked-page-buffer → main · +50 −1 · 1 files · 1 commits · open

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

**@⁠lhnizdo** on GitHub · 2026-11-26 14:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3246) `lhnizdo:pr/marked-page-buffer` → `main` · +50 −1 · 1 files · 1 commits · open `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.com/claude-code) https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
`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 <[email protected]>
Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:27:21 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 14:28 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 14:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3246#pullrequestreview-6075824391) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Reusing a thread-local Vec<u8> 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 15:28 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-26 15:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7196316002) **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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3246'
git switch 'github-bot/gh-3246'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3246'
git switch 'github-bot/gh-3246'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3246'
git switch 'main'
git merge --squash 'github-bot/gh-3246'
git switch 'main'
git merge --ff-only 'github-bot/gh-3246'
git switch 'main'
git merge 'github-bot/gh-3246'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3246
No description provided.