GPU: copy back ordinary writes before retaking shared pages #3108

Open
github-bot wants to merge 5 commits from github-bot/gh-3108 into main AGit
Owner

@⁠YouKnowWh on GitHub · 2026-11-26 08:22 UTC · original
YouKnowWh:fix/withheld-mark-copy-order → main · +117 −11 · 3 files · 5 commits · open

A submission with a missed list can lose a valid GPU write when two distinct host buffer copies cover the same 64 KiB title page. One copy has a held title-memory mark. The other has an ordinary mark for a write to a different byte. Processing the held mark first calls drop_withheld, which immediately retakes the shared page across copies on a missed submission. The ordinary write then fails to reach title memory.

Move the held-page drops after the ordinary marked copy-backs in copy_back_marks. The regression test executes a missed list with both bitmaps and checks both bytes. The withheld byte must stay at 0x11 and the valid write must change 0x22 to 0xbb.

Verified on Windows with a GeForce RTX 5070 Ti, driver 621.14. On main at 63bcca4 the fixture returned (0x11, 0x22). With this patch it returned (0x11, 0xbb). The Windows diagnostics victory-gpu suite, run serially, went from 244 passed / 3 failed / 1 ignored (main plus the regression test) to 245 / 2 / 1. The two failures in both runs were dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views.

Related to #3089 and #3099. This reproduces directly on main and is independent of the optimization to reduce the number of dropped pages. #1998 addresses an overlapping withheld interval within a copy. This fixture uses two distinct copies of the same page. No title files are needed. No rendering or performance improvement was measured.

AI-assisted with Codex.

**@⁠YouKnowWh** on GitHub · 2026-11-26 08:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3108) `YouKnowWh:fix/withheld-mark-copy-order` → `main` · +117 −11 · 3 files · 5 commits · open A submission with a missed list can lose a valid GPU write when two distinct host buffer copies cover the same 64 KiB title page. One copy has a held title-memory mark. The other has an ordinary mark for a write to a different byte. Processing the held mark first calls `drop_withheld`, which immediately retakes the shared page across copies on a missed submission. The ordinary write then fails to reach title memory. Move the held-page drops after the ordinary marked copy-backs in `copy_back_marks`. The regression test executes a missed list with both bitmaps and checks both bytes. The withheld byte must stay at 0x11 and the valid write must change 0x22 to 0xbb. Verified on Windows with a GeForce RTX 5070 Ti, driver 621.14. On main at 63bcca4 the fixture returned (0x11, 0x22). With this patch it returned (0x11, 0xbb). The Windows diagnostics victory-gpu suite, run serially, went from 244 passed / 3 failed / 1 ignored (main plus the regression test) to 245 / 2 / 1. The two failures in both runs were `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. Related to #3089 and #3099. This reproduces directly on main and is independent of the optimization to reduce the number of dropped pages. #1998 addresses an overlapping withheld interval within a copy. This fixture uses two distinct copies of the same page. No title files are needed. No rendering or performance improvement was measured. AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:25:01 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:28 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 (including held_mark_preserves_an_ordinary_write_in_a_shared_page).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly ensures ordinary writes on shared pages are copied back before retaking them under a held mark.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 08:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3108#pullrequestreview-6070690020) · **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 (including `held_mark_preserves_an_ordinary_write_in_a_shared_page`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed on RTX 5090. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly ensures ordinary writes on shared pages are copied back before retaking them under a held mark. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

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

Automated triage for the maintainers.

Verdict: needs work. CI check passes.

In shadow::copy_back_marks, this PR runs the ordinary marked copy-backs before the held-page memory::drop_withheld calls. On a missed submission, drop_withheld calls watch::retake, which marks the page as changed in every copy. Shadow::copy_back_marked then returns early (saved.is_none() && t.changed(..)), so the bug you describe for two distinct copies sharing a page is real.

The reordering also changes the case where the same copy and page carry both a held mark (memory bitmap) and an ordinary mark. On main that page is retaken first and its copy-back skipped. With this PR, copy_back_marked writes the whole differing host page back, and that page includes the bytes the withheld list wrote. Withheld results then reach title memory, which withholding() exists to prevent.

What it needs:

  • Skip ordinary copy-back for any (copy, page) that also appears among the held pages. One way: resolve held to pages first and filter pages against it.
  • Add a test for the same-copy case alongside held_mark_preserves_an_ordinary_write_in_a_shared_page.

With that, this looks ready for review for merge.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3108#issuecomment-7186715002) <!-- victory-triage v1 head=9accaa33a922594ede1411a9096bd4181306db95 verdict=needs-work at=2026-11-26T08:31:06Z --> Automated triage for the maintainers. **Verdict: needs work.** CI `check` passes. In `shadow::copy_back_marks`, this PR runs the ordinary marked copy-backs before the held-page `memory::drop_withheld` calls. On a missed submission, `drop_withheld` calls `watch::retake`, which marks the page as changed in every copy. `Shadow::copy_back_marked` then returns early (`saved.is_none() && t.changed(..)`), so the bug you describe for two distinct copies sharing a page is real. The reordering also changes the case where the **same** copy and page carry both a held mark (memory bitmap) and an ordinary mark. On main that page is retaken first and its copy-back skipped. With this PR, `copy_back_marked` writes the whole differing host page back, and that page includes the bytes the withheld list wrote. Withheld results then reach title memory, which `withholding()` exists to prevent. What it needs: - Skip ordinary copy-back for any `(copy, page)` that also appears among the held pages. One way: resolve `held` to pages first and filter `pages` against it. - Add a test for the same-copy case alongside `held_mark_preserves_an_ordinary_write_in_a_shared_page`. With that, this looks ready for review for merge. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:51 UTC · original · requested changes

The production fix in crates/victory-gpu/src/shadow.rs::copy_back_marks (75a6a31c) looks solid:

  • held is populated from a single bitmap scan in ascending word/bit order (trailing_zeros()), so held.binary_search(n) is valid.
  • Filtering marked against held prevents a (copy, page) marked in both bitmaps from leaking withheld writes into title memory, while allowing distinct host copies covering the same title page to copy back their ordinary writes before drop_withheld(page, PAGE) retakes the page across all copies.
  • Checking marked.is_empty() && held.is_empty() ensures held-only submissions still run drop_withheld.

Root cause of the CI failure (reproduced locally on Windows 11 + WARP)

Running shadow:: locally shows why check failed on 75a6a31c:

  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features) and cargo xtask policy: clean.
  • Serial WARP (cargo test -p victory-gpu --lib --features diagnostics -- shadow:: --test-threads=1): 12/12 passed.
  • Default parallel WARP (cargo test -p victory-gpu --lib --features diagnostics -- shadow::): failed immediately (10 passed, 2 failed):
    • shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed: both writers' bytes, page 1: left (0, 17), right (187, 17)
    • shadow::tests::marks_of_shaders_using_title_memory_are_held_back: page 1 held back: left (170, 187), right (170, 0)

Both new regression tests call host.execute(&[&list]) inside shadow::tests. Because the pre-existing direct-bitmap tests (marked_pages_go_back_by_the_bytes_the_gpu_changed and marks_of_shaders_using_title_memory_are_held_back) mutate the global mark bitmaps and call copy_back_marks without holding host.submitted (tracked in #3085), executing submissions concurrently from the new tests steals/clears their bitmap bits under parallel cargo test.

To make CI green reliably without waiting on #3085, please either:

  • synchronize the direct-bitmap tests in shadow::tests against submissions (holding host.submitted, matching #3085), or
  • drive copy_back_marks directly in the new tests under host.submitted (or rebase once #3085 merges). Also note that calling crate::watch::tests::free(p) (MEM_RELEASE on main) can reuse addresses with leaked trackers under parallel runs until #3085 lands.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3108#pullrequestreview-6070998530) · **requested changes** The production fix in `crates/victory-gpu/src/shadow.rs::copy_back_marks` (`75a6a31c`) looks solid: - `held` is populated from a single bitmap scan in ascending word/bit order (`trailing_zeros()`), so `held.binary_search(n)` is valid. - Filtering `marked` against `held` prevents a `(copy, page)` marked in both bitmaps from leaking withheld writes into title memory, while allowing distinct host copies covering the same title page to copy back their ordinary writes before `drop_withheld(page, PAGE)` retakes the page across all copies. - Checking `marked.is_empty() && held.is_empty()` ensures held-only submissions still run `drop_withheld`. ### Root cause of the CI failure (reproduced locally on Windows 11 + WARP) Running `shadow::` locally shows why `check` failed on `75a6a31c`: - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) and `cargo xtask policy`: clean. - Serial WARP (`cargo test -p victory-gpu --lib --features diagnostics -- shadow:: --test-threads=1`): **12/12 passed**. - Default parallel WARP (`cargo test -p victory-gpu --lib --features diagnostics -- shadow::`): **failed immediately (10 passed, 2 failed)**: - `shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed`: `both writers' bytes, page 1: left (0, 17), right (187, 17)` - `shadow::tests::marks_of_shaders_using_title_memory_are_held_back`: `page 1 held back: left (170, 187), right (170, 0)` Both new regression tests call `host.execute(&[&list])` inside `shadow::tests`. Because the pre-existing direct-bitmap tests (`marked_pages_go_back_by_the_bytes_the_gpu_changed` and `marks_of_shaders_using_title_memory_are_held_back`) mutate the global mark bitmaps and call `copy_back_marks` without holding `host.submitted` (tracked in `#3085`), executing submissions concurrently from the new tests steals/clears their bitmap bits under parallel `cargo test`. To make CI green reliably without waiting on `#3085`, please either: - synchronize the direct-bitmap tests in `shadow::tests` against submissions (holding `host.submitted`, matching `#3085`), or - drive `copy_back_marks` directly in the new tests under `host.submitted` (or rebase once `#3085` merges). Also note that calling `crate::watch::tests::free(p)` (`MEM_RELEASE` on `main`) can reuse addresses with leaked trackers under parallel runs until `#3085` lands.
Run in parallel, victory-gpu's shadow and watch tests failed now and then
(about one run in three), each passing alone:

- A test can leave a tracker of its pool behind (a host copy or a
  texture's staging something global still holds) and then free the
  pool. Its pages stay in the guard set, and a pool another test got at
  the same addresses counts as guarded already: its writes never fault,
  so nothing is seen changed or saved (armed_ranges_keep_..., the
  partial-refresh tests). watch::tests::free now decommits the pool and
  keeps its addresses reserved, so no allocation lands there again.
- copy_back_marks takes every mark set in the bitmaps, and a test
  submitting alongside took the marks a mark test had just set
  (marked_pages_go_back_..., marks_of_shaders_using_title_memory_...).
  Those tests now hold the submission lock while they run, as the
  read-mark tests do (host::tests::no_submissions).
partial_refresh_under_marked_range_updates_saved_bytes failed now and then
in parallel: page 0 came back whole from the copy over the title's later
writes, or the copy's writes did not come back at all, as if a submission
of a test running alongside had worked through the copy first. It does no
submission of its own, so it holds the submission lock.
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/3108/head:github-bot/gh-3108'
git switch 'github-bot/gh-3108'

Merge

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