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

Open
YouKnowWh wants to merge 5 commits from upstream-pr/3108 into main
YouKnowWh commented 2026-11-26 08:22:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by YouKnowWh on 2026-11-26T08:22:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6622499739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3108). Originally posted by [YouKnowWh](https://github.com/YouKnowWh) on 2026-11-26T08:22:47Z. --- 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.
Dukestar69 commented 2026-11-26 09:05:55 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6070690020 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3108#pullrequestreview-6070690020). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T08:28:12Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 09:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:51:57Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6070998530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3108#pullrequestreview-6070998530). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:51:57Z. **Review:** CHANGES_REQUESTED --- 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.
Marvisak commented 2026-11-26 09:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:32:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186715002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3108#issuecomment-7186715002). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:32:19Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-26 10:04:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:27:33Z.

Review: APPROVED


Re-reviewed at 4f231225. Merging the #3085 test-isolation fix resolves the parallel WARP bitmap race cleanly, and the production logic in crates/victory-gpu/src/shadow.rs::copy_back_marks remains solid (ordinary marked copy-backs run before drop_withheld retakes shared pages, while pages marked in both bitmaps for the same copy are filtered out via held.binary_search and stay withheld).

Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer):

  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean
  • cargo xtask policy: 191 files ok
  • RTX 5090 default-parallel cargo test -p victory-gpu --lib shadow::: 10/10 runs passed (12/12 tests per run)
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1) default-parallel shadow::: 10/10 runs passed
  • RTX 5090 + VICTORY_D3D12_DEBUG=1: shadow:: 12/12 passed, watch:: 15/15 passed

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6071538190 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3108#pullrequestreview-6071538190). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:27:33Z. **Review:** APPROVED --- Re-reviewed at `4f231225`. Merging the `#3085` test-isolation fix resolves the parallel WARP bitmap race cleanly, and the production logic in `crates/victory-gpu/src/shadow.rs::copy_back_marks` remains solid (ordinary marked copy-backs run before `drop_withheld` retakes shared pages, while pages marked in both bitmaps for the same copy are filtered out via `held.binary_search` and stay withheld). Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer): - `cargo clippy --workspace --all-targets -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features -- -D warnings`: clean - `cargo xtask policy`: `191 files ok` - RTX 5090 default-parallel `cargo test -p victory-gpu --lib shadow::`: 10/10 runs passed (12/12 tests per run) - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`) default-parallel `shadow::`: 10/10 runs passed - RTX 5090 + `VICTORY_D3D12_DEBUG=1`: `shadow::` 12/12 passed, `watch::` 15/15 passed LGTM.
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/3108:upstream-pr/3108'
git switch 'upstream-pr/3108'

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