GPU: RwLock SHADER_HEAPS, shard HostHeap::kept, and batch dynamic slot release #3832

Open
CaullenOmdahl wants to merge 1 commit from upstream-pr/3832 into main
CaullenOmdahl commented 2026-11-29 12:16:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CaullenOmdahl on 2026-11-29T12:16:32Z.


Problem

  1. SHADER_HEAPS uses a global Mutex, serializing concurrent mirror, sync_heaps, make_read, read_textures, evict, release_dynamic, and with_host calls across title and recording threads even though the list only mutates on heap creation and drop.
  2. HostHeap::kept protects all 1,000,000+ title and dynamic slots with a single heap-wide Mutex<Vec<Kept>>, and HostHeap::keep unconditionally calls crate::host::retire while holding that mutex—even when a rewritten slot still references the exact same host ID3D12Resource.
  3. draw::State::drop releases dynamic descriptor slot runs one entry at a time, re-locking SHADER_HEAPS and HostHeap::next on every run.

Changes

  • RwLock SHADER_HEAPS: Take shared read locks for lookup/mirror/sync paths and exclusive write locks only in create_heap and Heap::drop. Concurrent HostHeap::mirror calls across threads remain synchronized per heap by HostHeap::made and the existing unaligned record recheck after prepare(&view).
  • Sharded HostHeap::kept (1024 slots/shard) & outside-lock retirement: Split HostHeap::kept into KEPT_PIECE shards, drop the shard lock before calling crate::host::retire (removing kept -> RETIRED lock nesting), and skip queuing a retire when the new view keeps the identical raw ID3D12Resource pointer.
  • Batched dynamic slot release: Add HostHeap::release_batch and descriptor::release_dynamic_batch, updating draw::State::drop to release MEMORY_HEAP and title-heap runs under at most one lock acquisition per heap.

Note: Composes cleanly without conflicts alongside the descriptor ViewRegistry / ShapeArena PR.

Ported from CaullenOmdahl/Boxon.

Validation

  • cargo xtask policy
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings
  • Unit tests in crates/victory-gpu/src/descriptor/host.rs covering cross-shard KEPT_PIECE boundaries, unchanged-resource reference counts on slot rewrites, and batched dynamic slot release.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5550614350 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3832). Originally posted by [CaullenOmdahl](https://github.com/CaullenOmdahl) on 2026-11-29T12:16:32Z. --- ## Problem 1. `SHADER_HEAPS` uses a global `Mutex`, serializing concurrent `mirror`, `sync_heaps`, `make_read`, `read_textures`, `evict`, `release_dynamic`, and `with_host` calls across title and recording threads even though the list only mutates on heap creation and drop. 2. `HostHeap::kept` protects all `1,000,000+` title and dynamic slots with a single heap-wide `Mutex<Vec<Kept>>`, and `HostHeap::keep` unconditionally calls `crate::host::retire` while holding that mutex—even when a rewritten slot still references the exact same host `ID3D12Resource`. 3. `draw::State::drop` releases dynamic descriptor slot runs one entry at a time, re-locking `SHADER_HEAPS` and `HostHeap::next` on every run. ## Changes - **`RwLock` `SHADER_HEAPS`:** Take shared read locks for lookup/mirror/sync paths and exclusive write locks only in `create_heap` and `Heap::drop`. Concurrent `HostHeap::mirror` calls across threads remain synchronized per heap by `HostHeap::made` and the existing unaligned record recheck after `prepare(&view)`. - **Sharded `HostHeap::kept` (`1024` slots/shard) & outside-lock retirement:** Split `HostHeap::kept` into `KEPT_PIECE` shards, drop the shard lock before calling `crate::host::retire` (removing `kept -> RETIRED` lock nesting), and skip queuing a retire when the new view keeps the identical raw `ID3D12Resource` pointer. - **Batched dynamic slot release:** Add `HostHeap::release_batch` and `descriptor::release_dynamic_batch`, updating `draw::State::drop` to release `MEMORY_HEAP` and title-heap runs under at most one lock acquisition per heap. Note: Composes cleanly without conflicts alongside the descriptor `ViewRegistry` / `ShapeArena` PR. Ported from [`CaullenOmdahl/Boxon`](https://github.com/CaullenOmdahl/Boxon). ## Validation - `cargo xtask policy` - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings` - Unit tests in `crates/victory-gpu/src/descriptor/host.rs` covering cross-shard `KEPT_PIECE` boundaries, unchanged-resource reference counts on slot rewrites, and batched dynamic slot release.
cloph-dsp commented 2026-11-29 12:38:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-29T12:38:56Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3832 at head b69a82faad8ec70719ee188447f9b525668ee617, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::release_batch_and_sharded_kept_handle_boundaries_and_same_resource_rewrites --exact --test-threads=1 --quiet → 1 passed, 0 failed, 232 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (3 files, +242/-83).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (2 pre-existing victory-gpu lib warnings).
  • GPU/driver: N/A (CPU-only descriptor/host test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7255963904 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3832#issuecomment-7255963904). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-29T12:38:56Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3832 at head `b69a82faad8ec70719ee188447f9b525668ee617`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::release_batch_and_sharded_kept_handle_boundaries_and_same_resource_rewrites --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 232 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check 63bcca4 HEAD` clean (3 files, +242/-83). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (2 pre-existing `victory-gpu` lib warnings). - GPU/driver: N/A (CPU-only descriptor/host test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
kilolimaVI commented 2026-11-29 16:41:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-29T16:41:02Z.


Hardware check on a Radeon 780M (RDNA3, Ryzen 7 8845HS), merged onto main 63bcca4: cargo test --profile diag -p victory-gpu --features diagnostics --lib passes 247/247 twice, and 251/251 twice together with #3831 (they merge clean). Note it conflicts with #3848. No frame-time claim from me: the synthetic world_frame_preparing bench (#2134) doesn't exercise the descriptor paths this changes.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7259095988 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3832#issuecomment-7259095988). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-29T16:41:02Z. --- Hardware check on a Radeon 780M (RDNA3, Ryzen 7 8845HS), merged onto main 63bcca4: `cargo test --profile diag -p victory-gpu --features diagnostics --lib` passes 247/247 twice, and 251/251 twice together with #3831 (they merge clean). Note it conflicts with #3848. No frame-time claim from me: the synthetic `world_frame_preparing` bench (#2134) doesn't exercise the descriptor paths this changes. AI-assisted (Claude).
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/3832:upstream-pr/3832'
git switch 'upstream-pr/3832'

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