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

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

@⁠reeledMarek on GitHub · 2026-11-25 15:33 UTC · original
reeledMarek:fix/gpu-view-addresses-lifetime-and-size → main · +36 −7 · 2 files · 1 commits · open

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.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2543) `reeledMarek:fix/gpu-view-addresses-lifetime-and-size` → `main` · +36 −7 · 2 files · 1 commits · open ## 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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:45 +00:00
github-bot changed title from GPU: keep view_addresses upload buffer alive on command lists and size it to HEAP_VIEWS to GPU: keep view_addresses upload buffer alive on command lists 2026-11-26 06:31:13 +00:00
github-bot force-pushed github-bot/gh-2543 from b451ae7e6d to 5e5dcbc13a 2026-11-26 06:31:14 +00:00 Compare
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:34 UTC · original · edited 2026-11-26 07:22 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 18:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2543#issuecomment-7171104727) · edited 2026-11-26 07:22 UTC <!-- 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)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-26 05:56 UTC · original

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.

**@⁠reeledMarek** on GitHub · 2026-11-26 05:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2543#issuecomment-7183936975) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:21 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2543#pullrequestreview-6074035488) · **approved these changes** 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.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:49 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2543#pullrequestreview-6079165278) · **approved these changes** 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 can be merged automatically.
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/2543/head:github-bot/gh-2543'
git switch 'github-bot/gh-2543'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2543'
git switch 'github-bot/gh-2543'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2543'
git switch 'github-bot/gh-2543'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2543'
git switch 'main'
git merge --squash 'github-bot/gh-2543'
git switch 'main'
git merge --ff-only 'github-bot/gh-2543'
git switch 'main'
git merge 'github-bot/gh-2543'
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!2543
No description provided.