GPU, Shaders: honor thread dimensions in direct DispatchX (#2750) #2841
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2841
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2841"
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?
@brainbudt on GitHub · 2026-11-25 21:50 UTC · original
brainbudt:fix/dispatchx-thread-dimensions→main· +430 −20 · 11 files · 1 commits · openUpstream
DispatchXforwards its arguments as D3D12 group counts for every flag value. A synthetic 64×1×1 kernel asked for 65 threads with flag0x20writes past slot 64. Issue #2750 reports the same flag on BVH builder requests.What changed
0x20, AMDUSE_THREAD_DIMENSIONS) as thread dimensions and compute host group counts with ceiling division per axis.EXECballot).Dispatch, flag-clearDispatchX, and complete groups continue using the existing pipeline with byte-identical DXIL.fxceless/victory-fork@36a2257.Verification
DispatchX(65, 1, 1, 0x20)wrote exactly slots0..64(upstream failed at slot 65); following ordinary 2-groupDispatchand flag-clear 2-groupDispatchXeach wrote 128; flag-clear 65 groups wrote 4,160.1.9.2609.5): accepted both ordinary (byte-identical to upstream) and bounded shaders.cargo check --workspace --target x86_64-pc-windows-msvc --tests, andcargo clippy --workspace --target x86_64-pc-windows-msvc --tests -- -D warningspassed.Reviewed with mistral-loop: 2 rounds with Mistral Large 4 and DeepSeek V4.1 Flash (Mistral Hosted) on high. Verdict: approved.
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
@Venom2054 on GitHub · 2026-11-25 22:08 UTC · original
Tested
274cdadbon a physical RTX 5070 Ti, driver 621.01, through the Windows D3D12 command-list entry points.0x8020. I replayed the X dimension of 82,606 seen in the #2750 prologue trace with a synthetic guest shader that stores its entrypopcount(EXEC_LO). D3D12 counted 82,624 invocations (2,582 groups). Exactly 82,606 slots were written. The last 14 active lanes each stored 14, and the remaining 18 slots in that group kept their sentinel. An ordinary two-group dispatch after a partial dispatch on the same list and UAV wrote all 64 slots with a population of 32.8 × 8 × 4groups and a guest shader with no bounds check, requests of16 × 13 × 8,16 × 16 × 5,10 × 16 × 5and10 × 13 × 5wrote exactly 1,664, 1,280, 800 and 650 cells respectively. I checked the coordinate value in every cell of the16 × 16 × 8volume and all 17 guard words for each case. The exactly divisible0x20control and ordinary dispatches before and after wrote all 2,048 cells.The PR's four original readbacks also reproduced on hardware (65 / 128 / 128 / 4,160). As a negative control on
bc677ec1, sending ordinary groups for the partial-Y case made the test fail at exactly(0, 13, 0), the first cell outside the requested volume.The attached patch adds the synthetic 3D regression test. To repeat it on Windows, apply it to the PR branch and run
cargo test --profile diag -p victory-gpu --lib dispatch_x_3d_writes_only_requested_voxels -- --ignored --nocapture. I haven't measured in-game lighting or frame time with this PR. Test and patch prepared with Codex.native-dispatchx-3d-tests.patch.txt
@oni-swr on GitHub · 2026-11-25 22:28 UTC · original
Independent Windows WARP verification of
274cdadbagainst currentmain(f3578e38). I confirmed Microsoft Basic Render Driver (vendor0x1414, device0x008c, software flag0x2) withVICTORY_D3D12_WARP=1and diagnostics enabled.DispatchXwith bit 5 set wrote exactly 65 slots. Ordinary two-group Dispatch and the two bit-5-clear DispatchX controls wrote 128, 128, and 4,160 slots, respectively.mainfailed at zero-based slot 65, which held 1 instead of 0.1.8.2502.11) accepted both ordinary and bounded DXIL, and the partial-dispatch group-barrier rejection test passed.AI-assisted with Codex (gpt-6.2-sol). Claude Code (claude-opus-5-5) prepared the initial WARP guard and main comparison harness. Synthetic data only.
@Machad3x on GitHub · 2026-11-25 22:30 UTC · original
Hardware result at head
274cdadb, cherry-picked onto a stack that also carries the console flow for wave64 programs (#439 / #2214), RTX 3080 Ti, driver 621.24.With the two together,
translate_partial_dispatchpanics at world load (bitcode.rs, "forward reference outside a phi") for a program that numbers its threads as the console does:dispatch_guardcallsthread_id, which returns theconsole_flatvalue cached by the body, in a block that does not dominate the guard. Resetting that cache besideself.user_data = Noneindispatch_guardfixes it; a synthetic wave64 program withv_readlane_b32translated as a partial dispatch for a 32-lane target reproduces it.mainhas no such cache today, so this matters when the two meet.With that fix (and #1273): one 7-minute run in play, no device removal; in the scene at a window, GPU step median 299 ms against 307 ms before (one run each).
Ran with AI assistance (Claude Code).
@fuzeofficlal on GitHub · 2026-11-25 22:40 UTC · original
Verified
274cdadbon Windows 11 (RTX 5090 + WARP + SDK10.0.26100.0dxil.dll) againstmain(f3578e3):cargo test --locked -p victory-shader --test dispatch_threads: 2/2 passed on RTX 5090 and WARP (includingdxil.dllvalidation of the guardedentry->body/abortsplit).victory-gpu:thread_dimensions_cover_partial_groups_on_each_axispassed (1/1);--ignoreddispatch_x_writes_only_requested_threadspassed on RTX 5090 (0.46s) and WARP (0.31s).cargo clippy --locked(victory-shaderdefault &--features host,diagnostics;victory-gpudefault &--features diagnostics,--all-targets -- -D warnings): 0 warnings;cargo xtask policy:193 files ok.Shader::partialcompilation leaves normalDispatch, non-0x20DispatchX, and exact-multiple dispatches untouched, andState::bind_dispatchswitches root/PSO cleanly between full and partial variants.crates/victory-shader/src/emit/lower.rsreaches523,090bytes here —1,198bytes shy of the 512 KiB (524,288-byte)xtask policylimit (#2836frees 821 bytes if landed alongside).Looks solid and ready to merge.
@Marvisak on GitHub · 2026-11-26 03:19 UTC · original
Automated triage for the maintainers.
Verdict: merge candidate.
dispatch_xincrates/victory-gpu/src/list.rsnow reads bit 5 of the flags (USE_THREAD_DIMENSIONS, from AMD's public register reference) as thread counts instead of group counts.thread_groupsuses ceiling division and refuses more than 65,535 groups per axis. Incomplete groups use a lazily made pipeline whose entry guard (Lower::dispatch_guardinemit/lower.rs) compares global thread IDs with the requested counts, which are passed throughDISPATCH_THREADSuser data. Ordinary dispatches keep the existing DXIL, and partial dispatches withs_barrierare refused. Hardware runs on an RTX 5070 Ti and RTX 5090, plus a WARP run, confirm exact writes, withmainfailing the same fixture at slot 65. There is no other open PR for this.Two notes for the maintainer:
lower.rsis about 1.2 KB under the 512 KiB policy cap with this PR.console_flatthread id needs resetting indispatch_guard. Whichever PR lands second should include that.CI: passing. Recommending a look, not approving.
Generated by Claude Code
274cdadb0ctoc2ed5d14c4@kotekompotek on GitHub · 2026-11-25 21:59 UTC · original · reviewed
Correct: thread-groups conversion uses the bound pipeline's own group size with div_ceil per axis, rejects zero/overflow (>65535 groups or u32::MAX threads) into a dropped dispatch rather than an invalid call, and binds the ORIGINAL thread dims into the shader's user data — which is what DispatchX's console callers pass and read. Partial-group handling via the bounded plan is covered by the hardware test that asserts only requested threads write. The const-generic THREADS split keeps the group-dispatch path unchanged. LGTM.
@Dukestar69 on GitHub · 2026-11-26 03:27 UTC · original · reviewed
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --test dispatch_threads: 2 passed, 0 failed.cargo test -p victory-gpu --lib/cargo clippy -p victory-gpu --all-targets -- -D warnings: fails to compile against currentorigin/main(63bcca4) becausedepth_bounds_test.rs(landed onmain) initializespipeline::Translatedwithout the newthreadsfield:cargo xtask policy: 194 files ok.Rebasing onto current
mainand addingthreads: Noneincrates/victory-gpu/src/pipeline/depth_bounds_test.rs:58should make the test target build cleanly.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@brainbudt on GitHub · 2026-11-26 10:22 UTC · original
Thanks @Dukestar69 — rebased onto
origin/main(63bcca4) and addedthreads: Noneincrates/victory-gpu/src/pipeline/depth_bounds_test.rs(headc2ed5d1).@fuzeofficlal on GitHub · 2026-11-26 10:52 UTC · original · approved these changes
Tested
c2ed5d14locally on Windows 11 (RTX 5090 + WARP,VICTORY_D3D12_DEBUG=1, and Windows SDK10.0.26100.0\x64\dxil.dll).Verification:
cargo xtask policyandcargo clippy -p victory-shader -p victory-gpu --tests -- -D warnings(default and--all-features): clean.cargo test -p victory-shader --test dispatch_threadswith SDKdxil.dll: 2/2 passed (both full and partial-dispatch DXIL containers validate cleanly withIDxcValidator, including bothUserDataCBV handle annotations fixed up byreplace_const).list::dispatch_tests::thread_dimensions_cover_partial_groups_on_each_axis: passed.list::dispatch_tests::dispatch_x_writes_only_requested_threads -- --ignored: passed on RTX 5090, RTX 5090 +VICTORY_D3D12_DEBUG=1(--features diagnostics), and WARP +VICTORY_D3D12_DEBUG=1(--features diagnostics).placed_uav_tests,pipeline::make::tests(2/2), anddraw::tests(20/20 on RTX 5090): all passed.The entry-guard structure is sound:
ir::build_boundedalready rejects branches to block 0 so moving guest inputs/body to block 1 has no entry-PHI hazard,library::namekeys PSOs by serialized root signature and DXIL bytes so full and partial pipelines do not collide,State::bind_dispatchrebinds by raw COM pointer when toggling between full and partial variants on one guest pipeline, exact multiples stay on the unguarded pipeline (preserving shaders withs_barrier), and divergent barriers in partial dispatches are cleanly refused. Looks ready to merge.@Jackster on GitHub · 2026-11-26 16:06 UTC · original · edited 2026-11-26 16:08 UTC
AMD verification of
c2ed5d1on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), Windows 11, hardware adapter:dispatch_x_writes_only_requested_threadspasses on the hardware adapter: 65 threads with flag0x20write exactly slots 0..64, and the ordinary and flag-clear controls keep their old counts.--test dispatch_threads: 2/2.cargo test -p victory-gpu --lib: 232 passed / 0 failed / 2 ignored.63bcca4, the same fixture withthread_groupsremoved: fails at slot 65 (slot 65, expected 65 writes), so the upstream forwarding reproduces on this card.Synthetic only, no game files. AI-assisted.
@kilolimaVI on GitHub · 2026-11-26 20:52 UTC · original · edited 2026-11-26 20:54 UTC
NEW-284 verification on current head, Windows 11, toolchain 1.98.1,
--test-threads=1. Hardware: AMD Radeon 780M (RDNA3 iGPU). WARP:VICTORY_WARP=1for victory-shader,VICTORY_D3D12_WARP=1with--features diagnosticsfor victory-gpu.cargo test -p victory-shader -p victory-gpu --locked --no-fail-fast: no failures on the 780M; on WARP only the four synthetic_tests failures main63bcca4also has (WARP-only harness issue, fixed by #2225). victory-gpu on WARP: 247 passed, 0 failed (main: 246).thread_dimensions_cover_partial_groups_on_each_axis,partial_and_group_dispatch_translate_to_distinct_programs,partial_dispatch_refuses_a_divergent_group_barrier.dispatch_x_writes_only_requested_threads(--ignored) passes on the 780M and on WARP. CI never runs it, so this is its first SM 6.6 hardware result.AI-assisted (Claude).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.