Skip to content

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

Open
danielibabet wants to merge 1 commit into
Marvisak:mainfrom
danielibabet:pr/perf-copyback-heaps-indirect
Open

danielibabet wants to merge 1 commit into
Marvisak:mainfrom
danielibabet:pr/perf-copyback-heaps-indirect

Conversation

@danielibabet

Copy link
Copy Markdown

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 <andrewpozdnakov7-jpg@users.noreply.github.com> if folding it into another commit. AI-assisted with Codex.

@danielibabet

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants