Repository navigation
vulkan: a counted dispatch with no count buffer ignores the count offset (RT-INDIRECT-DISPATCH-COUNT-NULL-OFFSET) - #2491
Conversation
With LEONIDA_INDIRECT_GROUP_BUDGET, IndirectDispatchCounter::Batch::prepare accepts a dispatch batch that has no count buffer. It still applied the count offset: an unaligned offset was refused, and an aligned one became the job's count address (0x40 for offset 64 on a null buffer). emit() then pushed that address with has_count 1, so the shader read memory at a raw GPU address. prepare now zeroes the offset when there is no count buffer, as IndirectArgumentClamp::prepare ignores it. The replay passes a null count buffer and offset 0 when the command has no count buffer, as it already does for prepare_indirect_clamp. From kevincommits' finding in ProjectLeonida#1608 (item 2). indirect_dispatch_count_alloc_test gains a case that follows the repro. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
left a comment
There was a problem hiding this comment.
Reviewed de25d7cb9 (runtime/src/vulkan_indirect_dispatch_count.h, runtime/src/vulkan_replay.h, runtime/test/indirect_dispatch_count_alloc_test.cpp) and tested:
- Zeroing
count_offsetwhen!countinIndirectDispatchCounter::Batch::prepare(matchingIndirectArgumentClamp::prepare) and gatingp.source.buffer/count_offsetonind->count_bufferinvulkan_replay.h:4148cleanly prevents non-nullcount_offsetfrom failing alignment or turning into a raw count GPU address withhas_count = 1. - Tested on Windows 11 (MSVC 19.44):
indirect_dispatch_count_allocpassed (0.03 s).
Looks good to merge.
AI-assisted (Antigravity, Gemini).
|
Reviewed at head Verification
Notes
Approve. AI-assisted review + local MSVC verification. |
|
#2491 | head de25d7c (merged cleanly with main d48a957) | |
timbot103
left a comment
There was a problem hiding this comment.
Reviewed de25d7cb9 and found no issues. The counted-dispatch fallback now passes a null handle and zero offset for a fixed-count dispatch. The helper also normalizes the offset before alignment and device-address arithmetic, so it emits a zero count address with has_count = 0 and the shader skips the count load. A real count buffer still goes through replay bounds and alignment checks and the helper’s device-address overflow check. See runtime/src/vulkan_replay.h:4104, runtime/src/vulkan_replay.h:4147, runtime/src/vulkan_indirect_dispatch_count.h:85, and runtime/src/indirect_dispatch_count.comp:26.
The D3D12 entry point, the legacy command-list recorder, and the shared stateful draw, indexed-draw, and mesh replay validator reject nonzero offsets paired with an absent count buffer. Existing validation tests assert this behavior. The clamp helper and draw and mesh emission guard count reads by buffer presence. See runtime/shims/d3d12_com.cpp:1003, runtime/src/command_list.h:953, runtime/test/d3d12_execute_indirect_validation_test.cpp:198, runtime/test/d3d12_state_map_test.cpp:797, runtime/src/vulkan_replay.h:2724, runtime/src/vulkan_replay.h:5661, and runtime/src/vulkan_indirect_clamp.h:597.
The new mock test exercises unaligned, aligned, and near-limit offsets with an absent count buffer and checks the emitted count address and flag for both buffer states. Its environment setup uses _putenv_s on Windows and setenv on Linux before the first budget read. The existing GPU budget test exercises the default clamp path with a zero offset in its fixed-count cases, so the mock test provides direct coverage of the helper regression. See runtime/test/indirect_dispatch_count_alloc_test.cpp:177, runtime/test/indirect_dispatch_count_alloc_test.cpp:300, runtime/CMakeLists.txt:3206, and runtime/test/d3d12_indirect_dispatch_count_test.cpp:120.
Static audit only. No builds, tests, or GPU runs performed for this review.
AI-assisted.
|
Tested de25d7c merged (no commit) with main 8fb9748: MSVC 19.52, Windows 11 10.0.26300.
AI-assisted (Claude Code). |
Claimed in the coordination issue as: RT-INDIRECT-DISPATCH-COUNT-NULL-OFFSET (#1608 (comment))
What and why
Item 2 of @kevincommits' finding in #1608 (#1608 (comment)). Thanks for the audit and the repro.
With
LEONIDA_INDIRECT_GROUP_BUDGETset,IndirectDispatchCounter::Batch::prepare(vulkan_indirect_dispatch_count.h) accepts a dispatch batch with no count buffer. It still applied the count offset:0x40.emit()then pushed that address withhas_count = 1, soindirect_dispatch_count.compread a raw GPU address. The replay (vulkan_replay.h) passedp.source.buffer_offset + ind->count_offseteven for a command with no count buffer.The fix ignores the offset without a count buffer, as
IndirectArgumentClamp::preparedoes:preparesetscount_offsetto 0 whencountis null. The alignment and overflow checks then pass, and the count address stays 0, soemit()pusheshas_count = 0.ind->count_bufferis null, asprepare_indirect_clampjust above it already does.With a count buffer nothing changes: the offset is still checked and added.
Overlap: #1863 also edits
vulkan_replay.h. It already conflicts withmain(labeledneeds rebase); its rebase would meet this two-line change too. No conflict with #2469 or #2489.Tested
Windows 11, MSVC (VS 18), RelWithDebInfo, on
main43a9d56.indirect_dispatch_count_alloc_test(CPU, mock driver) gains case 6, which follows the repro. It sets the budget to 4 before anything reads it.~3all prepare, with a count address of 0.emit()pushes count 0 andhas_count0.emit()pushes that address withhas_count1.With
main'svulkan_indirect_dispatch_count.hthe case fails on its first check (offset 2 refused). With the fix the whole test passes.ctest -R "^(indirect_dispatch_count_alloc|d3d12_indirect_dispatch_count|d3d12_indirect_group_budget|d3d12_indirect_zero|indirect_clamp)$": 5/5 pass. The GPU ones run in seconds;d3d12_indirect_group_budgetcovers the replay path with the budget set.scripts/check_no_game_data.py: clean.The replay change has no test of its own: no CPU test drives
prepare_counted_dispatchthrough the replay.GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code