Skip to content

cs_indirect_dispatch_count: read the root UAV from s4:s5, as #4312 moved it (#6162) - #7133

Closed
Conrage wants to merge 1 commit into
ProjectLeonida:mainfrom
Conrage:fix-6162-indirect-dispatch-root-uav
Closed

Conrage wants to merge 1 commit into
ProjectLeonida:mainfrom
Conrage:fix-6162-indirect-dispatch-root-uav

Conversation

@Conrage

@Conrage Conrage commented Nov 23, 2026 •

Copy link
Copy Markdown

Requested by João · project thread

Claimed in the coordination issue as: #6162, in #7049

Fixes #6162

What and why

#4312 (D3D-448) moved the compute root arguments to start at s4 and updated cs_user_data.comp, cs_set0_sample.comp and cs_sg_probe.comp. It missed runtime/test/glsl/cs_indirect_dispatch_count.comp, which still read its root UAV from pc.s[0]/pc.s[1]. Those words belong to the driver and stay 0, so the shader updated the wrong address, and d3d12_indirect_dispatch_count reported layer 0/0, expected 6/10 for the "count 0, update 1" case.

This PR changes the fixture to read pc.s[4]/pc.s[5] and updates its header comment to say why. It is the one-line change the issue reporter bisected and confirmed. A scan of runtime/test/glsl/*.comp found no other fixture that reads pc.s[0] or pc.s[1].

Tested

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

@tikD1337

Copy link
Copy Markdown
Contributor

Review: #7133 cs_indirect_dispatch_count: read the root UAV from s4:s5, as #4312 moved it (#6162)

Verdict: Approve. This is a one-file fix to a test fixture. It makes the synthetic compute shader follow the same compute root-argument layout as the runtime and the other compute fixtures.

Environment

  • Windows 11, CPython 3.13
  • Runtime targets configured with CMake + Ninja (MSVC /W4 /permissive- /utf-8, as set in runtime/CMakeLists.txt)

What changed

runtime/test/glsl/cs_indirect_dispatch_count.comp:

  • The root UAV address is now built from pc.s[4], pc.s[5]. It used to be pc.s[0], pc.s[1].
  • The header comment now says s4:s5, and a second comment line explains why: compute root arguments start at s4, and s0..s3 belong to the driver block.

Why it is correct

  • The runtime's layout. rt::rootsig::stage_base(Stage::Compute) returns 4 (runtime/src/root_signature.h:138-141). pack_stage starts placing root parameters at out.base = stage_base(stage) (runtime/src/root_signature.cpp:54). The test's root signature has one parameter, a D3D12_ROOT_PARAMETER_TYPE_UAV (runtime/test/d3d12_indirect_dispatch_count_test.cpp:39-45), so its 64-bit GPU VA lands in s4:s5. Before this PR the shader read s0:s1, which the layer leaves at 0. Its atomics then hit heap_base + 0 instead of the UAV, so the readback never changed.
  • Matches the expected result. For the "count 0, update 1" case, expected(0, true) adds up only the second dispatch (count 3): w[0] = 1+2+3 = 6 and w[1] = 1+3+6 = 10. That is the 6/10 the commit message says the test should report, in place of the 0/0 it reported before.
  • Consistent with the other compute fixtures. cs_sg_probe.comp:28 uses exactly the same add64(pc.heap_base, uvec2(pc.s[4], pc.s[5])) pattern. cs_user_data.comp and cs_set0_sample.comp also index from s[4]. This was the last compute fixture still reading the old layout.
  • The rest of the shader is unchanged. It still declares the 144-byte push-constant block (uint s[32]; uvec2 heap_base; uvec2 code_base;), keeps the carry-propagating add64 and the two atomics. The CMake add_custom_command already lists the .comp file in DEPENDS, so the SPIR-V is rebuilt with no build change.

Notes (not blocking)

  1. Graphics and mesh fixtures still read pc.s[0]. These are vs_draw.vert:19, ms_draw.mesh:25 and ps_image_atomic.frag:22, but stage_base gives 8 for VS/PS/GS and 16 for mesh. I didn't follow how those tests fill their user data. If they also go through pack_stage, they have the same bug and their results are 0 for the wrong reason. If they write raw push constants on purpose, a one-line comment like the one added here would make that clear. Either way, this belongs in the coordination issue as a finding:, not in this PR.
  2. The offset is hard-coded. The fixture assumes s4 because the compute base is a constexpr. If stage_base ever moves again, the test will fail the same way it did this time: correct code, wrong address, a silent 0/0. You could fail loudly instead, for example with a static_assert(rt::rootsig::stage_base(Stage::Compute) == 4) in d3d12_indirect_dispatch_count_test.cpp. That's optional.

Test results (no game files needed)

Check Result
git diff --check PASS
python -m compileall -q make_game.py tools tests PASS
python -I scripts/check_no_game_data.py PASS
python -I make_game.py --help PASS
Targeted Python tests none apply (the change is GLSL only); none failed

The test that proves this fix is the GPU/WARP CTest d3d12_indirect_dispatch_count, and it was not part of this run. It needs glslangValidator (Vulkan_GLSLANG_VALIDATOR_EXECUTABLE), a Vulkan device and D3D12 WARP. I checked the 6/10 above by working the arithmetic against expected() and the s4:s5 layout by reading the code. Please post the ctest -R d3d12_indirect_dispatch_count output, with GPU and driver, as AGENTS.md asks. If WARP is the in-box build 10.0.22621.5415, its stale-count exception is already handled at d3d12_indirect_dispatch_count_test.cpp:231-250, so that is not a failure.

Project rules

AI-assisted.

@dadsmallbuk1

Copy link
Copy Markdown

Tested ae2dca2 on NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 (26200), native MSVC 2022 RelWithDebInfo with glslangValidator: pass, and the failure it fixes reproduces on main.

AI-assisted (Claude Code).

…eonida#4312 moved it (ProjectLeonida#6162)

ProjectLeonida#4312 (D3D-448) moved the compute root arguments to start at s4 and updated
cs_user_data, cs_set0_sample and cs_sg_probe, but this fixture still read its
root UAV from s0:s1, which the driver block leaves at 0. The shader then
updated the wrong address and d3d12_indirect_dispatch_count reported 0/0
for the "count 0, update 1" case instead of 6/10.
@ErayOzdayioglu

Copy link
Copy Markdown

Tested the current head 4436e8c (the earlier GPU check was of ae2dca2) on Windows 11 26200 with MSVC 14.51 (VS 2026) and Vulkan SDK 1.4.363. d3d12_indirect_dispatch_count_test was built from this head. pass, and the first AMD run:

GPU this head control: parent's cs_indirect_dispatch_count.comp, same build otherwise
RTX 5070 (617.42) exit 0: "8 native WARP / Vulkan GPU comparisons passed; count=0,1,max,>max, nonzero offsets and GPU count overwrite, no validation errors" exit 1: count 0 update 1: host 6/10, layer 0/0, expected 6/10
Radeon iGPU, Ryzen 5 7600 (RDNA2, 32.0.21042.62) exit 0, same line exit 1, same failure

So the failure from #6162 reproduces on both vendors without the fixture change, and this one-line change fixes it on both.

AI-assisted: yes

@Drdg263

Drdg263 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested PR head 4436e8cea (fast-forward on 1cc6e3c12) on Windows 11 Pro 25H2 (Build 26200.7462) with MSVC 19.44.35230.0 (VS 2022 Build Tools 17.14.45 + Windows SDK 10.0.26100.0), Vulkan SDK 1.4.363.0, CMake 4.4.4, Ninja 1.13.2 (DISABLE_RTSS_LAYER=1):

Control (main 1cc6e3c12):

  • ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R "^d3d12_indirect_dispatch_count$" (LEONIDA_VK_DEVICE=5070, LEONIDA_HOST_ADAPTER=5070): FAILED (count 0 update 1: host 6/10, layer 0/0, expected 6/10).

PR #7133 (4436e8cea):
Built d3d12_indirect_dispatch_count_test cleanly in a fresh worktree (RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON):

  • NVIDIA GeForce RTX 5070 Laptop GPU (driver 621.24, subgroup 32..32, LEONIDA_VK_DEVICE=5070, LEONIDA_HOST_ADAPTER=5070):
    • d3d12_indirect_dispatch_count_test.exe and ctest -R "^d3d12_indirect_dispatch_count$": PASS (exit 0, 0.29 sec) — counted ExecuteIndirect(DISPATCH): 8 native WARP / Vulkan GPU comparisons passed; count=0,1,max,>max, nonzero offsets and GPU count overwrite, no validation errors.
  • AMD Radeon(TM) 610M (driver 26.11.2, subgroup 32..64, LEONIDA_VK_DEVICE=610M, LEONIDA_HOST_ADAPTER=610M):
    • d3d12_indirect_dispatch_count_test.exe and ctest -R "^d3d12_indirect_dispatch_count$": PASS (exit 0, 0.23 sec) — counted ExecuteIndirect(DISPATCH): 8 native WARP / Vulkan GPU comparisons passed; count=0,1,max,>max, nonzero offsets and GPU count overwrite, no validation errors.

Testing and report prepared with AI assistance.

@XIIYAZ

XIIYAZ commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4436e8cea merged into main bf85ff703 (clean merge) on RTX 3070, NVIDIA 617.42, Windows 11, MSVC 2022 RelWithDebInfo: d3d12_indirect_dispatch_count fails on main and passes with this PR (ctest -C RelWithDebInfo -R ^d3d12_indirect_dispatch_count$).

On main it fails with count 0 update 1: host 6/10, layer 0/0, expected 6/10; with this PR it passes. (#6564 and #6566 appear to fix the same line; I only tested this one.)

AI-assisted test run.

@best2135

Copy link
Copy Markdown

Checked the one-line s4:s5 fix (the same change as #6564 and #6566) applied onto main 1d21030, under Wine 11.20 Staging on an NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08, clang-cl/xwin cross-build): with the host side skipped, the layer gets 8/8 counted dispatches right, with no validation errors. Without the fix, it writes 0/0 in every case (#6162).

Under Wine, the test itself still exits 1 with no output. Wine's d3dcompiler_47 rejects the test's HLSL (InterlockedAdd on RWByteAddressBuffer), so the host reference never builds. That is a separate Wine issue, posted as a finding in #7804, not a problem with this PR. Since #6564, #7133 and #6566 make the same change, only one of them is needed.

AI-assisted check; outcomes only.

@Cryserrrrr

Copy link
Copy Markdown

Verified: it passes 3/3 on an RTX 4080 SUPER (610.88) and an RDNA2 iGPU (AMD 25.10.36), where main fails with count 0 update 1: host 6/10, layer 0/0. The older #5792 makes the identical s[4], s[5] change. Measurements and cause are there: #5792. AI-assisted (Claude Code).

@Urban225

Copy link
Copy Markdown
Contributor

Tested 4436e8c on AMD Radeon RX 7900 XTX (RDNA3), AMD proprietary 26.10.1, Windows 11, MSVC 19.44: fixes the failure on this card.

Targeted run: only this test was run on the PR, not the rest of ctest or the GPU suite.

AI-assisted (Claude wrote the test script and read the logs); the runs are from my machine.

@Conrage

Conrage commented Nov 23, 2026

Copy link
Copy Markdown
Author

I'm closing this as a duplicate of #6564 (@reeledMarek). That PR was opened earlier with the same pc.s[4]/pc.s[5] change to cs_indirect_dispatch_count.comp, and I missed it when I claimed this. The GPU runs posted here (RTX 5090, RTX 5070, RTX 5070 Laptop, Radeon 610M and a Ryzen iGPU, each failing on main and passing with the change) apply to #6564 too, since the shader line is identical. Thanks to everyone who tested.

AI-assisted: yes


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

d3d12_indirect_dispatch_count fails on main since #4312: cs_indirect_dispatch_count.comp still reads its root UAV from s0:s1

10 participants