GPU: release mark owners outside the marks lock #3143

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3145 into main
andrewpozdnakov7-jpg commented 2026-11-26 10:15:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T10:15:01Z.


Refs #3137.

copy_back_marks upgrades a weak shadow reference while holding the marks registry. When the mark falls outside the copy, dropping that temporary Arc can run Shadow::drop under the same lock. The path for held-back pages also processes them under the registry lock.

Snapshot strong references and their offsets under the lock. Validate the offsets, release rejected references, and process both marked and held-back pages after releasing the lock.

The same isolated Windows/WARP fixture on 63bcca4 lost the rejected owner before iteration. With this change it carries one reference out of the lookup, rejects the out-of-range page, and releases the owner. Its valid-page control resolves to the same address.

  • All 10 shadow tests passed. The full app-local WARP GPU suite passed 247 tests with one ignored.
  • Strict GPU Clippy passed with default and all features. cargo xtask policy checked 191 files.

The fixture checks mark ownership. The layout-rewrite performance measurement in #3137 remains a separate experiment.

AI-assisted. Synthetic data only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5508100038 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3145). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T10:15:01Z. --- Refs #3137. `copy_back_marks` upgrades a weak shadow reference while holding the marks registry. When the mark falls outside the copy, dropping that temporary `Arc` can run `Shadow::drop` under the same lock. The path for held-back pages also processes them under the registry lock. Snapshot strong references and their offsets under the lock. Validate the offsets, release rejected references, and process both marked and held-back pages after releasing the lock. The same isolated Windows/WARP fixture on `63bcca4` lost the rejected owner before iteration. With this change it carries one reference out of the lookup, rejects the out-of-range page, and releases the owner. Its valid-page control resolves to the same address. - All 10 `shadow` tests passed. The full app-local WARP GPU suite passed 247 tests with one ignored. - Strict GPU Clippy passed with default and all features. `cargo xtask policy` checked 191 files. The fixture checks mark ownership. The layout-rewrite performance measurement in #3137 remains a separate experiment. AI-assisted. Synthetic data only.
Dukestar69 commented 2026-11-26 10:28:35 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed (including a_rejected_mark_keeps_its_copy_until_after_the_lookup).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly drops mark owners outside the marks lock to avoid lock-ordering/reentrancy hazards.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072435930 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3145#pullrequestreview-6072435930). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:28:35Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 11/11 passed (including `a_rejected_mark_keeps_its_copy_until_after_the_lookup`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly drops mark owners outside the marks lock to avoid lock-ordering/reentrancy hazards. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 23:02:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:12Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

a_rejected_mark_keeps_its_copy_until_after_the_lookup passes, as do the shadow/withheld tests it touches. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205198041 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3145#issuecomment-7205198041). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:12Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `cargo test -p victory-gpu --lib`: 232 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. `a_rejected_mark_keeps_its_copy_until_after_the_lookup` passes, as do the shadow/withheld tests it touches. Synthetic only. AI-assisted.
fuzeofficlal commented 2026-11-26 23:50:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:50:25Z.

Review: APPROVED


Looks good — cleanly fixes a real MARKS -> Shadow::drop -> MARKS self-deadlock on both rejected mark indices and the held loop.

Checked crates/victory-gpu/src/shadow.rs:927-930 and shadow.rs:948-969, as well as every other marks() lock site in shadow.rs (254, 269, 700, 912):

  • Inside the registry lock, marked_pages only upgrades Weak<Shadow> handles into owners and releases the MutexGuard before filtering out-of-range offsets or yielding items to the caller.
  • Both out-of-range mark owners and held owners dropped during iteration (as well as crate::memory::drop_withheld) now run strictly outside the MARKS lock, allowing Shadow::drop to reclaim its mark bits without deadlocking.
  • (Non-blocking note: under Rust 2024 RPIT capture rules, adding + use<> to marked_pages's return type would let callers pass temporary slice literals without an extra binding, though current callers passing &held/&marked are unaffected.)

Verification (8ddfe76f):

  • cargo xtask policy and cargo clippy -p victory-gpu (default and --features diagnostics, --tests -- -D warnings): passed.
  • shadow::tests:: (10/10, including a_rejected_mark_keeps_its_copy_until_after_the_lookup): passed on both hardware GPU and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1).
  • Live global-MARKS regression and stress probe dropping the last external Arc<Shadow> on both a rejected out-of-range mark and a held mark (plus an 8-thread x 25-iteration concurrent create/lookup/drop stress loop): passed on both hardware GPU and WARP with zero deadlocks and clean mark owner reclamation.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081685348 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3145#pullrequestreview-6081685348). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:50:25Z. **Review:** APPROVED --- Looks good — cleanly fixes a real `MARKS` -> `Shadow::drop` -> `MARKS` self-deadlock on both rejected mark indices and the `held` loop. Checked `crates/victory-gpu/src/shadow.rs:927-930` and `shadow.rs:948-969`, as well as every other `marks()` lock site in `shadow.rs` (`254`, `269`, `700`, `912`): - Inside the `registry` lock, `marked_pages` only upgrades `Weak<Shadow>` handles into `owners` and releases the `MutexGuard` before filtering out-of-range offsets or yielding items to the caller. - Both out-of-range mark owners and `held` owners dropped during iteration (as well as `crate::memory::drop_withheld`) now run strictly outside the `MARKS` lock, allowing `Shadow::drop` to reclaim its mark bits without deadlocking. - (Non-blocking note: under Rust 2024 RPIT capture rules, adding `+ use<>` to `marked_pages`'s return type would let callers pass temporary slice literals without an extra binding, though current callers passing `&held`/`&marked` are unaffected.) Verification (`8ddfe76f`): - `cargo xtask policy` and `cargo clippy -p victory-gpu` (default and `--features diagnostics`, `--tests -- -D warnings`): passed. - `shadow::tests::` (10/10, including `a_rejected_mark_keeps_its_copy_until_after_the_lookup`): passed on both hardware GPU and WARP (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`). - Live global-`MARKS` regression and stress probe dropping the last external `Arc<Shadow>` on both a rejected out-of-range mark and a `held` mark (plus an 8-thread x 25-iteration concurrent create/lookup/drop stress loop): passed on both hardware GPU and WARP with zero deadlocks and clean mark owner reclamation.
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/3145:upstream-pr/3145'
git switch 'upstream-pr/3145'

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