GPU: a slot rewritten during a run keeps its view's copy of title memory until the run is over #2291

Open
denkencar-sketch wants to merge 2 commits from upstream-pr/2293 into main
denkencar-sketch commented 2026-11-25 10:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T10:05:18Z.


Summary

A descriptor slot rewritten during a run retired only its host buffer; the view's copy of title memory went at once, together with the marks the submission's copy-back still had to read. The copy is now kept until the run is over.

Testing

Test a_rewritten_slot_retires_its_copy_of_title_memory fails on main and passes with this change. The branch has a second, comment-only commit that moves two doc comments back to their items. cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

Not tried: a run in the game. The test depends on the global release_retired.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5489186828 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T10:05:18Z. --- ## Summary A descriptor slot rewritten during a run retired only its host buffer; the view's copy of title memory went at once, together with the marks the submission's copy-back still had to read. The copy is now kept until the run is over. ## Testing Test `a_rewritten_slot_retires_its_copy_of_title_memory` fails on `main` and passes with this change. The branch has a second, comment-only commit that moves two doc comments back to their items. `cargo test --workspace --locked` passes apart from known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). Not tried: a run in the game. The test depends on the global `release_retired`. AI-assisted.
catminou4 commented 2026-11-25 10:19:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:11Z.

Review: COMMENTED


A slot rewritten during a run keeps its view's copy of title memory until the work ran (retire(old, copy)). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Lifetime fix with regression test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6055712174 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293#pullrequestreview-6055712174). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T10:19:11Z. **Review:** COMMENTED --- A slot rewritten during a run keeps its view's copy of title memory until the work ran (retire(old, copy)). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Lifetime fix with regression test.
welisonzika14-jpg commented 2026-11-25 12:03:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T12:00:02Z.


First run on NVIDIA hardware here, as far as I can see (the reviews above are static or WARP). RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head 0318c56 merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's test descriptor::host::tests::a_rewritten_slot_retires_its_copy_of_title_memory passes on this card. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161785184 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293#issuecomment-7161785184). Originally posted by [welisonzika14-jpg](https://github.com/welisonzika14-jpg) on 2026-11-25T12:00:02Z. --- First run on NVIDIA hardware here, as far as I can see (the reviews above are static or WARP). RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `0318c56` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's test `descriptor::host::tests::a_rewritten_slot_retires_its_copy_of_title_memory` passes on this card. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Marvisak commented 2026-11-25 15:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T14:51:06Z.


Automated triage for the maintainers.

Verdict: merge candidate. I reviewed the rebased head ad5440a. HostHeap::keep (crates/victory-gpu/src/descriptor/host.rs) now passes the old slot's Arc<Shadow> to host::retire together with its resource, so the copy outlives the run. This matters because the copy owners in shadow::Marks are Weak, and copy_back_marks (host.rs ~1396) runs before release_retired (~1428). Without the change, a slot rewritten mid-run dropped its copy, and its marked writes were lost. retire has no other callers. The draw.rs test now waits for the release thread, which matches release_later.

Minor: a_rewritten_slot_retires_its_copy_of_title_memory asserts an exact strong_count while other tests may call the global release_retired in parallel. It could flake under the default thread count.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165914070 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293#issuecomment-7165914070). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T14:51:06Z. --- <!-- victory-triage v1 head=ad5440a91b715b66c87b73bfb75b1140c63458fe verdict=merge-candidate at=2026-11-26T03:22:05Z --> Automated triage for the maintainers. **Verdict: merge candidate.** I reviewed the rebased head `ad5440a`. `HostHeap::keep` (`crates/victory-gpu/src/descriptor/host.rs`) now passes the old slot's `Arc<Shadow>` to `host::retire` together with its resource, so the copy outlives the run. This matters because the copy owners in `shadow::Marks` are `Weak`, and `copy_back_marks` (host.rs ~1396) runs before `release_retired` (~1428). Without the change, a slot rewritten mid-run dropped its copy, and its marked writes were lost. `retire` has no other callers. The `draw.rs` test now waits for the release thread, which matches `release_later`. Minor: `a_rewritten_slot_retires_its_copy_of_title_memory` asserts an exact `strong_count` while other tests may call the global `release_retired` in parallel. It could flake under the default thread count. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 15:13:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:13:26Z.

Review: APPROVED


Reviewed descriptor/host.rs, draw.rs, and host.rs at ad5440a9 merged onto origin/main (63bcca43) and verified on RTX 5090 and WARP (VICTORY_D3D12_WARP=1) with VICTORY_D3D12_DEBUG=1.

Lifetime & locking audit

  • Safe retirement & timely drainage: HostHeap::keep (crates/victory-gpu/src/descriptor/host.rs:561) passes both the displaced ID3D12Resource and Option<Arc<Shadow>> to host::retire (crates/victory-gpu/src/host.rs:3677,3683), keeping the shadow copy (and its Weak-referenced Marks entry) alive until Host::submit finishes copy_back_marks and calls release_retired() (host.rs:3688).
  • No lock-held drops: release_retired() swaps RETIRED out with std::mem::take and sends the Vec to the background victory-release thread (release_later), so Arc<Shadow> drops (which lock ARENA/MARKS) happen completely outside both HostHeap::kept and RETIRED, and RETIRED is drained on every submission.
  • Test synchronization: draw.rs:3634-3637 cleanly updates structured_views_off_their_buffers_elements_get_their_own_copy to drain release_retired() and wait for the background release thread. (Minor non-blocking note: a_rewritten_slot_retires_its_copy_of_title_memory at descriptor/host.rs:2095 asserts an exact Arc::strong_count against the process-global RETIRED list, which can contend if another test calls release_retired() concurrently.)
  • Merge compatibility: git merge-tree confirms clean merges with both #2329 and #2298.

Verification

  • cargo run -p xtask -- policy: 191 files ok.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean.
  • descriptor:: draw:: host:: with VICTORY_D3D12_DEBUG=1: 62/62 passed on RTX 5090 (skipping dynamic_slots_are_held_until_released) and 63/63 passed on WARP (--features diagnostics, skipping the pre-existing main compositor_failure_presents_primary_in_the_same_frame Debug Layer mismatch), including a_rewritten_slot_retires_its_copy_of_title_memory (descriptor/host.rs:2095) and structured_views_off_their_buffers_elements_get_their_own_copy.
<!-- greyfinch-sync:Marvisak/VIctory:review:6076555016 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293#pullrequestreview-6076555016). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T15:13:26Z. **Review:** APPROVED --- Reviewed `descriptor/host.rs`, `draw.rs`, and `host.rs` at `ad5440a9` merged onto `origin/main` (`63bcca43`) and verified on RTX 5090 and WARP (`VICTORY_D3D12_WARP=1`) with `VICTORY_D3D12_DEBUG=1`. ### Lifetime & locking audit - **Safe retirement & timely drainage**: `HostHeap::keep` (`crates/victory-gpu/src/descriptor/host.rs:561`) passes both the displaced `ID3D12Resource` and `Option<Arc<Shadow>>` to `host::retire` (`crates/victory-gpu/src/host.rs:3677,3683`), keeping the shadow copy (and its `Weak`-referenced `Marks` entry) alive until `Host::submit` finishes `copy_back_marks` and calls `release_retired()` (`host.rs:3688`). - **No lock-held drops**: `release_retired()` swaps `RETIRED` out with `std::mem::take` and sends the `Vec` to the background `victory-release` thread (`release_later`), so `Arc<Shadow>` drops (which lock `ARENA`/`MARKS`) happen completely outside both `HostHeap::kept` and `RETIRED`, and `RETIRED` is drained on every submission. - **Test synchronization**: `draw.rs:3634-3637` cleanly updates `structured_views_off_their_buffers_elements_get_their_own_copy` to drain `release_retired()` and wait for the background release thread. (Minor non-blocking note: `a_rewritten_slot_retires_its_copy_of_title_memory` at `descriptor/host.rs:2095` asserts an exact `Arc::strong_count` against the process-global `RETIRED` list, which can contend if another test calls `release_retired()` concurrently.) - **Merge compatibility**: `git merge-tree` confirms clean merges with both `#2329` and `#2298`. ### Verification - `cargo run -p xtask -- policy`: 191 files ok. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean. - `descriptor:: draw:: host::` with `VICTORY_D3D12_DEBUG=1`: **62/62 passed** on RTX 5090 (skipping `dynamic_slots_are_held_until_released`) and **63/63 passed** on WARP (`--features diagnostics`, skipping the pre-existing `main` `compositor_failure_presents_primary_in_the_same_frame` Debug Layer mismatch), including `a_rewritten_slot_retires_its_copy_of_title_memory` (`descriptor/host.rs:2095`) and `structured_views_off_their_buffers_elements_get_their_own_copy`.
Dukestar69 commented 2026-11-26 22:11:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T22:11:08Z.

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Retiring the title-memory copy of a rewritten descriptor slot until in-flight GPU work finishes prevents use-after-free when a slot is overwritten mid-run.
  • cargo test -p victory-gpu --lib descriptor::host::tests:: -- --skip dynamic_slots_are_held_until_released --test-threads=1: 15 passed, 0 failed (including a_rewritten_slot_retires_its_copy_of_title_memory).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6081019048 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2293#pullrequestreview-6081019048). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T22:11:08Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Retiring the title-memory copy of a rewritten descriptor slot until in-flight GPU work finishes prevents use-after-free when a slot is overwritten mid-run. - `cargo test -p victory-gpu --lib descriptor::host::tests:: -- --skip dynamic_slots_are_held_until_released --test-threads=1`: 15 passed, 0 failed (including `a_rewritten_slot_retires_its_copy_of_title_memory`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2293:upstream-pr/2293'
git switch 'upstream-pr/2293'

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