GPU: inline CBV/placed records, wait-free ShapeArena, and RwLock ViewMap #3831

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

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


Problem

Every create_cbv, create_placed_srv, and create_placed_uav call currently acquires a single global Mutex<Views>, searches a BTreeMap<View, u32> over 124-byte View values, and appends a permanent entry to Views::list. Meanwhile, command-list recorders (view_at) and heap sync scans (views_current, ~700,000 slots/frame) contend on that same global mutex and stride across (View, u32) tuples just to check 4-byte generations.

Changes

  • Inline CONSTANT and PLACED descriptor records: Encode standard constant buffer views (< 47-bit VA, < 16 KiB byte-exact or 256-byte aligned < 4 MiB) and placed-memory views (< 1 TiB VA plus a 22-bit shape index) directly in the 62 payload bits below two KIND_SHIFT bits in generation. Recycled table generations wrap within 1..=GENERATIONS (2^30 - 1) so they never become 0 or enter the kind bits.
  • Wait-free ShapeArena: Intern distinct placed-view shapes in a segmented append-only slab arena (2048 x 2048 capacity) published via Release/Acquire atomics so PLACED lookups (view_at, views_current) never touch the Views lock.
  • RwLock<Views> + word-hashed ViewMap + dense current Vec: Replace Mutex<Views> and BTreeMap with an RwLock over word-hashed maps, a read-lock fast path for already-registered views in words_for, and a separated current: Vec<u32> generation slice.

Ported from CaullenOmdahl/Boxon (measured +2.3% steady-state frame-time improvement in world scenes on Ryzen 9 5900X + RX 6800).

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.rs covering inline CBV/placed encoding, fallback table entries, 30-bit generation wrap-around, ShapeKey collision chains, views_current, and concurrent wait-free ShapeArena reads across slab boundaries.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5550613911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3831). Originally posted by [CaullenOmdahl](https://github.com/CaullenOmdahl) on 2026-11-29T12:16:28Z. --- ## Problem Every `create_cbv`, `create_placed_srv`, and `create_placed_uav` call currently acquires a single global `Mutex<Views>`, searches a `BTreeMap<View, u32>` over 124-byte `View` values, and appends a permanent entry to `Views::list`. Meanwhile, command-list recorders (`view_at`) and heap sync scans (`views_current`, ~700,000 slots/frame) contend on that same global mutex and stride across `(View, u32)` tuples just to check 4-byte generations. ## Changes - **Inline `CONSTANT` and `PLACED` descriptor records:** Encode standard constant buffer views (`< 47-bit` VA, `< 16 KiB` byte-exact or `256`-byte aligned `< 4 MiB`) and placed-memory views (`< 1 TiB` VA plus a 22-bit shape index) directly in the 62 payload bits below two `KIND_SHIFT` bits in `generation`. Recycled table generations wrap within `1..=GENERATIONS` (`2^30 - 1`) so they never become `0` or enter the kind bits. - **Wait-free `ShapeArena`:** Intern distinct placed-view shapes in a segmented append-only slab arena (`2048 x 2048` capacity) published via `Release`/`Acquire` atomics so `PLACED` lookups (`view_at`, `views_current`) never touch the `Views` lock. - **`RwLock<Views>` + word-hashed `ViewMap` + dense `current` Vec:** Replace `Mutex<Views>` and `BTreeMap` with an `RwLock` over word-hashed maps, a read-lock fast path for already-registered views in `words_for`, and a separated `current: Vec<u32>` generation slice. Ported from [`CaullenOmdahl/Boxon`](https://github.com/CaullenOmdahl/Boxon) (measured `+2.3%` steady-state frame-time improvement in world scenes on Ryzen 9 5900X + RX 6800). ## 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.rs` covering inline CBV/placed encoding, fallback table entries, 30-bit generation wrap-around, `ShapeKey` collision chains, `views_current`, and concurrent wait-free `ShapeArena` reads across slab boundaries.
kilolimaVI commented 2026-11-29 16:40:45 +00:00 (Migrated from github.com)

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


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 250/250 twice, and 251/251 twice together with #3832 (the two merge clean). 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:7259092430 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3831#issuecomment-7259092430). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-29T16:40:45Z. --- 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 250/250 twice, and 251/251 twice together with #3832 (the two merge clean). 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/3831:upstream-pr/3831'
git switch 'upstream-pr/3831'

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