GPU: use RwLock for read-mostly tables and add per-HostList VA/view caches #1356

Open
github-bot wants to merge 1 commit from github-bot/gh-1356 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 17:35 UTC · original
wbkepler:gpu/concurrent-read-locks-and-va-cache → main · +708 −75 · 8 files · 1 commits · open

Summary

Reduces multi-thread CPU recording contention and repeated lookup overhead in victory-gpu:

  • Converts read-mostly global Mutex tables queried on per-draw/dispatch/bind hot paths to std::sync::RwLock with shared .read() hit paths (shadow::{BUFFERS, LOOSE}, descriptor::{SHADER_HEAPS, VIEWS}, HostHeap::made, texture::{STAGING, HOST_WRITTEN}, resource::PLACED_TEXTURES, draw::host_signature::MADE, pipeline::SHADERS), using .iter().rev().find in descriptor::shader_slot.
  • Adds bounded, allocation-free 16-slot per-HostList inline ShadowCache (with nested-buffer-safe CachedRange::Subrange/Exact interval bounds) and ViewCache, cleared on HostList::reset() and invalidated via Acquire/Release AtomicU64 generation counters bumped under write locks in shadow::{register, unregister} and descriptor::forget.
  • Routes draw.rs per-draw VB/IB/root-view/indirect/table/readable lookups through HostList::{find_shadow, lookup_view} and HostHeap::mirror_cached.

Verification

  • cargo clippy --workspace --all-targets & -p victory --features diagnostics --all-targets — passed (0 new warnings)
  • cargo test --workspace — passed
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics host::tests — passed (6/6)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 17:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1356) `wbkepler:gpu/concurrent-read-locks-and-va-cache` → `main` · +708 −75 · 8 files · 1 commits · open ## Summary Reduces multi-thread CPU recording contention and repeated lookup overhead in `victory-gpu`: - Converts read-mostly global `Mutex` tables queried on per-draw/dispatch/bind hot paths to `std::sync::RwLock` with shared `.read()` hit paths (`shadow::{BUFFERS, LOOSE}`, `descriptor::{SHADER_HEAPS, VIEWS}`, `HostHeap::made`, `texture::{STAGING, HOST_WRITTEN}`, `resource::PLACED_TEXTURES`, `draw::host_signature::MADE`, `pipeline::SHADERS`), using `.iter().rev().find` in `descriptor::shader_slot`. - Adds bounded, allocation-free 16-slot per-`HostList` inline `ShadowCache` (with nested-buffer-safe `CachedRange::Subrange`/`Exact` interval bounds) and `ViewCache`, cleared on `HostList::reset()` and invalidated via `Acquire`/`Release` `AtomicU64` generation counters bumped under write locks in `shadow::{register, unregister}` and `descriptor::forget`. - Routes `draw.rs` per-draw VB/IB/root-view/indirect/table/readable lookups through `HostList::{find_shadow, lookup_view}` and `HostHeap::mirror_cached`. ## Verification - `cargo clippy --workspace --all-targets` & `-p victory --features diagnostics --all-targets` — passed (0 new warnings) - `cargo test --workspace` — passed - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics host::tests` — passed (6/6) - `cargo xtask policy` — passed (151 files ok)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:37 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1356#issuecomment-7149503804) <!-- victory-triage v1 head=0804561542508f6837c46c44bc7093e3d239d755 verdict=needs-rebase at=2026-11-25T01:23:54Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/resource.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 16:26 UTC · original

A data point for the buffer-lookup cache in this PR: on main + #1978 + #2821 + #3258 + #3274 + #3275, a rough thread-local stand-in for it in front of shadow::find (validated by a generation counter, but with no nested-buffer check) took the list bench's draw sequence from 2,485 to 1,894 ns per draw on 5 threads (−24%) and from 1,351 to 1,242 ns on 1 thread (RTX 4060 Laptop, median of 7). Details are in #2586 (7197644545). Your CachedRange version is the correct form of it. Rebased on its own (BUFFERS is a Mutex on main, and #2821/#2096 change it), it would likely be the next clear gain for the recording threads.

AI use: Claude Code (Claude Opus 5.5) ran the measurement and drafted this comment.

**@⁠KainanP** on GitHub · 2026-11-26 16:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1356#issuecomment-7197647405) A data point for the buffer-lookup cache in this PR: on main + #1978 + #2821 + #3258 + #3274 + #3275, a rough thread-local stand-in for it in front of `shadow::find` (validated by a generation counter, but with no nested-buffer check) took the list bench's draw sequence from 2,485 to 1,894 ns per draw on 5 threads (−24%) and from 1,351 to 1,242 ns on 1 thread (RTX 4060 Laptop, median of 7). Details are in #2586 (7197644545). Your `CachedRange` version is the correct form of it. Rebased on its own (`BUFFERS` is a `Mutex` on main, and #2821/#2096 change it), it would likely be the next clear gain for the recording threads. _AI use: Claude Code (Claude Opus 5.5) ran the measurement and drafted this comment._
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor.rs
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/pipeline.rs
  • crates/victory-gpu/src/resource.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1356/head:github-bot/gh-1356'
git switch 'github-bot/gh-1356'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1356'
git switch 'github-bot/gh-1356'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1356'
git switch 'github-bot/gh-1356'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1356'
git switch 'main'
git merge --squash 'github-bot/gh-1356'
git switch 'main'
git merge --ff-only 'github-bot/gh-1356'
git switch 'main'
git merge 'github-bot/gh-1356'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1356
No description provided.