Repository navigation
perf(runtime): hash the border colour table and key replaced views by address (d3d12_vulkan_device) - #8159
Open
TG0000 wants to merge 1 commit into
Open
perf(runtime): hash the border colour table and key replaced views by address (d3d12_vulkan_device)#8159TG0000 wants to merge 1 commit into
TG0000 wants to merge 1 commit into
Conversation
…ews by address register_border_color (CreateSampler and every static sampler with a custom border colour) scanned the whole table, up to 4000 entries, under descriptor_mutex. forget_image (every texture destruction) ran std::erase_if over every replaced view of every live texture. Both move into runtime/src/descriptor_tables.h, standard library only. Past 16 colours a hash index answers; past 384 replaced views they move into a multimap by the texture's address. Below those sizes the old linear code stays, since it is the faster there. Indices, releases and release order are unchanged: colours are never removed or reordered, and std::multimap keeps equal keys in insertion order. runtime/test/descriptor_tables_test.cpp checks both against copies of the old code on fixed cases and 400 random sequences, then times them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Independent Windows 11 MSVC + full Environment
Build & Code Audit
Test & Benchmark Results
|
|
Tested
|
This was referenced Nov 23, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: new item, claimed in #8047 (claim). Depends on: nothing.
What
Two linear scans under
DeviceState::descriptor_mutexinruntime/shims/d3d12_vulkan_device.cpp:register_border_color: runs on everyCreateSamplerand every root-signature static sampler with a border colour other than the three named ones. It compared the colour with every entry in the table, up to 4000 entries ofmemcmp.forget_image: runs on every texture destruction. It ranstd::erase_ifoverreplaced_images, which holds the replaced views of every live texture, to find the ones belonging to the texture being destroyed.Both move into
runtime/src/descriptor_tables.h, which uses only the standard library and no Vulkan types:BorderColorTable: up to 16 colours it uses the same scan as before. Past 16 a hash index answers (FNV-1a overis_intand the 16 bytes; equality is stillis_intplusmemcmp, so -0.0 and 0.0 stay different and NaNs still find themselves). It still clamps a new colour to 3999 once the table is full, and still logs that.ReplacedImages<ImageEntry>: up to 384 views it uses the same vector anderase_ifas before. Past 384 it moves them, in order, into astd::multimapby the texture's address, so a destruction visits only that texture's views.The thresholds are where the old code stops being faster in the benchmark below, so small tables (the common case) keep the old cost.
No behavioural change
std::multimapkeeps equal keys in insertion order (C++11 and later). The vector-to-map move inserts in vector order. So the views of an address are released in the same ordererase_ifreleased them, and the samedefer_destroycalls happen in the same sequence.bind_sampler) readsis_intand the 16 colour bytes as before. It nowmemcpys them intoVkClearColorValue, with astatic_asserton the size.Tests
runtime/test/descriptor_tables_test.cppis registered with CTest asdescriptor_tables. It runs on the CPU only, against copies of the old code:is_int). Every returned index, everyfullflag and the final table must match the old scan exactly.erase_ifon every take.--benchruns larger sizes.Measured with llvm-mingw clang++ 20261117,
-O2, Windows 11, x86-64. Lower is better.erase_ifper destroyOld: O(N) per call, holding the descriptor mutex that
bind_image,bind_samplerand every descriptor write also take. New: O(1) per lookup for border colours, and O(log N + k) per destroy for replaced views, where k is that texture's own views.What I ran:
clang++ -std=c++20 -O2 -Wall -Wextra -Werror runtime/test/descriptor_tables_test.cpp: all checks passed.cmake -S runtime -G Ninja -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFFwith llvm-mingw, then a full build of that target set (150/150), thenctest -R descriptor_tables: passed.Not compiled locally:
d3d12_vulkan_device.cppitself. There is no Windows SDKd3d12.hon this machine, and llvm-mingw's copy is too old forgen_d3d12_stubs.py. Instead I compiled the exact edited code paths (the members,register_border_color, thebind_imageadd,forget_image, thebind_samplerread side) in a translation unit against Vulkan-Headers, with-Wall -Wextra -Wshadow -Werror. It compiled cleanly. The MSVC build in CI is the real check for the full file. No GPU was involved: these are CPU-only data structures. The translator suite wasn't run because the translator is untouched.AI-assisted: written with Claude Code (Claude Opus 5.5), reviewed and run by me.
🤖 Generated with Claude Code