GPU: back indirect arguments in VRAM, use RwLock for SHADER_HEAPS, and batch copy_back_marks #3320

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

@⁠danielibabet on GitHub · 2026-11-26 17:42 UTC · original
danielibabet:pr/perf-copyback-heaps-indirect → main · +99 −32 · 4 files · 1 commits · open

Summary

Three independent CPU/GPU contention and barrier fixes on top of main:

  1. VRAM-backed indirect argument buffers + drop redundant post-clamp UAV barrier (indirect.rs, host.rs)
    • Add Host::uav_buffer (D3D12_HEAP_TYPE_DEFAULT, ALLOW_UNORDERED_ACCESS, COMMON) and back HostList::arguments in VRAM instead of L0 system memory (shared_buffer), avoiding PCIe round-trips for both clamp UAV stores and ExecuteIndirect reads.
    • Remove the redundant uav_barrier() (pResource = None) right before transitioning out from UNORDERED_ACCESS to INDIRECT_ARGUMENT in indirect::bound (the resource transition already synchronizes out, and the next bound call issues the pre-dispatch uav_barrier() for budget).
    • Update indirect::tests::clamped and argument_buffers_move_from_their_current_states to read back out via readback.
  2. Eliminate SHADER_HEAPS mutex contention during descriptor mirroring (descriptor.rs)
    • Switch SHADER_HEAPS from Mutex to RwLock: mirror (title threads), sync_heaps (submission thread), and all read-only queries take .read(), while Drop and create take .write(), so sync_heaps no longer stalls title threads writing descriptors (MirrorWaitUs).
  3. Reuse scratch buffer and batch Tracked::taken in copy_back_marks (shadow.rs)
    • Reuse a single pooled(PAGE) scratch buffer across all marked pages in copy_back_marks instead of heap-allocating and zeroing vec![0u8; n] per 64 KiB page.
    • Batch t.taken(&list) once per Shadow instead of calling VirtualProtect / taking the GUARDS lock page by page.

Verification

  • cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views: 229 passed; 0 failed; 1 ignored; 2 filtered out
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings
  • cargo run -p xtask --locked -- policy: asset policy: 191 files ok
**@⁠danielibabet** on GitHub · 2026-11-26 17:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320) `danielibabet:pr/perf-copyback-heaps-indirect` → `main` · +99 −32 · 4 files · 1 commits · open ### Summary Three independent CPU/GPU contention and barrier fixes on top of `main`: 1. **VRAM-backed indirect argument buffers + drop redundant post-clamp UAV barrier (`indirect.rs`, `host.rs`)** - Add `Host::uav_buffer` (`D3D12_HEAP_TYPE_DEFAULT`, `ALLOW_UNORDERED_ACCESS`, `COMMON`) and back `HostList::arguments` in VRAM instead of `L0` system memory (`shared_buffer`), avoiding PCIe round-trips for both `clamp` UAV stores and `ExecuteIndirect` reads. - Remove the redundant `uav_barrier()` (`pResource = None`) right before transitioning `out` from `UNORDERED_ACCESS` to `INDIRECT_ARGUMENT` in `indirect::bound` (the resource transition already synchronizes `out`, and the next `bound` call issues the pre-dispatch `uav_barrier()` for `budget`). - Update `indirect::tests::clamped` and `argument_buffers_move_from_their_current_states` to read back `out` via `readback`. 2. **Eliminate `SHADER_HEAPS` mutex contention during descriptor mirroring (`descriptor.rs`)** - Switch `SHADER_HEAPS` from `Mutex` to `RwLock`: `mirror` (title threads), `sync_heaps` (submission thread), and all read-only queries take `.read()`, while `Drop` and `create` take `.write()`, so `sync_heaps` no longer stalls title threads writing descriptors (`MirrorWaitUs`). 3. **Reuse scratch buffer and batch `Tracked::taken` in `copy_back_marks` (`shadow.rs`)** - Reuse a single `pooled(PAGE)` scratch buffer across all marked pages in `copy_back_marks` instead of heap-allocating and zeroing `vec![0u8; n]` per 64 KiB page. - Batch `t.taken(&list)` once per `Shadow` instead of calling `VirtualProtect` / taking the `GUARDS` lock page by page. ### Verification - `cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views`: `229 passed; 0 failed; 1 ignored; 2 filtered out` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings - `cargo run -p xtask --locked -- policy`: `asset policy: 191 files ok`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:42:53 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 17:48 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Backing indirect argument buffers in VRAM (with CopyBufferRegion readback in tests), switching SHADER_HEAPS to RwLock, and reusing title_buf + batching t.taken(&synced) in copy_back_marks are clean and sound.
  • cargo test -p victory-gpu --lib indirect:: -- --test-threads=1 (RTX 5090): 6 passed, 0 failed.
  • cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released (RTX 5090): 21 passed, 0 failed.
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1 (RTX 5090): 10 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 17:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320#pullrequestreview-6078605074) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Backing indirect argument buffers in VRAM (with `CopyBufferRegion` readback in tests), switching `SHADER_HEAPS` to `RwLock`, and reusing `title_buf` + batching `t.taken(&synced)` in `copy_back_marks` are clean and sound. - `cargo test -p victory-gpu --lib indirect:: -- --test-threads=1` (RTX 5090): 6 passed, 0 failed. - `cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released` (RTX 5090): 21 passed, 0 failed. - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1` (RTX 5090): 10 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 17:54 UTC · original

I checked the DEFAULT-heap argument buffers with the #3307 + #3197 + #2996 composition. They conflict in allocation and in tests that directly mapped the argument buffer. Exact integration 6be1c86 keeps the DEFAULT heap, cached width and shared argument state, and uses a real readback copy for those tests.

Verified app-local Agility 1.620.2/WARP 1.0.22 passed all 15 indirect tests. The mixed test alternates window and single clamps in one list, grows the buffer with 6,000 records, checks the output, and replays transitions back to COMMON. The translated 24-group mesh test and full GPU diagnostics (259 passed, 0 failed, 1 ignored) passed with VICTORY_CLAMP_WINDOW=0 and 1. Strict GPU Clippy passed with default and all features. Asset policy passed. This verifies DEFAULT-heap behavior on WARP. Discrete-GPU placement and PCIe timing still need a hardware run.

@⁠danielibabet the integration is available if #3307 lands first. Please retain its Git author if using the resolution, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit. AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7199825808) I checked the DEFAULT-heap argument buffers with the [#3307 + #3197 + #2996 composition](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3307). They conflict in allocation and in tests that directly mapped the argument buffer. [Exact integration `6be1c86`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6be1c86e642c281375cd13908a5f6376dc9b097c) keeps the DEFAULT heap, cached width and shared argument state, and uses a real readback copy for those tests. Verified app-local Agility 1.620.2/WARP 1.0.22 passed all 15 indirect tests. The mixed test alternates window and single clamps in one list, grows the buffer with 6,000 records, checks the output, and replays transitions back to COMMON. The translated 24-group mesh test and full GPU diagnostics (259 passed, 0 failed, 1 ignored) passed with `VICTORY_CLAMP_WINDOW=0` and `1`. Strict GPU Clippy passed with default and all features. Asset policy passed. This verifies DEFAULT-heap behavior on WARP. Discrete-GPU placement and PCIe timing still need a hardware run. @⁠danielibabet the integration is available if #3307 lands first. Please retain its Git author if using the resolution, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with Codex.
Author
Owner

@⁠danielibabet on GitHub · 2026-11-26 18:20 UTC · original

Thanks @⁠andrewpozdnakov7-jpg for verifying against #3307 + #3197 + #2996 and preparing the integration (\6be1c86)! If #3307 lands before #3320, we'll rebase #3320 onto it and make sure to preserve your Git authorship / \Co-authored-by.

**@⁠danielibabet** on GitHub · 2026-11-26 18:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7200343489) Thanks @⁠andrewpozdnakov7-jpg for verifying against #3307 + #3197 + #2996 and preparing the integration (\6be1c86\)! If #3307 lands before #3320, we'll rebase #3320 onto it and make sure to preserve your Git authorship / \Co-authored-by\.
Author
Owner

@⁠borosf on GitHub · 2026-11-26 19:03 UTC · original

Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head 332461e:

cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings
cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings

Result: victory-gpu lib: 2 known baseline failures; the waits_end_on_ticks timing test is flaky under load (this PR does not touch frame.rs).

Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.

Synthetic tests only; no game data used. Full log kept locally. — borosf

**@⁠borosf** on GitHub · 2026-11-26 19:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7201150665) Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head `332461e`: ``` cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1 cargo clippy -p victory-gpu --all-targets --locked -- -D warnings cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings ``` Result: victory-gpu lib: 2 known baseline failures; the waits_end_on_ticks timing test is flaky under load (this PR does not touch frame.rs). Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions. Synthetic tests only; no game data used. Full log kept locally. — borosf
Author
Owner

@⁠Machad3x on GitHub · 2026-11-26 20:44 UTC · original

A data point on the SHADER_HEAPS RwLock change, measured on one Windows machine (RTX 3080 Ti, Ryzen 7 5700X) running a commercial title:

We tried the same idea on our branch: SHADER_HEAPS as an RwLock, with readers taking a shared lock.

Metric (per measurement window) Mutex RwLock
Wait on view writes 209 ms 0 ms
Heap sync time 43 ms 160 ms
Frame time 309-321 ms 408-445 ms

So we dropped it. Our reading: the contention moved into the per-heap sync instead of disappearing, and frame time got worse overall.

We are now testing per-slot locks (64 striped locks, atomic "made" keys with a busy sentinel) together with the RwLock, and will report numbers.

This work was done with AI assistance (Claude).

**@⁠Machad3x** on GitHub · 2026-11-26 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3320#issuecomment-7203032199) A data point on the `SHADER_HEAPS` `RwLock` change, measured on one Windows machine (RTX 3080 Ti, Ryzen 7 5700X) running a commercial title: We tried the same idea on our branch: `SHADER_HEAPS` as an `RwLock`, with readers taking a shared lock. | Metric (per measurement window) | Mutex | RwLock | |---|---|---| | Wait on view writes | 209 ms | 0 ms | | Heap sync time | 43 ms | 160 ms | | Frame time | 309-321 ms | 408-445 ms | So we dropped it. Our reading: the contention moved into the per-heap sync instead of disappearing, and frame time got worse overall. We are now testing per-slot locks (64 striped locks, atomic "made" keys with a busy sentinel) together with the `RwLock`, and will report numbers. This work was done with AI assistance (Claude).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3320'
git switch 'github-bot/gh-3320'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3320'
git switch 'github-bot/gh-3320'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3320'
git switch 'main'
git merge --squash 'github-bot/gh-3320'
git switch 'main'
git merge --ff-only 'github-bot/gh-3320'
git switch 'main'
git merge 'github-bot/gh-3320'
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!3320
No description provided.