GPU: release replaced title memory layouts off the submitting thread #3142

Open
Ingenioeren wants to merge 1 commit from upstream-pr/3144 into main
Ingenioeren commented 2026-11-26 10:10:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-26T10:10:21Z.


What

Queue the replaced title-memory layout on the existing release thread. The rewrite runs between submissions and updates the page table and its descriptors before handing off the old layout. Copies still used by the new table or by recorded work retain their own references. No extra GPU fence is needed. If the release worker is unavailable, the existing queue helper drops the value inline.

Keep upgraded shadow owners alive until the marks lock is released, including owners of withheld pages and owners rejected by the page bounds check.

Why

Replacing a layout can drop thousands of shadow references on the submitting thread while the heap locks are held. The diagnosis in #3137 also identified that dropping the last shadow reference during marks lookup can re-enter the marks lock and deadlock. The two changes address those paths together.

How tested

  • cargo test --locked --offline -p victory-gpu mark_lookup_releases_its_last_reference_outside_the_lock on origin/main (63bcca4) with only the regression test and its test-only hook applied. It failed with a five-second timeout after the weak upgrade became the last strong reference.
  • cargo test --locked --offline -p victory-gpu mark_lookup_releases_its_last_reference_outside_the_lock with the fix. One passed, covering both the withheld-page and out-of-range mark paths.
  • cargo test --locked --offline -p victory-gpu passed with 232 passed, 0 failed, and 1 ignored (the existing synthetic benchmark object::tests::benchmark_private_data_release). There were no doctests.
  • cargo clippy --locked --offline -p victory-gpu --all-targets passed with no warnings.
  • cargo run --locked --offline -p xtask -- policy --staged passed for all 3 staged files.

Test limits

No game run, independent performance measurement, or direct test of the layout destructor's thread.

Fixes #3137

AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624315698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3144). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-26T10:10:21Z. --- ## What Queue the replaced title-memory layout on the existing release thread. The rewrite runs between submissions and updates the page table and its descriptors before handing off the old layout. Copies still used by the new table or by recorded work retain their own references. No extra GPU fence is needed. If the release worker is unavailable, the existing queue helper drops the value inline. Keep upgraded shadow owners alive until the marks lock is released, including owners of withheld pages and owners rejected by the page bounds check. ## Why Replacing a layout can drop thousands of shadow references on the submitting thread while the heap locks are held. The diagnosis in #3137 also identified that dropping the last shadow reference during marks lookup can re-enter the marks lock and deadlock. The two changes address those paths together. ## How tested - `cargo test --locked --offline -p victory-gpu mark_lookup_releases_its_last_reference_outside_the_lock` on `origin/main` (`63bcca4`) with only the regression test and its test-only hook applied. It failed with a five-second timeout after the weak upgrade became the last strong reference. - `cargo test --locked --offline -p victory-gpu mark_lookup_releases_its_last_reference_outside_the_lock` with the fix. One passed, covering both the withheld-page and out-of-range mark paths. - `cargo test --locked --offline -p victory-gpu` passed with 232 passed, 0 failed, and 1 ignored (the existing synthetic benchmark `object::tests::benchmark_private_data_release`). There were no doctests. - `cargo clippy --locked --offline -p victory-gpu --all-targets` passed with no warnings. - `cargo run --locked --offline -p xtask -- policy --staged` passed for all 3 staged files. ## Test limits No game run, independent performance measurement, or direct test of the layout destructor's thread. Fixes #3137 AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
Dukestar69 commented 2026-11-26 11:03:46 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib memory:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views: 7/7 passed.
  • 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 defers dropping replaced title memory layouts off the submitting thread.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072445034 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3144#pullrequestreview-6072445034). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:29:07Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib memory:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views`: 7/7 passed. - `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 defers dropping replaced title memory layouts off the submitting thread. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
andrewpozdnakov7-jpg commented 2026-11-26 11:04:02 +00:00 (Migrated from github.com)

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


@Ingenioeren I checked the destructor thread you listed as untested on exact head 35b9c70608 and parent main 63bcca43c6.

I ran the same fixture on Windows with WARP verified by the DXGI software adapter flag. It rewrote a real D3D12 page table twice, put a thread marker at the end of the old Layout, and waited for its last Arc to drop. The second rewrite published generation 2 on both builds, and the old Arc count reached zero on both.

Build Thread that dropped the old layout
main 63bcca4 The thread calling Shared::rewrite
this head 35b9c70 victory-release

The assertion for off-thread disposal failed on main and passed here. This establishes the handoff for one synthetic table rewrite. The reporter's timing measurements still need a title run.

My narrower #3145 covers the same mark-owner lifetime change. This PR also carries the layout handoff, so the two patches should be considered together. If you adopt our test approach or carry code from #3145, please retain the Git author when cherry-picking. If it is folded into another commit, please use the trailer below.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189659779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3144#issuecomment-7189659779). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T10:39:35Z. --- @Ingenioeren I checked the destructor thread you listed as untested on exact head 35b9c706083a75e765ee8bd84c22a0d4ac34ebfa and parent main 63bcca43c6a00a758510398fa43096ce7e4f7df0. I ran the same fixture on Windows with WARP verified by the DXGI software adapter flag. It rewrote a real D3D12 page table twice, put a thread marker at the end of the old Layout, and waited for its last Arc to drop. The second rewrite published generation 2 on both builds, and the old Arc count reached zero on both. | Build | Thread that dropped the old layout | | --- | --- | | main 63bcca4 | The thread calling Shared::rewrite | | this head 35b9c70 | victory-release | The assertion for off-thread disposal failed on main and passed here. This establishes the handoff for one synthetic table rewrite. The reporter's timing measurements still need a title run. My narrower #3145 covers the same mark-owner lifetime change. This PR also carries the layout handoff, so the two patches should be considered together. If you adopt our test approach or carry code from #3145, please retain the Git author when cherry-picking. If it is folded into another commit, please use the trailer below. Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
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/3144:upstream-pr/3144'
git switch 'upstream-pr/3144'

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