GPU: argument clamp with enhanced barriers (VICTORY_NARROW_WAITS, opt-in) #139

Open
ROZEREX wants to merge 2 commits from upstream-pr/139 into main
ROZEREX commented 2026-11-25 14:11:03 +00:00 (Migrated from github.com)
First-time contributor

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

  • before the clamp: a global barrier on earlier compute + copy writes only, plus a buffer barrier for the scratch buffer's previous indirect read;
  • after it: a buffer barrier on the scratch buffer (compute UAV → indirect argument).

The title's own barriers are unchanged.

Measured (RTX 3090 24 GB, driver 621.40, i7-14700K, Windows 11 24H2, prison yard):

  • title's card time (VICTORY_GPU_TIMING): 190 → 134 ms/frame
  • card wait 286 → 79 ms/frame, median 2.0 → 4.0 fps (with VICTORY_RELAY=2 VICTORY_WIDE_MERGE=1 VICTORY_WIDE_BACK=1)
  • screenshots of the same scene match
  • the D3D12 debug layer (VICTORY_D3D12_DEBUG=1) reports nothing

Tests: 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

<!-- greyfinch-sync:Zettrox/ztrx:issue:6606108418 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/139). Originally posted by [ROZEREX](https://github.com/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): - before the clamp: a global barrier on earlier compute + copy writes only, plus a buffer barrier for the scratch buffer's previous indirect read; - after it: a buffer barrier on the scratch buffer (compute UAV → indirect argument). The title's own barriers are unchanged. **Measured** (RTX 3090 24 GB, driver 621.40, i7-14700K, Windows 11 24H2, prison yard): - title's card time (`VICTORY_GPU_TIMING`): 190 → 134 ms/frame - card wait 286 → 79 ms/frame, median 2.0 → 4.0 fps (with `VICTORY_RELAY=2 VICTORY_WIDE_MERGE=1 VICTORY_WIDE_BACK=1`) - screenshots of the same scene match - the D3D12 debug layer (`VICTORY_D3D12_DEBUG=1`) reports nothing **Tests:** `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](https://claude.com/claude-code)
chenzhehao1129-eng commented 2026-11-25 15:08:45 +00:00 (Migrated from github.com)
Author
First-time contributor

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=indirect already drops the two waits for earlier shader writes around each clamp and keeps the legacy state transitions:

frame time fps
as shipped 292 ms 3
waits dropped, transitions kept 270 ms 4

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_ACCESS and UNORDERED_ACCESS -> INDIRECT_ARGUMENT transitions 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:

  1. done() (crates/victory-gpu/src/indirect.rs, the code after ExecuteIndirect) also records an INDIRECT_ARGUMENT -> COMMON transition 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.
  2. The scratch buffer is a single reused slot (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, dropped lines, 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.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165156475 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/139#issuecomment-7165156475). Originally posted by [chenzhehao1129-eng](https://github.com/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=indirect` already drops the two waits for earlier shader writes around each clamp and keeps the legacy state transitions: | | frame time | fps | |---|---|---| | as shipped | 292 ms | 3 | | waits dropped, transitions kept | **270 ms** | 4 | 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_ACCESS` and `UNORDERED_ACCESS -> INDIRECT_ARGUMENT` transitions 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:** 1. `done()` (`crates/victory-gpu/src/indirect.rs`, the code after `ExecuteIndirect`) also records an `INDIRECT_ARGUMENT -> COMMON` transition 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. 2. The scratch buffer is a single reused slot (`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, `dropped` lines, `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.
ROZEREX commented 2026-11-25 15:08:45 +00:00 (Migrated from github.com)
Author
First-time contributor

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

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165259244 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/139#issuecomment-7165259244). Originally posted by [ROZEREX](https://github.com/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_on` returns 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.)
Artking175 commented 2026-11-25 15:08:45 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Artking175 on 2026-11-25T14:37:26Z.


I reproduced a scratch-buffer state mismatch on f9faa22 with VICTORY_NARROW_WAITS=1 and VICTORY_BARRIER_TEST=indirect together. 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 ExecuteIndirect calls using the same scratch buffer in one command list. With both flags set, the diagnostic switch makes the clamp record legacy transitions. done_on still returns early because narrow_waits() is true. The second clamp expects COMMON and the Debug Layer reports that the buffer is still in INDIRECT_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-gpu library suite with diagnostics had 117 passed, 0 failed, 1 ignored.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165565136 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/139#issuecomment-7165565136). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-25T14:37:26Z. --- I reproduced a scratch-buffer state mismatch on `f9faa22` with `VICTORY_NARROW_WAITS=1` and `VICTORY_BARRIER_TEST=indirect` together. 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 `ExecuteIndirect` calls using the same scratch buffer in one command list. With both flags set, the diagnostic switch makes the clamp record legacy transitions. `done_on` still returns early because `narrow_waits()` is true. The second clamp expects `COMMON` and the Debug Layer reports that the buffer is still in `INDIRECT_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](https://github.com/Artking175/ztrx/commit/a676079101993c303170ab044ecb7941d6de7ef6) · [Patch](https://github.com/Artking175/ztrx/commit/a676079101993c303170ab044ecb7941d6de7ef6.patch) With the fix, all four flag combinations passed the hardware probe with the same readback and no Debug Layer errors. The `victory-gpu` library suite with diagnostics had 117 passed, 0 failed, 1 ignored.
chenzhehao1129-eng commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

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 @ f9faa22 applied with git apply --3way onto 90b529f (clean, touches only crates/victory-gpu/src/indirect.rs, +110). Release build, VICTORY_RELAY=2, same binary both runs, only VICTORY_NARROW_WAITS toggled. 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).

frame preparing copies on the GPU copying back
VICTORY_NARROW_WAITS=0 256.1 ms 109.7 ms 40.5 ms 130.7 ms 211.3 ms
VICTORY_NARROW_WAITS=1 253.9 ms 112.3 ms 40.4 ms 126.9 ms 206.9 ms
−0.9% +2.4% −0.2% −2.9% −2.1%

So 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:

  1. It is worth merging as an opt-in: on GPU-bound machines it is a real win, it is gated, and it leaves the default path alone. It just should not be advertised as a general framerate fix — the gain is conditional on the clamp waits being the critical path.
  2. If you want a second data point for the report, VICTORY_RELAY=2 alone on this machine sits at ~256 ms and NARROW_WAITS moves it to ~254 ms; the spread between runs is about ±3 ms, so this is inside noise, not a small win.
  3. On a machine like this the levers that matter are the prepare/copy-back path (110 + 40 + 63 MB a frame) and the 344 draws a frame dropped without a host pipeline, not the barriers.

Happy to take another run if you want a variant measured (e.g. with the done() transition also narrowed, or with VICTORY_CARD_* tuning on top).

No game data included; counts and timings only. AI-assisted.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165973000 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/139#issuecomment-7165973000). Originally posted by [chenzhehao1129-eng](https://github.com/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` @ `f9faa22` applied with `git apply --3way` onto `90b529f` (clean, touches only `crates/victory-gpu/src/indirect.rs`, +110). Release build, `VICTORY_RELAY=2`, same binary both runs, only `VICTORY_NARROW_WAITS` toggled. 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). | | frame | preparing | copies | on the GPU | copying back | |---|---|---|---|---|---| | `VICTORY_NARROW_WAITS=0` | 256.1 ms | 109.7 ms | 40.5 ms | **130.7 ms** | 211.3 ms | | `VICTORY_NARROW_WAITS=1` | 253.9 ms | 112.3 ms | 40.4 ms | **126.9 ms** | 206.9 ms | | | **−0.9%** | +2.4% | −0.2% | **−2.9%** | −2.1% | So 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:** 1. It is worth merging as an opt-in: on GPU-bound machines it is a real win, it is gated, and it leaves the default path alone. It just should not be advertised as a general framerate fix — the gain is conditional on the clamp waits being the critical path. 2. If you want a second data point for the report, `VICTORY_RELAY=2` alone on this machine sits at ~256 ms and `NARROW_WAITS` moves it to ~254 ms; the spread between runs is about ±3 ms, so this is inside noise, not a small win. 3. On a machine like this the levers that matter are the prepare/copy-back path (110 + 40 + 63 MB a frame) and the 344 draws a frame dropped without a host pipeline, not the barriers. Happy to take another run if you want a variant measured (e.g. with the `done()` transition also narrowed, or with `VICTORY_CARD_*` tuning on top). No game data included; counts and timings only. AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/139:upstream-pr/139'
git switch 'upstream-pr/139'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/139'
git switch 'upstream-pr/139'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/139'
git switch 'upstream-pr/139'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/139'
git switch 'main'
git merge --squash 'upstream-pr/139'
git switch 'main'
git merge --ff-only 'upstream-pr/139'
git switch 'main'
git merge 'upstream-pr/139'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Zettrox/ztrx!139
No description provided.