runtime: share indirect clamp buffers across queue families and fix safety bugs #1832
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1832
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1832/head"
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?
@IlyassRS3 on GitHub · 2026-11-25 12:46 UTC · original
IlyassRS3:fix/rt-indirect-clamp-sharing-and-safety→main· +478 −21 · 6 files · 1 commits · merged 2026-11-25 19:27 UTCItem ID:
RT-INDIRECT-CLAMP-SHARING-AND-SAFETYClaim: #1608
Summary
Fixes queue-family sharing and four safety/correctness issues in
IndirectArgumentClamp(runtime/src/vulkan_indirect_clamp.h) and itsScratchBuffersoverload (runtime/src/vulkan_scratch.h) when indirect clamping runs across graphics and async-compute queues during world rendering:VK_SHARING_MODE_CONCURRENT) on both scratch chunks andHostAreacounter buffersenable_indirect_clamp()previously did not receivestate_.families(unlikeenable_copy_scratch()10 lines earlier inruntime/shims/d3d12_vulkan_device.cpp).std::vector<std::uint32_t> families = {}parameter to the explicit-usageScratchBuffersconstructor (runtime/src/vulkan_scratch.h),IndirectArgumentClamp, andVulkanContext::enable_indirect_clamp(), and forwardedstate_.familiesfromruntime/shims/d3d12_vulkan_device.cpp.IndirectArgumentClamp::make_area()now callsshare_across_queue_families(info, families_)on the host-visible counter buffer as well, because direct and async-compute queues copy counter slots into the sameHostArea::buffer.VkDeviceMemoryleak onvkBindBufferMemoryretry + strong exception safety inmake_area()/Batch::prepare()make_area()looped over candidate host-visible memory types and allocated a newVkDeviceMemoryeach iteration without freeing the failed allocation whenvkBindBufferMemoryfailed, leaking device memory. Now freesarea.memorybefore retrying, and cleans uparea.buffer/area.memoryifareas_.push_backorfree_slots_.reservethrows.Batch::prepare()now releases the claimed slot ifslots_.push_back(slot)throws.HostAreacounter slots to avoid double-counting on aborted batchesIndirectArgumentClamp::release()read the 4 counter words fromarea.hostand pushed the slot onto LIFOfree_slots_without zeroing them. If a later batch reused that slot and was destroyed without submitting to the GPU (e.g., failed replay or failedvkQueueSubmit),~Batch()calledrelease(slots_, true)and re-added the prior submission's counters.std::memset(words, 0, 4 * sizeof(std::uint32_t))) right after reading them.argument_offsetandcount_offsetindirect_clamp.compreadsuintwords via BDA (arguments_va + argument_offset,count_va + count_offset).prepare()checkedstride % 4, but notargument_offset % 4orcount_offset % 4. Now rejects misaligned offsets cleanly viafallback(...).areas_[slot.area].bufferread undermutex_out.stats_buffer = ... areas_[slot.area].bufferinto the existingstd::lock_guard lock(mutex_)block 2 lines below inprepare(), removing the unlocked read ofareas_without adding any extra lock acquisition.Tests
Added pure-CPU mock-Vulkan test
runtime/test/indirect_clamp_safety_test.cpp(registered as CTestindirect_clamp_safetyunderif(TARGET Vulkan::Headers)inruntime/CMakeLists.txt).Verified locally on macOS arm64 (Apple Clang) using the pinned Khronos
Vulkan-Headers(6802bb4733b63ed5efd3adb308a6c885ef180ea1):indirect_clamp_safety_test: PASS under ASan+UBSan, PASS under TSan (0 races), PASS under-O2(3 consecutive runs),-Wall -Wextra -Werror -Wno-missing-field-initializers.vulkan_scratch_test: PASS under ASan+UBSan.replay_pipeline_compiles_test.cppanddepth24_convert_test.cppagainst the updated headers.main'svulkan_indirect_clamp.h+vulkan_scratch.h: fails 11 assertions across sharing mode,vkBindBufferMemoryretry leak, stale counter double-count, and misaligned offset acceptance.python3 -I scripts/check_no_game_data.py ...andpython3 -I tests/test_text_write_line_endings.pypass.Disclosure
@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 12:47 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@potatoe0100 on GitHub · 2026-11-25 13:50 UTC · original
Tested
9428f57damerged ontomain98c2f7777(clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 (MSVC 19.44) RelWithDebInfo + Ninja.indirect_clamp_safetypasses. Fullctest -j 6: all pass apart fromxmem_no_write_watch, which failed while another build was running on this PC;xmemfailed the same way in themainrun under that load.run_gpu_tests.py: 209/263 passed, 53 skipped, identical tomain(cs_imgatomic_extfails onmaintoo).AI-assisted (Claude)
@Timon360SB on GitHub · 2026-11-25 13:52 UTC · original
Independent verification — Turing and Blackwell
Tested the PR on two NVIDIA architectures under native Windows, comparing the exact merge base against the PR head.
0d80bc5df7c873f40965f34f185cb969137867659428f57da22a4693885a5671c61789ddd8bd664dEnvironment
MSVC 19.44.35230, Ninja Multi-Config, RelWithDebInfo.
Three repetitions per revision, GPU and validation configuration. Validated runs requested core validation, GPU-assisted validation and synchronization validation.
Results
All 24 CTest sessions completed successfully.
Across 192 scheduled test executions: 180 passed, 12 expected skips, 0 failures.
Individual tests
indirect_clampindirect_dispatch_count_allocd3d12_indirect_group_budgetd3d12_indirect_dispatch_countd3d12_stateful_indirect_pixelsd3d12_stateful_indirect_counted_pixelsd3d12_graphics_indirect_heap_resourcesvk_sync_validationThe synchronization validation self-test was skipped when
validation was disabled, as intended.
Reproducible counter difference
One measurable difference was observed in
indirect_clamp.Base:
Head:
This difference reproduced in all 12 executions per revision
across both GPUs and both validation configurations.
The call count and clamped-count total remain unchanged.
In-range records remain bit-identical and the budget
saturation checks continue to pass.
This is consistent with the stale counter-slot
double-counting fix described in the PR, although these
runs do not independently isolate that mechanism.
GPU readback and validation
ExecuteIndirect(DISPATCH) comparisons passed in every run.
zero RGBA mismatches across 1,966,080 pixel checks
in total, including direct and indirect controls.
PS resource payloads across three indirect draws and
two direct controls per execution.
intentional WRITE_AFTER_WRITE hazard without a barrier
and reported zero errors with the barrier.
in the captured test logs.
Conclusion
No regressions observed in the eight selected CTest
scenarios on either Turing or Blackwell.
The reproducible 73-to-72 counter change provides an
additional observable result consistent with the
counter-reset correction.
Coverage limitations: the new
indirect_clamp_safetymock-Vulkan test, fault-injection scenarios, dedicated
multi-queue-family stress testing and the full CTest suite
were not included in this run.
Synthetic tests only. No game files used.
AI-assisted: yes, test automation and result analysis.
@aslan2142 on GitHub · 2026-11-25 19:27 UTC · original
Merged, thanks! Tested
9428f57damerged ontomainwith the full Windows suite under Wine (llvmpipe and a RADV iGPU):indirect_clamp_safetyis the only change frommain, and it passes on both devices. Built againstmain's headers (families argument dropped, checks made non-fatal), 11 of its checks fail there: the queue-family sharing, the cleanup after a failed bind, the counter zeroing and the offset alignment.maine48ff0374+9428f57da: it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 6 changed files.AI-assisted (Claude Code, Claude Opus 5.5).