You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Item ID: RT-VK-DEPTH24-CONVERTER-OVERFLOW-AND-COLLECT (claimed in #1608)
Summary
Hardens and optimizes leonida::Depth24Converter (runtime/src/vulkan_depth24.h), which backs D24_UNORM_S8_UINT copies on GPUs without native D24 (including MoltenVK/macOS and AMD/Intel drivers) as well as 96-bit R32G32B32 texel repacks:
Null loader/device guard in Functions::load(): rejects null PFN_vkGetDeviceProcAddr or VK_NULL_HANDLE device before dereferencing get, so loaded() returns false and ~Depth24Converter() skips all teardown calls safely.
Overflow-proof 64-bit validation and O(1) partitioning in prepare() / make_part() / scratch() / run():
Guards (height - 1) * app_row_words + aw, (slices - 1) * app_slice_words + one_slice_words, span_words * 4, app_offset + span_bytes, sw * h * s * 4, caller scratch_offset % 4 / scratch_offset + total_scratch_bytes, and make_part()'s window + range > app_size against uint64_t wrap.
Replaces the O(slices + rows) linear while loops (which could wrap uint64_t in app_bytes/scratch_bytes) with exact O(1) division, and validates max_range_ > 256 and row/slice feasibility before allocating any internal scratch buffer.
Guards scratch() against alignment/addition wrap and uses bitmask alignment (& ~(alignment - 1)).
Guards run() against unloaded/zero extents and uses (extent - 1u) / 8u + 1u so width/height near UINT32_MAX cannot wrap to 0 workgroups.
Atomic rollback on mid-loop make_part() failure: clears parts and restores whole.scratch / whole.scratch_offset if descriptor allocation fails partway through a multi-part copy.
Per-semaphore cached queries and O(N) compaction in collect() and forget():
Caches vkGetSemaphoreCounterValue() per distinct VkSemaphore within each collect() pass (avoiding redundant per-batch driver calls and repeated DeviceFaultDiagnostics::observe() calls on a lost semaphore).
Replaces O(N²) std::vector::erase() loops with in-place compaction + single resize().
New portable pure-CPU unit testruntime/test/vulkan_depth24_unit_test.cpp wired into runtime/CMakeLists.txt (vulkan_depth24_unit) covering all 6 areas with mock Vulkan dispatch callbacks (no GPU or Vulkan loader required).
Testing & Disclosure
AI-assisted: yes
GPUs tested: none (macOS host, CPU-only portable unit test with mock Vulkan dispatch)
The reason will be displayed to describe this comment to others. Learn more.
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.
Still needed (STALE, needs a rebase): main has neither vulkan_depth24_unit_test nor this PR's runtime/src/vulkan_depth24.h changes. The rebase looks mechanical: keep both CMake blocks.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needs rebaseConflicts with the base branch: rebase it on main
5 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item ID:
RT-VK-DEPTH24-CONVERTER-OVERFLOW-AND-COLLECT(claimed in #1608)Summary
Hardens and optimizes
leonida::Depth24Converter(runtime/src/vulkan_depth24.h), which backsD24_UNORM_S8_UINTcopies on GPUs without native D24 (including MoltenVK/macOS and AMD/Intel drivers) as well as 96-bitR32G32B32texel repacks:Functions::load(): rejects nullPFN_vkGetDeviceProcAddrorVK_NULL_HANDLEdevice before dereferencingget, soloaded()returnsfalseand~Depth24Converter()skips all teardown calls safely.prepare()/make_part()/scratch()/run():(height - 1) * app_row_words + aw,(slices - 1) * app_slice_words + one_slice_words,span_words * 4,app_offset + span_bytes,sw * h * s * 4, callerscratch_offset % 4/scratch_offset + total_scratch_bytes, andmake_part()'swindow + range > app_sizeagainstuint64_twrap.whileloops (which could wrapuint64_tinapp_bytes/scratch_bytes) with exact O(1) division, and validatesmax_range_ > 256and row/slice feasibility before allocating any internal scratch buffer.scratch()against alignment/addition wrap and uses bitmask alignment (& ~(alignment - 1)).run()against unloaded/zero extents and uses(extent - 1u) / 8u + 1usowidth/heightnearUINT32_MAXcannot wrap to 0 workgroups.make_part()failure: clearspartsand restoreswhole.scratch/whole.scratch_offsetif descriptor allocation fails partway through a multi-part copy.collect()andforget():vkGetSemaphoreCounterValue()per distinctVkSemaphorewithin eachcollect()pass (avoiding redundant per-batch driver calls and repeatedDeviceFaultDiagnostics::observe()calls on a lost semaphore).std::vector::erase()loops with in-place compaction + singleresize().runtime/test/vulkan_depth24_unit_test.cppwired intoruntime/CMakeLists.txt(vulkan_depth24_unit) covering all 6 areas with mock Vulkan dispatch callbacks (no GPU or Vulkan loader required).Testing & Disclosure
clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_depth24_unit_test.cpp: PASSclang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_depth24_unit_test.cpp: PASSclang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_depth24_unit_test.cpp: PASSpython3 -I scripts/check_no_game_data.py runtime/src/vulkan_depth24.h runtime/test/vulkan_depth24_unit_test.cpp runtime/CMakeLists.txt: PASSpython3 -I tests/test_text_write_line_endings.py: PASS (3/3)