Skip to content

GPU: scale indirect Wave64 dispatches in list-owned arguments - #11

Merged
r4tedx merged 1 commit into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:gpu/wave64-indirect-dispatch
Nov 24, 2026
Merged

r4tedx merged 1 commit into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:gpu/wave64-indirect-dispatch

Conversation

@mohammadallami75-ops

@mohammadallami75-ops mohammadallami75-ops commented Nov 24, 2026 •

Copy link
Copy Markdown

Rebased on the rebuilt shader/wave-per-group at 7ae51da, which includes the current Marvisak#439 head. This adapts r4tedx’s 831cdb3 and fc57738 from testers/indirect-wave-dispatch and removes the Marvisak#242 dependency.

Compute indirect dispatches write packed records and the effective count into a list-owned buffer. The source and count stay available to later GPU writers. X scaling is overflow-safe, and the group cap and list budget account for scaled host work.

Verification

  • The State::execute_indirect regression checks two counted dispatches, each with the original 384 lane values. Both passed on an RTX 2080 SUPER (621.01, Wave32). Forcing waves = 1 at the call site failed at lane 192 (expected 104, got 0).
  • The test uses VICTORY_ADAPTER and VICTORY_WARP and selects native Wave64 on a compatible adapter. WARP passed the k=1 and k=2 GPU-written argument regressions and the scaled-limit and budget checks. Its four-lane device skipped the translated fixture. Native Wave64 hardware and in-game execution remain unverified.
  • Locked workspace tests passed (384 passed, six ignored), and both CI Clippy commands passed locally.

AI-assisted implementation and testing.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks for this. I reviewed it, built it, and ran it on an RTX 5070, a Radeon iGPU and WARP. Short version: the scaling is correct, but I am not merging it into shader/wave-per-group as it stands, mainly because of what it brings with it.

What holds up

The scaling in the clamp shader (clamp x to 65535, multiply only when x <= 65535 / group_waves, else an empty dispatch; group cap and list budget applied to host work after scaling) could not be broken:

  • A review-only test with 16 records for each k in {1, 2, 3, 4, 7, 16} at stride 20, checked against a 64-bit reference model (floor(65535/k) and ±1, 65535, 65536, u32::MAX, values where x*k would wrap, zero dimensions, the 2^20 cap boundary): output records, payload words, budget charge and the unchanged source all match on WARP, the RTX 5070 and the Radeon iGPU.
  • The same arguments clamped three times in one list (k = 4, the third with count 2 of 3) scale once each time; source and count are unchanged.
  • With the clamp unavailable a k > 1 dispatch is dropped, not run unscaled.
  • Both CI clippy commands are clean. cargo test --workspace --locked --no-fail-fast: 338 passed, 0 failed, 5 ignored. (A first run failed frame::tests::waits_end_on_ticks_and_count_frames, which this PR does not touch and which fails here under CPU load.)

Why not as is

  1. Scope. Of +1501/−92, about +1203/−78 is upstream GPU: make ExecuteIndirect clamping countBuffer-aware and non-destructive Marvisak/VIctory#242 (byte-identical to its head ee61c57), which is still open and currently conflicts with main. Your own change is small (indirect.rs +23/−4 outside tests). The scaling needs GPU: make ExecuteIndirect clamping countBuffer-aware and non-destructive Marvisak/VIctory#242's source/destination split, so it cannot be separated. shader/wave-per-group is meant to go upstream on top of Shaders: one console wave sharing LDS runs in the console flow on 32-lane hosts Marvisak/VIctory#439, and I do not want it to depend on someone else's open PR.
  2. The draw.rs wiring has no test. Forcing let waves = 1; at the call in execute_indirect leaves every test passing: the GPU test drives record_clamp and a hand-written ExecuteIndirect, never State::execute_indirect.
  3. Adapter selection in the new GPU test. It takes the first adapter with vendor id 0x10de, ignores VICTORY_ADAPTER / VICTORY_WARP, and returns as passed when there is no NVIDIA adapter. Nothing in the PR runs on a 64-lane host.
  4. warp_reads_arguments_written_earlier_in_the_list was changed to k = 2, so the GPU-written path lost its k = 1 test.

Two things that are not this PR's fault but came out of the review: Marvisak#242's unwritten-arguments path reads the title's buffer through a root SRV, which leaves it in a read state for the rest of the list (a later UAV writer in the same list would be formally invalid; results were correct on all three adapters here, and the debug layer is not installed on this machine, so I could neither confirm nor rule that out). And on the Radeon iGPU a multi-record indirect dispatch ran only its first record in every case tried, with or without this PR's code; I will look at that separately.

What I suggest

The base has moved: shader/wave-per-group is being rebuilt on the current Marvisak#439 head, and the indirect path there will use a separate pass that writes scaled records into a list-owned buffer (the approach of 831cdb3 on testers/indirect-wave-dispatch, which you credited), so it needs neither Marvisak#242 nor an in-place rewrite. If Marvisak#242 lands upstream first, your b3c2052 on top of it is the simpler form and I would take it then, with a test through State::execute_indirect and the usual adapter selection. Your reference cases (the 384 lane values over two counted dispatches) are a good check for either form.

All tests here were synthetic. The title was not used in these tests. AI-assisted (Claude Code).

@mohammadallami75-ops
mohammadallami75-ops force-pushed the gpu/wave64-indirect-dispatch branch from b3c2052 to bccc358 Compare November 24, 2026 14:44
@mohammadallami75-ops

Copy link
Copy Markdown
Author

Thanks for the review. Updated in bccc358.

  • Scope. Rebased on the rebuilt shader/wave-per-group and adapted your 831cdb3 and fc57738 approach. Packed records and the effective count live on the list. Title arguments and count stay UAVs, including for a later writer in the same list. The GPU: make ExecuteIndirect clamping countBuffer-aware and non-destructive Marvisak/VIctory#242 dependency is gone.
  • Wiring. The test calls State::execute_indirect twice and checks all 384 reference values per dispatch. Both passed on the RTX 2080 SUPER (621.01, Wave32). Forcing waves = 1 at the call site failed at lane 192 (expected 104, got 0).
  • Adapters and coverage. The test follows VICTORY_ADAPTER and VICTORY_WARP and uses native Wave64 when supported. WARP passed the GPU-written argument regression at k=1 and k=2, plus the scaled X, group cap and budget checks. Its four-lane device skipped the translated fixture.
  • Checks. Locked workspace tests passed locally (384 passed, six ignored), as did both CI Clippy commands. These were synthetic fixtures on physical Wave32 hardware and on WARP. Native Wave64 execution, the Radeon multi-record observation and in-game behavior remain unverified here.

AI-assisted implementation and testing.

@mohammadallami75-ops mohammadallami75-ops changed the title GPU: scale multi-wave Wave64 indirect dispatches in the clamp GPU: scale indirect Wave64 dispatches in list-owned arguments Nov 24, 2026
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for reworking it so quickly; bccc358 is the shape I asked for (one commit, list-owned records, no Marvisak#242, a test through State::execute_indirect, the usual adapter selection). I reviewed and ran it again. Most of it checks out, but I am not merging it yet, for one reason that matters more than the rest: a review probe of the new pass produced NVIDIA driver errors here.

The fault (RTX 5070, driver 616.92). A probe that only calls indirect::dispatch() with in-range buffers, five rewrites in one list, one of them with 6,000 active records (stride 12, k = 2, which also grows the list-owned buffer), aborted the test process on the NVIDIA card in 3 of 3 runs, right after recording. Windows logged nvlddmkm event 153 at each of the three runs. The same probe completed with every value as expected on the Radeon iGPU and on WARP, and the card recovered (a later run of your tests passed). I stopped GPU work on it there, so it is not isolated: it could be the record count or the growth. The suspect is the budget loop in the shader:

budget.InterlockedAdd(0, 0, used);
[allow_uav_condition]
while (true) { ... budget.InterlockedCompareExchange(0, used, used + cost, observed);
    if (observed == used) break; used = observed; }

Every active record contends on one word and one thread wins per round. Your tests never put more than 3 records in a pass. To be clear about where this comes from: my own 831cdb3 has the same loop, so this is my design's fault as much as the port's, and I will fix it there too. A bounded form avoids the question: one unconditional InterlockedAdd of the cost, check the value it returns, and subtract again on refusal (the base clamp adds once per record).

What checked out

  • Scaling by readback on the Radeon and WARP, stride 20 with payload: k = 3 takes 21845 to 65535 and 21846 to an empty record; k = 2 does not wrap at 0x80000001; k = 1 clamps 65535, 65536 and 0xFFFFFFFF to 65535 as the base does; the group cap and budget apply after scaling.
  • Records at or past the count are zeroed and not charged; the refusals (bad stride, unaligned source or count, zero records, too many records, 32-bit offset overflow) return before anything is recorded.
  • The title's argument and count buffers are only ever root UAVs; the list-owned buffer goes COMMON → UAV → INDIRECT_ARGUMENT with a UAV barrier and back; the caller rebinds its pipeline and roots after the pass. One buffer per list, reused, and growth keeps the old one alive until reset.
  • The bundled changes are all needed (a test-only pipeline helper, the shader crate's host feature for tests, the test device taken from the shader crate's host so VICTORY_ADAPTER / VICTORY_WARP apply).
  • Both CI clippy commands clean; cargo test --workspace --locked: 384 passed, 0 failed, 6 ignored. Your execute_indirect test passes on the RTX 5070 (k = 2) and the Radeon (k = 1); with the scaling forced off it fails at lane 192 (0 for 104), as you said. It merges cleanly onto the current base 252a095.

What I would change, besides the loop

  1. Every indirect dispatch now takes the new pass, k = 1 included. That changes ordinary shaders: their records are no longer clamped in place, refused records and records past the count are no longer charged, and if the new shader fails to build their dispatches are dropped where the base ran them through the clamp. Either gate the rewrite on waves > 1, or keep it for all on purpose: say so in the commit, fall back to the clamp for k = 1 when the pass is unavailable, and remove the clamp's now-dead dispatch branch.
  2. No test executes more than one record (both executing tests use count 1 of max 2; multi-record output is only read back). Please add one with count ≥ 2 and distinct outputs. Expect it to fail on the Radeon iGPU: that driver runs only the first record of a multi-record indirect dispatch, with or without this PR (reproduced again through execute_indirect at k = 1: 128 lanes written for 256). That is a separate problem.
  3. if max == 0 { return true; } now applies to draws and mesh too, which then skip prepare and the drawn count; scope it to dispatches.
  4. The "no debug-layer messages" assertions pass vacuously without a diagnostics build and an installed debug layer (not installed here either), so resource states are verified by reading only.

Smaller: one expected value depends on record 3 winning the budget race against record 4; a test registers a stack array as the title buffer; the test pipeline helper polls for 10 s.

If you rework the budget step, please do not test large record counts in a loop on your own card: one run, and check the System log for nvlddmkm afterwards. I will do the isolation here under the same rule once I have the bounded form.

All tests synthetic. The title was not used in these tests. AI-assisted (Claude Code).

@mohammadallami75-ops
mohammadallami75-ops force-pushed the gpu/wave64-indirect-dispatch branch from bccc358 to 2ab8b25 Compare November 24, 2026 16:52
@mohammadallami75-ops

Copy link
Copy Markdown
Author

@r4tedx Updated to 2ab8b25 on 252a095 in one commit, with no Marvisak#242 dependency.

  • The rewrite reserves each nonzero cost with one atomic add and refunds refusals. UAV barriers separate batches of up to 4,032 records so outstanding reservations fit in 32 bits. Exact accepted work is charged back to the shared list budget. Pending refunds can conservatively reject a record.
  • Only k > 1 uses the list-owned rewrite and effective count. Title buffers stay UAVs on that path. k = 1 keeps the in-place clamp. The zero-max shortcut applies only to dispatches.
  • The counted regression runs two records through State::execute_indirect and checks distinct X and Y output regions, the shared origin, and the excluded third record. It passed at k = 1 and k = 2 on the RTX 2080 SUPER (621.01). WARP passed k = 1 execution and k = 2 rewrite coverage. Its four-lane device skipped the translated fixture. The independently reproduced Radeon first-record-only behavior predates this rewrite.
  • The budget test no longer depends on which record wins. Title buffers are heap-backed, and the test PSO is built synchronously. Debug assertions now check the submission result when the info queue is active. The debug layer or info queue was unavailable here.

Locked workspace tests had 387 passes, zero failures and six ignored. Both CI Clippy commands passed. Rustfmt found existing differences with no new hunks. The single RTX stress run recorded five rewrites in one list, including 6,000 active records. Two fit the budget, scratch grew once, and the System log showed zero new nvlddmkm events. The RTX 5070 failure remains unisolated. All runs were synthetic. In-game and native Wave64 execution remain unverified.

AI.

@mohammadallami75-ops

Copy link
Copy Markdown
Author

@r4tedx One edge case I spotted after posting the update. If an ordinary compute pipeline isn’t ready, 2ab8b25 drops the dispatch before clamping its arguments. The base branch clamped them before dropping it, so a later command reusing that buffer could see different values. I found this by inspection and haven’t reproduced an in-game effect. I’ve left the commit as-is while you test the bounded rewrite.

AI.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Third round, at 2ab8b25 (fetched from your branch; the PR ref was still serving the previous head for a while). The important result first.

The many-record case now runs on the RTX 5070. One run, through indirect::dispatch() only: five rewrites in one list, k = 3 at stride 20, 6,000 active records with buffer growth, 6,000 with count 4,100, 4,096 with count 4,032 (across your batch boundary), and 6,000 cap-sized records contending for the budget. Every record and count word read back as expected, exactly one cap-sized record was accepted, the budget charge was exact, the source was unchanged. No nvlddmkm event was logged (the System log still holds only the three from the earlier incident). The same probe passed on WARP and the Radeon iGPU first. The previous version aborted on this card with the same record count and the same growth, so the retry loop is the likely cause, and the single add with a refund is the fix. Thank you for turning that around.

The earlier findings

  1. Budget step: resolved. No loop is left; the cost is bounded at 2^20 host groups, a batch of 63 groups (4,032 records) cannot wrap the word, each refund follows its own reservation in the same thread, no record is accepted past the remaining budget, and the second phase charges back exactly what was accepted. Near exhaustion, which record is refused depends on timing (record 0 on WARP, 64 on the Radeon, 2336 on the RTX in the probe); a refused record runs fully empty, never partly.
  2. Only k > 1 takes the rewrite: resolved. If its shader fails to build, a k > 1 dispatch is dropped, never run unscaled, and k = 1 does not touch it.
  3. A counted multi-record test through State::execute_indirect: resolved (execute_indirect_runs_both_counted_records).
  4. max == 0 scoped to dispatches: resolved.
  5. The smaller ones: resolved (one non-zero cost per pass in the budget test, heap-backed title buffer, synchronous test pipeline; pipeline/make.rs only makes make visible to the test helper).

Both CI clippy commands are clean; cargo test --workspace --locked: 387 passed, 0 failed, 6 ignored on the RTX 5070. Your five indirect tests: 5 of 5 on the RTX 5070 and on WARP, 4 of 5 on the Radeon (below).

What is left before I merge it

  • Commit a many-record test. Nothing in the PR puts more than 3 records in a pass, so the batching (first, the step of 63, the refund under contention) has no test of its own. The probe I ran is yours to take; I can attach its source. It should stay a single run in the suite.
  • The count-buffer barrier at draw.rs (UAV to INDIRECT_ARGUMENT on a separate count buffer for dispatches). It only applies at k = 1, the path that was to stay as the base, and its before-state is wrong when the list did not write the count as a UAV earlier (the buffer is then in COMMON); your own counted test is that case. No debug layer here to confirm, so this is by reading. Please remove it, or handle count-buffer states for all kinds in a separate change.
  • The edge case you found yourself (a dispatch with no ready pipeline is now dropped before its arguments are clamped, where the base clamped first): yes, restore the base order for k = 1. The same early return also stopped calling note_drop, so diagnostics lose the reason (being made, refused, untranslated); the direct path still calls it.
  • The counted test on the Radeon iGPU fails at k = 1 (lane 0: left 1, right 2): that driver runs only the first record of a multi-record indirect dispatch, with or without this PR. The test should skip or expect that on such an adapter rather than leave the suite red there.
  • Two pure reformatting hunks in draw.rs can go.

Two notes, not requests: each k > 1 indirect dispatch now costs at least three dispatches and four UAV barriers, and the 2^20 cap now counts host groups (2^20 / k console groups). Both are fine by me; the second deserves a line in the doc.

With those in, I will merge it into shader/wave-per-group and it becomes the indirect path of the multi-wave form.

All runs synthetic. The title was not used in these tests. AI-assisted (Claude Code).

@mohammadallami75-ops
mohammadallami75-ops force-pushed the gpu/wave64-indirect-dispatch branch from 2ab8b25 to 37b4070 Compare November 24, 2026 18:34
@mohammadallami75-ops

Copy link
Copy Markdown
Author

@r4tedx Updated in one commit, 37b4070, on 88b38e8.

  • Restored clamp-before-prepare and drop diagnostics for ordinary dispatches. Removed the separate count-buffer barrier and both formatting-only hunks. The docs now give the per-record 2^20 cap in host groups.
  • The counted test accepts the exact known first-record-only readback on Radeon UMA at k=1. It still requires both records at k>1 and on other adapters.
  • Added one five-rewrite regression at k=3 and stride 20. It covers scratch growth, count cutoffs across the 4,032-record boundary and 6,000 competing records. It checks every packed record and count, exactly one large acceptance, exact budget charge and unchanged inputs.

The probe passed on WARP and in one RTX 2080 SUPER run. The Windows System log had zero new nvlddmkm events in that run. Both CI Clippy commands passed. The full locked workspace run passed 390 tests with 6 ignored. After the shader-only rebase, the locked suite passed 392 with 6 ignored, with the unchanged stress probe excluded from the rerun. The RTX executed both counted records at k=1 and k=2. WARP passed the applicable regressions. The D3D12 debug layer was unavailable locally.

AI.

@r4tedx
r4tedx merged commit c734600 into r4tedx:shader/wave-per-group Nov 24, 2026
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Merged into shader/wave-per-group as c734600. Thank you for four fast, careful rounds.

Final check at 37b4070:

  • All five points are in: the many-record regression (rewrite_many_records_once: 6,000 records at k = 3 and stride 20, growth, count cut-offs at 4,100 and exactly at the 4,032 boundary, every record and count checked, exactly one cap-sized record accepted, the budget charge exact, inputs unchanged); the count-buffer barrier gone; the base's order restored for ordinary dispatches with note_drop kept, and a test for it; the counted test accepting exactly "first record only" on an AMD integrated adapter at k = 1 and strict everywhere else; the reformatting hunks gone and the cap stated in host groups.
  • For a group_waves == 1 pipeline what still differs from the base is the pipeline being looked up before the clamp as well as after, and a zero-max dispatch returning early without commands. Both are harmless.
  • Both CI clippy commands clean. The suite on the RTX 5070: 392 passed, 0 failed, 6 ignored without the many-record test. The six indirect tests pass on the Radeon iGPU (the counted one printing the known first-record-only readback).
  • The many-record test: WARP, then the Radeon, then once on the RTX 5070: passed each time, and no nvlddmkm event was logged by any of these runs.

Not covered by anything here: the D3D12 debug layer is not installed on this machine, so resource states are verified by reading only; and no test has a title count larger than the max. Neither holds the merge.

This is now the indirect path of the multi-wave form on the branch, which a title report on Marvisak#439 says the cascade-shadow passes need (343 of 343 of them go through ExecuteIndirect).

All runs synthetic. The title was not used in these tests. AI-assisted (Claude Code).

r4tedx added a commit that referenced this pull request Nov 24, 2026
e234090 bounded the split dispatch's compare-exchange loop at 1,024
retries. A 6,000-record stress test (added here) showed what that costs:
on a Radeon iGPU (64-lane waves) only 2,771 of 6,000 small records were
accepted with the budget almost untouched, because every lane of a wave
expects the same value and only one wins each round. It never reached
the RTX 5070.

The pass now uses the scheme fork PR #11 measured with 6,000 records on
an RTX 5070, a Radeon iGPU and WARP: word 0 keeps counting threads for
the legacy clamp; a second word, in groups, takes one InterlockedAdd per
record with a refund on refusal. Records cost at most 2^20 groups and
batches are at most 63 groups, so the word stays below 2^32 with every
refund pending. A first phase seeds it from word 0 and a last one writes
the accepted groups back.

Test: `split_dispatch_charges_thousands_of_records_exactly` (ignored by
default, a GPU stress) runs 6,000 records through the pass and checks
each output and the budget. For it, diagnostics builds take
`VICTORY_D3D12_ADAPTER` (a substring of the adapter's description) to
put the host device on another GPU, and say on stderr which device the
WARP or named path chose.

Untested at commit time: waiting for the machine's test queue (WARP,
then the Radeon, then the RTX 5070).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants