Repository navigation
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
Conversation
…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>
Author
|
Closing in favour of #646 (@mynzjerko): it's the same fix (thread counts for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
XboxBvhBuilderlaunches its in-place rehydration stagecaa78b8ca62bc3d6throughDispatchX(x, 1, 1, 0x20). The inline form of the same call (XboxBvhBuilder.dll0x1536a) writes DISPATCH_DIRECT's five dwords,0x4003cc00, x, 1, 1, 0x20. The initiator0x20isUSE_THREAD_DIMENSIONS: x is a number of threads.list.rsdispatch_xdrops 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 at0x2b4and 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):
ceil(x/64)groups, no lane limit)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_xwithflags & 0x20runsceil(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 dwordUSER_THREAD_LIMIT(0x104, next toUSER_VIEW_BIAS). With the switch, every compute program starts withthreadId.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,28918b71and4ddd6f97have nos_barrier, so the early exit can't stall a barrier in them.Results (RTX 4090,
VICTORY_BVH_BUILDER=1, otherwise the settings from #16)caa78b8cgroups per dispatch0xffffffffffffffffbuilder runsto the crashEach rehydration's stages now fill one contiguous layout: the decoder
5e687674up to the header's size, then28918b71(128-byte nodes) andcaa78b8c(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-aliasin Yorivel/victory-fork, not in this PR.🤖 Generated with Claude Code