perf(gpu/desc): coalesce dynamic table copies, direct CBVs, and TLS mirror cache #393

Merged
Androtim merged 5 commits from upstream-pr/393 into main 2026-12-03 22:54:07 +00:00
Androtim commented 2026-12-03 13:17:24 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:17:24Z.


Summary

Reduces per-table CPU descriptor overhead in crates/victory-gpu/src/descriptor/host.rs and crates/victory-gpu/src/draw.rs:

  1. Stack-buffered coalescing PendingCopies (descriptor/host.rs, draw.rs):

    • Replaces heap-backed ListedCopyBatch with a fixed stack-buffered PendingCopies (backed by a per-thread CPU-only PendingStage descriptor slice) that partitions primary slots [0..RAW_TWINS) and twin slots [RAW_TWINS..) separately, coalesces contiguous destination/source ranges into batched CopyDescriptors / CopyDescriptorsSimple calls, and flushes on partition overflow, duplicate destination slots, heap switches, or at the end of State::tables before root tables are bound/drawn.
    • Routes make_listed_batched, make_at_settled, make_null_settled, direct CBVs, and raw twin writes/clears through PendingCopies, updating raw-twin staging detection via is_cpu_staging_twin for move_raw.
    • Also adds lock-free pin_slots tracking in HostHeap so keep_inner avoids kept / kept_pins lock churn on unpinned slots even when global pin_count > 0.
  2. Direct CBV fast path (HostHeap::commit_direct_cbv) (descriptor/host.rs, draw.rs):

    • Adds inline_constant decoding and HostHeap::commit_direct_cbv for View::Constant in State::tables, bypassing VIEWS locks and extra COM refcount churn while preserving resource lifetime (kept / RETIRED), raw buffer twins (RAW_TWINS / clear on zero size), untrack_rtas, and zeroing write_stride / write_address.
  3. Zero-clone mirror_for_table_with + TLS MirrorCache (descriptor/host.rs, draw.rs):

    • Adds a TLS 2-way set-associative MirrorCache plus HostHeap::mirror_for_table_with, iew_with, iew_with_words, and listed_view_with, and updates State::table_entry, State::tables, and the
      eady_once fallback in draw.rs to inspect &View without cloning or re-locking VIEWS on cache hits.
    • Cache hits validate descriptor key/generation (key != 0, quick_key(index) == key, iews_entry_alive for non-inline entries) and !tlas_gen_stale(index) so slot overwrites, descriptor::forget, and TLAS generation bumps never yield stale resource pointers.

Verification

  • Added unit tests pending_copies_tests and mirror_cache_tests covering range coalescing, [0..RAW_TWINS) / [RAW_TWINS..) partition separation, duplicate/overflow flushes, commit_direct_cbv / make_at_settled / make_null_settled twin/stride/address invariants, and MirrorCache 2-way eviction, descriptor::forget invalidation, slot overwrites, and TLAS generation invalidation.
  • Ran cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets -- -D warnings (passed).
  • Ran cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets --all-features -- -D warnings (passed).
  • Ran cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1 (842 passed, 0 failed, 39 ignored).
<!-- greyfinch-sync:Androtim/MiniVI:issue:5627266841 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/393). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:17:24Z. --- ## Summary Reduces per-table CPU descriptor overhead in crates/victory-gpu/src/descriptor/host.rs and crates/victory-gpu/src/draw.rs: 1. **Stack-buffered coalescing PendingCopies** (descriptor/host.rs, draw.rs): - Replaces heap-backed ListedCopyBatch with a fixed stack-buffered PendingCopies (backed by a per-thread CPU-only PendingStage descriptor slice) that partitions primary slots [0..RAW_TWINS) and twin slots [RAW_TWINS..) separately, coalesces contiguous destination/source ranges into batched CopyDescriptors / CopyDescriptorsSimple calls, and flushes on partition overflow, duplicate destination slots, heap switches, or at the end of State::tables before root tables are bound/drawn. - Routes make_listed_batched, make_at_settled, make_null_settled, direct CBVs, and raw twin writes/clears through PendingCopies, updating raw-twin staging detection via is_cpu_staging_twin for move_raw. - Also adds lock-free pin_slots tracking in HostHeap so keep_inner avoids kept / kept_pins lock churn on unpinned slots even when global pin_count > 0. 2. **Direct CBV fast path (HostHeap::commit_direct_cbv)** (descriptor/host.rs, draw.rs): - Adds inline_constant decoding and HostHeap::commit_direct_cbv for View::Constant in State::tables, bypassing VIEWS locks and extra COM refcount churn while preserving resource lifetime (kept / RETIRED), raw buffer twins (RAW_TWINS / clear on zero size), untrack_rtas, and zeroing write_stride / write_address. 3. **Zero-clone mirror_for_table_with + TLS MirrorCache** (descriptor/host.rs, draw.rs): - Adds a TLS 2-way set-associative MirrorCache plus HostHeap::mirror_for_table_with, iew_with, iew_with_words, and listed_view_with, and updates State::table_entry, State::tables, and the eady_once fallback in draw.rs to inspect &View without cloning or re-locking VIEWS on cache hits. - Cache hits validate descriptor key/generation (key != 0, quick_key(index) == key, iews_entry_alive for non-inline entries) and !tlas_gen_stale(index) so slot overwrites, descriptor::forget, and TLAS generation bumps never yield stale resource pointers. ## Verification - Added unit tests pending_copies_tests and mirror_cache_tests covering range coalescing, [0..RAW_TWINS) / [RAW_TWINS..) partition separation, duplicate/overflow flushes, commit_direct_cbv / make_at_settled / make_null_settled twin/stride/address invariants, and MirrorCache 2-way eviction, descriptor::forget invalidation, slot overwrites, and TLAS generation invalidation. - Ran cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets -- -D warnings (passed). - Ran cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu --all-targets --all-features -- -D warnings (passed). - Ran cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1 (842 passed, 0 failed, 39 ignored).
Androtim commented 2026-12-03 13:33:26 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:33:26Z.


Triage (00083399, CI check PASS):

  • High-impact Rank #2 descriptor CPU optimization (+1,328/-174 across descriptor/host.rs & draw.rs: stack-buffered coalescing PendingCopies, HostHeap::commit_direct_cbv, TLS MirrorCache).
  • Holding auto-merge for Gate 2 Deep Reasoning Audit (#282) (aliasing/flush safety, direct CBV lifetime/raw-twin invariants, TLS MirrorCache invalidation) + Gate 3 plain --release A/B (preparing/SUBMIT BUSY/FPS, 0 crashes/DRED) + visual check.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7379995993 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/393#issuecomment-7379995993). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:33:26Z. --- Triage (`00083399`, **CI `check` PASS**): - High-impact Rank #2 descriptor CPU optimization (`+1,328/-174` across `descriptor/host.rs` & `draw.rs`: stack-buffered coalescing `PendingCopies`, `HostHeap::commit_direct_cbv`, TLS `MirrorCache`). - Holding auto-merge for **Gate 2 Deep Reasoning Audit (`#282`)** (aliasing/flush safety, direct CBV lifetime/raw-twin invariants, TLS `MirrorCache` invalidation) + **Gate 3 plain `--release` A/B** (`preparing`/`SUBMIT BUSY`/FPS, `0` crashes/DRED) + visual check.
Androtim commented 2026-12-03 16:02:10 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T16:02:10Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-rebase · CI (check): none

This PR no longer merges cleanly into main.

To change the verdict: Rebase onto current main and resolve conflicts; CI and triage will run again automatically.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7384146791 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/393#issuecomment-7384146791). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T16:02:10Z. --- <!-- minivi-triage v1 head=ee51c4f025cc21cbb688c45a117a8173f4b6dbe7 verdict=needs-rebase ci=none at=2026-12-03T16:02:49Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-rebase` · **CI (`check`):** `none` This PR no longer merges cleanly into `main`. **To change the verdict:** Rebase onto current `main` and resolve conflicts; CI and triage will run again automatically. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-12-03 19:32:45 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T19:32:45Z.


Marking triage: needs rebase after #403 (a0e86cc2) and #402 (158fba11) merged onto main (overlapping descriptor/host.rs). Audit Pass #17 was already clean — once rebased with green CI + Gate 3 GPU A/B, ready to merge!

<!-- greyfinch-sync:Androtim/MiniVI:comment:7389862405 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/393#issuecomment-7389862405). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T19:32:45Z. --- Marking `triage: needs rebase` after `#403` (`a0e86cc2`) and `#402` (`158fba11`) merged onto `main` (overlapping `descriptor/host.rs`). Audit Pass #17 was already clean — once rebased with green CI + Gate 3 GPU A/B, ready to merge!
Androtim commented 2026-12-03 20:32:54 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T20:32:54Z.


Verified clean rebase onto main (d0222e16) and CI check PASS. Removed triage: needs rebase — Audit Pass #17 was clean; ready to merge once Gate 3 plain---release A/B posts.

<!-- greyfinch-sync:Androtim/MiniVI:comment:7391408883 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/393#issuecomment-7391408883). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T20:32:54Z. --- Verified clean rebase onto `main` (`d0222e16`) and CI `check` PASS. Removed `triage: needs rebase` — Audit Pass #17 was clean; ready to merge once Gate 3 plain-`--release` A/B posts.
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
Androtim/MiniVI!393
No description provided.