GPU: back indirect arguments in VRAM, use RwLock for SHADER_HEAPS, and batch copy_back_marks #3320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3320"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T17:42:04Z.
Summary
Three independent CPU/GPU contention and barrier fixes on top of
main:indirect.rs,host.rs)Host::uav_buffer(D3D12_HEAP_TYPE_DEFAULT,ALLOW_UNORDERED_ACCESS,COMMON) and backHostList::argumentsin VRAM instead ofL0system memory (shared_buffer), avoiding PCIe round-trips for bothclampUAV stores andExecuteIndirectreads.uav_barrier()(pResource = None) right before transitioningoutfromUNORDERED_ACCESStoINDIRECT_ARGUMENTinindirect::bound(the resource transition already synchronizesout, and the nextboundcall issues the pre-dispatchuav_barrier()forbudget).indirect::tests::clampedandargument_buffers_move_from_their_current_statesto read backoutviareadback.SHADER_HEAPSmutex contention during descriptor mirroring (descriptor.rs)SHADER_HEAPSfromMutextoRwLock:mirror(title threads),sync_heaps(submission thread), and all read-only queries take.read(), whileDropandcreatetake.write(), sosync_heapsno longer stalls title threads writing descriptors (MirrorWaitUs).Tracked::takenincopy_back_marks(shadow.rs)pooled(PAGE)scratch buffer across all marked pages incopy_back_marksinstead of heap-allocating and zeroingvec![0u8; n]per 64 KiB page.t.taken(&list)once perShadowinstead of callingVirtualProtect/ taking theGUARDSlock 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 outcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warningscargo run -p xtask --locked -- policy:asset policy: 191 files okImported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:48:34Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
CopyBufferRegionreadback in tests), switchingSHADER_HEAPStoRwLock, and reusingtitle_buf+ batchingt.taken(&synced)incopy_back_marksare 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).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T17:54:10Z.
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
6be1c86keeps 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=0and1. 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.Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T18:20:26Z.
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.
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T19:03:34Z.
Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head
332461e: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
Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T19:06:12Z.
Thanks @borosf for verifying on Intel Arc B580!
Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-26T20:44:55Z.
A data point on the
SHADER_HEAPSRwLockchange, measured on one Windows machine (RTX 3080 Ti, Ryzen 7 5700X) running a commercial title:We tried the same idea on our branch:
SHADER_HEAPSas anRwLock, with readers taking a shared lock.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).
Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-11-26T21:19:48Z.
Thanks for sharing those real-title numbers @Machad3x! Moving contention into per-heap sync and regressing frame time (309-321 ms -> 408-445 ms) is definitely not worth keeping.
I've reverted the
SHADER_HEAPSRwLockchange from this PR in3afe123(descriptor.rsback tomain), leaving just the VRAM-backed indirect argument buffers and batchedcopy_back_marks(verified withcargo clippy -p victory-gpu --all-targets -- -D warningsandcargo xtask policy— 191 files ok).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:00:32Z.
Review: APPROVED
Clean, focused change now that the
SHADER_HEAPSRwLockedit has been reverted in3afe123b.Checked both remaining parts:
HostList::argumentswith aDEFAULT-heap UAV buffer (crates/victory-gpu/src/host.rs:2252, 2715) and dropping the redundant post-clampuav_barrier()before theUNORDERED_ACCESS -> INDIRECT_ARGUMENTtransition (crates/victory-gpu/src/indirect.rs:232-236):boundstill opens with[uav_barrier(), COMMON -> UNORDERED_ACCESS](ordering both earlier title UAV writes and previousbudgetwrites), the explicit transition synchronizesoutforExecuteIndirectandcapture::read_indirect, anddone()transitionsoutback toCOMMON.pooled(PAGE)scratch buffer and batchingt.taken(&list)perShadowincopy_back_marks(crates/victory-gpu/src/shadow.rs:491, 949-986) matchescopy_back_or_not's batching model and keepstitle_buf[..n]withinPAGE.Verification on
origin/main(63bcca43):cargo xtask policy: ok (191 files ok)cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): cleancargo test --locked -p victory-gpu --features diagnostics -- indirect:: shadow:: capture:: --test-threads=1withVICTORY_D3D12_DEBUG=1: 27/27 passed on RTX 5090 and 27/27 passed on WARPindirect::bound->capture::read_indirect->indirect::donecycles on the sameDEFAULT-heap arguments buffer underVICTORY_D3D12_DEBUG=1: zero debug layer errors on both RTX 5090 and WARP.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T22:02:04Z.
I retested the integration with your
3afe123lock rollback in6229e40. In the combined tree,descriptor.rsis byte-for-byte identical to main. The default-heap argument buffer, shared clamp state, mesh flattening and batch copy-back changes are still present.On app-local WARP, all 15 indirect tests and the 24-group mesh readback passed with
VICTORY_CLAMP_WINDOW=0and1. The full GPU suite reported 259 passed and one ignored under each setting. Strict GPU Clippy in both configurations and the asset policy check passed. These results verify the buffer and draw behavior on a synthetic workload. The real-title frame times are from @Machad3x's measurement above.@danielibabet, this updates the previous combined branch if #3307 lands first. Please keep the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if you fold the resolution into another commit.Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T07:05:52Z.
Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is
mainplus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).Merged here as its current head
3afe123breduced to the part that still applies on this stack: indirect arguments in VRAM plus the dropped post-clamp UAV barrier (the copy-back third overlaps #3246/#3341, and theRwLockpart was withdrawn).No gain here. Two test regressions on the GPU (vkd3d-proton, RTX 5090), both passing on the base:
indirect::tests::clamped_records_hold_every_word(indirect.rs:838) andindirect::tests::spread_records_split_large_x_and_keep_small_unspread(:1074) fail withMap→0x80070057. The argument buffer moved to a DEFAULT heap (Host::uav_buffer), and these two tests still map it directly; a third site,read_words(out, …)at:1396inhoisted_transitions…, has the same pattern but is masked by an unrelated failure. They need the read-back copy the PR already uses elsewhere. Test-only: no production path maps an argument buffer.AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T08:29:13Z.
Thanks @neonbyte1. I checked the named tests against upstream
63bcca4, #33203afe123, #3307f23c88fand our published combination. None of those trees contains the three test functions from your report. The two readbacks in #3320 itself already use the copy to a readback heap.Could you link the commit or branch that adds
clamped_records_hold_every_wordandspread_records_split_large_x_and_keep_small_unspread? The test-source commit is enough. That will give us a base for a test-only follow-up using the existing readback path.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T11:53:59Z.
One concern with the
copy_back_marksbatching at head3afe123b(read from the code, not run).A title write can be lost between a page's copy-back and its batched
taken.shadow.rs:525-530: whencopy_back_markedwrites page P back, it holdswatch::writing(from, n).Drop for Writing(watch.rs:786-793) callschanged(), which marks P changed and gives it write access back. The page is then only pushed ontosynced.shadow.rs:959-971/:980-985:t.taken(&list)runs only when the loop reaches a page of anotherShadow, or at the end.taken(watch.rs:545-560) protects the pages and then doeschanged.remove(&page)andself.changed.taken(page).Scenario: P is copied back and left open. The loop goes on to P+1 … P+k of the same
Shadow. Each of those costs a 64 KiBread_into, a compare or merge, maybe awrite_mapped, and two guard-lock rounds. Meanwhile a title thread writes P. P is open, so there is no fault and the write isn't recorded anywhere. Thentaken([P, …])clears P's changed mark. The host copy keeps the shaders' bytes and never picks up the title's write. Nothing re-marks it later, because the page is guarded again and clean.mainhas the same race. There, though,takenruns right after each page's write, so the window is a few microseconds. Here it lasts as long as the rest of thatShadow's marked pages take, which can be thousands of pages per frame on the scenes in #3425.Possible fixes, keeping most of the gain:
t.taken(&[page])right away for pages wherewritten.is_some(), and batch only the pages that were already equal (those were never opened, so there is no window).Writingguards until the batchedtaken, so P stays inbusyand a title write is seen throughchanged. This needs checking againstprotect'sbusyfilter, which would then skip P.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by danielibabet on 2026-12-01T09:33:08Z.
Thanks @KainanP — great catch!
Pushed
352164fto pr/perf-copyback-heaps-indirect:View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.