GPU: drop only marked pages for withheld marked ranges #3099

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

@⁠fuzeofficlal on GitHub · 2026-11-26 08:01 UTC · original
fuzeofficlal:perf/gpu-withheld-drop-only-marked-pages-3089 → main · +364 −22 · 2 files · 1 commits · open

Closes #3089

Summary

When a submission withholds a declared Step::GpuWrite range, Host::execute previously called crate::memory::drop_withheld(address, len) over the entire range, forcing every 64 KiB page in that range to be re-copied from title memory on the next refresh even when shaders only touched a fraction of the pages.

Where every step naming a withheld range marks its written pages (marked == true) and the copy's mark bits are complete, only pages actually marked in the written-pages bitmaps contain withheld shader bytes:

  • Merge marked with AND (crates/victory-gpu/src/host.rs): Track marked per merged (copy, address, len) entry as the logical AND across all Step::GpuWrite steps naming that range. Any range with an unmarked writer (e.g., clears, unmarked root UAVs, untracked copies, or copies without mark bits) still drops whole.
  • Skip whole-range drop for complete marked ranges (crates/victory-gpu/src/host.rs, crates/victory-gpu/src/shadow.rs): Skip drop_withheld(address, len) for withheld ranges where marked && shadow.marks_complete(). marks_complete() checks that all mark bits of the copy lie below the bitmap's last dword (which is cleared whole for the overflow sink bit on main until #2269 lands), safely falling back to a whole-range drop for that dword without conflicting with #2269. keep_writes and note_withheld still run as before.
  • Drop withheld ordinary-bitmap pages after marked copy-backs (crates/victory-gpu/src/shadow.rs): Pages from the title-memory bitmap (held) are already dropped page by page. Pages from the ordinary bitmap that copy_back_marks filters out as withheld are now collected, deduplicated, and dropped via drop_withheld(page, PAGE) after all non-withheld copy_back_marked calls finish, preventing an immediate watch::retake on a shared page from marking another copy's page changed before its own copy-back runs.

Tests

  • Added host-execution tests in crates/victory-gpu/src/host.rs (withholding):
    • withheld_marked_range_drops_only_marked_pages
    • withheld_overlapping_ordinary_marked_write_drops_only_marked_pages
    • withheld_range_mixing_marked_and_unmarked_steps_drops_whole_range
    • withheld_marked_drop_runs_after_other_copy_marked_copy_back
  • Added unit test shadow::tests::marks_below_last_word_excludes_the_sink_dword in crates/victory-gpu/src/shadow.rs.
  • Verified:
    • cargo test -p victory-gpu --locked -- withholding:: shadow::tests::marks_below_last_word shadow::tests::marked_pages_go_back shadow::tests::marks_of_shaders_using_title_memory shadow::tests::what_a_frame_withholds (9 passed on RTX 5090)
    • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked (251 passed, 0 failed)
    • cargo clippy --workspace --all-targets --locked -- -D warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
    • cargo test -p xtask --locked policy::tests::repository_passes_policy
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3099) `fuzeofficlal:perf/gpu-withheld-drop-only-marked-pages-3089` → `main` · +364 −22 · 2 files · 1 commits · open Closes #3089 ### Summary When a submission withholds a declared `Step::GpuWrite` range, `Host::execute` previously called `crate::memory::drop_withheld(address, len)` over the entire range, forcing every 64 KiB page in that range to be re-copied from title memory on the next refresh even when shaders only touched a fraction of the pages. Where every step naming a withheld range marks its written pages (`marked == true`) and the copy's mark bits are complete, only pages actually marked in the written-pages bitmaps contain withheld shader bytes: - **Merge `marked` with AND (`crates/victory-gpu/src/host.rs`)**: Track `marked` per merged `(copy, address, len)` entry as the logical AND across all `Step::GpuWrite` steps naming that range. Any range with an unmarked writer (e.g., clears, unmarked root UAVs, untracked copies, or copies without mark bits) still drops whole. - **Skip whole-range drop for complete marked ranges (`crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/shadow.rs`)**: Skip `drop_withheld(address, len)` for withheld ranges where `marked && shadow.marks_complete()`. `marks_complete()` checks that all mark bits of the copy lie below the bitmap's last dword (which is cleared whole for the overflow sink bit on `main` until #2269 lands), safely falling back to a whole-range drop for that dword without conflicting with #2269. `keep_writes` and `note_withheld` still run as before. - **Drop withheld ordinary-bitmap pages after marked copy-backs (`crates/victory-gpu/src/shadow.rs`)**: Pages from the title-memory bitmap (`held`) are already dropped page by page. Pages from the ordinary bitmap that `copy_back_marks` filters out as `withheld` are now collected, deduplicated, and dropped via `drop_withheld(page, PAGE)` after all non-withheld `copy_back_marked` calls finish, preventing an immediate `watch::retake` on a shared page from marking another copy's page changed before its own copy-back runs. ### Tests - Added host-execution tests in `crates/victory-gpu/src/host.rs` (`withholding`): - `withheld_marked_range_drops_only_marked_pages` - `withheld_overlapping_ordinary_marked_write_drops_only_marked_pages` - `withheld_range_mixing_marked_and_unmarked_steps_drops_whole_range` - `withheld_marked_drop_runs_after_other_copy_marked_copy_back` - Added unit test `shadow::tests::marks_below_last_word_excludes_the_sink_dword` in `crates/victory-gpu/src/shadow.rs`. - Verified: - `cargo test -p victory-gpu --locked -- withholding:: shadow::tests::marks_below_last_word shadow::tests::marked_pages_go_back shadow::tests::marks_of_shaders_using_title_memory shadow::tests::what_a_frame_withholds` (9 passed on RTX 5090) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked` (251 passed, 0 failed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `cargo test -p xtask --locked policy::tests::repository_passes_policy`
Keep the AND of Step::GpuWrite's marked flag when merging declared ranges in Host::execute, skip whole-range drop_withheld for withheld ranges whose steps are all marked (and whose copy has all mark bits below the bitmap's cleared last dword), and drop pages filtered as withheld in shadow::copy_back_marks one by one after the marked copy-backs complete.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:06:55 +00:00
Author
Owner

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

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib host::withholding -- --test-threads=1: 5/5 passed on RTX 5090 and WARP (all 4 new marked-page withholding tests pass, plus all remaining host:: tests).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly restricts withheld-marked-range drops to the actually marked pages while preserving the full-range drop when marked and unmarked steps are mixed.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 08:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3099#pullrequestreview-6070490277) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 11/11 passed on RTX 5090 and WARP. - `cargo test -p victory-gpu --lib host::withholding -- --test-threads=1`: 5/5 passed on RTX 5090 and WARP (all 4 new marked-page withholding tests pass, plus all remaining `host::` tests). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly restricts withheld-marked-range drops to the actually marked pages while preserving the full-range drop when marked and unmarked steps are mixed. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:24 UTC · original

Automated triage for the maintainers.

Merge candidate. This implements #3089. For a withheld Step::GpuWrite range whose steps are all marked, Host::execute (crates/victory-gpu/src/host.rs) now skips the whole-range drop_withheld. shadow::copy_back_marks instead drops only the ordinary-bitmap pages it filters out as withheld, and only after the other copies' marked copy-backs have run. Pages from the title-memory bitmap were already dropped page by page.

What I checked against main:

  • marked is ANDed across every step that names the same (copy, address, len), so a range with any unmarked writer is still dropped whole.
  • Shadow::marks_complete falls back to a whole-range drop for any copy whose mark run reaches the bitmap's last dword. copy_back_marks clears that dword unread (bits[words - 1] = 0, #2269), which is the concern raised on #3089. Marks::take can hand out bits there, so the fallback is needed and is in the right place.
  • Dropping per 64 KiB page can only drop more than the declared range, never less.

CI (check) passes.

A note for review: the saving depends on marks being complete for marked steps. A view write that loses its mark (other than the last-dword case handled here) would now leave withheld bytes in the copy, where before they were dropped. The measurements are on #3089 (another contributor's fork); the PR itself adds synthetic tests only.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3099#issuecomment-7186556900) <!-- victory-triage v1 head=af3b74cc22567ff4519042ce6c477ccde50753f2 verdict=merge-candidate at=2026-11-26T08:18:11Z --> Automated triage for the maintainers. **Merge candidate.** This implements #3089. For a withheld `Step::GpuWrite` range whose steps are all marked, `Host::execute` (`crates/victory-gpu/src/host.rs`) now skips the whole-range `drop_withheld`. `shadow::copy_back_marks` instead drops only the ordinary-bitmap pages it filters out as withheld, and only after the other copies' marked copy-backs have run. Pages from the title-memory bitmap were already dropped page by page. What I checked against main: - `marked` is ANDed across every step that names the same `(copy, address, len)`, so a range with any unmarked writer is still dropped whole. - `Shadow::marks_complete` falls back to a whole-range drop for any copy whose mark run reaches the bitmap's last dword. `copy_back_marks` clears that dword unread (`bits[words - 1] = 0`, #2269), which is the concern raised on #3089. `Marks::take` can hand out bits there, so the fallback is needed and is in the right place. - Dropping per 64 KiB page can only drop more than the declared range, never less. CI (`check`) passes. A note for review: the saving depends on marks being complete for marked steps. A view write that loses its mark (other than the last-dword case handled here) would now leave withheld bytes in the copy, where before they were dropped. The measurements are on #3089 (another contributor's fork); the PR itself adds synthetic tests only. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Machad3x on GitHub · 2026-11-26 10:07 UTC · original

Thank you for these tests; three of them are now in my fork (Ryzen 7 5700X, RTX 3080 Ti), under your authorship, and pass on top of an equivalent change.

One related ordering problem showed up while reviewing them. It is on main too, not introduced here: in copy_back_marks, the held pages (marks in the title-memory bitmap while memory is withheld) are dropped before the marked copy-backs. When the submission missed, drop_withheld retakes at once, which marks the page changed in every copy holding it, so another copy's run_back skips the page and its ordinary write never reaches title memory.

withheld_marked_drop_runs_after_other_copy_marked_copy_back reproduces it with one change: the outer copy's mark set in the title-memory bitmap (mark_page_for_test(p, true)) instead of the ordinary one. title(32) stays 0x22 where 0xbb was expected.

What fixed it here: drop the held pages together with the others, after the copy-backs, and keep a held (copy, page) out of that copy's own copy-back (a page both kinds of shader marked through one copy would otherwise go back with the held bytes in it). The early return on marked.is_empty() has to go, or move below the drop.

Tested with the crate's tests and one 5-minute run in the game.

AI-assisted.

**@⁠Machad3x** on GitHub · 2026-11-26 10:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3099#issuecomment-7188944847) Thank you for these tests; three of them are now in my fork (Ryzen 7 5700X, RTX 3080 Ti), under your authorship, and pass on top of an equivalent change. One related ordering problem showed up while reviewing them. It is on `main` too, not introduced here: in `copy_back_marks`, the `held` pages (marks in the title-memory bitmap while memory is withheld) are dropped *before* the marked copy-backs. When the submission missed, `drop_withheld` retakes at once, which marks the page changed in every copy holding it, so another copy's `run_back` skips the page and its ordinary write never reaches title memory. `withheld_marked_drop_runs_after_other_copy_marked_copy_back` reproduces it with one change: the outer copy's mark set in the title-memory bitmap (`mark_page_for_test(p, true)`) instead of the ordinary one. `title(32)` stays `0x22` where `0xbb` was expected. What fixed it here: drop the held pages together with the others, after the copy-backs, and keep a held `(copy, page)` out of that copy's own copy-back (a page both kinds of shader marked through one copy would otherwise go back with the held bytes in it). The early `return` on `marked.is_empty()` has to go, or move below the drop. Tested with the crate's tests and one 5-minute run in the game. AI-assisted.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:41 UTC · original

Thanks @⁠Machad3x for adopting the tests and flagging that pre-existing copy_back_marks ordering edge case when a held page is shared with a non-marked copy — worth keeping this PR focused on #3089 and tracking that ordering interaction separately.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3099#issuecomment-7197966970) Thanks @⁠Machad3x for adopting the tests and flagging that pre-existing `copy_back_marks` ordering edge case when a held page is shared with a non-marked copy — worth keeping this PR focused on #3089 and tracking that ordering interaction separately.
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/3099/head:github-bot/gh-3099'
git switch 'github-bot/gh-3099'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3099'
git switch 'github-bot/gh-3099'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3099'
git switch 'github-bot/gh-3099'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3099'
git switch 'main'
git merge --squash 'github-bot/gh-3099'
git switch 'main'
git merge --ff-only 'github-bot/gh-3099'
git switch 'main'
git merge 'github-bot/gh-3099'
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!3099
No description provided.