GPU: rebind replaced descriptor heaps by host identity #1331

Open
EatCodeSleep2 wants to merge 1 commit from upstream-pr/1331 into main
EatCodeSleep2 commented 2026-11-24 17:30:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T17:30:03Z.


Summary

Compare the D3D12 descriptor heaps resolved for the current draw or dispatch against the host objects already bound. When a title heap is released and its address is reused, the new host heap is distinct because the recording still holds a reference to the old host heap. Rebind and invalidate both cached root signatures when the host heap changes.

Refs #1242, finding VIC-BT-013.

Verification

  • The synthetic regression binds a native heap twice, then replaces it and verifies the root bindings are invalidated. It fails when the cache deliberately treats occupied heap slots as identical.
  • The focused test passed on native Direct3D 12 and WARP.
  • GPU diagnostics library suite: 54 passed, 1 ignored. All-targets Clippy with diagnostics passed.

The test checks host heap replacement during recording. It does not force guest allocator address reuse or submit GPU work. AI-assisted. No game files used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587643636 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1331). Originally posted by [EatCodeSleep2](https://github.com/EatCodeSleep2) on 2026-11-24T17:30:03Z. --- ## Summary Compare the D3D12 descriptor heaps resolved for the current draw or dispatch against the host objects already bound. When a title heap is released and its address is reused, the new host heap is distinct because the recording still holds a reference to the old host heap. Rebind and invalidate both cached root signatures when the host heap changes. Refs #1242, finding VIC-BT-013. ## Verification - The synthetic regression binds a native heap twice, then replaces it and verifies the root bindings are invalidated. It fails when the cache deliberately treats occupied heap slots as identical. - The focused test passed on native Direct3D 12 and WARP. - GPU diagnostics library suite: 54 passed, 1 ignored. All-targets Clippy with diagnostics passed. The test checks host heap replacement during recording. It does not force guest allocator address reuse or submit GPU work. AI-assisted. No game files used.
acetonahard-code commented 2026-11-24 20:03:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T19:21:21Z.


Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current main (ffe310e).

cargo test -p victory-gpu passed failed ignored
main 50 0 1
main + this PR 51 0 1
main, --all-features 53 0 1
main + this PR, --all-features 54 0 1
  • The new test passes.
  • Run with --nocapture, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device.
  • cargo clippy --all-targets -- -D warnings, with and without --all-features: clean.
  • Minor: cargo fmt --check would rewrap one block this PR adds (draw.rs). main isn't rustfmt-clean either, so take it or leave it.
  • frame::tests::waits_end_on_ticks_and_count_frames failed once and passed on a rerun. It's timing-flaky on main too (2 of 10 full-suite runs here), and unrelated to this PR.

I didn't test with game data.


Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141975873 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1331#issuecomment-7141975873). Originally posted by [acetonahard-code](https://github.com/acetonahard-code) on 2026-11-24T19:21:21Z. --- Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current `main` (ffe310e). | `cargo test -p victory-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 50 | 0 | 1 | | `main` + this PR | 51 | 0 | 1 | | `main`, `--all-features` | 53 | 0 | 1 | | `main` + this PR, `--all-features` | 54 | 0 | 1 | - The new test passes. - Run with `--nocapture`, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device. - `cargo clippy --all-targets -- -D warnings`, with and without `--all-features`: clean. - Minor: `cargo fmt --check` would rewrap one block this PR adds (`draw.rs`). `main` isn't rustfmt-clean either, so take it or leave it. - `frame::tests::waits_end_on_ticks_and_count_frames` failed once and passed on a rerun. It's timing-flaky on `main` too (2 of 10 full-suite runs here), and unrelated to this PR. I didn't test with game data. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
catminou4 commented 2026-11-24 21:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:07:44Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS, so this is source review plus the PR's own Windows tests.

Heap rebinding is now keyed on the host heap's COM identity (heap.as_raw()) instead of the title's descriptor-heap address: a title that destroys and recreates a heap at the same guest address now gets SetDescriptorHeaps called again, and host_roots is reset so root bindings are re-made. The old host heap is kept alive by the recording (list.keep), so dropping the title's reference cannot free it mid-list. The test drops the original heap before binding the replacement — exactly the lifetime hazard. Sound.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046527258 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1331#pullrequestreview-6046527258). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:07:44Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS, so this is source review plus the PR's own Windows tests. Heap rebinding is now keyed on the host heap's COM identity (`heap.as_raw()`) instead of the title's descriptor-heap address: a title that destroys and recreates a heap at the same guest address now gets `SetDescriptorHeaps` called again, and `host_roots` is reset so root bindings are re-made. The old host heap is kept alive by the recording (`list.keep`), so dropping the title's reference cannot free it mid-list. The test drops the original heap before binding the replacement — exactly the lifetime hazard. Sound.
wbkepler commented 2026-11-24 21:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T20:56:25Z.


On whether the new key can itself hit ABA: I don't think it can. Every host heap whose as_raw() ends up in host_heaps has just been passed to list.keep, which holds it until HostList::reset. On upstream the only call to that for title lists is list.rs reset, and it is immediately followed by state.reset(pipeline), which zeroes host_heaps. So a cached identity can't be freed and reused while it is still cached. (The p.copy.reset() in host.rs is a prelude copy list with no State.)

Merge-order note: #1382 rewrites the same SetDescriptorHeaps block in State::prepare (a stack array instead of the Vec). The two conflict textually but don't clash in intent, so whichever lands second just needs a rebase. The host-identity comparison here should be kept.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144259802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1331#issuecomment-7144259802). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T20:56:25Z. --- On whether the new key can itself hit ABA: I don't think it can. Every host heap whose `as_raw()` ends up in `host_heaps` has just been passed to `list.keep`, which holds it until `HostList::reset`. On upstream the only call to that for title lists is `list.rs` `reset`, and it is immediately followed by `state.reset(pipeline)`, which zeroes `host_heaps`. So a cached identity can't be freed and reused while it is still cached. (The `p.copy.reset()` in `host.rs` is a prelude copy list with no `State`.) Merge-order note: #1382 rewrites the same `SetDescriptorHeaps` block in `State::prepare` (a stack array instead of the `Vec`). The two conflict textually but don't clash in intent, so whichever lands second just needs a rebase. The host-identity comparison here should be kept. _AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090._
Marvisak commented 2026-11-25 02:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:22:39Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/draw.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149482688 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1331#issuecomment-7149482688). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:22:39Z. --- <!-- victory-triage v1 head=84845210cc9e32b9e976ff1d69d5e8b93340c7f8 verdict=needs-rebase at=2026-11-25T01:22:37Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/draw.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1331:upstream-pr/1331'
git switch 'upstream-pr/1331'

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