GPU: reduce contention in ordered indirect argument clamps #155

Open
syrrath-creator wants to merge 2 commits from upstream-pr/155 into main
syrrath-creator commented 2026-11-25 16:13:05 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by syrrath-creator on 2026-11-25T15:37:20Z.


The indirect-argument clamp charges draws and dispatches against a work budget that lives in CPU-visible memory. The budget and mesh statistics belong to the command list. The first commit uses ordinary loads and stores when only one record can reach those words. The second compiles a separate pipeline on demand for requests of 2–64 records. One threadgroup can charge all active records together if every record fits, or empty positive-cost records if the budget is already full. For partially affordable groups, the original atomics arbitrate against the untouched budget. Zero-cost records, argument payloads and mesh statistics preserve their existing behavior.

Both paths use the existing GPU-side ordering between clamps on the renderer’s single direct queue. The diagnostic switch that omits the global UAV barriers keeps atomic admission. The standard shader for single-record and multi-group requests is byte-identical between the two commits. The group pipeline falls back to the standard shader if its compilation fails. First use of the extra pipeline took 32.48 ms of CPU time on the RTX 4090 (26.84–37.77 ms across six fresh processes with the driver cache active); subsequent calls reuse it.

RTX 4090 results

Each row is a separate synthetic command list with 1,024 clamp calls. The two stages were measured in separate runs. Times are median GPU milliseconds from four fresh processes and 24 warm observations per variant, using alternating AB/BA order and 1 GHz D3D12 timestamps. The mesh and compute execution rows use real ExecuteIndirect commands and check how many groups actually ran.

Change Per call Before After
Upstream → single-record commit Clamp and execute one mesh record 7.971 ms 5.983 ms
Upstream → single-record commit Clamp and execute one compute record 4.305 ms 3.734 ms
Single-record → both commits Clamp 16 mesh records 100.659 ms 2.491 ms
Single-record → both commits Clamp and execute 16 compute records 129.648 ms 33.097 ms

For the 16-compute case, CPU command recording took 2.380 → 2.403 ms and elapsed time from queue submission through the fence was 130.734 → 33.921 ms. In a separate 128-call boundary test, an already-full 16-record budget took 1.438 → 0.295 ms. When every group had exactly one record’s cost left, the fallback took 0.292 → 0.321 ms. A 65-record control took 177.560 → 178.023 ms on the standard shader. The synthetic command lists do not establish a gameplay FPS change.

On the physical RTX 4090, 1,792 fenced pairs matched byte-for-byte. A separate CPU oracle checked 1,251 further deterministic pairs and 317 contested-budget pairs, including the 63/64/65-record boundaries. The patch also merges cleanly with #139. A combined run exercised its opt-in enhanced barriers on the RTX, with native mesh/compute execution and checked output.

Source, detailed results and reproduction instructions

<!-- greyfinch-sync:Zettrox/ztrx:issue:6608133061 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/155). Originally posted by [syrrath-creator](https://github.com/syrrath-creator) on 2026-11-25T15:37:20Z. --- The indirect-argument clamp charges draws and dispatches against a work budget that lives in CPU-visible memory. The budget and mesh statistics belong to the command list. The first commit uses ordinary loads and stores when only one record can reach those words. The second compiles a separate pipeline on demand for requests of 2–64 records. One threadgroup can charge all active records together if every record fits, or empty positive-cost records if the budget is already full. For partially affordable groups, the original atomics arbitrate against the untouched budget. Zero-cost records, argument payloads and mesh statistics preserve their existing behavior. Both paths use the existing GPU-side ordering between clamps on the renderer’s single direct queue. The diagnostic switch that omits the global UAV barriers keeps atomic admission. The standard shader for single-record and multi-group requests is byte-identical between the two commits. The group pipeline falls back to the standard shader if its compilation fails. First use of the extra pipeline took 32.48 ms of CPU time on the RTX 4090 (26.84–37.77 ms across six fresh processes with the driver cache active); subsequent calls reuse it. ### RTX 4090 results Each row is a separate synthetic command list with 1,024 clamp calls. The two stages were measured in separate runs. Times are median GPU milliseconds from four fresh processes and 24 warm observations per variant, using alternating AB/BA order and 1 GHz D3D12 timestamps. The mesh and compute execution rows use real ExecuteIndirect commands and check how many groups actually ran. | Change | Per call | Before | After | | --- | --- | ---: | ---: | | Upstream → single-record commit | Clamp and execute one mesh record | 7.971 ms | 5.983 ms | | Upstream → single-record commit | Clamp and execute one compute record | 4.305 ms | 3.734 ms | | Single-record → both commits | Clamp 16 mesh records | 100.659 ms | 2.491 ms | | Single-record → both commits | Clamp and execute 16 compute records | 129.648 ms | 33.097 ms | For the 16-compute case, CPU command recording took 2.380 → 2.403 ms and elapsed time from queue submission through the fence was 130.734 → 33.921 ms. In a separate 128-call boundary test, an already-full 16-record budget took 1.438 → 0.295 ms. When every group had exactly one record’s cost left, the fallback took 0.292 → 0.321 ms. A 65-record control took 177.560 → 178.023 ms on the standard shader. The synthetic command lists do not establish a gameplay FPS change. On the physical RTX 4090, 1,792 fenced pairs matched byte-for-byte. A separate CPU oracle checked 1,251 further deterministic pairs and 317 contested-budget pairs, including the 63/64/65-record boundaries. The patch also merges cleanly with #139. A combined run exercised its opt-in enhanced barriers on the RTX, with native mesh/compute execution and checked output. [Source, detailed results and reproduction instructions](https://github.com/syrrath-creator/ztrx/tree/validation/ordered-indirect-hardware/scripts/bench/indirect-budget)
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/155:upstream-pr/155'
git switch 'upstream-pr/155'

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/155'
git switch 'upstream-pr/155'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/155'
git switch 'upstream-pr/155'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/155'
git switch 'main'
git merge --squash 'upstream-pr/155'
git switch 'main'
git merge --ff-only 'upstream-pr/155'
git switch 'main'
git merge 'upstream-pr/155'
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!155
No description provided.