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
{{ message }}
Repository navigation
runtime: speed up uav_clear format lookup and channel pack/unpack with unit tests (RT-UAV-CLEAR-FAST-PACK-AND-UNIT-TESTS) - #2009
Claim: RT-UAV-CLEAR-FAST-PACK-AND-UNIT-TESTS (claim comment #7170281757 on #1608).
Problem
In runtime/src/uav_clear.h:
layout(VkFormat) linearly scanned all 45 Layout entries on every ClearUnorderedAccessViewUint / ClearUnorderedAccessViewFloat call (up to 45 comparisons for R8_* formats).
detail::put() and detail::get() packed and unpacked every channel one bit at a time (for (unsigned i = 0; i < c.bits; ++i) — up to 128 loop iterations per element for R32G32B32A32_*) without guarding out-of-bounds (offset, bits) pairs.
There was no portable CPU-only unit test exercising uav_clear.h independently of a live Vulkan/D3D12 device.
Fix
Replace the 45-entry linear scan in layout(VkFormat) with a constexpr switch verified at compile time by a static_assert over layouts[].
Replace bit-by-bit loops in detail::put() / detail::get() with bounds-checked byte-aligned (8/16/32-bit) fast paths and a 64-bit word shift/mask path for packed sub-byte channels (10:10:10:2, 11:11:10, 5:6:5, 1:5:5:5, 4:4:4:4).
Move the unorm scale computation inside case Kind::unorm: in encode().
Add a portable Vulkan-headers-only CTest uav_clear_unit (runtime/test/uav_clear_unit_test.cpp) verifying all 45 formats, exhaustive bit-exact parity of put()/get() against a bit-by-bit reference across widths 1..32, bounds guards, NaN/Inf/edge float conversions, cross-format decodes, and raw_element().
Benchmark (clang++ -std=c++20 -O2, bit-exact A/B across all 45 formats)
45-format uint encode() + decode() sweep (500,000 iterations): 981.25 ms -> 388.01 ms (2.53x faster)
Hot 4-format mix (R32G32B32A32_UINT, R8G8B8A8_UNORM, A2B10G10R10_UINT_PACK32, R8_SINT, 5M calls): 237.19 ms -> 83.14 ms (2.85x faster)
Bit-exact parity verified on all 45 formats for both uint and float encode() + decode().
Verification
AI-assisted: yes (Antigravity agent by Google DeepMind).
GPUs tested: none (host is macOS arm64; no retail files).
Ran runtime/test/uav_clear_unit_test.cpp cleanly under:
Ran python3 -I scripts/check_no_game_data.py runtime/src/uav_clear.h runtime/test/uav_clear_unit_test.cpp runtime/CMakeLists.txt and python3 -I tests/test_text_write_line_endings.py: all passed.
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.
#2009 | head f133273 (merged cleanly with main 1bc055e) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(uav_clear_unit|d3d12_uav_clear|d3d12_short_uav_clear|replay_uav_clear_offset)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) + 200,000 × 45-format uint encode+decode A/B sweep | red & baseline on main: uav_clear_unit fails at line 116: CHECK failed: b == 0 (out-of-bounds detail::put lacked bounds guards) and runs the 45-format sweep in 728.81 ms | green on PR+main: 4/4 CTests pass (uav_clear_unit306.80 ms — 2.38x faster on MSVC RelWithDebInfo with bit-exact parity across all 45 formats, d3d12_uav_clear, d3d12_short_uav_clear, and replay_uav_clear_offset) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
Note: shares runtime/CMakeLists.txt with the open #2566; a rebase may be needed if #2566 lands first.
AI-assisted (Claude Code, Claude Opus 5.5).
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
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.
Claim:
RT-UAV-CLEAR-FAST-PACK-AND-UNIT-TESTS(claim comment#7170281757on #1608).Problem
In
runtime/src/uav_clear.h:layout(VkFormat)linearly scanned all 45Layoutentries on everyClearUnorderedAccessViewUint/ClearUnorderedAccessViewFloatcall (up to 45 comparisons forR8_*formats).detail::put()anddetail::get()packed and unpacked every channel one bit at a time (for (unsigned i = 0; i < c.bits; ++i)— up to 128 loop iterations per element forR32G32B32A32_*) without guarding out-of-bounds(offset, bits)pairs.uav_clear.hindependently of a live Vulkan/D3D12 device.Fix
layout(VkFormat)with aconstexpr switchverified at compile time by astatic_assertoverlayouts[].detail::put()/detail::get()with bounds-checked byte-aligned (8/16/32-bit) fast paths and a 64-bit word shift/mask path for packed sub-byte channels (10:10:10:2,11:11:10,5:6:5,1:5:5:5,4:4:4:4).unormscale computation insidecase Kind::unorm:inencode().uav_clear_unit(runtime/test/uav_clear_unit_test.cpp) verifying all 45 formats, exhaustive bit-exact parity ofput()/get()against a bit-by-bit reference across widths1..32, bounds guards, NaN/Inf/edge float conversions, cross-format decodes, andraw_element().Benchmark (
clang++ -std=c++20 -O2, bit-exact A/B across all 45 formats)encode()+decode()sweep (500,000 iterations):981.25 ms->388.01 ms(2.53x faster)R32G32B32A32_UINT,R8G8B8A8_UNORM,A2B10G10R10_UINT_PACK32,R8_SINT, 5M calls):237.19 ms->83.14 ms(2.85x faster)encode()+decode().Verification
runtime/test/uav_clear_unit_test.cppcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/src/uav_clear.h runtime/test/uav_clear_unit_test.cpp runtime/CMakeLists.txtandpython3 -I tests/test_text_write_line_endings.py: all passed.