runtime: speed up uav_clear format lookup and channel pack/unpack with unit tests (RT-UAV-CLEAR-FAST-PACK-AND-UNIT-TESTS) #2009
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2009
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/rt-uav-clear-fast-pack-and-tests"
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 successfully merged and closed
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.#2009 | head f1332737d4a8c039851a255a7ebe5e4f6abd3103 (merged cleanly with main 1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3) |
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 uintencode+decodeA/B sweep | red & baseline on main:uav_clear_unitfails atline 116: CHECK failed: b == 0(out-of-boundsdetail::putlacked bounds guards) and runs the 45-format sweep in728.81 ms| green on PR+main: 4/4 CTests pass (uav_clear_unit306.80 ms— 2.38x faster on MSVCRelWithDebInfowith bit-exact parity across all 45 formats,d3d12_uav_clear,d3d12_short_uav_clear, andreplay_uav_clear_offset) on RTX 3090 with0Khronos validation errors;check_no_game_data.py0violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesVerified by OreoFR
aa918e5d9+ PR headf1332737dctest -R ^uav_clear_unit$put()writes into the element for malformed channels (0 bits, 33 bits, offset past 128 bits)Note: shares
runtime/CMakeLists.txtwith the open #2566; a rebase may be needed if #2566 lands first.AI-assisted (Claude Code, Claude Opus 5.5).
Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: ctest -R ^uav_clear_unit$ red on main (line 94), green with the PR. AI-assisted: yes.