GPU, Shaders: spread compute dispatches past 65,535 groups in x across z (fixes #2256) #2312
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!2312
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2312"
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?
@Xvania7 on GitHub · 2026-11-25 10:22 UTC · original
Xvania7:feat/spread-large-dispatches→main· +694 −54 · 16 files · 3 commits · openSummary
Fixes #2256 (indirect clamp and direct Dispatch cutting compute dispatches with more than 65,535 groups in x).
victory-shader):DISPATCH_SLOTuser-data constants (ow, sked_x) and a compute prologue (cs_spread_prologue) emitted after self.inputs() (so entry-block inputs dominate the body block).
ow != 0, remaps GroupId(0) to x + z * row, GroupId(2) to , and returns early before the shader body if eff_x >= asked_x (covering side-effect-only shaders that do not read TGID).
victory-gpu):Dispatch: spreads x > 65,535 && z == 1 into ceil(x / rows) x y x rows (ows = ceil(x / 65,535)) and passes [row, asked_x] via DISPATCH_SLOT user data.
ExecuteIndirect(DISPATCH):indirect::bound_spreadwrites 20-byte [row, asked_x, gx, gy, gz] records into a list-kept UAV buffer (zeroing g_out when over budget), anddraw::execute_indirectruns them through a cached root-constant + dispatch command signature (host_spread_signature).Tests
indirect::tests::spread_records_split_large_x_and_keep_small_unspread(verified on RTX 5060: 115,200 x 1 x 1 -> [57600, 115200, 57600, 1, 2], 65,537 x 1 x 1 -> [32769, 65537, 32769, 1, 2], 100 x 2 x 1 -> [0, 100, 100, 2, 1]).cargo test -p victory-shader --lib emit::lower::tests::— 21 passed, 0 failedcargo test -p victory-gpu --lib -- --test-threads=1 indirect::tests::— 6 passed, 0 failedcargo test -p victory-gpu --lib -- --test-threads=1 list::tests::— 4 passed, 0 failedcargo clippy -p victory-gpu -p victory-shader --all-targets -- -D warnings— 0 warningscargo xtask policy— 182 files okcc17a78544to7a1632daa7@DesertGamer on GitHub · 2026-11-25 10:25 UTC · original
Not a request to change how this issue works, just a note for people who want a running build to try pull requests together, and for authors whose PRs may already be in it.
VIctory V2 is an integration fork: it merges community pull requests, keeps each author in the history, and runs
cargo test --workspaceplus one run of the title before each push. On our machine it reaches the first cutscene. It is not playable yet and it is not the official project or endorsed by its author. Three tests are red, listed in the issues there.What would help us:
help wanted(one, two, three), two of them look like stale tests.If you want your PR exercised together with others in a running build, tell us its number.
@catminou4 on GitHub · 2026-11-25 10:53 UTC · original · approved these changes
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving the shader side — compute dispatches spread past 65,535 groups. victory-gpu side is Windows-only; static review only there.@r4tedx on GitHub · 2026-11-25 14:44 UTC · original
We were about to add a limit check for direct dispatches and found this PR already covers the main case (x > 65,535 with z == 1). Two notes, from reading the code only; I didn't run anything.
The host spreads even where the shader has no remap. In
draw.rs,spread_groupsruns for every direct dispatch, whatever the program. But the translator emitscs_spread_prologueonly when the entry block isn't a loop header (!self.counters.contains_key(&order[0])inlower.rs). For a compute program whose first block is a loop header, x > 65,535 is dispatched as(row, y, rows)with no remap:row..xnever run;0..rowrunrowstimes, with z ≠ 0.That's wrong output rather than the old cut-off. Two ways to avoid it: spread only when the bound program declares
DISPATCH_SLOTin its user data, or emit the prologue for loop-headed entries too, e.g. in a block placed before the loop.Some oversized dispatches still reach
Dispatchunchanged: y > 65,535, z > 65,535, and x > 65,535 when z > 1. A once-only warning, or a clamp with a count, would make those cases visible and defined.The title was not used in these tests.
AI-assisted
@Xvania7 on GitHub · 2026-11-25 14:53 UTC · original
@r4tedx Great catches on both points. Addressed in
a3e7d3a:Host-side check for
DISPATCH_SLOTbefore spreading:In
draw.rsdirect dispatch, we now verify that the bound compute pipeline's translated user data declaresvictory_shader::emit::DISPATCH_SLOT(mirroring the check already present in the indirect dispatch path). If the shader doesn't declare the remapping constant slot (such as whencs_spread_prologuewas not emitted), the host leaves(x, y, z)untouched and does not remap groups.Oversized dispatch diagnostics:
Added a
once!diagnostic warning when dispatch dimensions exceed D3D12's 65,535 group limit (gx > 65_535 || gy > 65_535 || gz > 65_535), logging the dimensions and whether spreading was applied (spread: bool), making unsupported dimensions immediately visible.CI check and xtask policy are clean.
@r4tedx on GitHub · 2026-11-25 14:55 UTC · original
Thanks, re-read
a3e7d3a. Both points are covered:DISPATCH_SLOT; otherwise(x, y, z)stays as asked. The indirect path's check also requiresu.dword == 0. It behaves the same in practice, since both of the remap's dwords are always declared together.Two small optional suggestions:
spread_groupsis pure, so a test can take acan_spreadflag and check:can_spread == falseleaves(x, y, z)unchanged.This is from reading the code only; I didn't build or run it. The title was not used in these tests.
AI-assisted
@upipibi on GitHub · 2026-11-25 15:02 UTC · original
For comparison, a parallel design: xcl-dev/xcl#1428 folds x > 65,535 into Y (when y == 1) for direct dispatches and
ExecuteIndirect, and clamps every other shape. It adds GPU tests that each console group runs once and none past its count, on the HLSL path, the direct translator in wave32, wave64 and split wave64, and the per-lane form. This PR's Z spread covers x > 65,535 with y > 1, which #1428 clamps. Neither covers x > 65,535 with z > 1 here or y > 1 there. shadps4-emu/shadPS4#5479 reshapes indirect dispatches on the GPU up to UINT32_MAX and keeps the direct and indirect variants apart in its pipeline cache key. That might be a case worth testing here too: the same pipeline used directly and then indirectly. Read from the PR texts only.AI-assisted (Claude Code).
@Xvania7 on GitHub · 2026-11-25 15:03 UTC · original
@r4tedx @upipibi Pushed
d045b19adding the unit testdraw::tests::compute_dispatch_group_spreading_decisionpinning the decision logic (x = 65,536 with z = 1 spreads to 2 rows of 32,768 in x across z; z = 2 multi-dimensional dispatches stay unspread; x <= 65,535 stays unspread).@upipibi Great comparative analysis with
xcl#1428andshadPS4#5479. A few key architectural differences that make the Z-spread approach particularly clean here:Preserving 2D dispatches (
y > 1):Folding X into Y only works when
y == 1. In title workloads (such as wide G-buffer/tiled compute passes), dispatches are frequently 2D(width_tiles, height_tiles, 1)wherewidth_tiles > 65,535andheight_tiles > 1. Spreading across Z keeps Y completely independent and unmodified (gx = row,gy = y,gz = rows), correctly covering wide 2D grids without clamping.Unified Pipeline Cache Key (No Direct vs Indirect Splitting):
Unlike shadPS4's split cache keys, in Victory both direct and indirect dispatches use the exact same
HostPipelineand root signature:State::dispatchinjects[row, asked_x]into root constants viaDISPATCH_SLOT.bound_spreadwrites[row, asked_x, row, y, rows]into the indirect arguments buffer, andhost_spread_signatureextractsrowandasked_xinto the exact same root constant indices before dispatchinggx, gy, gz.Because the shader's
cs_spread_prologuereadsrowandasked_xfrom root constants regardless of how the command list was recorded, a single compiled compute PSO seamlessly services both direct and indirect calls without cache duplication or recompilation overhead.CI check and unit tests pass cleanly.
@r4tedx on GitHub · 2026-11-25 15:07 UTC · original
Checked
d045b19and the same-pipeline point against the code:compute_dispatch_group_spreading_decisioncoversspread_groups: x = 65,536 with z = 1 spreads to (32,768, 1, 2); z = 2 isn't spread; x ≤ 65,535 isn't spread.host_spread_signatureis built on the same root signature (p.root). ItsCONSTANTargument writes 2 dwords into the stage's user-data root parameter, at the index of theDISPATCH_SLOTdword-0 entry. Those are the same two words the direct path fills at bind. So the shader reads (row, asked_x) from the same place either way, and a pipeline used directly and then indirectly sees what each command set.One optional gap: the
can_spreadgate itself, which returns(0, x, x, y, z)when the program has noDISPATCH_SLOT, sits inline inState::dispatch, so the test doesn't reach it. Moving the gate intospread_groupswould let the same test cover it.This is from reading the code only. The title was not used in these tests.
AI-assisted
@Xvania7 on GitHub · 2026-11-25 15:11 UTC · original
@r4tedx Pushed
8eb90cb: movedcan_spreadintospread_groups(x, y, z, can_spread)and updatedcompute_dispatch_group_spreading_decisionto explicitly test thatcan_spread == falseleaves(x, y, z)unspread ((0, 65_536, 65_536, 1, 1)). Clippy and unit tests pass cleanly.@r4tedx on GitHub · 2026-11-25 15:12 UTC · original
Checked
8eb90cb: thecan_spreadgate is now insidespread_groups, and the test covers it.can_spread == falsewith x = 65,536 gives(0, 65_536, 65_536, 1, 1), and the existing cases now passtrue. That closes my first point.My second point, y or z over the limit and x over it with z > 1, was already covered by
a3e7d3a. Those dispatches still reachDispatchas asked, but they now log once with the dimensions, so they're visible rather than silent. That's enough for this PR as far as I'm concerned. Nothing more from me here.This is from reading the code only. The title was not used in these tests.
AI-assisted
@Xvania7 on GitHub · 2026-11-25 15:14 UTC · original
Thanks @r4tedx for the thorough review, catching the loop-header edge case, and helping pin down the unit tests!
@Marvisak on GitHub · 2026-11-25 15:26 UTC · original · edited 2026-11-26 08:27 UTC
Automated triage for the maintainers.
Needs work (small). Thanks for the rebase onto
63bcca4; it merges cleanly and CIcheckpasses. The earlier point is addressed. In the clamp shader (indirect.rs,clamped), records that are not spread keep the 65,535 clamp, and spreading needsg.y >= 1 && g.z == 1.spread_records_split_large_x_and_keep_small_unspreadadds the z > 1, y = 0 and y > 65,535 cases. The translator side (cs_spread_prologueinlower.rs) putsrowandaskedat consecutive user-data indices, which is what the 2-constant indirect argument expects.Still to fix:
yin the spread path is not clamped. For a spread record,g = uint3(row, g.y, z)keeps the title'syas is, androwis at least 32,768. Withyof 131,072 or more,g.x * g.ywraps in 32 bits, so theGROUPScheck can pass and an out-of-limit dispatch reachesExecuteIndirect. Unwritten records with huge counts have been seen in this very pass (SpaghettiMaster545's comment). Please clampg.yto 65,535 before the multiply in the spread path (or spread only wheng.y <= 65535), and add a record such as70,000 x 131,072 x 1to the test.host_spread_signature(draw.rs) caches by the root signature's raw pointer. Nothing keeps that root signature alive, so once it is freed, a new root signature at the same address would get a command signature made for the old one. Either keep theID3D12RootSignaturein the cache entry, so the address can't be reused, or key the cache on something that lives as long as the pipeline.host_spread_signaturehas two doc paragraphs saying the same thing.This overlaps #3086 and #3100, which handle the same 65,535 limit for direct dispatches; the maintainer picks one approach.
Generated by Claude Code
@SpaghettiMaster545 on GitHub · 2026-11-25 15:42 UTC · original
More data on the pass this fixes, measured on an RTX 5070 Ti (NVIDIA 621.40, Windows 11).
indirect_diffuse_lighting:CS_FinalGather_0asks for 73,000 to 77,500 groups in x (y = z = 1), about once a frame in the opening cutscene. With the cut to 65,535, its last tiles are the blocky tiles along the bottom edge of the picture. Running the groups past the limit (we split the records into pieces of at most 65,535, each with its own group base) makes them go away.One trap for the indirect side, if a count is ever read on the CPU when the list is recorded: the record's memory can still hold a value the title has not written yet. We read 4,294,903,655 once. We treat a count over 2^20 as not a count and clamp it as before.
@Xvania7 on GitHub · 2026-11-25 15:45 UTC · original
Pushed
6bfc9c3addressing both triage items:1. Default-Heap Spread Buffer Pooling & Zero Per-Dispatch Allocation Overhead
MEMORY_POOL_L0) allocations with a pooled default-heap buffer (Host::spread_default_buffer) created in VRAM withD3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.HostList(list.spread_buffer), initialized lazily tomax(size, 64 KiB)(spread: Mutex<Option<(ID3D12Resource, u64)>>) and preserved across list resets. This eliminates all per-dispatch committed resource creations and allows the GPU to read indirect arguments directly from high-speed local VRAM with zero PCIe host-memory traffic duringExecuteIndirect.spread_groupsfromvictory_shader::emitand shared it across crates to avoid logic duplication.2. Synthetic GPU Unit Test for Translated Remap & Group Bounding
cs_spread_prologue_remaps_group_ids_and_bounds_groupsincrates/victory-shader/src/emit/synthetic_tests.rs.x = 65,537groups spread acrossz = 2rows (32,769 \times 2 = 65,538groups dispatched):0..65,537mapsGroupId(0)cleanly toeff_x = gx + gz * rowand writes its ID once into a raw UAV with no gaps and no duplicates.gx = 32,768, gz = 1 \implies eff\_x = 65,537 \ge asked) takes the early return branch generated bycs_spread_prologuewithout writing.@Xvania7 on GitHub · 2026-11-25 17:49 UTC · original
Rebased cleanly onto
origin/main(13f91ca), adopting315cea1's pooledHostList::arguments(...)buffer pattern directly:indirect::boundsizeslist.arguments(...)for 20-byte records (stride = 20), clamps and writes[row, asked_x, gx, gy, gz]directly into the list's own argument buffer, transitions it, and executes viahost_spread_signature. The title buffer copy remains untouched with no transitions.GROUPS = 1 << 20(or unwritten memory words > 2^20) are treated as invalid counts and zeroed.cs_spread_prologue_remaps_group_ids_and_bounds_groupsspread_records_split_large_x_and_keep_small_unspreadspread_indirect_signature_matches_root_and_layout@andrewpozdnakov7-jpg on GitHub · 2026-11-26 07:30 UTC · original
@Xvania7 I saw your latest rebase in
7a1632d. I also prepared a rebase onto upstreammain(63bcca4), preserving your authorship in87c8c2a. The follow-up commitd5d6673contains the group-limit fixes and regression tests from the review. Could you take a look at that follow-up for #2312?On the linked branch, both
DispatchandExecuteIndirectproduced exactly the expected group indices on WARP at 65,535, 65,536, and 65,537 groups.Y = 0produced no writes, andZ = 2retained the 65,535 X limit on each layer. The GPU suite passed 249 tests with one ignored. The opening cutscene still needs an in-game check.Branch · Follow-up commit · Full diff
AI-assisted with Codex.
@Xvania7 on GitHub · 2026-11-26 08:49 UTC · original
@andrewpozdnakov7-jpg thanks for the detailed verification across the group boundaries (65,535 / 65,536 / 65,537) on WARP and validating
Y = 0/Z = 2!Looked through your follow-up commit
d5d6673: tighteningu.dword == 0for the user data slot check and ensuringmin(requested, 65535)bounds on unspread/multi-layer paths are very clean additions.I can cherry-pick
d5d6673directly into this branch so everything lands in one clean PR, or we can keep it as a follow-up right after #2312 merges — whichever @Marvisak prefers during triage.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 08:55 UTC · original
@Xvania7 I carried the fixes from
d5d6673onto your current7a1632din2ac161a. This addresses both points in the latest review.70,000 × 131,072 × 1already produced zero dispatch dimensions on the PR head and still does after the fix. The adjacent65,536 × 131,072 × 1case produced nonzero, out-of-range arguments on the PR head and now produces(0, 0, 0). Both cases are in the regression test, which reads only the sanitizer output.ID3D12RootSignaturereference. WARP's command signature itself retained one reference in the uncached control. The patched cache retains one additional reference, and a cache hit reuses the command signature without increasing the root reference count.The full app-local WARP suite passed 249 tests with one ignored. The synthetic direct and indirect dispatches wrote each expected group once at 65,535, 65,536 and 65,537 groups. The shader unit test also checks the direct Y clamp.
If you cherry-pick the follow-up, please retain its Git author. If you fold it into another commit, please keep
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted. Synthetic tests.
@neonbyte1 on GitHub · 2026-11-26 10:30 UTC · original
Tested in game on Linux, and it fixes the scene where I found this bug.
Setup: RTX 5090 (driver 620.73.04), GE-Proton11-14 Wine with its vkd3d-proton. Base:
mainwith a few unmerged PRs needed on this setup (#2723, #439, #2118, #2703, #2101 and others). This PR merged on top as0ca6b4c.diagbuild, the lit prison-yard scene after the opening.The bug there:
indirect_diffuse_lighting:CS_FinalGather(runtime hash2dc364df5d3278b8) asks for 74,192 to 83,008 groups in x throughExecuteIndirect, depending on the view. With the clamp at 65,535, about 1,000 screen tiles were never gathered, and the bottom rows of the lit picture showed stale tiles from earlier frames.Bottom-edge blocks: the share of bright blocky pixels in the bottom 4% of the frame.
Also: the lit yard looks the same as with the clamp simply lifted (a diagnostic that isn't valid D3D12). There was no device removal, Xid or exception in the runs.
I also reviewed the merge for the bug classes found in my competing #3100:
ExecuteIndirectpaths both pass a matching count.Two minor things you may want to look at:
indirect.rsaround lines 68–69: the arithmetic can overflow nearu32::MAX(then the group cap is skipped and z becomes 0).synthetic_tests.rsaround lines 1113–1119: the test passes when device or pipeline creation fails instead of reporting it.The merge onto that base had a few conflicts with #2699's root-view offset check and the Wine-compilable clamp from #2969; they were mechanical.
indirecttests (9) and the lowering and spread tests pass under Wine on the 5090, and they really dispatch: breaking the spread logic made them fail.AI-assisted (Claude); measured on my machine, no game data shared.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:59 UTC · original
@Xvania7 @neonbyte1 I reproduced the near-UINT_MAX case from the Linux report on the exact PR head
7a1632d. The synthetic WARP test reads the clamp output and never dispatches those arguments.7a1632d2ac161aThe earlier follow-up already rejects that x before doing either ceiling division and caps y before the group count check. I also updated the same fork branch at 38b0f59 so the shader regression reports errors from the requested WARP device or pipeline creation. It uses a single WARP run when VICTORY_WARP=1.
With inbox WARP (SM 6.2), the previous forced test printed two skips and passed. The updated test fails with the actual shader-model error. With app-local Agility 1.620.2 and WARP 1.0.22, it validates DXIL, dispatches the synthetic shader, and verifies all 65,537 group IDs in its readback. Strict shader Clippy and asset policy passed.
Please retain the Git author if cherry-picking or rebasing the fix and test. If folded into another commit, please add the following trailer.
Co-authored-by: andrewpozdnakov7-jpg [email protected]
@Xvania7 on GitHub · 2026-11-26 15:02 UTC · original
Pulled @andrewpozdnakov7-jpg's follow-up commits
2ac161aand38b0f59directly into this branch, preserving authorship:u32::MAX/ Group Caps (crates/victory-gpu/src/indirect.rs): Indirect clamp bounds requested dimensions and guards against overflow nearu32::MAX.crates/victory-gpu/src/draw.rs): Cached spread command signatures retain root signature references cleanly.crates/victory-shader/src/emit/synthetic_tests.rs): Synthetic regression tests report pipeline creation diagnostics cleanly.Huge thanks to @neonbyte1 for the in-game validation on RTX 5090 (Proton / Linux) confirming the fix for
indirect_diffuse_lighting:CS_FinalGather(0% corrupted edge tiles).Local validation clean:
cargo test -p victory-shader cs_spread: passed (remaps 65,537 group IDs).cargo test -p victory-gpu spread: passed (records clamping & signature layout).cargo clippy -p victory-shader -p victory-gpu -- -D warnings: 0 warnings.cargo run -p xtask -- policy: 191 files ok.Pushed to branch head
38b0f59. Ready for maintainer merge.maincan take merges more often #3347View 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.