Skip to content

Shaders, GPU: fold dispatches past 65,535 groups; indirect clamp at 2^16 groups with logging - #2

Open
mercuryVM wants to merge 3 commits into
mainfrom
impl2/fork-dispatch-fold
Open

mercuryVM wants to merge 3 commits into
mainfrom
impl2/fork-dispatch-fold

Conversation

@mercuryVM

Copy link
Copy Markdown
Owner

What

Two commits, on fork main f0df6a5.

1. Indirect argument clamp.

  • At most 2^16 groups per dispatch.
  • The list budget counts each program's real threads per group.
  • Every record the clamp reduces is logged.

World runs 17 and 18 on the RTX 5070 hung, both times in the same indirect dispatch: a loop-free meshlet-culling program whose arguments another pass writes. The old clamp let 2^20 groups through, and the budget counted every group as 64 threads.

  • The budget now reads the group size from the native program: compute numthreads, or a mesh group's lanes.
  • Records the clamp reduces are written to the list's budget buffer. They are logged before the list's next submission as indirect arguments clamped, with the shader, kind, read and left values. The first three per program and kind are logged, then every hundredth, at most 300 lines.

2. Folded dispatches.

  • One-dimensional dispatches of more than 65,535 groups now run whole.
  • The console runs more than 65,535 groups along x; D3D12 does not. The clamp cut such dispatches to 65,535. In world run 20 the indirect diffuse lighting's final gather asked for about 115,000 groups, so 43% of it never ran.
  • How a dispatch with y and z of 1 is split (GROUP_FOLD_ROW): rows of 65,535 groups along z, then a second dispatch for the rest. No padding groups.
  • Translated compute shaders that read their group id read a fold root constant.
    • It sits at b1 in the user-data space, one dword. Every compute root signature has it; it is 0 unless the dispatch is folded.
    • When it is non-zero: the group is that value minus one, plus x, plus z × 65,535, and z reads 0.
  • Direct dispatches fold on the CPU: two Dispatch calls with the constant.
  • Indirect dispatches with one uncounted record fold in the clamp.
    • The clamp writes the count and the records (constant, x, y, z) to a region of the list's fold buffer.
    • They are executed with a command signature of [root constant, dispatch].
    • Up to 2^22 groups fold. The budget still bounds the work.
    • Counted or multi-record indirect dispatches keep the plain clamp.
  • The test host's compute root signatures get the constant too. It is 0 unless a dispatch's roots set it.

Tests

Windows 11, RTX 5070, AMD CPU.

  • emit::fold_tests::folded_dispatches_number_groups_as_the_console passes on the RTX 5070 and on WARP. Cases:
    • groups as given;
    • a remainder from group 100;
    • two rows: groups 0, 1, 65535 and 65536, with z read as 0.
  • The clamp's HLSL compiles with fxc (cs_5_1).
  • cargo clippy --workspace --all-targets -- -D warnings: clean. -p victory-gpu -p victory-shader --all-features: clean.
  • cargo test --workspace --no-fail-fast -- --test-threads=1: 712 passed, 7 failed. The same 7 fail on fork main itself on this RTX 5070, and none is new: 2 victory-gpu heap tests that assume heaps of HEAP_VIEWS (NVIDIA caps at 10^6), 2 PSV0 container checks, 2 stride tests and 1 gather test.

Not tested

  • The indirect fold path end to end on a GPU: there is no harness for ExecuteIndirect in the tests. The next world run is that test. The "indirect arguments clamped" lines for the final gather should stop.
  • Whether the 2^16 limit alone ends the meshlet-culling hang: not run yet.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

mercuryVM and others added 3 commits November 24, 2026 21:22
…reductions logged

Two world runs on an RTX 5070 hung (device removed) in the same indirect
dispatch of a loop-free culling program whose arguments another pass writes
(meshlet culling; DRED stops at it). The clamp let a dispatch of 2^20 groups
through, and the list budget counted every group as 64 threads.

- A dispatch now runs at most 2^16 groups (mesh dispatches likewise).
- The budget counts each program's own threads per group (numthreads, or a
  mesh program's lanes), read from its native program once.
- Each record the clamp reduces is written to the list's budget buffer (up
  to 31 a run); before the list's next submission the host logs them at
  info, "indirect arguments clamped", with the program's hash, the kind and
  the arguments read and left (the first three per program and kind, then
  every hundredth, at most 300 lines).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 626b328)
(cherry picked from commit bface5a)
…un folded

The console runs more than 65,535 groups along x; the host does not, and
the indirect clamp cut such dispatches to 65,535 (in the world on an RTX
5070: the indirect diffuse lighting's final gather asks for about 115,000,
so 43% of it never ran).

Such a dispatch (y and z of 1) now runs folded: rows of 65,535 groups along
z, and a second dispatch for the rest. A compute shader that reads its
group id reads a fold root constant (b1 in the user-data space, one dword;
every compute root signature has it, 0 unless folded): non-zero, it is the
first group the dispatch runs plus one, the group is that plus x plus z
rows, and z reads 0 (`GROUP_FOLD_ROW`).

- Direct dispatches fold on the CPU (two Dispatch calls with the constant).
- Indirect ones (one uncounted record) fold in the argument clamp: it writes
  the count and the records (constant, then x, y, z) to a region of the
  list's fold buffer, executed with a command signature of the constant and
  a dispatch. Up to 2^22 groups fold; the budget still bounds the work.
- The test host's compute root signatures have the constant too (set to 0
  unless a dispatch's roots set it).

Test: emit::fold_tests on the RTX 5070 and WARP (groups as given, a folded
remainder from group 100, and two rows: groups 0, 1, 65535, 65536).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 365802a)
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.

1 participant