Skip to content

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

Open
reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-view-addresses-lifetime-and-size
Open

reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-view-addresses-lifetime-and-size

Conversation

@reeledMarek

@reeledMarek reeledMarek commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 GPU: view addresses for tables made afresh (dynamic slots) #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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@reeledMarek
reeledMarek force-pushed the fix/gpu-view-addresses-lifetime-and-size branch from b451ae7 to 5e5dcbc Compare November 26, 2026 05:55
@reeledMarek reeledMarek changed the title GPU: keep view_addresses upload buffer alive on command lists and size it to HEAP_VIEWS GPU: keep view_addresses upload buffer alive on command lists Nov 26, 2026
@reeledMarek

Copy link
Copy Markdown
Contributor Author

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 fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants