GPU: batch and parallelize descriptor heap syncs #3053

Open
MeMako wants to merge 4 commits from upstream-pr/3055 into main
MeMako commented 2026-11-26 05:40:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T05:40:25Z.


Draft — Part 3 of the triage-requested 3-part split.

  • Part 1 (ready for review): #3139 (pr/sync-heaps-1-batched-diff) — batched page ranges + single-lock zero-alloc diff (no thread or lock-scope changes).
  • Part 2 (queued behind #3139): MeMako:pr/sync-heaps-2-batched-buffers — shadow::find_existing_batch (with fixed shadow.rs doc comment) + PreparedBuffer / bindless::set_with (no thread or lock-scope changes). Will be opened once #3139 lands so GitHub shows only its own diff.
  • Part 3 (this PR): parallel page probing, Phase 1 diff, and Phase 3 descriptor creation via crate::texture::in_parallel, plus batched kept / retire_all / set_batch. Will be rebased onto Part 2 and paired with a standalone live main vs. Part 3 run before un-drafting.

Problem

descriptor::sync_heaps() runs before every submission on the submitting thread:

  1. Each dirty 64 KiB heap page is processed individually (HostHeap::sync_slots), allocating three temporary Vecs per page (records, current, stale) and locking VIEWS and self.made once per page while looking up VIEWS even for empty unchanged slots.
  2. Each changed slot is mirrored serially via HostHeap::mirror, taking self.made twice and VIEWS, self.kept, RETIRED, and self.viewed once per slot, running D3D12 Create*View serially, and calling shadow::for_view / shadow::find up to three times per buffer descriptor (prepare, make, and bindless::seen).

Fix (Clean 4-Commit Stack)

  1. 24618c9 (Part 1, #3139): Batches dirty page ranges and diffs directly against title memory, self.made, and VIEWS under one lock of each (made -> VIEWS), clamping with past_cap.max(last - 1) and skipping VIEWS for empty unchanged slots.
  2. 5825419 (Part 2): Adds shadow::find_existing_batch (placed cleanly after for_view so for_view keeps its doc comment), PreparedBuffer, prepare_resolved, make_with (removing duplicate GetDesc() in buffer_uav), bindless::Viewed::set_with / seen_entry, and tests for find_existing_batch and WHILE_PREPARING retries (sync_ranges_retries_slot_rewritten_while_preparing).
  3. cae33f6 (Part 3): Parallelizes dirty page probing (pages.len() >= 16), Phase 1 diff (total >= 32_768), Phase 2 texture preparation, and Phase 3 D3D12 descriptor creation (ready.len() >= 64) using the crate's existing crate::texture::in_parallel helper (max 4 workers, zero unsafe in parallel result collection). Holds self.made once across Phase 3, re-checks both live title slot bytes and VIEWS generation under made -> VIEWS (retrying concurrently rewritten or released slots via HostHeap::mirror after dropping self.made), and applies self.kept, host::retire_all, and bindless::Viewed::set_batch in one lock each.
  4. 566a27a (by @passerbyyhx, via MeMako/VIctory#1): Non-#[ignore] test a_sixteen_page_heap_sync_preserves_sparse_views_at_the_boundaries covering both the 16-page parallel probe and 32,768-slot Phase 1 parallel diff thresholds.
  • #3139 (Part 1): first PR of this split.
  • #2940 (bindless FxMap + O(1) forget): orthogonal; bindless.rs's Inner containers are untouched here.
  • #2821 (SHADER_HEAPS / BUFFERS / VIEWS RwLock): orthogonal; lock types are unchanged here, and holding self.made across Phase 3 keeps sync_ranges sound even under concurrent SHADER_HEAPS readers.

Verification & Standalone Benchmarks

Host: Windows 11 (10.0.26200), AMD Ryzen 9 7950X, AMD Radeon RX 9070 XT (RDNA 4, driver 32.0.32029.2010), base main 63bcca4.

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test --workspace --locked -- --test-threads=1: all passed, 0 failed (victory-gpu: 236 passed, victory-shader: 305 passed, xtask: 6 passed).
  • cargo run --locked -p xtask -- policy: asset policy: 191 files ok.

Standalone benchmark (--release, world_frame_sync_heaps, 700,416 slots across 342 dirty 64 KiB pages, 9-round medians, main vs. Part 3 alone):

Case main (63bcca4) median Part 3 (566a27a) median Speedup
Scan-only (0 changed / 700k scanned) 1.48 ms 0.72 ms 2.06x
Typical (6,000 changed / 700k scanned) 5.80 ms 4.31 ms 1.35x
Heavy (14,000 changed / 700k scanned) 10.32 ms (max 11.17 ms) 8.25 ms (max 8.67 ms) 1.25x

(A standalone live main vs. Part 3 title run — without other PRs — will be added before marking this PR ready for review.)

Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; PR and code drafted with Antigravity.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5504676541 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055). Originally posted by [MeMako](https://github.com/MeMako) on 2026-11-26T05:40:25Z. --- > **Draft — Part 3 of the triage-requested 3-part split.** > - **Part 1 (ready for review):** #3139 (`pr/sync-heaps-1-batched-diff`) — batched page ranges + single-lock zero-alloc diff (no thread or lock-scope changes). > - **Part 2 (queued behind #3139):** `MeMako:pr/sync-heaps-2-batched-buffers` — `shadow::find_existing_batch` (with fixed `shadow.rs` doc comment) + `PreparedBuffer` / `bindless::set_with` (no thread or lock-scope changes). Will be opened once #3139 lands so GitHub shows only its own diff. > - **Part 3 (this PR):** parallel page probing, Phase 1 diff, and Phase 3 descriptor creation via `crate::texture::in_parallel`, plus batched `kept` / `retire_all` / `set_batch`. Will be rebased onto Part 2 and paired with a standalone live `main` vs. Part 3 run before un-drafting. ## Problem `descriptor::sync_heaps()` runs before every submission on the submitting thread: 1. Each dirty 64 KiB heap page is processed individually (`HostHeap::sync_slots`), allocating three temporary `Vec`s per page (`records`, `current`, `stale`) and locking `VIEWS` and `self.made` once per page while looking up `VIEWS` even for empty unchanged slots. 2. Each changed slot is mirrored serially via `HostHeap::mirror`, taking `self.made` twice and `VIEWS`, `self.kept`, `RETIRED`, and `self.viewed` once per slot, running D3D12 `Create*View` serially, and calling `shadow::for_view` / `shadow::find` up to three times per buffer descriptor (`prepare`, `make`, and `bindless::seen`). ## Fix (Clean 4-Commit Stack) 1. **`24618c9` (Part 1, #3139):** Batches dirty page ranges and diffs directly against title memory, `self.made`, and `VIEWS` under one lock of each (`made` -> `VIEWS`), clamping with `past_cap.max(last - 1)` and skipping `VIEWS` for empty unchanged slots. 2. **`5825419` (Part 2):** Adds `shadow::find_existing_batch` (placed cleanly after `for_view` so `for_view` keeps its doc comment), `PreparedBuffer`, `prepare_resolved`, `make_with` (removing duplicate `GetDesc()` in `buffer_uav`), `bindless::Viewed::set_with` / `seen_entry`, and tests for `find_existing_batch` and `WHILE_PREPARING` retries (`sync_ranges_retries_slot_rewritten_while_preparing`). 3. **`cae33f6` (Part 3):** Parallelizes dirty page probing (`pages.len() >= 16`), Phase 1 diff (`total >= 32_768`), Phase 2 texture preparation, and Phase 3 D3D12 descriptor creation (`ready.len() >= 64`) using the crate's existing **`crate::texture::in_parallel`** helper (max 4 workers, zero `unsafe` in parallel result collection). Holds `self.made` once across Phase 3, re-checks both live title slot bytes and `VIEWS` generation under `made` -> `VIEWS` (retrying concurrently rewritten or released slots via `HostHeap::mirror` after dropping `self.made`), and applies `self.kept`, `host::retire_all`, and `bindless::Viewed::set_batch` in one lock each. 4. **`566a27a` (by `@passerbyyhx`, via `MeMako/VIctory#1`):** Non-`#[ignore]` test `a_sixteen_page_heap_sync_preserves_sparse_views_at_the_boundaries` covering both the 16-page parallel probe and 32,768-slot Phase 1 parallel diff thresholds. ## Related PRs - **#3139** (Part 1): first PR of this split. - **#2940** (`bindless` `FxMap` + O(1) `forget`): orthogonal; `bindless.rs`'s `Inner` containers are untouched here. - **#2821** (`SHADER_HEAPS` / `BUFFERS` / `VIEWS` `RwLock`): orthogonal; lock types are unchanged here, and holding `self.made` across Phase 3 keeps `sync_ranges` sound even under concurrent `SHADER_HEAPS` readers. ## Verification & Standalone Benchmarks **Host:** Windows 11 (`10.0.26200`), AMD Ryzen 9 7950X, AMD Radeon RX 9070 XT (RDNA 4, driver `32.0.32029.2010`), base `main` `63bcca4`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test --workspace --locked -- --test-threads=1`: all passed, 0 failed (`victory-gpu`: **236 passed**, `victory-shader`: **305 passed**, `xtask`: **6 passed**). - `cargo run --locked -p xtask -- policy`: `asset policy: 191 files ok`. **Standalone benchmark (`--release`, `world_frame_sync_heaps`, 700,416 slots across 342 dirty 64 KiB pages, 9-round medians, `main` vs. Part 3 alone):** | Case | `main` (`63bcca4`) median | Part 3 (`566a27a`) median | Speedup | |---|---:|---:|---:| | Scan-only (`0` changed / 700k scanned) | 1.48 ms | **0.72 ms** | **2.06x** | | Typical (`6,000` changed / 700k scanned) | 5.80 ms | **4.31 ms** | **1.35x** | | Heavy (`14,000` changed / 700k scanned) | 10.32 ms (max 11.17 ms) | **8.25 ms** (max 8.67 ms) | **1.25x** | *(A standalone live `main` vs. Part 3 title run — without other PRs — will be added before marking this PR ready for review.)* *Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; PR and code drafted with Antigravity.*
fuzeofficlal commented 2026-11-26 05:54:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:54:05Z.

Review: APPROVED


Reviewed head 1a09c6fe line-by-line (lock ordering, disjoint-slot parallelism, MRU buffer lookup, and resource retirement) and verified locally on Windows 11 (NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • RTX 5090: sync_ranges_mirrors_and_clears_many_slots_in_parallel, find_existing_batch_matches_find_for_nested_and_adjacent_buffers, and descriptor:: (22/22, skipping only the known RTX 1M-view heap cap test dynamic_slots_are_held_until_released) all passed.
  • WARP (VICTORY_D3D12_WARP=1): sync_ranges_mirrors_and_clears_many_slots_in_parallel, find_existing_batch_matches_find_for_nested_and_adjacent_buffers, and descriptor:: (23/23) all passed.
  • Clippy: cargo clippy -p victory-gpu --locked --all-targets -- -D warnings (default and --features diagnostics) — 0 warnings.

Lock ordering matches existing paths (SHADER_HEAPS -> self.made -> VIEWS in Phase 1; self.made dropped for Phase 2 find_existing_batch / texture::in_parallel; self.made -> self.kept then host::retire_all after releasing self.kept, and self.made -> self.viewed.inner in Phase 3). Sorting/merging raw_clamped into disjoint intervals ensures worker threads write disjoint 0..self.count descriptor slots, and Phase 3 re-checks both the live title slot bytes and made[index] != key before writing.

Minor non-blocking notes:

  1. In HostHeap::sync_ranges, if last > self.count { past_cap = Some(last - 1); } overwrites past_cap rather than taking .max(last - 1). Current callers pass sorted ranges, but taking the max keeps HIGHEST consistent regardless of input order.
  2. Between Phase 2 and Phase 3, if another thread calls resource::release -> descriptor::forget (bumping VIEWS generation without overwriting heap slot bytes), the now == raw check still passes with the snapshot View (same window as HostHeap::mirror on main); re-checking VIEWS generation when building ready would tighten that window.
  3. Non-#[ignore] coverage for the pages.len() >= 16 parallel probe path, the total >= 32_768 Phase 1 parallel diff path, and a Phase 2->3 retry trigger (via WHILE_PREPARING) would be nice additions.
<!-- greyfinch-sync:Marvisak/VIctory:review:6069189372 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#pullrequestreview-6069189372). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T05:54:05Z. **Review:** APPROVED --- Reviewed head `1a09c6fe` line-by-line (lock ordering, disjoint-slot parallelism, MRU buffer lookup, and resource retirement) and verified locally on Windows 11 (NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC): - **RTX 5090**: `sync_ranges_mirrors_and_clears_many_slots_in_parallel`, `find_existing_batch_matches_find_for_nested_and_adjacent_buffers`, and `descriptor::` (22/22, skipping only the known RTX 1M-view heap cap test `dynamic_slots_are_held_until_released`) all passed. - **WARP (`VICTORY_D3D12_WARP=1`)**: `sync_ranges_mirrors_and_clears_many_slots_in_parallel`, `find_existing_batch_matches_find_for_nested_and_adjacent_buffers`, and `descriptor::` (23/23) all passed. - **Clippy**: `cargo clippy -p victory-gpu --locked --all-targets -- -D warnings` (default and `--features diagnostics`) — 0 warnings. Lock ordering matches existing paths (`SHADER_HEAPS -> self.made -> VIEWS` in Phase 1; `self.made` dropped for Phase 2 `find_existing_batch` / `texture::in_parallel`; `self.made -> self.kept` then `host::retire_all` after releasing `self.kept`, and `self.made -> self.viewed.inner` in Phase 3). Sorting/merging `raw_clamped` into disjoint intervals ensures worker threads write disjoint `0..self.count` descriptor slots, and Phase 3 re-checks both the live title slot bytes and `made[index] != key` before writing. Minor non-blocking notes: 1. In `HostHeap::sync_ranges`, `if last > self.count { past_cap = Some(last - 1); }` overwrites `past_cap` rather than taking `.max(last - 1)`. Current callers pass sorted ranges, but taking the max keeps `HIGHEST` consistent regardless of input order. 2. Between Phase 2 and Phase 3, if another thread calls `resource::release` -> `descriptor::forget` (bumping `VIEWS` generation without overwriting heap slot bytes), the `now == raw` check still passes with the snapshot `View` (same window as `HostHeap::mirror` on `main`); re-checking `VIEWS` generation when building `ready` would tighten that window. 3. Non-`#[ignore]` coverage for the `pages.len() >= 16` parallel probe path, the `total >= 32_768` Phase 1 parallel diff path, and a Phase 2->3 `retry` trigger (via `WHILE_PREPARING`) would be nice additions.
kotekompotek commented 2026-11-26 06:04:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:04:00Z.

Review: APPROVED


Verified the concurrency design end-to-end: Phase 1 diffs under the same made→VIEWS lock order the serial path used; Phase 2 prepares outside locks (find_existing_batch is provably find-equivalent for buffer-resident queries — innermost containing = first .rev() match with end >= end, and the MRU's 'address < next_key_start' guarantees no deeper key; loose/ambiguous falls back to find); Phase 3 re-reads every record and retries changed slots through mirror — the TOCTOU that mattered. Ranges are sorted/merged so parallel slot writes are strictly disjoint; made is held across the whole apply; stride/mark/address/viewed/kept keep their own locking as in mirror. past_cap preserves the beyond-count path. sync_workers caps at half-parallelism ≤6 — leaves the title threads headroom. The 256-slot test discriminates make/clear/rewrite over split ranges.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069269933 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#pullrequestreview-6069269933). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:04:00Z. **Review:** APPROVED --- Verified the concurrency design end-to-end: Phase 1 diffs under the same made→VIEWS lock order the serial path used; Phase 2 prepares outside locks (find_existing_batch is provably find-equivalent for buffer-resident queries — innermost containing = first .rev() match with end >= end, and the MRU's 'address < next_key_start' guarantees no deeper key; loose/ambiguous falls back to find); Phase 3 re-reads every record and retries changed slots through mirror — the TOCTOU that mattered. Ranges are sorted/merged so parallel slot writes are strictly disjoint; made is held across the whole apply; stride/mark/address/viewed/kept keep their own locking as in mirror. past_cap preserves the beyond-count path. sync_workers caps at half-parallelism ≤6 — leaves the title threads headroom. The 256-slot test discriminates make/clear/rewrite over split ranges.
Marvisak commented 2026-11-26 07:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:19:03Z.


Automated triage for the maintainers.

Verdict: needs work. sync_heaps cost is a real target. However, this PR rewrites HostHeap::sync_slots into a three-phase multithreaded sync_ranges (about 800 lines in descriptor/host.rs). It also changes lock scope: self.made is now held across descriptor creation and the kept/RETIRED/viewed updates. That is too much to review as one change. Specific points:

  • Thread spawning per call. sync_heaps (page probing) and both sync_ranges phases use std::thread::scope plus scope.spawn. That creates fresh OS threads on every sync, before every submission, about 19 times a frame by your own figure. The crate already has a worker helper (crate::texture::in_parallel, used here for textures). Use it, or measure the spawn cost in the live case.
  • Misplaced doc comment. In crates/victory-gpu/src/shadow.rs, find_existing_batch is inserted between for_view's doc comment and for_view. for_view loses its documentation, and the new function inherits it.
  • Split the PR. First, the batched page probing and the single-lock diff, with no thread changes. Second, the batched buffer resolution (find_existing_batch / PreparedBuffer). Third, parallel descriptor creation. Each part can then be measured and reviewed on its own, especially the held-made lock order and the concurrent set_stride/set_mark/note_address writes.
  • Benchmark scope. The benchmark is synthetic, and the live figures come from a branch combined with #2940. Please give main against this PR alone in the live case.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184310551 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#issuecomment-7184310551). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:19:03Z. --- <!-- victory-triage v1 head=1a09c6fe3f70341252e08324ba0a757879866b39 verdict=needs-work at=2026-11-26T06:22:10Z --> Automated triage for the maintainers. **Verdict: needs work.** `sync_heaps` cost is a real target. However, this PR rewrites `HostHeap::sync_slots` into a three-phase multithreaded `sync_ranges` (about 800 lines in `descriptor/host.rs`). It also changes lock scope: `self.made` is now held across descriptor creation and the `kept`/`RETIRED`/`viewed` updates. That is too much to review as one change. Specific points: - **Thread spawning per call.** `sync_heaps` (page probing) and both `sync_ranges` phases use `std::thread::scope` plus `scope.spawn`. That creates fresh OS threads on every sync, before every submission, about 19 times a frame by your own figure. The crate already has a worker helper (`crate::texture::in_parallel`, used here for textures). Use it, or measure the spawn cost in the live case. - **Misplaced doc comment.** In `crates/victory-gpu/src/shadow.rs`, `find_existing_batch` is inserted between `for_view`'s doc comment and `for_view`. `for_view` loses its documentation, and the new function inherits it. - **Split the PR.** First, the batched page probing and the single-lock diff, with no thread changes. Second, the batched buffer resolution (`find_existing_batch` / `PreparedBuffer`). Third, parallel descriptor creation. Each part can then be measured and reviewed on its own, especially the held-`made` lock order and the concurrent `set_stride`/`set_mark`/`note_address` writes. - **Benchmark scope.** The benchmark is synthetic, and the live figures come from a branch combined with #2940. Please give `main` against this PR alone in the live case. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
MeMako commented 2026-11-26 10:05:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T09:57:10Z.


Updated #3055 per the triage review and @fuzeofficlal's notes, and marked it Draft while splitting it into three reviewable PRs:

  • 3-part split: Opened Part 1 as #3139 (pr/sync-heaps-1-batched-diff, +155/-36, batched page probing + single-lock zero-alloc diff, zero thread or lock-scope changes). Part 2 (pr/sync-heaps-2-batched-buffers) is pushed on my fork and will be opened once #3139 lands. #3055 now holds Part 3 cleanly stacked on top.
  • Threading (crate::texture::in_parallel): Replaced all custom std::thread::scope / scope.spawn loops in page probing, Phase 1 diff, and Phase 3 descriptor creation with crate::texture::in_parallel (max 4 workers).
  • Fixed shadow.rs doc comment: Moved find_existing_batch after for_view with its own doc comment so for_view keeps its documentation.
  • Reviewer notes & test coverage: Applied @fuzeofficlal's three notes (past_cap.max(last - 1), Phase 3 VIEWS generation re-check under made -> VIEWS, and non-#[ignore] WHILE_PREPARING retry test sync_ranges_retries_slot_rewritten_while_preparing), and included @passerbyyhx's MeMako/VIctory#1 commit (566a27a) covering both the 16-page and 32,768-slot parallel thresholds.
  • Benchmarks: Updated the PR description to standalone main (63bcca4) vs. Part 3 (566a27a) numbers only (no mixed #2940 figures). A standalone live main vs. Part 3 run will follow before un-drafting.

Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188701010 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#issuecomment-7188701010). Originally posted by [MeMako](https://github.com/MeMako) on 2026-11-26T09:57:10Z. --- Updated `#3055` per the triage review and `@fuzeofficlal`'s notes, and marked it **Draft** while splitting it into three reviewable PRs: - **3-part split:** Opened **Part 1** as #3139 (`pr/sync-heaps-1-batched-diff`, `+155/-36`, batched page probing + single-lock zero-alloc diff, zero thread or lock-scope changes). **Part 2** (`pr/sync-heaps-2-batched-buffers`) is pushed on my fork and will be opened once #3139 lands. `#3055` now holds **Part 3** cleanly stacked on top. - **Threading (`crate::texture::in_parallel`):** Replaced all custom `std::thread::scope` / `scope.spawn` loops in page probing, Phase 1 diff, and Phase 3 descriptor creation with `crate::texture::in_parallel` (max 4 workers). - **Fixed `shadow.rs` doc comment:** Moved `find_existing_batch` after `for_view` with its own doc comment so `for_view` keeps its documentation. - **Reviewer notes & test coverage:** Applied `@fuzeofficlal`'s three notes (`past_cap.max(last - 1)`, Phase 3 `VIEWS` generation re-check under `made -> VIEWS`, and non-`#[ignore]` `WHILE_PREPARING` retry test `sync_ranges_retries_slot_rewritten_while_preparing`), and included `@passerbyyhx`'s `MeMako/VIctory#1` commit (`566a27a`) covering both the 16-page and 32,768-slot parallel thresholds. - **Benchmarks:** Updated the PR description to standalone `main` (`63bcca4`) vs. Part 3 (`566a27a`) numbers only (no mixed `#2940` figures). A standalone live `main` vs. Part 3 run will follow before un-drafting. *Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.*
KainanP commented 2026-11-27 12:31:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T12:31:12Z.


Contention numbers for the SHADER_HEAPS wait in #3425, this PR (566a27a) against its base 63bcca4:

base #3055
sync_heaps, RTX, 12 runs 9.6 ms 7.6 ms (−20 %)
title-thread wait per frame 49.5 ms 39.7 ms
game-shaped heap (1,245,184 slots, pages past the cap too), 5 runs 7.9 ms 6.0 ms
Intel UHD (a78b), 5 runs 10.1 ms 8.5 ms

It was faster in all four setups. No views were lost or stale. The full victory-gpu suite on RTX fails only the two tests that main also fails here (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views).

The lock is still held for the whole pass, so title threads still wait for the entire (shorter) sync. The per-write p99 is 7.8 ms, against 9.7 ms on the base.

Bench: sync_contention_bench (#[ignore]d; commit f34bcfb8, cherry-picks onto any tree). A placed, write-watched view heap of 2^20 slots (the host heap caps it at 934,464 here). Each frame, one thread rewrites 200 random 64 KiB pages (50 changed records each) and runs one sync_heaps, while 5 title threads write a placed-buffer SRV every 20 µs into pages of their own. "Wait" is the title threads' time in view writes beyond the uncontended 2–3 µs, summed per frame. Release build, RTX 4060 Laptop, runs interleaved with the base, medians of 30 frames per run. The bench also checks that every view written before a sync is the slot's view address after it, and that every slot is right after a final quiet sync.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218338174 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#issuecomment-7218338174). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T12:31:12Z. --- Contention numbers for the `SHADER_HEAPS` wait in #3425, this PR (`566a27a`) against its base `63bcca4`: | | base | #3055 | |---|---|---| | `sync_heaps`, RTX, 12 runs | 9.6 ms | **7.6 ms** (−20 %) | | title-thread wait per frame | 49.5 ms | 39.7 ms | | game-shaped heap (1,245,184 slots, pages past the cap too), 5 runs | 7.9 ms | **6.0 ms** | | Intel UHD (a78b), 5 runs | 10.1 ms | 8.5 ms | It was faster in all four setups. No views were lost or stale. The full `victory-gpu` suite on RTX fails only the two tests that `main` also fails here (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). The lock is still held for the whole pass, so title threads still wait for the entire (shorter) sync. The per-write p99 is 7.8 ms, against 9.7 ms on the base. Bench: [`sync_contention_bench`](https://github.com/KainanP/VIctory/blob/bench/sync-heaps-contention/crates/victory-gpu/src/descriptor/sync_bench.rs) (`#[ignore]`d; commit `f34bcfb8`, cherry-picks onto any tree). A placed, write-watched view heap of 2^20 slots (the host heap caps it at 934,464 here). Each frame, one thread rewrites 200 random 64 KiB pages (50 changed records each) and runs one `sync_heaps`, while 5 title threads write a placed-buffer SRV every 20 µs into pages of their own. "Wait" is the title threads' time in view writes beyond the uncontended 2–3 µs, summed per frame. Release build, RTX 4060 Laptop, runs interleaved with the base, medians of 30 frames per run. The bench also checks that every view written before a sync is the slot's view address after it, and that every slot is right after a final quiet sync. _AI use: Claude Code (Claude Opus 5.5)._
KainanP commented 2026-11-27 13:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T13:06:20Z.


Follow-up to my contention numbers above, this time in the sync_slots shape #3425 reports (18.1 ms/frame for ~384k slots).

Bench: sync_slots_bench on bench/sync-slots (f233390e, on top of f34bcfb8). Each frame, 192 random 64 KiB pages (393,216 slots, the "384k slots" of #3425) of a 2^20-slot placed, write-watched view heap are written. 0, ~9,500 or ~85,000 records among them change, and one sync_heaps runs. Each shape runs without and with 5 title threads writing a view every 20 µs. It checks every changed slot's view address after each sync, and every slot at the end. RTX 4060 Laptop. Base 63bcca4 and the PRs ran interleaved (7 runs for the ~9.5k row, 3 for the others). Ratios are per-run against base. #3265, which doesn't touch the sync, gave ×0.81-1.04 in the same runs, so read anything within ~±15% as noise.

changed records title threads base sync_heaps #3055 ratio title wait/frame, base → #3055
0 0 2.9 ms 2.0 ms ×0.63
0 5 3.6 ms 2.3 ms ×0.66 18 → 11 ms
~9,500 0 12.3 ms 8.9 ms ×0.82
~9,500 5 13.1 ms 9.2 ms ×0.70 64 → 46 ms
~85,000 0 159 ms 104 ms ×0.66
~85,000 5 160 ms 101 ms ×0.68 779 → 418 ms

This is the only one of the open heap-sync PRs that's faster in every shape here. That covers #3139, #2971 and #3265 (control); #3356 was slower in the earlier contention runs. 0 lost and 0 stale slots in every run.

Where base's time goes, from the same bench with SYNC_SLOTS_DIRECT=1 (calling sync_slots per page, without the write-watch walk):

  • The record diff over 393k slots is ~1.2 ms.
  • The write-watch/page walk is ~1.7 ms.
  • A changed slot's mirror is ~1 µs on its own (9.5k changed: 10-12 ms).

So the in-game 18.1 ms is mostly mirror of changed slots, not the scan. Your batched buffer lookup and parallel make are aimed at the right part.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219062320 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3055#issuecomment-7219062320). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T13:06:20Z. --- Follow-up to my contention numbers above, this time in the `sync_slots` shape #3425 reports (18.1 ms/frame for ~384k slots). **Bench:** `sync_slots_bench` on [`bench/sync-slots`](https://github.com/KainanP/VIctory/commits/bench/sync-slots) (`f233390e`, on top of `f34bcfb8`). Each frame, 192 random 64 KiB pages (393,216 slots, the "384k slots" of #3425) of a 2^20-slot placed, write-watched view heap are written. 0, ~9,500 or ~85,000 records among them change, and one `sync_heaps` runs. Each shape runs without and with 5 title threads writing a view every 20 µs. It checks every changed slot's view address after each sync, and every slot at the end. RTX 4060 Laptop. Base `63bcca4` and the PRs ran interleaved (7 runs for the ~9.5k row, 3 for the others). Ratios are per-run against base. #3265, which doesn't touch the sync, gave ×0.81-1.04 in the same runs, so read anything within ~±15% as noise. | changed records | title threads | base `sync_heaps` | #3055 | ratio | title wait/frame, base → #3055 | |---|---|---|---|---|---| | 0 | 0 | 2.9 ms | **2.0 ms** | ×0.63 | | | 0 | 5 | 3.6 ms | **2.3 ms** | ×0.66 | 18 → 11 ms | | ~9,500 | 0 | 12.3 ms | **8.9 ms** | ×0.82 | | | ~9,500 | 5 | 13.1 ms | **9.2 ms** | ×0.70 | 64 → 46 ms | | ~85,000 | 0 | 159 ms | **104 ms** | ×0.66 | | | ~85,000 | 5 | 160 ms | **101 ms** | ×0.68 | 779 → 418 ms | This is the only one of the open heap-sync PRs that's faster in every shape here. That covers #3139, #2971 and #3265 (control); #3356 was slower in the earlier contention runs. 0 lost and 0 stale slots in every run. Where base's time goes, from the same bench with `SYNC_SLOTS_DIRECT=1` (calling `sync_slots` per page, without the write-watch walk): - The record diff over 393k slots is ~1.2 ms. - The write-watch/page walk is ~1.7 ms. - A changed slot's `mirror` is ~1 µs on its own (9.5k changed: 10-12 ms). So the in-game 18.1 ms is mostly `mirror` of changed slots, not the scan. Your batched buffer lookup and parallel make are aimed at the right part. _AI use: Claude Code (Claude Opus 5.5)._
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/3055:upstream-pr/3055'
git switch 'upstream-pr/3055'

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