GPU/draw: evict CBV-backed fresh_tables on State::replay across cut lists #742

Open
AscilCH wants to merge 1 commit from upstream-pr/742 into main
AscilCH commented 2026-11-25 06:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T06:09:35Z.


Summary

Fixes a GPU use-after-free and stale-constant bug when a command list is cut at a memory wait (crates/victory-gpu/src/draw.rs):

  • When State::tables populates a dynamic descriptor table containing a View::Constant(address, size), the CBV points to the current HostList's scratch upload memory (list.scratch(size)) and registers list.defer_fill(...) only on that HostList.
  • When list::cut splits the command list at a memory wait and runs State::replay on a fresh HostList (H2), State::replay previously retained all fresh_tables entries. If H2 reused a cached CBV table, it pointed into H1's scratch upload buffer without registering defer_fill on H2.
  • Because H1 executes and resets (list::recycle -> H1.reset()) before H2 is released from its value wait, H1's upload buffers are dropped or returned to the scratch pool while H2 still references their GPU VAs (and any constant-buffer updates written before H2 runs are never copied).
  • State::fresh_tables now tracks (first_slot, has_cbv) and State::replay evicts all CBV-backed entries (retain(|_, &mut (_, has_cbv)| !has_cbv)), while preserving non-CBV tables and keeping self.dynamic alive until the final part's state drops.

Verification

  • cargo test -p victory-gpu --locked -- draw::replay_tests: 1 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 new warnings (pre-existing 8dd30ab warnings in draw.rs:2377 and indirect.rs:1322 untouched)
  • cargo xtask policy: 171 files ok

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6598391892 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/742). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T06:09:35Z. --- ### Summary Fixes a GPU use-after-free and stale-constant bug when a command list is cut at a memory wait (`crates/victory-gpu/src/draw.rs`): - When `State::tables` populates a dynamic descriptor table containing a `View::Constant(address, size)`, the CBV points to the current `HostList`'s scratch upload memory (`list.scratch(size)`) and registers `list.defer_fill(...)` only on that `HostList`. - When `list::cut` splits the command list at a memory wait and runs `State::replay` on a fresh `HostList` (`H2`), `State::replay` previously retained all `fresh_tables` entries. If `H2` reused a cached CBV table, it pointed into `H1`'s scratch upload buffer without registering `defer_fill` on `H2`. - Because `H1` executes and resets (`list::recycle` -> `H1.reset()`) before `H2` is released from its value wait, `H1`'s upload buffers are dropped or returned to the scratch pool while `H2` still references their GPU VAs (and any constant-buffer updates written before `H2` runs are never copied). - `State::fresh_tables` now tracks `(first_slot, has_cbv)` and `State::replay` evicts all CBV-backed entries (`retain(|_, &mut (_, has_cbv)| !has_cbv)`), while preserving non-CBV tables and keeping `self.dynamic` alive until the final part's state drops. ### Verification - `cargo test -p victory-gpu --locked -- draw::replay_tests`: **1 passed, 0 failed** - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 new warnings (pre-existing `8dd30ab` warnings in `draw.rs:2377` and `indirect.rs:1322` untouched) - `cargo xtask policy`: `171 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
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/742:upstream-pr/742'
git switch 'upstream-pr/742'

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