mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1832] [MERGED] runtime: share indirect clamp buffers across queue families and fix safety bugs #1845
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1845
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1832
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:fix/rt-indirect-clamp-sharing-and-safety📝 Commits (1)
9428f57runtime: share indirect clamp buffers across queue families and fix safety bugs📊 Changes
6 files changed (+478 additions, -21 deletions)
View changed files
📝
runtime/CMakeLists.txt(+7 -0)📝
runtime/shims/d3d12_vulkan_device.cpp(+2 -1)📝
runtime/src/vulkan_backend.h(+3 -2)📝
runtime/src/vulkan_indirect_clamp.h(+46 -16)📝
runtime/src/vulkan_scratch.h(+5 -2)➕
runtime/test/indirect_clamp_safety_test.cpp(+415 -0)📄 Description
Item ID:
RT-INDIRECT-CLAMP-SHARING-AND-SAFETYClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162686562
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.