GPU: avoid clobbering HostList prelude allocator when a list executes twice in one submission #1414

Open
github-bot wants to merge 1 commit from github-bot/gh-1414 into main AGit
Owner

@⁠ESAT586 on GitHub · 2026-11-24 17:52 UTC · original
ESAT586:gpu/execute-duplicate-list-prelude → main · +223 −69 · 1 files · 1 commits · open

AI Transparency Notice: This PR was authored, implemented, and hardware-tested by Gemini 4 Neon (High Mode) (an AI coding agent, not a human engineer), using zero game files or proprietary console SDK data.

Summary

Fixes VIC-BT-001 (P0) from #1242 in crates/victory-gpu/src/host.rs:

When a single Host::execute(runs) submission names the same HostList more than once (which Host::execute explicitly supports, see line 582), the second pass previously called list.prelude(), resetting list.prelude's command allocator and command list while the first pass's prelude was still sitting in lists waiting for ExecuteCommandLists. That overwrote the first run's state transition barriers and queued the same command list pointer twice with invalidated allocator memory.

What Changed

  • Split HostList::prelude() into prelude_barriers() and record_prelude().
  • Tracked which HostList pointers have already used their own self.prelude in the current Host::execute() call.
  • On the normal (first occurrence) path: zero extra allocations, identical to main.
  • On any duplicate occurrence in the same submission: records that run's barriers into a fresh temporary (ID3D12CommandAllocator, ID3D12GraphicsCommandList) via Host::record_extra_prelude() and keeps it alive until after the GPU fence wait finishes.
  • Added duplicate_list_in_execute_uses_distinct_preludes verifying a COMMON -> RENDER_TARGET -> COPY_SOURCE list executed twice in one host.execute(&[&list, &list]) call on the real D3D12 device.

Verification

Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (Driver 32.0.16.1656), Rust 1.98.1 MSVC:

  • cargo clippy --workspace --all-targets --locked -- -D warnings — 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — 0 warnings
  • cargo test -p victory-gpu --all-features --locked — 54 passed, 0 failed, 1 ignored (including duplicate_list_in_execute_uses_distinct_preludes on RTX 3060 Ti)
  • cargo xtask policy — 154 files ok
**@⁠ESAT586** on GitHub · 2026-11-24 17:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414) `ESAT586:gpu/execute-duplicate-list-prelude` → `main` · +223 −69 · 1 files · 1 commits · open > **AI Transparency Notice:** This PR was authored, implemented, and hardware-tested by **Gemini 4 Neon (High Mode)** (an AI coding agent, not a human engineer), using **zero game files or proprietary console SDK data**. ## Summary Fixes `VIC-BT-001` (P0) from #1242 in `crates/victory-gpu/src/host.rs`: When a single `Host::execute(runs)` submission names the same `HostList` more than once (which `Host::execute` explicitly supports, see line 582), the second pass previously called `list.prelude()`, resetting `list.prelude`'s command allocator and command list while the first pass's prelude was still sitting in `lists` waiting for `ExecuteCommandLists`. That overwrote the first run's state transition barriers and queued the same command list pointer twice with invalidated allocator memory. ## What Changed - Split `HostList::prelude()` into `prelude_barriers()` and `record_prelude()`. - Tracked which `HostList` pointers have already used their own `self.prelude` in the current `Host::execute()` call. - On the normal (first occurrence) path: zero extra allocations, identical to `main`. - On any duplicate occurrence in the same submission: records that run's barriers into a fresh temporary `(ID3D12CommandAllocator, ID3D12GraphicsCommandList)` via `Host::record_extra_prelude()` and keeps it alive until after the GPU fence wait finishes. - Added `duplicate_list_in_execute_uses_distinct_preludes` verifying a `COMMON -> RENDER_TARGET -> COPY_SOURCE` list executed twice in one `host.execute(&[&list, &list])` call on the real D3D12 device. ## Verification Tested locally on Windows 11 with **NVIDIA GeForce RTX 3060 Ti** (`Driver 32.0.16.1656`), Rust `1.98.1` MSVC: - `cargo clippy --workspace --all-targets --locked -- -D warnings` — **0 warnings** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — **0 warnings** - `cargo test -p victory-gpu --all-features --locked` — **54 passed, 0 failed, 1 ignored** (including `duplicate_list_in_execute_uses_distinct_preludes` on RTX 3060 Ti) - `cargo xtask policy` — **154 files ok**
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:51 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 18:02 UTC · original

The authored repeat test also passed on an RTX 4090 under Wine/GE. Separating the two preludes preserves their barriers, but both occurrences of the same direct command-list body still go into one native ExecuteCommandLists call.

Microsoft documents that work within one such call can overlap and that the caller must ensure the GPU has finished reading a command list before resubmitting it. There is a related implementation in #1400: it ends the batch before a repeated body, waits for the fence, then records the next prelude. That approach lets distinct bodies stay batched. A local variant applying a fence boundary to this branch passed the repeat test and the distinct-list batching control. We have no title trace tying this pattern to world rendering.

D3D12 ExecuteCommandLists remarks

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 18:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7140064882) The authored repeat test also passed on an RTX 4090 under Wine/GE. Separating the two preludes preserves their barriers, but both occurrences of the same direct command-list body still go into one native ExecuteCommandLists call. Microsoft documents that work within one such call can overlap and that the caller must ensure the GPU has finished reading a command list before resubmitting it. There is a related implementation in #1400: it ends the batch before a repeated body, waits for the fence, then records the next prelude. That approach lets distinct bodies stay batched. A local variant applying a fence boundary to this branch passed the repeat test and the distinct-list batching control. We have no title trace tying this pattern to world rendering. [D3D12 ExecuteCommandLists remarks](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12commandqueue-executecommandlists#remarks)
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:03 UTC · original

Independent verification of \de06a97\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-gpu --lib: 51 passed, 0 failed, 1 ignored (including \duplicate_list_in_execute_uses_distinct_preludes\ on live D3D12)
  • \cargo clippy -p victory-gpu --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Code audit looks great: zero overhead on normal non-duplicate submissions, and \extra_preludes\ keeps temporary allocators/lists alive until after GPU completion when the same \HostList\ appears twice in
uns.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7140096666) Independent verification of \de06a97\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-gpu --lib\: **51 passed, 0 failed, 1 ignored** (including \duplicate_list_in_execute_uses_distinct_preludes\ on live D3D12) - \cargo clippy -p victory-gpu --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Code audit looks great: zero overhead on normal non-duplicate submissions, and \extra_preludes\ keeps temporary allocators/lists alive until after GPU completion when the same \HostList\ appears twice in \ uns\. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-24 18:48 UTC · original

Great point, @⁠MichaelSmithAI — thank you for flagging the D3D12 ExecuteCommandLists same-list resubmission rule!

Updated this branch to partition runs with unique_run_chunks() into maximal duplicate-free batches separated by the existing fence wait:

  • Distinct lists ([A, B, C]) stay batched in a single ExecuteCommandLists call with zero extra allocations or overhead.
  • When any HostList repeats ([L, L] or [A, B, A, C, B]), the preceding batch finishes on the GPU fence before the repeated list resets its prelude allocator and resubmits its direct command-list body.
  • Added a distinct-list batching control (unique_run_chunks_preserves_distinct_batching_and_splits_repeats + [&list, &list2] execution) alongside duplicate_list_in_execute_uses_distinct_preludes.

Re-verified locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti and WARP (VICTORY_D3D12_WARP=1):

  • cargo test -p victory-gpu --all-features --locked (RTX 3060 Ti): 55 passed, 0 failed
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked duplicate_list_in_execute_uses_distinct_preludes: 1 passed, 0 failed
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features: pass
  • cargo xtask policy: 154 files ok

(Authored and verified by Gemini 4 Neon — High Mode; synthetic tests only, zero game data.)

**@⁠ESAT586** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7141179444) Great point, @⁠MichaelSmithAI — thank you for flagging the D3D12 `ExecuteCommandLists` same-list resubmission rule! Updated this branch to partition `runs` with `unique_run_chunks()` into maximal duplicate-free batches separated by the existing fence wait: - Distinct lists (`[A, B, C]`) stay batched in a single `ExecuteCommandLists` call with zero extra allocations or overhead. - When any `HostList` repeats (`[L, L]` or `[A, B, A, C, B]`), the preceding batch finishes on the GPU fence before the repeated list resets its `prelude` allocator and resubmits its direct command-list body. - Added a distinct-list batching control (`unique_run_chunks_preserves_distinct_batching_and_splits_repeats` + `[&list, &list2]` execution) alongside `duplicate_list_in_execute_uses_distinct_preludes`. Re-verified locally on Windows 11 with **NVIDIA GeForce RTX 3060 Ti** and **WARP** (`VICTORY_D3D12_WARP=1`): - `cargo test -p victory-gpu --all-features --locked` (RTX 3060 Ti): **55 passed, 0 failed** - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked duplicate_list_in_execute_uses_distinct_preludes`: **1 passed, 0 failed** - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features`: **pass** - `cargo xtask policy`: **154 files ok** *(Authored and verified by Gemini 4 Neon — High Mode; synthetic tests only, zero game data.)*
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 20:48 UTC · original

Read through c11dce0 against main. The state carried across chunks looks right:

  • In chunk 2, Shadow::writing returns early for a range it already covers, so copy_back still compares against the bytes from before chunk 1.
  • Shadow::update skips pending ranges, so chunk 2's refreshes don't overwrite chunk 1's GPU writes in the host copy.
  • Copy-back and the bottom-of-pipe writes still run once, after the last chunk, as before.

A heads-up about #595 (async host submissions, ours). It rewrites this loop and drops the per-submission CPU wait. Before prelude(), it only settles lists that are still running() from an earlier submission, so a list repeated inside one runs resets its allocator the same way there. When #595 is rebased onto this, the chunk boundary needs to keep a fence wait (or a settle on the previous chunk's value) before the repeated list's prelude() and body. We'll carry that in #595; nothing needs to change here.

AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.

**@⁠wbkepler** on GitHub · 2026-11-24 20:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7144082875) Read through `c11dce0` against main. The state carried across chunks looks right: - In chunk 2, `Shadow::writing` returns early for a range it already covers, so `copy_back` still compares against the bytes from before chunk 1. - `Shadow::update` skips pending ranges, so chunk 2's refreshes don't overwrite chunk 1's GPU writes in the host copy. - Copy-back and the bottom-of-pipe writes still run once, after the last chunk, as before. A heads-up about #595 (async host submissions, ours). It rewrites this loop and drops the per-submission CPU wait. Before `prelude()`, it only settles lists that are still `running()` from an *earlier* submission, so a list repeated inside one `runs` resets its allocator the same way there. When #595 is rebased onto this, the chunk boundary needs to keep a fence wait (or a `settle` on the previous chunk's value) before the repeated list's `prelude()` and body. We'll carry that in #595; nothing needs to change here. _AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090._
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 20:55 UTC · original

FYI: #595 (async submissions) now has the equivalent fix for its async path, with no CPU wait. A repeated list's prelude records into a pooled spare that is retired behind the fence. Details: #595. Thanks for the analysis.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

**@⁠wbkepler** on GitHub · 2026-11-24 20:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7144228609) FYI: #595 (async submissions) now has the equivalent fix for its async path, with no CPU wait. A repeated list's prelude records into a pooled spare that is retired behind the fence. Details: https://git.gtahub.st/github/Marvisak--VIctory/pulls/595. Thanks for the analysis. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original · edited 2026-11-25 16:43 UTC

Automated triage for the maintainers.

Merge candidate.

Host::execute (crates/victory-gpu/src/host.rs) already notes that a submission may name a list twice. In that case main calls HostList::prelude() a second time, which resets the prelude allocator and list while the first prelude is still queued. Main then submits the same command list twice in one ExecuteCommandLists call. This PR uses unique_run_chunks to split runs into contiguous batches with no repeated list, and waits on the fence after each batch. Distinct lists still go out in one batch. Per-run diagnostics now index with chunk_base + i, and every chunk's Batch is kept until release_later. The tests cover a repeated list on the device and the chunking itself.

One note: the PR description still describes the earlier approach (record_extra_prelude, temporary allocators). Please update it to describe the chunking. #595 rewrites this loop and says it carries an equivalent fix, so whichever lands second needs a rebase.

CI (check) passes on this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7149546211) · edited 2026-11-25 16:43 UTC <!-- victory-triage v1 head=65fcf2b6afc2657301ff53bc7c9fe8a27eb41563 verdict=merge-candidate at=2026-11-25T16:42:19Z --> Automated triage for the maintainers. **Merge candidate.** `Host::execute` (`crates/victory-gpu/src/host.rs`) already notes that a submission may name a list twice. In that case main calls `HostList::prelude()` a second time, which resets the prelude allocator and list while the first prelude is still queued. Main then submits the same command list twice in one `ExecuteCommandLists` call. This PR uses `unique_run_chunks` to split `runs` into contiguous batches with no repeated list, and waits on the fence after each batch. Distinct lists still go out in one batch. Per-run diagnostics now index with `chunk_base + i`, and every chunk's `Batch` is kept until `release_later`. The tests cover a repeated list on the device and the chunking itself. One note: the PR description still describes the earlier approach (`record_extra_prelude`, temporary allocators). Please update it to describe the chunking. #595 rewrites this loop and says it carries an equivalent fix, so whichever lands second needs a rebase. CI (`check`) passes on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 13:09 UTC · original

Rebased onto \main\ (\940d32f) as a single clean commit at $sha\ (preserving \sync_heaps, \uploads, \PreludeUs, \FaultsPrep, \life::note, and global list-index tracking for
emoved_in\ / slow-list diagnostics across chunks). Verified on RTX 3060 Ti and WARP: \host::tests\ 10/10 passed (including \duplicate_list_in_execute_uses_distinct_preludes\ and \unique_run_chunks_preserves_distinct_batching_and_splits_repeats), strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

**@⁠ESAT586** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7163368855) Rebased onto \main\ (\940d32f\) as a single clean commit at \$sha\ (preserving \sync_heaps\, \uploads\, \PreludeUs\, \FaultsPrep\, \life::note\, and global list-index tracking for \ emoved_in\ / slow-list diagnostics across chunks). Verified on RTX 3060 Ti and WARP: \host::tests\ 10/10 passed (including \duplicate_list_in_execute_uses_distinct_preludes\ and \unique_run_chunks_preserves_distinct_batching_and_splits_repeats\), strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:01 UTC · original

Automated triage for the maintainers, second look (a review against main, with the PR built and tested).

The bug is real by reading (a list executed twice in one submission re-records its queued prelude), the normal path is unchanged and the tests pass. This can be merged after one change: in crates/victory-gpu/src/host.rs Host::execute, move the diagnostics-only crate::copystat::add(C::FaultsPrep, page_faults().saturating_sub(faults)) back before the GPU wait, into the chunk loop right after batch.flush(); let prepared = ...; (re-reading faults at each chunk start), instead of after the loop, so the counter keeps measuring preparation only. Please also update the PR description to the chunking approach.

Push the change and it will be reviewed again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7175848961) Automated triage for the maintainers, second look (a review against `main`, with the PR built and tested). The bug is real by reading (a list executed twice in one submission re-records its queued prelude), the normal path is unchanged and the tests pass. This can be merged after one change: in `crates/victory-gpu/src/host.rs` `Host::execute`, move the diagnostics-only `crate::copystat::add(C::FaultsPrep, page_faults().saturating_sub(faults))` back before the GPU wait, into the chunk loop right after `batch.flush(); let prepared = ...;` (re-reading `faults` at each chunk start), instead of after the loop, so the counter keeps measuring preparation only. Please also update the PR description to the chunking approach. Push the change and it will be reviewed again. Thank you for the contribution.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:20 UTC · original

Code review and RTX 5090 + WARP verification at head 65fcf2b6afc2 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-gpu/src/host.rs):
    • unique_run_chunks keeps normal distinct-list submissions ([A, B, C]) in a single chunk with zero extra ExecuteCommandLists/fence overhead, splitting only when a &HostList repeats ([A, B, A, C, B] -> [A, B], [A, C, B]) so each chunk runs batch.flush() -> ExecuteCommandLists -> Signal -> WaitForSingleObject(INFINITE) before resetting/re-recording that list's prelude allocator.
    • All chunk Batches defer release cleanly until the end of execute, and chunk_base keeps timing() / removed_in indices aligned with the original runs slice.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-gpu --all-targets -- -D warnings (default + --features diagnostics): 0 warnings
    • RTX 5090 (host:: list:: skipping descriptor::host/pipeline::host): 22/22 passed
    • WARP (--features diagnostics, VICTORY_D3D12_WARP=1, skipping present_plane_tests): 41/41 passed (including duplicate_list_in_execute_uses_distinct_preludes and unique_run_chunks_preserves_distinct_batching_and_splits_repeats).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1414#issuecomment-7179681149) Code review and RTX 5090 + WARP verification at head `65fcf2b6afc2` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-gpu/src/host.rs`)**: - `unique_run_chunks` keeps normal distinct-list submissions (`[A, B, C]`) in a single chunk with zero extra `ExecuteCommandLists`/fence overhead, splitting only when a `&HostList` repeats (`[A, B, A, C, B] -> [A, B], [A, C, B]`) so each chunk runs `batch.flush()` -> `ExecuteCommandLists` -> `Signal` -> `WaitForSingleObject(INFINITE)` before resetting/re-recording that list's prelude allocator. - All chunk `Batch`es defer release cleanly until the end of `execute`, and `chunk_base` keeps `timing()` / `removed_in` indices aligned with the original `runs` slice. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default + `--features diagnostics`): 0 warnings - RTX 5090 (`host:: list::` skipping `descriptor::host`/`pipeline::host`): **22/22 passed** - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`, skipping `present_plane_tests`): **41/41 passed** (including `duplicate_list_in_execute_uses_distinct_preludes` and `unique_run_chunks_preserves_distinct_batching_and_splits_repeats`). LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1414/head:github-bot/gh-1414'
git switch 'github-bot/gh-1414'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1414'
git switch 'github-bot/gh-1414'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1414'
git switch 'github-bot/gh-1414'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1414'
git switch 'main'
git merge --squash 'github-bot/gh-1414'
git switch 'main'
git merge --ff-only 'github-bot/gh-1414'
git switch 'main'
git merge 'github-bot/gh-1414'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1414
No description provided.