perf(gpu): batch list counters and use stack arrays in barrier/targets #511

Manually merged
github merged 1 commit from github-bot/gh-511 into main 2026-12-05 17:38:41 +00:00 AGit
Owner

@⁠Not4Eric on GitHub · 2026-12-04 20:24 UTC · original
Not4Eric:perf/list-batch-counters-stack-arrays → main · +129 −23 · 2 files · 1 commits · merged 2026-12-05 17:30 UTC

What this does

Cuts per-call heap allocations, lock traffic, and atomic contention during command-list recording and thin-list translation:

  1. Gates VALUE_WAITS (and its reset() mutex lock) behind #[cfg(not(windows))] since Windows builds never push to it.
  2. Replaces per-call Vec heap allocations in list::barrier (small stack array [Barrier; 16] with Vec overflow, short-circuiting the buf_uav check) and list::state::targets ([u64; 8] / borrowed slice).
  3. Adds thread-local CountBatch so list::thin::Recording::run batches DRAWS, DISPATCHES, TOTALS, and thin::STATS increments per translated chunk/run instead of hitting global atomics on every draw/dispatch.
  4. Short-circuits give_back on an empty Vec in list/thin.rs.

Checks

  • N/A: pure performance optimization preserving identical command-list translation and counter totals.
  • N/A: no switches added, changed, or removed.
  • No unrelated cleanup: diff is limited to crates/victory-gpu/src/list.rs and crates/victory-gpu/src/list/thin.rs.
  • N/A: existing list:: unit tests pass; no prior behavioural bug existed for a failing-before unit test.
  • Checked open PR queue: independent of #308 (ListFront) and #408 (enhanced barriers).
  • cargo xtask policy passed (360 files ok); no fork-only files, configs, or build outputs.

Verified

  • cargo xtask policy — 360 files ok
  • PROFILE=diag PKG=victory-gpu ./build.sh check — 0 warnings
  • PKG=victory-gpu ./build.sh test --lib -- list:: --test-threads=1 (Proton Wine on Linux, RX 9070 XT) — 5 passed; 0 failed, 0 warnings
  • Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton) translating ~55k–76k list calls/frame; not benchmarked in isolation.

Cost

None (reduces heap allocations and cross-core atomic traffic on victory-list-* threads; 0 new warnings).

AI-assisted: yes

**@⁠Not4Eric** on GitHub · 2026-12-04 20:24 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/511) `Not4Eric:perf/list-batch-counters-stack-arrays` → `main` · +129 −23 · 2 files · 1 commits · merged 2026-12-05 17:30 UTC ## What this does Cuts per-call heap allocations, lock traffic, and atomic contention during command-list recording and thin-list translation: 1. Gates `VALUE_WAITS` (and its `reset()` mutex lock) behind `#[cfg(not(windows))]` since Windows builds never push to it. 2. Replaces per-call `Vec` heap allocations in `list::barrier` (small stack array `[Barrier; 16]` with `Vec` overflow, short-circuiting the `buf_uav` check) and `list::state::targets` (`[u64; 8]` / borrowed slice). 3. Adds thread-local `CountBatch` so `list::thin::Recording::run` batches `DRAWS`, `DISPATCHES`, `TOTALS`, and `thin::STATS` increments per translated chunk/run instead of hitting global atomics on every draw/dispatch. 4. Short-circuits `give_back` on an empty `Vec` in `list/thin.rs`. ## Checks - N/A: pure performance optimization preserving identical command-list translation and counter totals. - N/A: no switches added, changed, or removed. - [x] No unrelated cleanup: diff is limited to `crates/victory-gpu/src/list.rs` and `crates/victory-gpu/src/list/thin.rs`. - N/A: existing `list::` unit tests pass; no prior behavioural bug existed for a failing-before unit test. - [x] Checked open PR queue: independent of #308 (`ListFront`) and #408 (enhanced barriers). - [x] `cargo xtask policy` passed (`360 files ok`); no fork-only files, configs, or build outputs. ## Verified - `cargo xtask policy` — `360 files ok` - `PROFILE=diag PKG=victory-gpu ./build.sh check` — 0 warnings - `PKG=victory-gpu ./build.sh test --lib -- list:: --test-threads=1` (Proton Wine on Linux, RX 9070 XT) — `5 passed; 0 failed`, 0 warnings - Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton) translating ~55k–76k list calls/frame; not benchmarked in isolation. ## Cost None (reduces heap allocations and cross-core atomic traffic on `victory-list-*` threads; 0 new warnings). AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 20:27:37 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 21:36 UTC · original

Checked 8bcb343 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). I tested the PR head as it is against main b581f7e, and it also merges cleanly onto main.

list:: passes 5/5 on both sides, plain and with --features diagnostics + VICTORY_D3D12_DEBUG=1, on the card and on WARP. The full lib run matches main. The only failures are the ones already failing natively on main (the two indirect::tests::host_list_* and the two pipeline::host library loads) plus the flaky watch test. Clippy shows no new warnings with or without diagnostics, and the diagnostics build compiles.

I also ran a throwaway test (not pushed) on both sides with the debug layer, card and WARP. It captures the slice that goes to ResourceBarrier.

  • Direct barrier() calls with 0 to 40 entries, with dropped entries mixed in and with or without a buffer transition (which adds the trailing UAV). Same order as expected on both sides, including 16, 17 and the spill caused by the trailing UAV, with no debug layer errors.
  • Three thin recordings on one back list, 3000 draws, 1000 dispatches and 60 barrier calls each. Between rounds they're detached and recycled into the idle pool, so the next round records into the recycled list. take_counts() is (3000, 1000) every round, the barrier slices match, and thin STATS read 12186 calls and 3 lists on both sides.

On the four points

  1. VALUE_WAITS. The only push is in wait_for under cfg(not(windows)) (main list.rs:2261), and Windows goes to cut(). The only other use is the retain in reset (main list.rs:699). Nothing pushes or reads it on Windows, so gating both is fine. I couldn't build a non-Windows target here.
  2. Barriers. Barrier is a plain Copy struct holding borrowed raw pointers, so there's no refcount involved. The array starts filled with UAV_BARRIER and only stack[..len] is read, so there are no uninitialized reads. The spill copies the first 16 in order. One small thing is that buffer_bytes now runs on every barrier instead of stopping at the first buffer, which is cheap. In state::targets, the one-range path now caps at 8 handles where main didn't, which is fine for D3D12. set_targets still allocates its own Vecs per call (draw.rs:1404), so that call still allocates.
  3. CountBatch. It flushes in Drop, so unwinding is covered too. That happens before done is set, so whoever waits on the recording sees the counts. It's a const thread-local with no destructor, so nothing is pending at thread exit, and the totals match main. Thin STATS are now added when run runs out of chunks, after done, so they can slip into the next frame-rate line. That's cosmetic.
  4. borrow_recording. This is a behaviour change rather than pure perf. It came in as the opt-in switch VICTORY_BORROW_RECORDING, off by default (ca97da2), and became a hard false when the switches went (2773fdf). With it on, the back list has no host list after detach, and the next RESET takes one from the idle pool. I found no use-after-reuse. Streams always start with RESET, Recording::drop only calls close, which is a no-op without a host, and a re-submit gets an empty closed list either way. One difference is that if fresh_list() fails, main just leaves that list out of the submission, while here reset calls crate::host::fail. Lists weren't run through a real queue, so it may be worth checking with the maintainer that flipping the old default is intended.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 21:36 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/511#issuecomment-7424904174) Checked 8bcb343 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). I tested the PR head as it is against main b581f7e, and it also merges cleanly onto main. `list::` passes 5/5 on both sides, plain and with `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, on the card and on WARP. The full lib run matches main. The only failures are the ones already failing natively on main (the two `indirect::tests::host_list_*` and the two `pipeline::host` library loads) plus the flaky watch test. Clippy shows no new warnings with or without diagnostics, and the diagnostics build compiles. I also ran a throwaway test (not pushed) on both sides with the debug layer, card and WARP. It captures the slice that goes to `ResourceBarrier`. - Direct `barrier()` calls with 0 to 40 entries, with dropped entries mixed in and with or without a buffer transition (which adds the trailing UAV). Same order as expected on both sides, including 16, 17 and the spill caused by the trailing UAV, with no debug layer errors. - Three thin recordings on one back list, 3000 draws, 1000 dispatches and 60 barrier calls each. Between rounds they're detached and recycled into the idle pool, so the next round records into the recycled list. `take_counts()` is (3000, 1000) every round, the barrier slices match, and thin STATS read 12186 calls and 3 lists on both sides. On the four points 1. VALUE_WAITS. The only push is in `wait_for` under `cfg(not(windows))` (main list.rs:2261), and Windows goes to `cut()`. The only other use is the `retain` in `reset` (main list.rs:699). Nothing pushes or reads it on Windows, so gating both is fine. I couldn't build a non-Windows target here. 2. Barriers. `Barrier` is a plain `Copy` struct holding borrowed raw pointers, so there's no refcount involved. The array starts filled with `UAV_BARRIER` and only `stack[..len]` is read, so there are no uninitialized reads. The spill copies the first 16 in order. One small thing is that `buffer_bytes` now runs on every barrier instead of stopping at the first buffer, which is cheap. In `state::targets`, the one-range path now caps at 8 handles where main didn't, which is fine for D3D12. `set_targets` still allocates its own Vecs per call (draw.rs:1404), so that call still allocates. 3. CountBatch. It flushes in `Drop`, so unwinding is covered too. That happens before `done` is set, so whoever waits on the recording sees the counts. It's a const thread-local with no destructor, so nothing is pending at thread exit, and the totals match main. Thin STATS are now added when `run` runs out of chunks, after `done`, so they can slip into the next frame-rate line. That's cosmetic. 4. borrow_recording. This is a behaviour change rather than pure perf. It came in as the opt-in switch `VICTORY_BORROW_RECORDING`, off by default (ca97da2), and became a hard false when the switches went (2773fdf). With it on, the back list has no host list after detach, and the next RESET takes one from the idle pool. I found no use-after-reuse. Streams always start with RESET, `Recording::drop` only calls `close`, which is a no-op without a host, and a re-submit gets an empty closed list either way. One difference is that if `fresh_list()` fails, main just leaves that list out of the submission, while here `reset` calls `crate::host::fail`. Lists weren't run through a real queue, so it may be worth checking with the maintainer that flipping the old default is intended. AI-assisted: yes
github-bot changed title from perf(gpu): batch list counters, use stack arrays, and borrow thin recordings to perf(gpu): batch list counters and use stack arrays in barrier/targets 2026-12-05 00:05:49 +00:00
github-bot force-pushed github-bot/gh-511 from 8bcb343e72 to 502f4219b5 2026-12-05 00:05:50 +00:00 Compare
Author
Owner

@⁠Not4Eric on GitHub · 2026-12-05 00:00 UTC · original

Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this

Pushed updates addressing your review:

  • Reverted back.borrow_recording = true back to false in list/thin.rs to keep this PR purely performance-focused without changing the opt-in recording-borrow behaviour, and updated the PR title/description.
  • Short-circuited the buf_uav check inside list::barrier().
**@⁠Not4Eric** on GitHub · 2026-12-05 00:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/511#issuecomment-7427750300) Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this Pushed updates addressing your review: - Reverted `back.borrow_recording = true` back to `false` in `list/thin.rs` to keep this PR purely performance-focused without changing the opt-in recording-borrow behaviour, and updated the PR title/description. - Short-circuited the `buf_uav` check inside `list::barrier()`.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 00:59 UTC · original

Re-checked 502f421 on native Windows (didn't run the game).

borrow_recording is back to false in list/thin.rs:323, so thin.rs matches main there and the fresh_list() failure path in reset (list.rs:717) is only reachable with the opt-in again, same as main. The buf_uav check at list.rs:848-853 now stops calling buffer_bytes once it's set. list:: passes 5/5, the full lib run shows only the four failures main already has natively plus the flaky watch test, clippy has nothing new with or without diagnostics, and it still merges cleanly onto current main. The 8-handle cap and the set_targets allocation were only side notes, fine as they are.

If you touch it again, rustfmt wants the let host: &[Barrier] = if ... line at list.rs:863 split over several lines. It was already like that before the amend.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 00:59 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/511#issuecomment-7428826524) Re-checked 502f421 on native Windows (didn't run the game). borrow_recording is back to false in list/thin.rs:323, so thin.rs matches main there and the fresh_list() failure path in reset (list.rs:717) is only reachable with the opt-in again, same as main. The buf_uav check at list.rs:848-853 now stops calling buffer_bytes once it's set. list:: passes 5/5, the full lib run shows only the four failures main already has natively plus the flaky watch test, clippy has nothing new with or without diagnostics, and it still merges cleanly onto current main. The 8-handle cap and the set_targets allocation were only side notes, fine as they are. If you touch it again, rustfmt wants the `let host: &[Barrier] = if ...` line at list.rs:863 split over several lines. It was already like that before the amend. AI-assisted: yes
github-bot force-pushed github-bot/gh-511 from 502f4219b5 to 8c2bd6443a 2026-12-05 11:46:02 +00:00 Compare
github manually merged commit 49f5f9e8fb into main 2026-12-05 17:38:41 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.