GPU and shaders: handle DispatchX USE_THREAD_DIMENSIONS partial thread groups (#16) #646
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!646
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-646"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@mynzjerko on GitHub · 2026-11-25 03:57 UTC · original
mynzjerko:fix/dispatch-x-thread-dimensions→main· +463 −35 · 8 files · 1 commits · openProblem
In
crates/victory-gpu/src/list.rs,DispatchX(x, y, z, flags)ignoredflagsand forwarded(x, y, z)directly toID3D12GraphicsCommandList::Dispatch(x, y, z)as thread-group counts.The ray-tracing structure builder calls
DispatchXwith bit 5 (0x20=COMPUTE_DISPATCH_INITIATOR::USE_THREAD_DIMENSIONS, e.g.0x0020/0x8020) set. In that mode:(x, y, z)are raw thread counts, not thread-group counts.DTid >= count) are masked off in initial hardwareEXEC.Treating raw thread counts as full 64-thread groups caused:
EXECpopcounts (s_bcnt1_i32_b64(exec)returning 64 instead of the partial count) and unmasked whole-wave reductions on partial tail waves.Fix
victory-gpucrates/victory-gpu/src/pipeline.rs: store compute[numthreads(x, y, z)]onTranslated.crates/victory-gpu/src/list.rs: forwardflagsfromdispatch_xtostate::dispatch_x.crates/victory-gpu/src/draw.rs: whenflags & 0x20 != 0(USE_THREAD_DIMENSIONS), skip zero-sized dispatches, convert raw thread counts to host group counts viadiv_ceil, and supply any non-multiple axis limits through host user-data dwordUSER_DISPATCH_THREADS(0x104,0= no cap for normalDispatchor exact multiples).victory-shadercrates/victory-shader/src/emit/shader.rs&mod.rs: define and exportUSER_DISPATCH_THREADS = 0x104.crates/victory-shader/src/emit/lower.rs: adddispatch_threads_prologuefor spilled compute programs (all ray-tracing structure builder stages) along any axis with group dimension > 1:exchange.is_none(), entry block has no back-edge — native Wave64 hosts and Wave32 programs): branch inactive lanes out toRetafter entry inputs (groupId, relabelledthread_id), and place entry-EXECballots/SCC tests inbody_entryso hardwareEXEC,s_bcnt1_i32_b64(exec), wave reductions, and stores see the exact active lane set with zero per-instruction guard overhead.exchange.is_some()for wave64-on-wave32 hosts, or programs containings_barrier): keep all threads alive soGroupMemoryBarrierWithGroupSync/exchange_halvesnever deadlock (even whenlimit <= 32leaves the upper 32-lane half with 0 active lanes), while predicating memory/LDS accesses (effect_guard), active ballots (mask_dword),scc_some,wave_wide, and whole-wave reduction masks (section_val).Verification
draw::tests::dispatch_x_thread_dimensions_convert_to_groups_and_partial_limitsincrates/victory-gpu/src/draw.rs.emit::wave64_tests::spilled_compute_masks_partial_dispatch_threads_on_wave64_and_wave32incrates/victory-shader/src/emit/wave64_tests.rstestings_bcnt1_i32_b64(exec), whole-wave OR, and unconditional per-lanebuffer_store_dwordx2atlimit = 45, 1, 0:host_wave=64(early-exit) andhost_wave=32(predicatedexchange_halves, no barrier hang atlimit = 1), both validated bydxil.dll.cargo test -p victory-shader --lib(215 passed, 0 failed),cargo test -p victory-gpu(119 passed, 0 failed),cargo xtask policy(asset policy: 169 files ok).VICTORY_BVH_BUILDER=1on AMD Radeon RX 9070: eliminates the BVH over-dispatch memory corruption crash (previously crashing within ~7–14 s on empty box-node bounds); sustained 2+ minutes / 8,900+ submissions of builder execution with zero CPU memory corruption.Refs #16.
AI-assisted (Antigravity); verified locally on an AMD Radeon RX 9070. No game data.
@Revens2 on GitHub · 2026-11-25 09:22 UTC · original
RTX 5070 (32-lane): in-game check of this PR with #36 and #579 on
a26859f: 2 of 2 runs held 600 s withVICTORY_BVH_BUILDER=1, no exception.Runs: diag build,
VICTORY_RELAY=2, builder started ~107 s in, so ~8 min with it running; world reached, 0 first-chance exceptions, 0 device removals, 0.3-0.4 fps. On the same tree with the earlierVICTORY_THREAD_DIMSvariant (Yorivel's2521646, which launches ceil(x/threads) groups and lets late lanes leave at entry), both runs ended 4-6 s afterbuilder runs(one at+0x8f92a, read of all ones). Details on #16. Two runs per arm, so a lead.Tests on that tree (
cargo test --workspace --locked): 536 passed, 10 ignored, 1 failed:xtask policy::tests::repository_passes_policy, because #36 + this PR together makelower.rs528,884 bytes against the 524,288 limit (each is under it alone on its own base;mainis 514,840). Merging both needs room in that limit or a split of the file.AI-assisted (Claude Code, Claude Sonnet 5.5): the runs are mine, on my own copy of the title. Counts only, no game data.
System Initand presents 100% black frames with 3 draws/frame #950System Initand presents 100% black frames with 3 draws/frame #950@pr0vId3nce on GitHub · 2026-11-25 16:03 UTC · original
RTX 4080 (32-lane): held 546 s with the builder on, no exceptions, and the shade is lit
Setup: RTX 4080 16 GB (driver 32.0.16.1088), Ryzen 9 7900X, 32 GB, Windows 11 26200, diag build, Series X profile. Tree:
main0b0074e0b+ #156 (so the builder's three prefix-sum passes translate on 32 lanes) + this PR's170c24269; one textual conflict between the two inemit/mod.rs's export list, nothing else.VICTORY_BVH_BUILDER=1, a checkpoint in the first gameplay scene, 540 s limit.the ray-tracing structure builder runs: all of its programs have host pipelines pipelines=53, then 546 s to the time limit with 0 first-chance and 0 unhandled exceptions. Without the thread-count handling, four of four earlier runs here (c96b4f2and0b0074ewith #156) ended in0xc0000005shortly after that line (8 to 10 s in the two I timed).mainleaves them black, with a few blocky tiles along the lower edge. Judged by eye againstmainon the same checkpoint; I have no console reference.Two card tests beside the PR's own, both on the RTX 4080 and on a Ryzen 7900X iGPU (gfx1036), host waves of 32 (neither device took the 64-lane form of these programs, so that mode did not run here):
spilled_compute_masks_partial_dispatch_threads_on_wave64_and_wave32: passes;s_or_saveexec_b64 -1) and mask by the saved EXEC. Limits 70, 100, 33, 1 and none: all 256 dwords right. I can send it as a patch if it is wanted.Independent of the thread (found before I read its later half), in case it helps a reviewer:
28918b7150a7aad5,caa78b8ca62bc3d6) come throughDispatchXwith0x20: 2,244 and 4,002 of the 12,589 builder dispatches before the crash.28918b71gives each thread 128 bytes (group << 13for 64 threads). As groups, 1,606 covers 13 MB.What comes next on this card:
no number left for another copy … COPIES=1023comes two seconds into the world andshaders touched pages that had no copy50 times in the run, so part of the structures reads as zeros. In a trace of another run the builder's root views alone name 529 distinct 4 MiB windows in its first frame and 838 over 58 frames. The frame time is the per-list refresh and compare of those copies, as #284 describes.One thing for whoever merges:
main+ #156 + this PR putslower.rsat 530,706 bytes, over the 512 KiB limit ofcargo xtask policy(Revens2 saw the same with #36).AI-assisted (Claude Code); measured on my machine. No game data.
@mynzjerko on GitHub · 2026-11-25 17:05 UTC · original
Thanks @Revens2 and @pr0vId3nce for the thorough 32-lane hardware and in-game verifications (RTX 5070 600 s and RTX 4080 546 s with zero exceptions and lit shade)!
I've rebased this PR onto latest \main\ (\
ca8829f, now commit \36a2257) to resolve the conflict in \crates/victory-gpu/src/draw.rs's unit tests, and moved \effect_guard\ and \dispatch_threads_prologue\ into a small child module \crates/victory-shader/src/emit/dispatch.rs\ (same #[path = ...]\ pattern as \intersect.rs). That brings \lower.rs\ down to 517,044 bytes (+2,204 bytes over \main's 514,840, leaving >7 KiB of headroom under the 512 KiB \xtask policy\ limit) so it combines more easily with #36 / #156.Re-verified on RX 9070:
@pr0vId3nce I'd gladly include your multi-group wave-reduction / prefix-sum test (limits 70, 100, 33, 1, none) if you'd like to share it as a patch or gist.
@Dathinel on GitHub · 2026-11-26 00:22 UTC · original
Two portable RTX 3050 Laptop (wave32) checks for review at
36a2257b, using synthetic inputs:Hardware runs used the PR integrated onto local 504db0e. Both standalone patches apply to the PR head. No game files or scene-quality measurements in these tests. AI-assisted.
@KyleS98 on GitHub · 2026-11-26 13:03 UTC · original
An independent confirmation from an RTX 3090 Ti (32-lane), and a note on why this no longer merges.
I opened #1292 for the same bug without having seen this PR, and have closed it in favour of this one. I have not run this PR's code; what follows is from my own smaller version of the same fix (x only) on
main06702fe.The counts are threads: one more piece of evidence. Tracing every builder dispatch with its root arguments, one structure gets 25
DispatchXcalls in a row, alternating the two box stages. Each stage's records begin exactlyxtimes the node size after the previous stage's:Flags I saw:
0x20on28918b7150a7aad5andcaa78b8ca62bc3d6,0x8020on4ddd6f9702fab2a7and5062bc7a48e842f8. Every other builder program came through plainDispatch, and everyDispatchXhad y = z = 1.In the title (Series X,
VICTORY_BVH_BUILDER=1 VICTORY_FIRSTLANE_OWN=1, 300 s): with the counts taken as threads the builder ran about 3 minutes to the end of the run, with no exception and no device loss. Before, every run of mine died within seconds of the first builder submission. It also crashes that way on an AMD card running the wave64 programs natively, so it is not the paired 32-lane form.It was not usable: 4 to 7 s a frame, and
no number left for another copy; its pages read zeros COPIES=1023in the log. That matches what others report here and on #994.Why this conflicts with
mainnow (head36a2257againstceb9e1f):draw.rs,emit/mod.rsandemit/shader.rs. The one that needs a decision isshader.rs:mainhas since takenRootType::Other(0x104)forUSER_DISPATCH_SPREAD, the code this PR uses forUSER_DISPATCH_THREADS, so the word needs a new number (0x105 isUSER_THREAD_LIMITin #994, if the two are meant to coexist). The other two look like both sides adding lines at the same place.AI-assisted (Claude Code, Claude Fable 5.2).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.