perf(gpu): shard HostHeap::mirror across 256 descriptor stripes #16

Closed
Vladimir-Human wants to merge 0 commits from upstream-pr/16 into main
Vladimir-Human commented 2026-11-25 16:32:53 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T16:32:53Z.


Replace HostHeap's single global made: Mutex<Vec<u64>> and kept: Mutex<...> with a lock-free AtomicU64 fast-path + 256 cache-line-aligned descriptor stripes and canonical-order stale != index invalidation (crates/victory-gpu/src/descriptor/host.rs), bringing KLBF Lab up to parity with victory-perf / flamingo on high-draw scenes.

What is in it (crates/victory-gpu/src/descriptor/host.rs)

  • Lock-free fast-path hits (made: Box<[AtomicU64]>): HostHeap::mirror checks tag == VIEW_TAG && key != 0 && self.made[index].load(Ordering::Acquire) == key && let Some(view) = view_at(i, generation), publishing key (Ordering::Release) only after make()/null_for() and replace_kept() complete. texture_views_remade clears made[slot] under its stripe guard while rewriting views so concurrent fast-path readers never observe a half-updated descriptor.
  • 256 striped slot locks & kept + lock-free copied: shards slow-path Create*View (make()) and kept resource slots across 256 cache-line-aligned stripes ((index & 255, index >> 8)), retiring displaced ID3D12Resource handles via crate::host::retire strictly outside kept and slot_locks. copied uses OnceLock<Box<[AtomicU64]>> CAS.
  • Deadlock-free cross-stripe stale != index invalidation: Spans::clashing_slots + HostHeap::note_buffer_checked(..., held_stripes) pre-checks missing stale stripes under placed before mutating state; HostHeap::mirror merges missing stripes into needed_stripes and acquires them strictly in ascending index order (0..255).
  • Tests & benchmarks: adds mirror_release_acquire_later_and_forget_semantics, concurrent_cache_hit_and_distinct_create_view_storm, concurrent_same_slot_and_stale_invalidations_do_not_deadlock, concurrent_stale_invalidation_and_cbv_overwrite_never_clobbers_live_slot, concurrent_texture_views_remade_and_fast_path_stay_consistent, and 8-thread --release benchmarks.

Verification (f5a960c, Windows 11 Build 26300, NVIDIA GeForce RTX 4070 SUPER, Rust 1.98.1)

  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked --lib descriptor::host::tests:: -- --test-threads=1: 24 passed, 0 failed, 2 ignored (#[ignore] benches) (0 D3D12 debug errors/warnings).
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): 0 warnings in crates/victory-gpu/src/descriptor/host.rs (fails only on pre-existing origin/klbf-amd / beta lints in untouched sgd5.rs:557, resource.rs:2667, draw.rs:2441, indirect.rs:1574).
  • cargo test --workspace --locked: 585 passed, 1 pre-existing failed, 14 ignored (sole failure is pre-existing origin/klbf-amd / beta xtask policy::tests::repository_passes_policy on untouched crates/victory-shader/src/emit/lower.rs > 512 KiB and docs/klbf/logo.svg).
  • Independent BEFORE (0ad4037) vs AFTER (f5a960c) 8-thread --release benchmark on RTX 4070 SUPER:
    • bench_mirror_fast_path_8_threads[cbv_inline] (400k hits): median 50.639 -> 0.782 ms (64.8x faster, 7.90 -> 511.51 Mops/s)
    • bench_mirror_fast_path_8_threads[mixed_cbv_srv] (400k hits): median 52.075 -> 13.479 ms (3.86x faster, 7.68 -> 29.68 Mops/s)
    • bench_mirror_slow_path_create_views_8_threads (16,384 slots): median 12.002 -> 6.569 ms (1.83x faster, 1,365 -> 2,494 Kviews/s).

Not tested

  • Retail title E2E runtime run (clean-room development environment without game files).
  • AMD/Intel GPUs and Linux hosts.

AI use

  • AI-assisted implementation, concurrency proof/audit, and benchmarks (gemini-4-hydrogen-xhigh + gemini-4-neon-xhigh).
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5495180935 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/16). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T16:32:53Z. --- Replace `HostHeap`'s single global `made: Mutex<Vec<u64>>` and `kept: Mutex<...>` with a lock-free `AtomicU64` fast-path + 256 cache-line-aligned descriptor stripes and canonical-order `stale != index` invalidation (`crates/victory-gpu/src/descriptor/host.rs`), bringing KLBF Lab up to parity with `victory-perf` / `flamingo` on high-draw scenes. ### What is in it (`crates/victory-gpu/src/descriptor/host.rs`) - **Lock-free fast-path hits (`made: Box<[AtomicU64]>`)**: `HostHeap::mirror` checks `tag == VIEW_TAG && key != 0 && self.made[index].load(Ordering::Acquire) == key && let Some(view) = view_at(i, generation)`, publishing `key` (`Ordering::Release`) only after `make()`/`null_for()` and `replace_kept()` complete. `texture_views_remade` clears `made[slot]` under its stripe guard while rewriting views so concurrent fast-path readers never observe a half-updated descriptor. - **256 striped slot locks & `kept` + lock-free `copied`**: shards slow-path `Create*View` (`make()`) and kept resource slots across 256 cache-line-aligned stripes (`(index & 255, index >> 8)`), retiring displaced `ID3D12Resource` handles via `crate::host::retire` strictly outside `kept` and `slot_locks`. `copied` uses `OnceLock<Box<[AtomicU64]>>` CAS. - **Deadlock-free cross-stripe `stale != index` invalidation**: `Spans::clashing_slots` + `HostHeap::note_buffer_checked(..., held_stripes)` pre-checks missing stale stripes under `placed` **before** mutating state; `HostHeap::mirror` merges missing stripes into `needed_stripes` and acquires them strictly in ascending index order (`0..255`). - **Tests & benchmarks**: adds `mirror_release_acquire_later_and_forget_semantics`, `concurrent_cache_hit_and_distinct_create_view_storm`, `concurrent_same_slot_and_stale_invalidations_do_not_deadlock`, `concurrent_stale_invalidation_and_cbv_overwrite_never_clobbers_live_slot`, `concurrent_texture_views_remade_and_fast_path_stay_consistent`, and 8-thread `--release` benchmarks. ### Verification (`f5a960c`, Windows 11 Build 26300, NVIDIA GeForce RTX 4070 SUPER, Rust 1.98.1) - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked --lib descriptor::host::tests:: -- --test-threads=1`: **24 passed, 0 failed, 2 ignored (`#[ignore]` benches)** (`0` D3D12 debug errors/warnings). - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default & `--all-features`): **0 warnings in `crates/victory-gpu/src/descriptor/host.rs`** (fails only on pre-existing `origin/klbf-amd` / `beta` lints in untouched `sgd5.rs:557`, `resource.rs:2667`, `draw.rs:2441`, `indirect.rs:1574`). - `cargo test --workspace --locked`: **585 passed, 1 pre-existing failed, 14 ignored** (sole failure is pre-existing `origin/klbf-amd` / `beta` `xtask` `policy::tests::repository_passes_policy` on untouched `crates/victory-shader/src/emit/lower.rs` > 512 KiB and `docs/klbf/logo.svg`). - **Independent BEFORE (`0ad4037`) vs AFTER (`f5a960c`) 8-thread `--release` benchmark on RTX 4070 SUPER**: - `bench_mirror_fast_path_8_threads[cbv_inline]` (400k hits): median **`50.639 -> 0.782 ms`** (**64.8x faster**, `7.90 -> 511.51 Mops/s`) - `bench_mirror_fast_path_8_threads[mixed_cbv_srv]` (400k hits): median **`52.075 -> 13.479 ms`** (**3.86x faster**, `7.68 -> 29.68 Mops/s`) - `bench_mirror_slow_path_create_views_8_threads` (16,384 slots): median **`12.002 -> 6.569 ms`** (**1.83x faster**, `1,365 -> 2,494 Kviews/s`). ### Not tested - Retail title E2E runtime run (clean-room development environment without game files). - AMD/Intel GPUs and Linux hosts. ### AI use - AI-assisted implementation, concurrency proof/audit, and benchmarks (`gemini-4-hydrogen-xhigh` + `gemini-4-neon-xhigh`).
HandshakeHackin commented 2026-11-25 16:52:53 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T16:52:53Z.


I ran the four new concurrent descriptor tests on Windows with VICTORY_D3D12_WARP=1 and the diagnostics feature. All four passed. In the verification checkout I made the test setup fail if it could not create the host or descriptor heap, so a missing adapter could not silently skip the assertions. This covers the software backend. I did not measure performance.

Windows WARP test output

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7168672015 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/16#issuecomment-7168672015). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-25T16:52:53Z. --- I ran the four new concurrent descriptor tests on Windows with `VICTORY_D3D12_WARP=1` and the diagnostics feature. All four passed. In the verification checkout I made the test setup fail if it could not create the host or descriptor heap, so a missing adapter could not silently skip the assertions. This covers the software backend. I did not measure performance. [Windows WARP test output](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45657892942/job/139359416688)
PastiiJay commented 2026-11-25 17:02:35 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T17:02:35Z.


Thanks a lot @Vladimir-Human! Noted. I'll test it on the RX 9070 XT in the next test build and report back here.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7168914510 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/16#issuecomment-7168914510). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T17:02:35Z. --- Thanks a lot @Vladimir-Human! Noted. I'll test it on the RX 9070 XT in the next test build and report back here.
akimfomin commented 2026-11-28 01:05:53 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by akimfomin on 2026-11-28T01:05:53Z.


PortBridge surfaced this work while checking Vice-Tay #390. I verified the two PR heads f5a960c and 59563b9 directly. Git found no common ancestor for those refs. The patches touch the same descriptor file and overlap at the queue entry, but certify different steps: mirrored descriptor publication here and queued writes plus final bake in #390.

I also saw your existing KLBF port at 6f98983 and HandshakeHackin’s WARP checks. A complementary test for that port would keep the existing stale-view and CBV-overwrite controls, then take #390’s cross-shard queue case: update a texture after the advisory bake and require that the final bake binds the newer descriptor. It can use generated slots on WARP. If your team or agent wants an independent check on a follow-up, PortBridge #98 takes just its public PR, target SHA and expected behavior.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7231418221 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/16#issuecomment-7231418221). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-28T01:05:53Z. --- PortBridge surfaced this work while checking [Vice-Tay #390](https://github.com/TaynanGT/Vice-Tay/pull/390). I verified the two PR heads `f5a960c` and `59563b9` directly. Git found no common ancestor for those refs. The patches touch the same descriptor file and overlap at the queue entry, but certify different steps: mirrored descriptor publication here and queued writes plus final bake in #390. I also saw your existing KLBF port at `6f98983` and HandshakeHackin’s WARP checks. A complementary test for that port would keep the existing stale-view and CBV-overwrite controls, then take #390’s cross-shard queue case: update a texture after the advisory bake and require that the final bake binds the newer descriptor. It can use generated slots on WARP. If your team or agent wants an independent check on a follow-up, [PortBridge #98](https://github.com/akimfomin/PortBridge/issues/98) takes just its public PR, target SHA and expected behavior.
Vladimir-Human commented 2026-11-28 18:14:00 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:14:00Z.


Re-ported onto stable-amd (v26.11.6) in #182 (https://github.com/PastiiJay/klbf-lab/pull/182).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243633001 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/16#issuecomment-7243633001). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:14:00Z. --- Re-ported onto `stable-amd` (`v26.11.6`) in #182 (https://github.com/PastiiJay/klbf-lab/pull/182).

Pull request closed

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
PastiiJay/klbf-lab!16
No description provided.