GPU: a list used twice in one submission gets a prelude per use #3160

Open
kotekompotek wants to merge 1 commit from upstream-pr/3162 into main
kotekompotek commented 2026-11-26 10:38:35 +00:00 (Migrated from github.com)

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


HostList::prelude keeps one (allocator, list) pair. When one submission names the same list twice, prelude() runs once per use — and the second use's allocator.Reset() + list.Reset() destroys the recording the first use just made. ExecuteCommandLists then runs the second use's transitions twice and the first use's never: textures the first use needs are left in the wrong state.

The pair is now a small pool. prelude() pops a free pair (or makes another for a second or later use), records on it, and moves it to a flight list; execute moves the flight pairs back to free once every group's submission is waited for — the same lifetime the single pair had, just per use.

host::tests::a_second_use_gets_its_own_prelude records two uses and checks each got its own command list and its own move, in order.

Found by the #1242 audit (VIC-BT-001). Touches prelude(), which #2908 rewrites for parallel recording — whichever lands second rebases; the pool here also gives that change its per-thread pair for free.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5508449951 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3162). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T10:38:35Z. --- `HostList::prelude` keeps one `(allocator, list)` pair. When one submission names the same list twice, `prelude()` runs once per use — and the second use's `allocator.Reset()` + `list.Reset()` destroys the recording the first use just made. `ExecuteCommandLists` then runs the second use's transitions twice and the first use's never: textures the first use needs are left in the wrong state. The pair is now a small pool. `prelude()` pops a free pair (or makes another for a second or later use), records on it, and moves it to a `flight` list; `execute` moves the flight pairs back to `free` once every group's submission is waited for — the same lifetime the single pair had, just per use. `host::tests::a_second_use_gets_its_own_prelude` records two uses and checks each got its own command list and its own move, in order. Found by the #1242 audit (VIC-BT-001). Touches `prelude()`, which #2908 rewrites for parallel recording — whichever lands second rebases; the pool here also gives that change its per-thread pair for free.
Dukestar69 commented 2026-11-26 10:48:08 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • cargo test -p victory-gpu --lib host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released: passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090 and WARP.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly ensures a command list submitted twice in one submission receives a prelude per use.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072763906 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3162#pullrequestreview-6072763906). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:48:08Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed on RTX 5090 and WARP. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly ensures a command list submitted twice in one submission receives a prelude per use. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 23:02:08 +00:00 (Migrated from github.com)

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


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.

The added test a_second_use_gets_its_own_prelude passes; the prelude/list tests around it are unchanged. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205197126 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3162#issuecomment-7205197126). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:08Z. --- 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. The added test `a_second_use_gets_its_own_prelude` passes; the prelude/list tests around it are unchanged. Synthetic only. AI-assisted.
fuzeofficlal commented 2026-11-26 23:50:26 +00:00 (Migrated from github.com)

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

Review: APPROVED


Looks good — cleanly fixes prelude allocator/list clobbering when the same HostList appears multiple times in a single submission.

Checked crates/victory-gpu/src/host.rs:917-925, host.rs:1410-1412, and host.rs:2001-2091:

  • Each use that requires a prelude pops an idle (ID3D12CommandAllocator, ID3D12GraphicsCommandList) pair from preludes.free or creates a fresh one via new_prelude(), then records it into preludes.flight, preventing a second use from resetting the first use's queued prelude before GPU execution.
  • reclaim_preludes() runs only after all execution groups have waited on their fences and passed the GetDeviceRemovedReason() check (host.rs:1399-1412), is idempotent when the same list appears multiple times in runs, and reuses pooled pairs on subsequent submissions without unbounded growth.
  • Lock ordering (self.states -> brief self.preludes) is consistent and free of inversion.

Verification (2b80a5b8):

  • cargo xtask policy and cargo clippy -p victory-gpu (default and --features diagnostics, --tests -- -D warnings): passed.
  • host::tests::a_second_use_gets_its_own_prelude: passed on both hardware GPU and WARP.
  • Live GPU execution probe submitting [list_a, list_b, list_a, list_b] followed by [list_a, list_a, list_b] with real texture transitions (COMMON -> COPY_DEST -> PIXEL_SHADER_RESOURCE -> COPY_SOURCE) and readback verification: passed with zero D3D12 Debug Layer and GPU-Based Validation (VICTORY_D3D12_DEBUG=1, VICTORY_D3D12_GBV=1) errors on both hardware GPU (with and without VICTORY_GPU_TIMING=1) and WARP, confirming exact readback (0xab) and pool reuse (free.len() == 2, flight.is_empty() across both submissions).
<!-- greyfinch-sync:Marvisak/VIctory:review:6081685509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3162#pullrequestreview-6081685509). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:50:26Z. **Review:** APPROVED --- Looks good — cleanly fixes prelude allocator/list clobbering when the same `HostList` appears multiple times in a single submission. Checked `crates/victory-gpu/src/host.rs:917-925`, `host.rs:1410-1412`, and `host.rs:2001-2091`: - Each use that requires a prelude pops an idle `(ID3D12CommandAllocator, ID3D12GraphicsCommandList)` pair from `preludes.free` or creates a fresh one via `new_prelude()`, then records it into `preludes.flight`, preventing a second use from resetting the first use's queued prelude before GPU execution. - `reclaim_preludes()` runs only after all execution groups have waited on their fences and passed the `GetDeviceRemovedReason()` check (`host.rs:1399-1412`), is idempotent when the same list appears multiple times in `runs`, and reuses pooled pairs on subsequent submissions without unbounded growth. - Lock ordering (`self.states` -> brief `self.preludes`) is consistent and free of inversion. Verification (`2b80a5b8`): - `cargo xtask policy` and `cargo clippy -p victory-gpu` (default and `--features diagnostics`, `--tests -- -D warnings`): passed. - `host::tests::a_second_use_gets_its_own_prelude`: passed on both hardware GPU and WARP. - Live GPU execution probe submitting `[list_a, list_b, list_a, list_b]` followed by `[list_a, list_a, list_b]` with real texture transitions (`COMMON -> COPY_DEST -> PIXEL_SHADER_RESOURCE -> COPY_SOURCE`) and readback verification: passed with zero D3D12 Debug Layer and GPU-Based Validation (`VICTORY_D3D12_DEBUG=1`, `VICTORY_D3D12_GBV=1`) errors on both hardware GPU (with and without `VICTORY_GPU_TIMING=1`) and WARP, confirming exact readback (`0xab`) and pool reuse (`free.len() == 2`, `flight.is_empty()` across both submissions).
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/3162:upstream-pr/3162'
git switch 'upstream-pr/3162'

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