GPU: release unused depth-twin scratch buffers via Weak cache and keep 1 spare placement heap #3454

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

@⁠Luislariosss on GitHub · 2026-11-27 03:09 UTC · original
Luislariosss:feat/twin-scratch-reclaim → main · +59 −17 · 2 files · 1 commits · open

Summary

Reclaims idle D3D12 DEFAULT-heap memory from depth-twin scratch buffers and spare texture-placement heaps:

  1. Weak-referenced depth-twin scratch cache (twin.rs): SCRATCH previously held strong ID3D12Resource references for every power-of-two size class ever created, keeping all scratch buffers alive for the lifetime of the process even after the twins using them were destroyed. Storing Weak<SharedScratch> in SCRATCH and Arc<SharedScratch> on Twin preserves full sharing among live twins of the same size class while automatically releasing the ID3D12Resource once the last Twin referencing it drops. Buffer creation and any duplicate drop also run outside SCRATCH.lock().
  2. Texture placement spare heap (placement.rs): lower SPARE from 2 (128 MiB of idle 64 MiB DEFAULT heaps) to 1 (64 MiB), returning an extra 64 MiB once textures are evicted while keeping one warm heap to avoid churn at a heap boundary.

Validation

  • cargo test -p victory-gpu --lib -- twin:: placement::: 5/5 passed (including new shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean.
  • cargo xtask policy: 191 files ok.
**@⁠Luislariosss** on GitHub · 2026-11-27 03:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3454) `Luislariosss:feat/twin-scratch-reclaim` → `main` · +59 −17 · 2 files · 1 commits · open ### Summary Reclaims idle D3D12 `DEFAULT`-heap memory from depth-twin scratch buffers and spare texture-placement heaps: 1. **Weak-referenced depth-twin scratch cache (`twin.rs`)**: `SCRATCH` previously held strong `ID3D12Resource` references for every power-of-two size class ever created, keeping all scratch buffers alive for the lifetime of the process even after the twins using them were destroyed. Storing `Weak<SharedScratch>` in `SCRATCH` and `Arc<SharedScratch>` on `Twin` preserves full sharing among live twins of the same size class while automatically releasing the `ID3D12Resource` once the last `Twin` referencing it drops. Buffer creation and any duplicate drop also run outside `SCRATCH.lock()`. 2. **Texture placement spare heap (`placement.rs`)**: lower `SPARE` from `2` (128 MiB of idle 64 MiB `DEFAULT` heaps) to `1` (64 MiB), returning an extra 64 MiB once textures are evicted while keeping one warm heap to avoid churn at a heap boundary. ### Validation - `cargo test -p victory-gpu --lib -- twin:: placement::`: 5/5 passed (including new `shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean. - `cargo xtask policy`: 191 files ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:13:22 +00:00
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-27 03:16 UTC · original

Note: the only CI failure on run \45932472460\ (231/232 passed) is the unrelated timing-sensitive test \ ictory-gpu::frame::tests::waits_end_on_ticks_and_count_frames\ (this PR only touches \placement.rs\ and \ win.rs). Could a maintainer re-run the failed job?

**@⁠Luislariosss** on GitHub · 2026-11-27 03:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/3454#issuecomment-7208857845) Note: the only CI failure on run \45932472460\ (231/232 passed) is the unrelated timing-sensitive test \ ictory-gpu::frame::tests::waits_end_on_ticks_and_count_frames\ (this PR only touches \placement.rs\ and \ win.rs\). Could a maintainer re-run the failed job?
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 03:27 UTC · original

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

  • Head: e746a9e1986f82e907c5d9a6388affa4e1c0ea7a, 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: 247 passed, 0 failed, 1 ignored (base: 246/0/1; +1 is twin::tests::shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops, which passes with a WARP device)
  • No new failures vs base. waits_end_on_ticks_and_count_frames passed on base and on this head here, so it looks like the timing flake mentioned in the CI note (not caused by this change). I did not re-run clippy.

Review: no failure found, one point to check. Before, the shared scratch buffer lived for the whole process, so no submission could lose it. Now the ID3D12Resource is released as soon as the last Twin drops. If a recorded or running list still copies through it, that is a use-after-release unless the owning Resource is already dropped only after the GPU is done; host::retire exists for this. I did not verify the drop timing of Resource::twin, so please confirm or retire the buffer. The test returns early when there is no host device; it did run here.

**@⁠oni-swr** on GitHub · 2026-11-27 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3454#issuecomment-7209002402) **WARP test report** (AI-assisted with Claude; synthetic tests only, no game files) - Head: `e746a9e1986f82e907c5d9a6388affa4e1c0ea7a`, 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`: **247 passed, 0 failed, 1 ignored** (base: 246/0/1; +1 is `twin::tests::shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops`, which passes with a WARP device) - No new failures vs base. `waits_end_on_ticks_and_count_frames` passed on base and on this head here, so it looks like the timing flake mentioned in the CI note (not caused by this change). I did not re-run clippy. **Review:** no failure found, one point to check. Before, the shared scratch buffer lived for the whole process, so no submission could lose it. Now the `ID3D12Resource` is released as soon as the last `Twin` drops. If a recorded or running list still copies through it, that is a use-after-release unless the owning `Resource` is already dropped only after the GPU is done; `host::retire` exists for this. I did not verify the drop timing of `Resource::twin`, so please confirm or retire the buffer. The test returns early when there is no host device; it did run here.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-27 08:47 UTC · original

NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head e746a9e (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: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops.
  • --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.
**@⁠futurepro62** on GitHub · 2026-11-27 08:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3454#issuecomment-7213930850) NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head `e746a9e` (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`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `shared_scratch_reuses_live_buffer_and_releases_when_last_owner_drops`. - `--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.
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/3454/head:github-bot/gh-3454'
git switch 'github-bot/gh-3454'

Merge

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