GPU: a released view heap takes its title memory page table with it #2232

Merged
denkencar-sketch merged 1 commit from upstream-pr/2234 into main 2026-11-25 21:55:52 +00:00
denkencar-sketch commented 2026-11-25 08:31:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T08:31:23Z.


Summary

A view heap that is released keeps its title memory page table. Heap::drop removes the heap from SHADER_HEAPS but never from memory::SHARED, so:

  • the table (a 16.8 MiB mapping) and the Arc<Shadow> copies it names live on for the rest of the process, and
  • a heap allocated later at the same address finds the stale table. Shared::host is meant to tell the two heaps apart ("a heap made later at a released one's address is another"), but it is the address of the HostHeap, which sits inline in Heap::host (OnceLock<Option<HostHeap>>), so it is the heap's address plus a constant and always equal. The old view pairs, null slot and generation are then reused on the new host heap.

Change

memory::release(key) drops the heap's SHARED entry; Heap::drop calls it after letting go of the SHADER_HEAPS lock (bind and prepare take the table's lock inside the heaps' lock, so it is not taken the other way round). Lists that named the table hold their own clone of it, as the existing comment in bind says.

Testing

descriptor::tests::a_released_view_heap_drops_its_page_table creates a shader-visible view heap, binds a list (making its table), releases the heap and checks the table is gone. It fails on main ("released with its heap") and passes with this change. cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean.

Not tried: a run in the game, and the address-reuse case itself (the test shows the table outliving its heap, which is what makes the reuse possible). modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too (5 of 20 runs of cargo test -p victory-hle --lib); it is unrelated.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600405023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2234). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T08:31:23Z. --- ## Summary A view heap that is released keeps its title memory page table. `Heap::drop` removes the heap from `SHADER_HEAPS` but never from `memory::SHARED`, so: - the table (a 16.8 MiB mapping) and the `Arc<Shadow>` copies it names live on for the rest of the process, and - a heap allocated later at the same address finds the stale table. `Shared::host` is meant to tell the two heaps apart ("a heap made later at a released one's address is another"), but it is the address of the `HostHeap`, which sits inline in `Heap::host` (`OnceLock<Option<HostHeap>>`), so it is the heap's address plus a constant and always equal. The old view pairs, `null` slot and `generation` are then reused on the new host heap. ## Change `memory::release(key)` drops the heap's `SHARED` entry; `Heap::drop` calls it after letting go of the `SHADER_HEAPS` lock (`bind` and `prepare` take the table's lock inside the heaps' lock, so it is not taken the other way round). Lists that named the table hold their own clone of it, as the existing comment in `bind` says. ## Testing `descriptor::tests::a_released_view_heap_drops_its_page_table` creates a shader-visible view heap, binds a list (making its table), releases the heap and checks the table is gone. It fails on `main` ("released with its heap") and passes with this change. `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` is clean. Not tried: a run in the game, and the address-reuse case itself (the test shows the table outliving its heap, which is what makes the reuse possible). `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too (5 of 20 runs of `cargo test -p victory-hle --lib`); it is unrelated. AI-assisted.
catminou4 commented 2026-11-25 09:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:31Z.

Review: COMMENTED


A released view heap takes its title memory page table with it; lock-order comment (heaps lock → table lock) documented. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Includes a host-GPU test (no-ops without one).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054380614 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2234#pullrequestreview-6054380614). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:31Z. **Review:** COMMENTED --- A released view heap takes its title memory page table with it; lock-order comment (heaps lock → table lock) documented. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Includes a host-GPU test (no-ops without one).
DenRakEiw commented 2026-11-25 09:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T09:02:30Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib a_released_view_heap_drops_its_page_table — passed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean cleanup dropping a view heap's title-memory page table when the heap is released. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054567154 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2234#pullrequestreview-6054567154). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T09:02:30Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib a_released_view_heap_drops_its_page_table` — passed on RTX 5090 - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean cleanup dropping a view heap's title-memory page table when the heap is released. Looks good. AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-25 14:07:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:30:21Z.


Automated triage for the maintainers.

Merge candidate (worth a look). Heap::drop in descriptor.rs now calls a new memory::release(key) that drops the heap's SHARED page-table entry, after letting go of the SHADER_HEAPS lock (matching the heaps-then-table order memory::bind uses). On main the entry outlives its heap, and the s.host check in bind cannot tell a later heap at the same address apart, since the HostHeap sits inline in Heap, so its address is the key plus a constant; lists keep their own clone of the table, so dropping the entry is safe. A test covers the release, and CI check passes on this head.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163873462 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2234#issuecomment-7163873462). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:21Z. --- <!-- victory-triage v1 head=b4640273e9b2f6761a6ad13439dbee67ecbfcf6e verdict=merge-candidate at=2026-11-25T13:41:00Z --> Automated triage for the maintainers. **Merge candidate (worth a look).** `Heap::drop` in `descriptor.rs` now calls a new `memory::release(key)` that drops the heap's `SHARED` page-table entry, after letting go of the `SHADER_HEAPS` lock (matching the heaps-then-table order `memory::bind` uses). On `main` the entry outlives its heap, and the `s.host` check in `bind` cannot tell a later heap at the same address apart, since the `HostHeap` sits inline in `Heap`, so its address is the key plus a constant; lists keep their own clone of the table, so dropping the entry is safe. A test covers the release, and CI `check` passes on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:03:35 +00:00
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!2232
No description provided.