Repository navigation
Conversation
Under Wine, D3DCompile is Wine's d3dcompiler_47 (vkd3d-shader HLSL): it
has no methods on writable byte address buffers (E5005 'Load' is not
defined on RWByteAddressBuffer) and ignores a [RootSignature] attribute,
so the code holds no root signature to make. Every run-time shader of
ours failed there: the argument clamp ("no argument clamp: indirect
execution dropped", every indirect draw and dispatch then dropped as
not bounded), the depth twin's 16-bit conversion ("no depth
conversion"), and the tests' own shaders.
A new module, compute, compiles a shader and serializes its root
signature in Rust from the parameters the host binds. The clamp keeps
main's design (one group, tiles of 64, groupshared costs charged in
order, the list's budget, the record's rest copied) with the title's
records a StructuredBuffer<uint> (t0) and the clamped records and the
budget RWStructuredBuffer<uint> (u0, u1), indexed in words: bound()
already refuses addresses and strides not multiples of 4. Its root
signature is b0 (4 constants), SRV t0, UAV u1, UAV u0, as bound()
binds them. The depth conversion indexes its scratch buffer in words
(footprint offsets and pitches are multiples of 4) with b0 (8
constants) and UAV u0. Test shaders lose their RootSignature
attributes the same way.
A new test checks every word the clamp writes for draws, indexed
draws, dispatches, mesh dispatches, records past the budget and the
budget spent.
The approach is Mumogg's (Marvisak#1279: structured buffers indexed in words,
the root signature serialized beside the shader), ported to main's
rewritten clamp and extended to the depth conversion.
The tests that bound their own root signatures:
The marked-UAV, placed-view and depth-twin rebind tests compile their
shaders with a [RootSignature] attribute Wine's compiler ignores, and
the marked write ORs its page bit through a byte address buffer method
it lacks. Their root signatures are made with crate::compute from what
the tests bind, and the bitmap is a RWStructuredBuffer<uint> indexed in
words.
emit/lower.rs is 520,563 bytes, 3,725 under the asset policy's 512 KiB per-file limit, and open PRs that grow it (Marvisak#2968, Marvisak#2977) leave it about 27 bytes short. Its test module moves, unchanged but for rustfmt's layout of the one indentation level less, to emit/lower_tests.rs, still a child module of `lower` (`#[path]`), so it keeps its access to the private items it tests. lower.rs is now 468,320 bytes.
* pr/lower-tests: Shaders: lower's tests in their own file, under the policy's size limit
D3D12 allows at most 65,535 thread groups per dimension, and the indirect
clamp cuts larger counts to that. The title asks for more: GTA VI's
indirect_diffuse_lighting:CS_FinalGather dispatches 74,000-83,000 groups in
x (8 per screen tile), so the last ~1,000 tiles were never gathered and the
bottom of the lit picture showed stale tiles from earlier frames.
A translated compute shader that reads TGID x now adds a group-id base,
one dword in b0 of register space 3 (`GROUP_BASE_SPACE`), loaded once in
the entry block. The host binds it as one root constant:
- A direct dispatch sets the base and dispatches at most 65,535 groups at
a time; shaders without the base dispatch as before.
- The indirect clamp expands each dispatch record into 17 records of
{base, x, y, z} (17 x 65,535 covers the clamp's 2^20 limit), executed
through a command signature of [CONSTANT base, DISPATCH] for the
pipeline's root signature, with the title's count times 17.
Mesh shaders, y and z, and every non-compute stage are unchanged: over the
title's shader pack 2,532 compute programs' DXIL changes (those reading
TGID x) and no vertex, pixel or mesh program does.
Dukestar69
left a comment
There was a problem hiding this comment.
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 x group 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).
|
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:
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 |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Covering ExecuteIndirect for compute dispatches past 65,535 groups in x is genuinely useful (building beyond #3086, which handles direct dispatches), and the clamp + [CONSTANT, DISPATCH] command-signature idea is the right direction. However, reviewing 6d3848e0 line by line and testing natively on Windows 11 (RTX 5090, WARP, and Windows SDK fxc.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.resources emission 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 TGID x and has no user data/samplers/root views/view marks). Please keep || self.memory.is_some() alongside || self.group_base.is_some().
2. Counted ExecuteIndirect still passes the unmultiplied title count buffer (crates/victory-gpu/src/draw.rs:1853-1879)
In draw.rs, indirect::bound writes min(counts[0], records) * 17 into clamped at host_stride * host_max, and the #[cfg(feature = "diagnostics")] read_indirect block reads that multiplied count — but the ExecuteIndirect call right above it still passes the original title count buffer:
list.list.ExecuteIndirect(
&signature,
host_max,
&clamped,
0,
counter.as_ref().map(|(s, _)| &s.buffer),
counter.as_ref().map_or(0, |(s, at)| s.offset(*at)),
)For any counted indirect compute dispatch (e.g. title count = 1, x = 80,000), ExecuteIndirect reads count 1 instead of 17 and drops chunks 1..16.
Also, in the diagnostics block below it, if chunked { Some((&clamped, ...)) } passes Some even when counter is None (where count_word was false and nothing was allocated/written at that offset). Both ExecuteIndirect and read_indirect should use Some((&clamped, u64::from(host_stride) * u64::from(host_max))) if and only if chunked && counter.is_some().
3. 17x buffer under-allocation in indirect::bound (crates/victory-gpu/src/indirect.rs:676-679)
let host_stride = if chunked { 16 } else { stride };
let words = (host_stride / 4) as u64 * u64::from(records.max(1));
let count_word = chunked && count.is_some();
let out = list.arguments(4 * (words + u64::from(count_word)))?;words multiplies by records instead of records * 17 when chunked (kind == 3), even though the clamp shader writes records * 17 * 4 words plus the count word at index records * 17 * 4. Small counts (records <= 240) happen to be masked by list.arguments's 64 KiB floor, but any records > 240 overflows the UAV buffer on the GPU.
4. Three logic bugs in the kind == 3 clamp HLSL (crates/victory-gpu/src/indirect.rs:520-594)
- Accepted chunked dispatches never deduct from
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. - Multi-record / cross-tile budget rejection leaves chunks unzeroed: storing a single scalar
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_limit silently skips on FXC syntax error (crates/victory-gpu/src/draw.rs:4017-4198)
Compiling SOURCE directly with Windows SDK fxc.exe /T cs_5_1 /E main fails with:
error X3000: syntax error: unexpected token 'out'
out is a reserved HLSL keyword (RWStructuredBuffer<uint> out : register(u0);). Because the test does let Ok((root, pso)) = compute(...) else { return; // no shader compiler here };, it silently returns ok on every run without dispatching anything!
Once out is renamed, there is also a second bug on line 4146: params[0] is a Root UAV (D3D12_ROOT_PARAMETER_TYPE_UAV), yet l.SetComputeRootUnorderedAccessView(uav_param, gpu) passes slots.0.GetGPUDescriptorHandleForHeapStart().ptr (a descriptor-heap GPU handle) instead of out.GetGPUVirtualAddress() (and slots creates an unused raw UAV for an RWStructuredBuffer<uint>). Please fix both and assert on compilation failure rather than returning early when D3DCompile rejects the shader.
6. Architecture / coordination note with #3086
Since #3086 already covers direct dispatches cleanly by placing GROUP_BASE inside stage.user_data (which is always a D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS root parameter in pipeline/host.rs:479-492), note that D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT can target (param, DestOffsetIn32BitValues = u.index, Num32BitValuesToSet = 1) directly without needing a separate GROUP_BASE_SPACE = 3 root parameter or HostShader/shader_cache schema changes. Also, on the direct-dispatch path, splitting x > 65_535 even when group_base is None (as #3086 does) avoids passing an illegal x > 65_535 to ID3D12GraphicsCommandList::Dispatch.
|
Thanks for the careful review, and you're right on all of it. In particular:
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 AI-assisted (Claude); measured on my machine, no game data shared. |
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.