Skip to content

Dispatches past the host's group limit run in pieces, each told where its groups start - #976

Closed
MoscaLosca wants to merge 1 commit into
fxceless:mainfrom
MoscaLosca:dispatch-group-split
Closed

MoscaLosca wants to merge 1 commit into
fxceless:mainfrom
MoscaLosca:dispatch-group-split

Conversation

@MoscaLosca

Copy link
Copy Markdown

What

A dispatch that asks for more thread groups in x than the host runs in one
dispatch (65,535) used to lose its tail, or hand the whole count to the driver.
Now:

  • Dispatch, DispatchX and DispatchMesh run as pieces of at most 65,535
    groups. The translated program adds the piece's first group to its group id
    (SV_DispatchThreadID and the mesh stage's group are built from the same op,
    so all of them move with it). The dword is one the host computes
    (USER_GROUP_BASE, an Other root kind after USER_VIEW_BIAS): bound to 0
    by every bind, set again before each piece from the second on.
  • A dispatch past the limit whose program reads no group id is clamped to
    65,535 with a note, instead of the whole count going to the driver.
  • The indirect light pass's compute record (the counted one, run 200, about
    77,500 groups in x) is not fixed: its count arrives in GPU memory, and
    splitting it would need the host to read each record's count, or a per-record
    group base the argument buffer does not carry. The clamp now counts these too
    (budget words 12 and 16, beside the mesh notes at 4 and 8), and the frame
    line reports the largest group count asked for, so the next run measures what
    the cut-off costs and whether the indirect split is worth building.

VICTORY_GROUP_SPLIT=0 restores the old behavior.

Status

  • Unit-tested: a program that reads its group id is checked to read the base
    with the split on and not with it off (victory-shader, 172 passed;
    victory-formats 25).
  • Clippy clean (Windows target, blake3/pure, also with diagnostics).
  • Not yet seen in a run of the title. The shader cache key includes the
    translator sources (build.rs), so nothing to clear by hand.
  • Watch for in the log: a dispatch asks for more groups in x than the host runs: it runs in pieces (the fix working, with the number of pieces),
    ... and its program reads no group id (an over-limit dispatch not
    recoverable), and the frame line's
    indirect compute dispatches: the largest group count asked for ....

README and docs/fork-ray-tracing.md updated, including the honest status.

… its groups start

The title asks some passes for more thread groups in x than the host
runs in one dispatch (65,535), and the groups after it were lost, or
the count itself went to the driver, which has no duty to survive it:

- Dispatch, DispatchX and DispatchMesh are run as pieces of at most
  65,535 groups, and the translated program adds the piece's first
  group to its group id (SV_DispatchThreadID and the mesh stage's group
  are built from the same op, so all of them move with it). The dword
  is one the host computes (USER_GROUP_BASE, an Other root kind after
  USER_VIEW_BIAS), bound at 0 by every bind and set again before each
  piece from the second on. VICTORY_GROUP_SPLIT=0 turns it off.
- A dispatch past the limit whose program reads no group id is clamped
  to 65,535 with a note (its ids cannot move), where before the whole
  count went to the driver.
- A group count that arrives in GPU memory (the indirect light pass's
  compute record of about 77,500 groups, run 200) is still clamped, now
  counted as well: the clamp notes the largest group count its compute
  records asked for (budget words 12 and 16, beside the mesh notes at 4
  and 8), and the frame line reports it, so the next run measures what
  the cut-off costs.

Built and unit-tested (the program that reads its group id is checked
to read the base with the split on and not with it off); not yet seen
in a run of the title.
@SantannaCarlos

Copy link
Copy Markdown
Contributor

This and #834 are two halves of the same mechanism: #834 runs the indirect compute records past 65,535 groups in x as a second execution, this one splits direct and mesh dispatches. Both add a host-set dword, USER_GROUP_BASE at 0x104, to the group id in x where a program reads it, and both leave it at 0 everywhere else.

So if both go in, they should keep one constant and one lowering: resolving the conflict by keeping both lowering blocks would add the base twice. With one lowering, the host side of each is unchanged (this one sets the dword per piece of a direct or mesh dispatch, #834 sets it around the second indirect execution). I can rebase #834 onto this one if it lands first.

@avt0m4t48

Copy link
Copy Markdown

I reproduced a local-ID regression on 23affc7. compute_id adds USER_GROUP_BASE to the X component of both groupId and threadIdInGroup. The synthetic shader writes both values to fixed output offsets. WARP returns the expected [0, 0] at base 0. At base 65,535 it returns [65535, 65535] instead of [0, 65535]. Derived indices and local groupshared indexing can then use a shifted local ID.

Restricting the addition to DXIL groupId fixes both readbacks. A shader that only reads its local ID also stops gaining group-base metadata. The fixture sets the piece base directly and exercises shader lowering and GPU readback. The host's command loop was checked separately in source, including piece boundaries, root indices, and the following zero-base bind. I did not run a retail dispatch.

The README's coverage sentence should also reflect the host fallback. The current host truncates an oversized dispatch when the shader lacks group-base metadata. A shader that reads no group X can still need every group to run, for example to contribute to an atomic counter.

WARP reproduction · Corrected Windows suite · Small candidate patch

AI-assisted using Codex.

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.

3 participants