GPU: split compute dispatches past 65,535 groups in x #3098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3100"
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?
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T08:02:06Z.
D3D12 allows at most 65,535 thread groups per dimension per dispatch, and the indirect clamp cuts larger counts to that. GTA VI asks for more.
indirect_diffuse_lighting:CS_FinalGather(2dc364df5d3278b8) dispatches 74,192 to 83,008 groups in x depending on the view, 8 per screen tile. With the clamp, about 1,000 tiles at the end were never gathered. The bottom rows of the lit picture showed stale tile content from earlier frames, a band of coloured blocks along the bottom edge.Stacked on #2969 (this extends its Wine-compilable clamp) and #3097 (
lower.rstests in their own file, for room under the 512 KiB limit). Please review fromGPU: split compute dispatches past 65,535 groups in xon.What changes:
b0of register space 3 (GROUP_BASE_SPACE), loaded once in the entry block. Mesh shaders, y and z are unchanged.{base, x, y, z}. 17 × 65,535 covers the clamp's 2^20 limit. They execute through a command signature[CONSTANT base, DISPATCH]made for the pipeline's root signature, with the title's count multiplied by 17. Empty chunks dispatch nothing.Census over the title's shader pack (
VICTORY_EMIT_DUMP, byte comparison of every emitted program, before and after on this branch):The same programs fail to translate before and after (227).
In game (Linux: GE-Proton11-14 Wine, vkd3d-proton, RTX 5090 driver 620.73.04; prison yard, frames 1450–1700). I measured the share of bright blocky pixels in the bottom 4% of the frame:
The diagnostic switch only confirmed the cause. It isn't something to ship: NVIDIA's Vulkan driver happens to accept more than 65,535 groups, but D3D12 drivers needn't.
With the fix, the lit yard looks the same as with the cap lifted. There was no device removal or Xid in any run.
Tests, under
cargo xtask wine-test(#1218) on the same machine:indirect8/8 and the new tests below.cargo clippy --workspace --all-targets(with and withoutdiagnostics) andcargo xtask policyare clean.chunked_dispatch_records_hold_every_word:[140000, 1, 1]becomes bases 0, 65,535 and 131,070 with x 65,535, 65,535 and 8,930, then 14 empty chunks, count 17.group_base_covers_a_dispatch_past_the_host_limit: 70,000 groups, direct and throughExecuteIndirect. Every one of the 70,000 output words is written once.Limits:
AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:10:12Z.
Review: APPROVED
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed on RTX 5090 (includinggroup_base_covers_a_dispatch_past_the_host_limit, also passed underVICTORY_WARP=1).cargo test -p victory-gpu --lib indirect:: -- --test-threads=1: 8/8 passed on RTX 5090 (includingchunked_dispatch_records_hold_every_word).cargo clippy -p victory-gpu --all-targets -- -D warnings&cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 193 files ok.Cleanly splits compute dispatches past the D3D12 65,535
xgroup limit via a root constant group base for both direct and indirect dispatches.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:40:02Z.
Review: CHANGES_REQUESTED
Covering
ExecuteIndirectfor compute dispatches past 65,535 groups inxis genuinely useful (building beyond#3086, which handles direct dispatches), and the clamp +[CONSTANT, DISPATCH]command-signature idea is the right direction. However, reviewing6d3848e0line by line and testing natively on Windows 11 (RTX 5090, WARP, and Windows SDKfxc.exe) turned up several blocking bugs, including a silently skipped test:1. Accidental deletion of
|| self.memory.is_some()in DXIL emission (crates/victory-shader/src/emit/shader.rs:630-633)Replacing
|| self.memory.is_some()with|| self.group_base.is_some()omits the entire!dx.resourcesemission for any shader whose only resource is read-only title memory (self.memory.is_some(), e.g., a VS/PS/MS or a CS that does not read TGIDxand has no user data/samplers/root views/view marks). Please keep|| self.memory.is_some()alongside|| self.group_base.is_some().2. Counted
ExecuteIndirectstill passes the unmultiplied title count buffer (crates/victory-gpu/src/draw.rs:1853-1879)In
draw.rs,indirect::boundwritesmin(counts[0], records) * 17intoclampedathost_stride * host_max, and the#[cfg(feature = "diagnostics")]read_indirectblock reads that multiplied count — but theExecuteIndirectcall right above it still passes the original title count buffer:For any counted indirect compute dispatch (e.g. title count = 1,
x = 80,000),ExecuteIndirectreads count1instead of17and drops chunks1..16.Also, in the
diagnosticsblock below it,if chunked { Some((&clamped, ...)) }passesSomeeven whencounterisNone(wherecount_wordwasfalseand nothing was allocated/written at that offset). BothExecuteIndirectandread_indirectshould useSome((&clamped, u64::from(host_stride) * u64::from(host_max)))if and only ifchunked && counter.is_some().3. 17x buffer under-allocation in
indirect::bound(crates/victory-gpu/src/indirect.rs:676-679)wordsmultiplies byrecordsinstead ofrecords * 17whenchunked(kind == 3), even though the clamp shader writesrecords * 17 * 4words plus the count word at indexrecords * 17 * 4. Small counts (records <= 240) happen to be masked bylist.arguments's 64 KiB floor, but anyrecords > 240overflows the UAV buffer on the GPU.4. Three logic bugs in the
kind == 3clamp HLSL (crates/victory-gpu/src/indirect.rs:520-594)left/budget[0]: in thelane == 0loop,else { left -= costs[i]; }is attached toif (kind == 3) { ... } else if (costs[i] > left) { ... } else { left -= costs[i]; }, soleft -= costs[i]never executes forkind == 3.rejectmeans a second over-budget title record in the same 64-lane tile (or across a tile boundary) overwritesreject, soh - h % CHUNKS == rejectonly zeroes the latest rejected record's remaining chunks while earlier rejected records' chunks1..16still run. Sinceleftdrops to0on the first rejection, checkingh >= reject(oncerejectis set on the first rejected record) cleanly zeroes every chunk from that point on across all remaining tiles.GROUPS = 2^20cap is bypassed forkind == 3:dispatch_costreturns0whenx > GROUPS / (y * z), so e.g.[65535, 65535, 1]chargescost = 0(passes budget) whileclampedwrites[0, 65535, 65535, 1]straight intodest(4.3B groups), and[2_000_000, 1, 1]writes17 * 65535 = 1,114,095 > 2^20groups. Please apply the sameGROUPSclamp/zeroing todestforkind == 3askind == 2does.5.
draw::tests::group_base_covers_a_dispatch_past_the_host_limitsilently skips on FXC syntax error (crates/victory-gpu/src/draw.rs:4017-4198)Compiling
SOURCEdirectly with Windows SDKfxc.exe /T cs_5_1 /E mainfails with:outis a reserved HLSL keyword (RWStructuredBuffer<uint> out : register(u0);). Because the test doeslet Ok((root, pso)) = compute(...) else { return; // no shader compiler here };, it silently returnsokon every run without dispatching anything!Once
outis renamed, there is also a second bug on line 4146:params[0]is a Root UAV (D3D12_ROOT_PARAMETER_TYPE_UAV), yetl.SetComputeRootUnorderedAccessView(uav_param, gpu)passesslots.0.GetGPUDescriptorHandleForHeapStart().ptr(a descriptor-heap GPU handle) instead ofout.GetGPUVirtualAddress()(andslotscreates an unused raw UAV for anRWStructuredBuffer<uint>). Please fix both and assert on compilation failure rather than returning early whenD3DCompilerejects the shader.6. Architecture / coordination note with
#3086Since
#3086already covers direct dispatches cleanly by placingGROUP_BASEinsidestage.user_data(which is always aD3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTSroot parameter inpipeline/host.rs:479-492), note thatD3D12_INDIRECT_ARGUMENT_TYPE_CONSTANTcan target(param, DestOffsetIn32BitValues = u.index, Num32BitValuesToSet = 1)directly without needing a separateGROUP_BASE_SPACE = 3root parameter orHostShader/shader_cacheschema changes. Also, on the direct-dispatch path, splittingx > 65_535even whengroup_baseisNone(as#3086does) avoids passing an illegalx > 65_535toID3D12GraphicsCommandList::Dispatch.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:24:33Z.
Automated triage for the maintainers.
Needs work. Splitting x past 65,535 groups with a group-id base is a reasonable approach to a real D3D12 limit, and CI passes. The PR's own commit (
6d3848e, on top of #2969 and #3097) has a regression in the translator, though:crates/victory-shader/src/emit/shader.rs, the resource-metadata condition: the diff replaces|| self.memory.is_some()with|| self.group_base.is_some()instead of adding the new term. A program whose only resource is the title-memory page table (t0inMEMORY_SPACE, frommemory_handle) would no longer get its resource metadata, so its SRV is not declared. Please keep thememoryterm and addgroup_basebeside it.struct Shader: the doc comment ofuser_data("Dwords of user data the shader reads") was replaced bygroup_base's doc, souser_datalost its doc. Please restore it.indirect.rs, clamp shader, kind 3 budget rejection:rejectholds a single record. If two chunked records are rejected in the same tile, or a rejected record's chunks spill into a tile where a later record is rejected, the second loop marks only the last rejected record's chunksPAST. The earlier record's remaining chunks then run with their x counts. That leaves a partial dispatch once the 2^27 budget runs out. A test with the budget exhausted across more than one chunked record would cover it.What would change the verdict: the first two fixed, the third fixed or shown not to happen, and a test for a memory-only program's metadata. The PR will also need a rebase once #2969 and #3097 land. It also overlaps #3086 and #2312, which handle the same 65,535 limit.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T09:46:50Z.
Thanks for the careful review, and you're right on all of it. In particular:
|| self.memory.is_some()was replaced instead of extended.ExecuteIndirectgets the title's unmultiplied count.records, notrecords × 17.group_base_covers_a_dispatch_past_the_host_limitnever ran:outdoesn't compile, and the test returns early as if no compiler were present. I reported it as passing. That was wrong, and I should have checked that it actually dispatched.I also missed that #2312 (Xvania7, opened earlier) already fixes the same issue, #2256, for direct and indirect dispatches, and that #3086 covers direct ones. So I'm closing this rather than fixing it, and I'll test #2312 on the RTX 5090 under Wine in the scene where I found the bug. The scene: GTA VI's
indirect_diffuse_lighting:CS_FinalGatherasks for 74,192–83,008 groups in x throughExecuteIndirect. With the clamp at 65,535, about 1,000 screen tiles were never gathered, and the bottom of the lit picture showed stale tiles. I'll post the before/after on #2312.AI-assisted (Claude); measured on my machine, no game data shared.
Pull request closed