GPU: scope indirect clamp UAV barriers and skip zero-record clamps #2168
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2168
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2168"
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?
@RVZO6 on GitHub · 2026-11-25 06:50 UTC · original
RVZO6:rvzo/indirect-barriers→main· +146 −17 · 3 files · 1 commits · openSummary
Replaces both global NULL-resource UAV barriers in
crates/victory-gpu/src/indirect.rs(indirect::bound) with targeted resource barriers and skips emptymax == 0indirect calls early inState::execute_indirect(draw.rs):indirect.rs,host.rs):uav_barrier()(pResource = None) withuav_barrier_for(args_res)(plusuav_barrier_for(count_res)when a distinctcountbuffer is passed).uav_barrier()withuav_barrier_for(budget_res)alongside the existingoutUNORDERED_ACCESS -> INDIRECT_ARGUMENTtransition (returning(&ID3D12Resource, u64)fromHostList::budget()).draw.rs,indirect.rs):State::execute_indirectreturns early whenmax == 0, skipping buffer refresh, clamp dispatch, barriers, and pipeline state invalidation.indirect::boundpreserves balancedCOMMON -> INDIRECT_ARGUMENTtransitions when called directly withrecords == 0(skipping dispatch and UAV barriers).Tests & Verification
indirect::tests::scoped_uav_barriers_and_zero_record_skipverifying thatbound()emits targeted UAV barriers onargs, distinctcount, andlist.budget()(neverNULL), skips dispatch/UAV barriers onrecords == 0, and replays cleanly under sequential submissions.windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtaskpolicy 6/6,victory-gpu+victory-shaderall green): https://github.com/RVZO6/VIctory/actions/runs/45662428628AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@nathanbzrr on GitHub · 2026-11-25 08:40 UTC · original
Verified head
8e87a3971103c930de1ce33663ae8a966a269c7amerged ontomain(940d32f69b) on Windows 11 x64 / AMD Radeon RX 7600 & WARP:--features diagnostics+VICTORY_D3D12_DEBUG=1:indirect::tests9 passed, 0 failed (RX 7600 & WARP);draw::tests5 passed, 0 failed (RX 7600).Live D3D12 Debug Layer error on distinct
countbuffer (indirect.rs:234, 274-278, 290-300):bound()emits onlyuav_barrier_for(count)on a distinctcountbuffer (count != buffer) and never transitions itUNORDERED_ACCESS -> INDIRECT_ARGUMENTor back indone().Running a synthetic test (
bound(&list, &count, ...)+doneto leavecountinUNORDERED_ACCESS, thenbound(&list, &args, Some(&count), ...)+ExecuteIndirect(..., Some(&count), 0)submitted on a direct queue with--features diagnosticsandVICTORY_D3D12_DEBUG=1) failed identically on both RX 7600 and WARP:Source-level UAV race on
budgetacross repeated list execution (host.rs:959, 1742,indirect.rs:177, 274-278):Host::executeallows the sameHostListto be executed twice in oneExecuteCommandLists(&[list, list])batch. Because PR #2168 removes the post-clamp UAV barrier and emitsuav_barrier_for(budget)only whenbudget_written == true(never on the list's first clamp), the final clamp of execution 1 writesbudgetwithout a trailing barrier and execution 2's first clamp reads/writesbudgetimmediately without a leading barrier.(Proposed / uncompiled fix direction:) bind distinct
countasu2in the clamp CS (Load(0)promotesCOMMON -> UNORDERED_ACCESS), transition/restore bothbufferand distinctcountUNORDERED_ACCESS <-> INDIRECT_ARGUMENT(and aligncapture.rs), and bundleuav_barrier_for(budget_res)into the post-clampResourceBarrier(&[...])batch alongsidetransition(buffer)(same API call count, removesbudget_written).AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@MamaLeVrai on GitHub · 2026-11-25 08:52 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head
8e87a397intomain940d32fin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with--all-features: clean.cargo test --workspace --locked: 705 passed, 0 failed, 10 ignored, two runs (mainalone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
@RVZO6 on GitHub · 2026-11-25 09:19 UTC · original
Thanks @nathanbzrr for the RX 7600 +
VICTORY_D3D12_DEBUG=1audit — both defects are fixed incd29144:countbuffer state (indirect.rs,draw.rs,capture.rs):countbuffers asu2(count_buf) in the clamp compute shader (promoting a freshCOMMONcount buffer toUNORDERED_ACCESSand bounding clamping tomin(records, count_buf.Load(0))).bound()now transitions bothargsand any distinctcountbufferUNORDERED_ACCESS -> INDIRECT_ARGUMENT,done()restores bothINDIRECT_ARGUMENT -> UNORDERED_ACCESS, andcapture::read_indirecttransitions a distinctcountbuffer fromINDIRECT_ARGUMENTinstead ofUNORDERED_ACCESS.budgetUAV barrier (indirect.rs,host.rs):uav_barrier_for(budget_res)into the post-clampResourceBarrierbatch alongside the transitions (same single API call, removedbudget_writtentracking) so repeated executions of the sameHostListstay synchronized.indirect::tests::distinct_count_buffer_transitions_for_execute_indirect_and_restorescovering both acountbuffer already inUNORDERED_ACCESSand a freshCOMMONcountbuffer withExecuteIndirect, plus repeatedhost.execute(&[&list, &list]).Verified on fork
windows-latestMSVC + Windows WARP SM 6.6 CI (Run45581807630): bothclippy -D warningsbuilds clean,716 passed; 0 failed; 10 ignored,xtask6/6.AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@Marvisak on GitHub · 2026-11-25 13:27 UTC · original · edited 2026-11-25 18:26 UTC
Automated triage for the maintainers.
Needs work. The rebased change looks sound as far as I can read it. In
indirect::bound, the global UAV barrier before the clamp now targetsargs(plus a separatecountbuffer). After the clamp it targets the list's budget buffer, and theUNORDERED_ACCESS -> INDIRECT_ARGUMENTtransition onoutstill waits for the clamp to finish. Title shader writes to argument buffers go to the same host copies (crate::shadow,crate::memory), so the scoped barrier covers them. Before this can be a merge candidate, it needs:indirect_budget_dirty,BarrierPlan::for_call,Clamped::Skippedand four tests. None of these is in the current head, which has one test,scoped_uav_barriers_and_zero_record_skip.records == 0branch inindirect::bound.State::execute_indirectnow returns early whenmax == 0, so that branch is reached only from the test. Either drop it, or say which caller needs it. Also,mainalready ran no clamp work for zero records (Dispatch(records.min(1), ..)).CI: the
checkrun passed on the current head.Generated by Claude Code
@r4tedx on GitHub · 2026-11-25 13:40 UTC · original
Tested
cd29144with a change stacked on it (batched clamps, r4tedx/VIctorygpu/batched-clamps-upstream), on WARP withVICTORY_D3D12_DEBUG=1and the debug layer's messages printed.distinct_count_buffer_transitions_for_execute_indirect_and_restoresraises this forhost.execute(&[&list, &list]):D3D12 doesn't let one command list run again before its previous execution has finished, and that includes twice in the same call. So the second run of the list may not exercise the restore path the test means to check; the test still passes. Executing two separately recorded lists, or the same list in two calls with a wait between them, would test it as intended.
The other
indirect::tests passed on WARP (15 passed, 1 ignored). The title was not used in these tests.AI-assisted
@RVZO6 on GitHub · 2026-11-25 17:20 UTC · original
Rebased onto current
main(13f91ca, head0f616ae) on top of315cea1's list-owned argument buffer design (now 146 insertions / 17 deletions acrossindirect.rs,draw.rs,host.rs, nocapture.rschanges needed):indirect::bound()with targeted UAV barriers onargs(and any distinctcountbuffer) pre-clamp andlist.budget()post-clamp.records == 0(keepingout'sCOMMON -> INDIRECT_ARGUMENT -> COMMONtransitions balanced ifbound()is called directly).VICTORY_D3D12_DEBUG=1catch on simultaneous list re-submission:scoped_uav_barriers_and_zero_record_skipnow submits sequentially after completion and verifies UAV barrier targets + transition replay.Verified green on
windows-latestMSVC + WARP SM 6.6 CI (Run 45662428628).@DenRakEiw on GitHub · 2026-11-25 07:03 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib indirect::— 9 passed, 0 failed on RTX 5090cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean scoping of indirect clamp UAV barriers and skipping of zero-record clamps. Looks good.
AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 07:17 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Indirect clamp UAV barriers scoped + zero-record skips — barrier-scope tightening; perf fix.
@neonbyte1 on GitHub · 2026-11-26 11:48 UTC · original
An in-game data point for this idea, from an RTX 5090 (driver 620.73.04) under Wine with vkd3d-proton (GE-Proton11-14), in GTA VI's lit prison-yard scene, warm runs, 10 minutes each.
I tested my own prototype of the same change, not this PR's code, behind a switch so both modes ran from one build:
UAV → INDIRECT_ARGUMENTtransition already orders the write;INDIRECT_ARGUMENTbetween clamps, instead of returning toCOMMONafter every execution.That removes about 20,000 of the ~25,000 clamp barrier entries per frame (~4,900 indirect executions per frame in this scene). The result:
So no measurable gain here. The difference between the two "on" runs is as large as the gap between "on" and "off". There were no device removals and indirect drops were unchanged (~50 per frame). My guess is that vkd3d-proton already merges or elides most of those barriers when translating to Vulkan, but I haven't verified that. A stamp-per-clamp probe had suggested up to ~99 ms/frame, but the probe's own timestamps inflated that.
None of this argues against the change on correctness grounds, and native Windows drivers may behave differently. I just wouldn't expect a frame-time win from it on NVIDIA under Proton.
AI-assisted (Claude); measured on my machine, no game data shared.
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.