Skip to content

DispatchX with USE_THREAD_DIMENSIONS (flag 0x20) runs threads, not groups: the BVH builder's rehydration overran its structures (#16) - #840

Closed
Yorivel wants to merge 1 commit into
fxceless:mainfrom
Yorivel:fix/dispatch-thread-dims
Closed

Yorivel wants to merge 1 commit into
fxceless:mainfrom
Yorivel:fix/dispatch-thread-dims

Conversation

@Yorivel

@Yorivel Yorivel commented Nov 25, 2026

Copy link
Copy Markdown

Problem

XboxBvhBuilder launches its in-place rehydration stage caa78b8ca62bc3d6 through DispatchX(x, 1, 1, 0x20). The inline form of the same call (XboxBvhBuilder.dll 0x1536a) writes DISPATCH_DIRECT's five dwords, 0x4003cc00, x, 1, 1, 0x20. The initiator 0x20 is USE_THREAD_DIMENSIONS: x is a number of threads. list.rs dispatch_x drops the flags and launches x groups of 64.

Every lane of that program stores a 64-byte node at root2 + c[0] + (group << 12) + tid × 64, unbounded, with no early exit (the launch exec mask is saved at 0x2b4 and restored before the stores). So the extra lanes wrote up to 64× the node area, over neighbouring structures and title objects. This is the source of the all-ones pointers and empty-box bounds in #16's crashes.

Evidence (RTX 4090; 648 rehydrated structures in 41 batches, each paired with its own dispatches):

x read as structures writing past the next one in their batch
groups (now) 70
threads 0
whole last groups (ceil(x/64) groups, no lane limit) 21

3,913 of 3,918 dispatches have an x that isn't a multiple of 64. On the console the lanes past x don't run, so both halves of the fix below are needed.

Change (opt-in: VICTORY_THREAD_DIMS=1)

  • list.rs: dispatch_x with flags & 0x20 runs ceil(x / numthreads.x) (and y, z) groups (dispatch_threads).
  • pipeline.rs: compute_threads(pipeline), the group size from the native program (ComputeIo.threads), cached per pipeline.
  • shader.rs, lower.rs: a host-computed user-data dword USER_THREAD_LIMIT (0x104, next to USER_VIEW_BIAS). With the switch, every compute program starts with threadId.x < limit, otherwise it branches to the existing abort exit.
  • draw.rs: the dword is x during a thread-dimension dispatch and all ones otherwise (State::thread_limit).
  • shader_cache.rs: the cache key covers the switch.

The default behaviour is unchanged. All 52 builder programs translate, validate (dxil.dll) and create pipelines with the guard on a 32-lane host. caa78b8c, 28918b71 and 4ddd6f97 have no s_barrier, so the early exit can't stall a barrier in them.

Results (RTX 4090, VICTORY_BVH_BUILDER=1, otherwise the settings from #16)

before with the switch
caa78b8c groups per dispatch up to 365 at most 17, mostly 1
reads of 0xffffffffffffffff dozens, many threads 0–2
first-chance exceptions 10–20 1
time from builder runs to the crash 5–11 s 3.5–67 s; one run drew the world (3,563 draws/frame)

Each rehydration's stages now fill one contiguous layout: the decoder 5e687674 up to the header's size, then 28918b71 (128-byte nodes) and caa78b8c (64-byte nodes) alternating. Checked on three structures from three runs.

Not fixed by this: a remaining single crash per run. It comes from a few stray builder writes some KB past a structure's end, which none of the four programs' node ranges reaches; the data-driven parent-link stores are the likely path (details in #16). That is a separate defect.

Diagnostics used (logs of dispatch roots and callers, write-backs with their bytes, physical views, the title's builder calls) are on diag/bvh-alias in Yorivel/victory-fork, not in this PR.

🤖 Generated with Claude Code

…Y_THREAD_DIMS=1)

The console's ray-tracing builder launches its in-place rehydration stage
(caa78b8ca62bc3d6) with DispatchX(x, 1, 1, 0x20); 0x20 is the dispatch
initiator's USE_THREAD_DIMENSIONS, so x counts threads. dispatch_x dropped
the flags and ran x groups of 64; every lane of that program stores a
64-byte node, so rehydrations wrote up to 64 times their node area over
the next structures and title objects (fork fxceless#16).

With the switch: the groups that hold the threads run (the group size from
the pipeline's native program), and compute programs end at once for
lanes at or past a host-computed user-data dword (USER_THREAD_LIMIT; all
ones for other dispatches), as the console runs no lane past x. The shader
cache key covers the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yorivel

Yorivel commented Nov 25, 2026

Copy link
Copy Markdown
Author

Closing in favour of #646 (@mynzjerko): it's the same fix (thread counts for DispatchX with USE_THREAD_DIMENSIONS, plus masking the lanes past the count), on by default, and it was opened first. Curry-976's run on #646 (builder 4+ min, no crash) and the 5070 bisection in #16 cover it on three cards now. The measurements in this PR's description still apply to #646 if they're useful for review.

@Yorivel Yorivel closed this Nov 25, 2026
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