GPU: argument clamp with enhanced barriers (VICTORY_NARROW_WAITS, opt-in) #139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/139"
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 Zettrox/ztrx. Originally posted by ROZEREX on 2026-11-25T13:55:31Z.
Every indirect call clamps its record in a compute pass between two legacy UAV barriers on all resources. Those drain all earlier work, pixel shading included; the world frame makes ~5,000–6,400 such calls (~20 µs each on the card in GPU timing runs).
With
VICTORY_NARROW_WAITS=1(only where OPTIONS12 reports enhanced barriers; off by default):The title's own barriers are unchanged.
Measured (RTX 3090 24 GB, driver 621.40, i7-14700K, Windows 11 24H2, prison yard):
VICTORY_GPU_TIMING): 190 → 134 ms/frameVICTORY_RELAY=2 VICTORY_WIDE_MERGE=1 VICTORY_WIDE_BACK=1)VICTORY_D3D12_DEBUG=1) reports nothingTests:
cargo test -p victory-gpu --release indirect: 7 passed.Not tested: other GPUs (AMD, older NVIDIA).
AI use: written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code
Imported from Zettrox/ztrx. Originally posted by chenzhehao1129-eng on 2026-11-25T14:21:37Z.
Independent measurement on a second GPU, which supports the diagnosis (and says which half of the pair costs the time).
Machine: Windows 11 10.0.26100, Ryzen 9 9900X, 61.5 GB, RTX 4070 Ti SUPER 16 GB, driver 32.0.15.8097, diagnostics build,
VICTORY_RELAY=2, title 1.0.2.1 (Series X), prison cell scene, ~4,930 draws a frame.How many clamps: the existing counter in the frame line gives 5,283 / 5,167 / 5,127 indirect commands bounded per frame over three consecutive lines — the same 5,000-6,400 range you report.
Which part costs it.
VICTORY_BARRIER_TEST=indirectalready drops the two waits for earlier shader writes around each clamp and keeps the legacy state transitions:So the two "wait for every earlier shader write" barriers are only ~7% of it. The cost is in what the narrow version also removes: the legacy
COMMON -> UNORDERED_ACCESSandUNORDERED_ACCESS -> INDIRECT_ARGUMENTtransitions per clamp, which drain pixel shading as well. That matches your 190 -> 134 ms: the win is not dropping a wait, it is not doing a full transition twice per record.Two things worth adding to the report if you redo it:
done()(crates/victory-gpu/src/indirect.rs, the code afterExecuteIndirect) also records anINDIRECT_ARGUMENT -> COMMONtransition between executions. With narrow waits that transition is presumably the next drain; if it stayed legacy in your build, the 134 ms may still be leaving something on the table.HostList::indirect_scratch), so clamps are strictly sequential by construction; that is why the same buffer can be reused at offset 0 every time, and it also means the narrow barrier has to cover the previous indirect read of that buffer (which your description does).Happy to run your patch on this card (a run to the world is ~2.5 minutes, and I can report frame time,
droppedlines,no free dynamic descriptor slots, and screenshots of three scenes) if you push a branch.No game data included; counts and timings only. AI-assisted.
Imported from Zettrox/ztrx. Originally posted by ROZEREX on 2026-11-25T14:25:35Z.
Thanks for measuring on a 4070 Ti SUPER — very useful, and the split makes sense. With
VICTORY_NARROW_WAITS=1,done()records nothing (done_onreturns early; the scratch buffer is only ever barred with enhanced barriers), and the previous indirect read of the scratch buffer is covered by the buffer barrier before the next clamp — so in this patch neither legacy transition is left on the table.Next step, being measured now: removing the clamp pass altogether. An amplification stage of ours ahead of each translated mesh shader reads and bounds the record and launches the mesh groups, so an indirect mesh call becomes
DispatchMesh(1,1,1)with no pass, scratch buffer or barrier per call (VICTORY_MESH_LAUNCH). I'll push it to a branch once it's measured here — a run on your card would be great.(Reply written with Claude Code.)
Imported from Zettrox/ztrx. Originally posted by Artking175 on 2026-11-25T14:37:26Z.
I reproduced a scratch-buffer state mismatch on
f9faa22withVICTORY_NARROW_WAITS=1andVICTORY_BARRIER_TEST=indirecttogether. Environment was Windows 10 22H2, RTX 2060, driver 531.41, Agility SDK 1.608.2, and the D3D12 Debug Layer.The synthetic probe records two
ExecuteIndirectcalls using the same scratch buffer in one command list. With both flags set, the diagnostic switch makes the clamp record legacy transitions.done_onstill returns early becausenarrow_waits()is true. The second clamp expectsCOMMONand the Debug Layer reports that the buffer is still inINDIRECT_ARGUMENT.The fix carries the barrier mode selected by the clamp with the scratch buffer, including in the ahead-window path. The final transition uses that mode. The command-list interface query stays in the recording path. Fix commit · Patch
With the fix, all four flag combinations passed the hardware probe with the same readback and no Debug Layer errors. The
victory-gpulibrary suite with diagnostics had 117 passed, 0 failed, 1 ignored.Imported from Zettrox/ztrx. Originally posted by chenzhehao1129-eng on 2026-11-25T14:53:21Z.
Tested on a second GPU: the patch does what it says, but on a CPU-bound machine it is a no-op end to end. Posting the negative result because it marks where the patch helps.
Conditions.
ROZEREX:narrow-waits@f9faa22applied withgit apply --3wayonto90b529f(clean, touches onlycrates/victory-gpu/src/indirect.rs, +110). Release build,VICTORY_RELAY=2, same binary both runs, onlyVICTORY_NARROW_WAITStoggled. Scene: prison yard, ~4,950 draws/frame, 15–18 steady samples each. The patch does activate here:argument clamp: enhanced barriers (VICTORY_NARROW_WAITS) on=true(RTX 4070 Ti SUPER reports enhanced barrier support).Machine. Windows 11 10.0.26100, Ryzen 9 9900X, 61.5 GB, RTX 4070 Ti SUPER 16 GB, driver 32.0.15.8097, title 1.0.2.1 (Series X).
VICTORY_NARROW_WAITS=0VICTORY_NARROW_WAITS=1So the GPU half of the frame drops in the same direction as your 190 → 134 ms, but the frame itself does not move (4 fps either way).
Why it is 0 here: the frame is not wait-bound on this card. GPU time is only ~127 ms of a 254 ms frame; the rest is host-side work — 110 ms preparing, 40 ms of copies (about 120 MB a frame), and a copy-back path that moves ~63 MB a frame. Cutting 3% off the GPU portion cannot show up while the host is the critical path. On your 3090 the frame was ~190 ms GPU + ~286 ms waiting, so removing the drains paid 29%.
What this suggests for the patch:
VICTORY_RELAY=2alone on this machine sits at ~256 ms andNARROW_WAITSmoves it to ~254 ms; the spread between runs is about ±3 ms, so this is inside noise, not a small win.Happy to take another run if you want a variant measured (e.g. with the
done()transition also narrowed, or withVICTORY_CARD_*tuning on top).No game data included; counts and timings only. AI-assisted.
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.