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

Open
lhnizdo wants to merge 1 commit from upstream-pr/3246 into main
lhnizdo commented 2026-11-26 14:25:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-26T14:25:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5511784829 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3246). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-26T14:25:03Z. --- `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
Dukestar69 commented 2026-11-26 14:28:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:28:20Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6075824391 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3246#pullrequestreview-6075824391). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T14:28:20Z. **Review:** APPROVED --- 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).
oni-swr commented 2026-11-26 16:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T15:28:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196316002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7196316002). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T15:28:27Z. --- **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.
neonbyte1 commented 2026-11-27 07:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T07:05:54Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7212139954 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7212139954). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T07:05:54Z. --- 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._
andrewpozdnakov7-jpg commented 2026-11-27 23:33:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T23:33:41Z.


I tested #3627 on top of the current #3246 head c2e4507, with both commits retained as parents of c09d8dc. The two synthetic WARP copy-back calls still account for three compared pages, with one call in the single-page bucket and one in the 2–15 bucket. The withheld page is excluded. The four bucket boundaries and window reset passed.

The existing partial-page regression also passed with thread-local scratch reuse. In total, 247 existing GPU tests passed with one ignored, plus the app-local WARP 1.0.22 and Agility 1.620.2 identity check. Strict all-features GPU Clippy and the asset policy check passed.

The tested combination is available for measuring the workload discussed in #3604. The maintainers can review the scratch lifetime and the diagnostic change independently.

Combined commit · Counter results in #3627

If you reuse the diagnostic change, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding it into another commit.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7230234547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3246#issuecomment-7230234547). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T23:33:41Z. --- I tested #3627 on top of the current #3246 head c2e4507, with both commits retained as parents of c09d8dc. The two synthetic WARP copy-back calls still account for three compared pages, with one call in the single-page bucket and one in the 2–15 bucket. The withheld page is excluded. The four bucket boundaries and window reset passed. The existing partial-page regression also passed with thread-local scratch reuse. In total, 247 existing GPU tests passed with one ignored, plus the app-local WARP 1.0.22 and Agility 1.620.2 identity check. Strict all-features GPU Clippy and the asset policy check passed. The tested combination is available for measuring the workload discussed in #3604. The maintainers can review the scratch lifetime and the diagnostic change independently. [Combined commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/c09d8dcebc2f5fd659b462358c11db5d02ad25b5) · [Counter results in #3627](https://github.com/Marvisak/VIctory/pull/3627#issuecomment-7230199354) If you reuse the diagnostic change, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.
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/3246:upstream-pr/3246'
git switch 'upstream-pr/3246'

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/3246'
git switch 'upstream-pr/3246'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3246'
git switch 'upstream-pr/3246'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3246'
git switch 'main'
git merge --squash 'upstream-pr/3246'
git switch 'main'
git merge --ff-only 'upstream-pr/3246'
git switch 'main'
git merge 'upstream-pr/3246'
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
Marvisak/VIctory!3244
No description provided.