GPU: remove dropped host descriptor heaps from GPU_RANGES #3452

Open
alexandruiulian201-bot wants to merge 1 commit from upstream-pr/3452 into main
alexandruiulian201-bot commented 2026-11-27 03:06:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexandruiulian201-bot on 2026-11-27T03:06:41Z.


Problem

HostHeap::new appends the heap's GPU address range to the global GPU_RANGES list used by near_heaps in device-removed diagnostics, but HostHeap never removes its entry when dropped. When descriptor heaps are released and recreated (or across tests), near_heaps continues to report stale/destroyed heap ranges and can collide with newly allocated heaps reusing the same GPU virtual address.

Fix

  • Tag each registered GpuRange with a unique monotonic id (AtomicU64) and store range_id on HostHeap.
  • Implement Drop for HostHeap to remove its range_id from GPU_RANGES.
  • Extract pure register_gpu_range, unregister_gpu_range, and near_heaps_in helpers with unit tests covering range formatting and unregistering only the matching heap even when GPU start addresses match.

Verification

  • cargo test -p victory-gpu --lib --locked gpu_ranges_unregister_removes_only_matching_heap: 1 passed.
  • cargo test -p victory-gpu --lib --locked near_heaps_formats_below_inside_and_past_end: 1 passed.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test -p xtask --bin xtask --locked: 6 passed (repository_passes_policy ok).

AI-assisted. Synthetic unit tests only (no game files used).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5520478722 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3452). Originally posted by [alexandruiulian201-bot](https://github.com/alexandruiulian201-bot) on 2026-11-27T03:06:41Z. --- ### Problem `HostHeap::new` appends the heap's GPU address range to the global `GPU_RANGES` list used by `near_heaps` in device-removed diagnostics, but `HostHeap` never removes its entry when dropped. When descriptor heaps are released and recreated (or across tests), `near_heaps` continues to report stale/destroyed heap ranges and can collide with newly allocated heaps reusing the same GPU virtual address. ### Fix - Tag each registered `GpuRange` with a unique monotonic `id` (`AtomicU64`) and store `range_id` on `HostHeap`. - Implement `Drop` for `HostHeap` to remove its `range_id` from `GPU_RANGES`. - Extract pure `register_gpu_range`, `unregister_gpu_range`, and `near_heaps_in` helpers with unit tests covering range formatting and unregistering only the matching heap even when GPU start addresses match. ### Verification - `cargo test -p victory-gpu --lib --locked gpu_ranges_unregister_removes_only_matching_heap`: 1 passed. - `cargo test -p victory-gpu --lib --locked near_heaps_formats_below_inside_and_past_end`: 1 passed. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean. - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test -p xtask --bin xtask --locked`: 6 passed (`repository_passes_policy` ok). AI-assisted. Synthetic unit tests only (no game files used).
oni-swr commented 2026-11-27 03:27:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T03:27:20Z.


WARP test report (AI-assisted with Claude; synthetic tests only, no game files)

  • Head: 5d0e2240c9e393a4faf22f2c9f7bbff681928b22, base: origin/main @ 63bcca4 (this PR's merge base)
  • Windows 11 Pro, build 10.0.26200; D3D12 on WARP only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1, adapter vendor 0x1414 / software flag), DXIL validator dxil.dll from the Windows SDK 10.0.26100
  • Note: VICTORY_D3D12_WARP is only honored with --features diagnostics (host.rs create()); without it cargo test -p victory-gpu --lib picks the hardware GPU. I ran with --features diagnostics.
  • cargo test -p victory-gpu --lib --locked --features diagnostics: 248 passed, 0 failed, 1 ignored (base: 246 passed, 0 failed, 1 ignored; the +2 are this PR's gpu_ranges_unregister_removes_only_matching_heap and near_heaps_formats_below_inside_and_past_end, both pass)
  • cargo test -p xtask --bin xtask --locked: 6 passed
  • No new failures vs base. frame::tests::waits_end_on_ticks_and_count_frames passed on base and head here. I did not re-run clippy.

Review: no correctness issue found. Ids are unique and monotonic, nothing can return between registration and the HostHeap construction (no leaked range), and Drop tolerates a poisoned lock. Nit: the tests cover the pure helpers only, not that dropping a real HostHeap unregisters its range.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7209001510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3452#issuecomment-7209001510). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T03:27:20Z. --- **WARP test report** (AI-assisted with Claude; synthetic tests only, no game files) - Head: `5d0e2240c9e393a4faf22f2c9f7bbff681928b22`, base: `origin/main` @ `63bcca4` (this PR's merge base) - Windows 11 Pro, build 10.0.26200; D3D12 on WARP only (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, adapter vendor 0x1414 / software flag), DXIL validator `dxil.dll` from the Windows SDK 10.0.26100 - Note: `VICTORY_D3D12_WARP` is only honored with `--features diagnostics` (`host.rs` `create()`); without it `cargo test -p victory-gpu --lib` picks the hardware GPU. I ran with `--features diagnostics`. - `cargo test -p victory-gpu --lib --locked --features diagnostics`: **248 passed, 0 failed, 1 ignored** (base: 246 passed, 0 failed, 1 ignored; the +2 are this PR's `gpu_ranges_unregister_removes_only_matching_heap` and `near_heaps_formats_below_inside_and_past_end`, both pass) - `cargo test -p xtask --bin xtask --locked`: 6 passed - No new failures vs base. `frame::tests::waits_end_on_ticks_and_count_frames` passed on base and head here. I did not re-run clippy. **Review:** no correctness issue found. Ids are unique and monotonic, nothing can return between registration and the `HostHeap` construction (no leaked range), and `Drop` tolerates a poisoned lock. Nit: the tests cover the pure helpers only, not that dropping a real `HostHeap` unregisters its range.
cloph-dsp commented 2026-11-27 06:42:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T06:42:50Z.


Independent CPU-only verification of PR #3452 (GPU_RANGES unregister).

  • Windows, rustc/cargo 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR (D:\Victory-Contrib\target-3452-watch), CARGO_BUILD_JOBS=2.
  • Head 5d0e2240c9e393a4faf22f2c9f7bbff681928b22, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Commands (each --exact --test-threads=1 --quiet):
    • cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::gpu_ranges_unregister_removes_only_matching_heap -> 1 passed; 0 failed; 233 filtered.
    • cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::near_heaps_formats_below_inside_and_past_end -> 1 passed; 0 failed; 233 filtered.
  • Negative controls: both new test names absent on base 63bcca4 via git grep -F.
  • git diff --check 63bcca4 HEAD exit 0 (clean).
  • Only the named synthetic tests were replayed; the full crate suite and real D3D12 GPU-range bookkeeping were not exercised.
  • AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only descriptor accounting). No game data, assets, shaders, DRM or decrypt used.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7211777784 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3452#issuecomment-7211777784). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T06:42:50Z. --- Independent CPU-only verification of PR #3452 (`GPU_RANGES unregister`). - Windows, rustc/cargo 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR` (`D:\Victory-Contrib\target-3452-watch`), `CARGO_BUILD_JOBS=2`. - Head `5d0e2240c9e393a4faf22f2c9f7bbff681928b22`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Commands (each `--exact --test-threads=1 --quiet`): - `cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::gpu_ranges_unregister_removes_only_matching_heap` -> `1 passed; 0 failed; 233 filtered`. - `cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::near_heaps_formats_below_inside_and_past_end` -> `1 passed; 0 failed; 233 filtered`. - Negative controls: both new test names absent on base `63bcca4` via `git grep -F`. - `git diff --check 63bcca4 HEAD` exit 0 (clean). - Only the named synthetic tests were replayed; the full crate suite and real D3D12 GPU-range bookkeeping were not exercised. - AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only descriptor accounting). No game data, assets, shaders, DRM or decrypt used.
futurepro62 commented 2026-11-27 08:28:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T08:28:03Z.


NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head 5d0e224 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: gpu_ranges_unregister_removes_only_matching_heap, near_heaps_formats_below_inside_and_past_end.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7213568211 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3452#issuecomment-7213568211). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T08:28:03Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head `5d0e224` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `gpu_ranges_unregister_removes_only_matching_heap`, `near_heaps_formats_below_inside_and_past_end`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
AurumCarlos commented 2026-11-27 09:11:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-27T09:11:07Z.

Review: COMMENTED


The Drop removes the range when the HostHeap goes, but the host heap itself can outlive it. Lists keep the ID3D12DescriptorHeap they bind (draw.rs:1027, list.keep(h)), so a title heap released before its submitted lists finish leaves a live GPU heap that is no longer in GPU_RANGES. A device-removed fault in one of those lists, reading through that heap, then gets no near_heaps entry for it, and that's the case the report is most useful for.

The address-reuse case in the description can't happen while a list holds the heap, since its GPU range stays allocated. Keeping the entry and marking it released at drop (; view heap 0x…+0x… (released): inside, slot N) would keep both cases readable without losing the in-flight one.

<!-- greyfinch-sync:Marvisak/VIctory:review:6085847960 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3452#pullrequestreview-6085847960). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-27T09:11:07Z. **Review:** COMMENTED --- The `Drop` removes the range when the `HostHeap` goes, but the host heap itself can outlive it. Lists keep the `ID3D12DescriptorHeap` they bind (`draw.rs:1027`, `list.keep(h)`), so a title heap released before its submitted lists finish leaves a live GPU heap that is no longer in `GPU_RANGES`. A device-removed fault in one of those lists, reading through that heap, then gets no `near_heaps` entry for it, and that's the case the report is most useful for. The address-reuse case in the description can't happen while a list holds the heap, since its GPU range stays allocated. Keeping the entry and marking it released at drop (`; view heap 0x…+0x… (released): inside, slot N`) would keep both cases readable without losing the in-flight one.
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/3452:upstream-pr/3452'
git switch 'upstream-pr/3452'

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