GPU: keep view_addresses upload buffer alive on command lists #2541

Open
reeledMarek wants to merge 1 commit from upstream-pr/2543 into main
reeledMarek commented 2026-11-25 15:33:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:33:46Z.


Summary

  • HostHeap::view_addresses previously returned only the raw GPU virtual address u64, so command lists binding stage.view_addresses never called list.keep(...) on the underlying ID3D12Resource. If the HostHeap is dropped while a command list using view_addresses is still recording or executing, the GPU reads freed memory.
  • Return Option<(&ID3D12Resource, u64)> from HostHeap::view_addresses() and call list.keep(table) in crates/victory-gpu/src/draw.rs before setting the root SRV.
  • Rebased onto current main (63bcca4, preserving #1906's address_slots() sizing and view_addresses_cover_tables_made_afresh invariants) and added a COM refcount regression test view_addresses_buffer_stays_alive_on_list.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5494378393 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2543). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:33:46Z. --- ## Summary - `HostHeap::view_addresses` previously returned only the raw GPU virtual address `u64`, so command lists binding `stage.view_addresses` never called `list.keep(...)` on the underlying `ID3D12Resource`. If the `HostHeap` is dropped while a command list using `view_addresses` is still recording or executing, the GPU reads freed memory. - Return `Option<(&ID3D12Resource, u64)>` from `HostHeap::view_addresses()` and call `list.keep(table)` in `crates/victory-gpu/src/draw.rs` before setting the root SRV. - Rebased onto current `main` (`63bcca4`, preserving #1906's `address_slots()` sizing and `view_addresses_cover_tables_made_afresh` invariants) and added a COM refcount regression test `view_addresses_buffer_stays_alive_on_list`.
Marvisak commented 2026-11-25 19:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:34:52Z.


Automated triage for the maintainers.

Merge candidate. Narrowed after the rebase, now that #1906 handles address_slots() sizing in main. HostHeap::view_addresses (descriptor/host.rs) now returns the table buffer along with its GPU address. In State (draw.rs), the binding of stage.view_addresses calls list.keep(table) before Set*RootShaderResourceView. That matches how the descriptor heaps themselves are kept on the list. The other callers (the warm-up call in draw.rs and a test's .is_some()) still compile unchanged. The refcount test is unusual but test-only.

CI: check passing; merges cleanly.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171104727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2543#issuecomment-7171104727). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:34:52Z. --- <!-- victory-triage v1 head=5e5dcbc13a5baf13fa66878d23ff60c157541580 verdict=merge-candidate at=2026-11-26T07:22:41Z --> Automated triage for the maintainers. **Merge candidate.** Narrowed after the rebase, now that #1906 handles `address_slots()` sizing in `main`. `HostHeap::view_addresses` (`descriptor/host.rs`) now returns the table buffer along with its GPU address. In `State` (`draw.rs`), the binding of `stage.view_addresses` calls `list.keep(table)` before `Set*RootShaderResourceView`. That matches how the descriptor heaps themselves are kept on the list. The other callers (the warm-up call in `draw.rs` and a test's `.is_some()`) still compile unchanged. The refcount test is unusual but test-only. CI: `check` passing; merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #2543] GPU: keep view_addresses upload buffer alive on command lists and size it to HEAP_VIEWS to [PR #2543] GPU: keep view_addresses upload buffer alive on command lists 2026-11-26 06:02:29 +00:00
reeledMarek commented 2026-11-26 06:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:56:03Z.


Rebased cleanly onto current main (63bcca4). Since #1906 (2bba792) now handles address_slots() sizing for dynamic tables (and tests desc.Width == 16 * end), this PR now focuses solely on keeping the view_addresses upload buffer alive on command lists via list.keep(table). Updated the PR title/description and test accordingly.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183936975 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2543#issuecomment-7183936975). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:56:03Z. --- Rebased cleanly onto current `main` (`63bcca4`). Since #1906 (`2bba792`) now handles `address_slots()` sizing for dynamic tables (and tests `desc.Width == 16 * end`), this PR now focuses solely on keeping the `view_addresses` upload buffer alive on command lists via `list.keep(table)`. Updated the PR title/description and test accordingly.
fuzeofficlal commented 2026-11-26 12:21:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T12:21:22Z.

Review: APPROVED


Reviewed and verified at head 5e5dcbc1 against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1):

  • Design & correctness:
    • Returning Option<(&ID3D12Resource, u64)> from HostHeap::view_addresses (crates/victory-gpu/src/descriptor/host.rs:567-590) and calling list.keep(table) in crates/victory-gpu/src/draw.rs:852-864 before SetComputeRootShaderResourceView / SetGraphicsRootShaderResourceView closes the lifetime gap if a HostHeap is dropped while a command list referencing its view-address table is still recording or executing.
    • Checked every view_addresses call site across the workspace (draw.rs:711-714, draw.rs:852-864, descriptor/host.rs:2151): draw.rs:862 is the sole GPU binding site and matches the existing list.keep(table) pattern used at draw.rs:676, 818. HostList::reset() drops self.deferred().kept cleanly with no leaks, verified by view_addresses_buffer_stays_alive_on_list (descriptor/host.rs:2467-2493).
    • Note for maintainers: #2543 and #2542 have no production-code overlap (only a trivial test-append conflict at the bottom of crates/victory-gpu/src/descriptor/host.rs).
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (191 files ok); cargo clippy -p victory-gpu --all-targets -- -D warnings clean with default features and --all-features.
    • RTX 5090 (default): view_addresses_buffer_stays_alive_on_list 1/1 passed.
    • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): descriptor::host::tests + draw::tests 35/35 passed (skipping pre-existing NVIDIA 1M view-heap cap dynamic_slots_are_held_until_released).
    • WARP (VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1: descriptor::host::tests + draw::tests 36/36 passed.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074035488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2543#pullrequestreview-6074035488). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T12:21:22Z. **Review:** APPROVED --- Reviewed and verified at head `5e5dcbc1` against `origin/main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`): - **Design & correctness**: - Returning `Option<(&ID3D12Resource, u64)>` from `HostHeap::view_addresses` (`crates/victory-gpu/src/descriptor/host.rs:567-590`) and calling `list.keep(table)` in `crates/victory-gpu/src/draw.rs:852-864` before `SetComputeRootShaderResourceView` / `SetGraphicsRootShaderResourceView` closes the lifetime gap if a `HostHeap` is dropped while a command list referencing its view-address table is still recording or executing. - Checked every `view_addresses` call site across the workspace (`draw.rs:711-714`, `draw.rs:852-864`, `descriptor/host.rs:2151`): `draw.rs:862` is the sole GPU binding site and matches the existing `list.keep(table)` pattern used at `draw.rs:676, 818`. `HostList::reset()` drops `self.deferred().kept` cleanly with no leaks, verified by `view_addresses_buffer_stays_alive_on_list` (`descriptor/host.rs:2467-2493`). - Note for maintainers: `#2543` and `#2542` have no production-code overlap (only a trivial test-append conflict at the bottom of `crates/victory-gpu/src/descriptor/host.rs`). - **Verification**: - Clean `git merge-tree` against `origin/main` (`63bcca43`); `cargo xtask policy` (`191 files ok`); `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean with default features and `--all-features`. - RTX 5090 (default): `view_addresses_buffer_stays_alive_on_list` **1/1** passed. - RTX 5090 + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`): `descriptor::host::tests` + `draw::tests` **35/35** passed (skipping pre-existing NVIDIA 1M view-heap cap `dynamic_slots_are_held_until_released`). - WARP (`VICTORY_D3D12_WARP=1`) + `VICTORY_D3D12_DEBUG=1`: `descriptor::host::tests` + `draw::tests` **36/36** passed. LGTM.
Dukestar69 commented 2026-11-26 18:49:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T18:49:10Z.

Review: APPROVED


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

  • Returning (&ID3D12Resource, u64) from HostHeap::view_addresses() and calling list.keep(table) prevents use-after-free on the view-address upload buffer if the title releases the descriptor heap before the recorded command list executes.
  • cargo test -p victory-gpu --lib descriptor::host::tests::view_addresses_buffer_stays_alive_on_list -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib descriptor::host::tests::view_addresses_cover_tables_made_afresh -- --test-threads=1: passed.
  • 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:6079165278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2543#pullrequestreview-6079165278). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T18:49:10Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Returning `(&ID3D12Resource, u64)` from `HostHeap::view_addresses()` and calling `list.keep(table)` prevents use-after-free on the view-address upload buffer if the title releases the descriptor heap before the recorded command list executes. - `cargo test -p victory-gpu --lib descriptor::host::tests::view_addresses_buffer_stays_alive_on_list -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib descriptor::host::tests::view_addresses_cover_tables_made_afresh -- --test-threads=1`: passed. - `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/2543:upstream-pr/2543'
git switch 'upstream-pr/2543'

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