Repository navigation
Conversation
…x by memchr BindlessSet::queue() kept its one-write-per-slot map in a std::unordered_map: a heap node for every descriptor queued (up to five per add_image), all freed again by flush(). The map is now one position array per binding, sized to the binding's count in create_layout(); flush() zeroes only the entries it used. flush()'s in-place VkWriteDescriptorSet array is a reused member. allocate() looked for the first free index one byte at a time; memchr finds the same first zero byte. No behaviour change: bindless_queue_test drives BindlessSet through a fake Vulkan device and digests every descriptor write and returned index; the digest is the same built against the previous header. It also compares copies of the old queue and allocate with the new ones on fixed and random inputs. Per streamed frame (256 adds with storage views, 256 updates, two flushes): 206 -> 48 us and 2811 -> 0 heap allocations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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), a CPU hot path in
runtime/src/vulkan_bindless.h.What
BindlessSetdoes this work every time a texture is streamed in or out, or a view changes:queue()kept its one-write-per-slot map in astd::unordered_map<uint64_t, size_t>. Every descriptor it queued (up to five peradd_image: sampled, three storage, r32ui) allocated a heap node, andflush()freed them all withclear(). The map is now onestd::vector<uint32_t>per binding (pending_at_, 1 + the place inpending_, 0 when the slot has no pending write).create_layout()sizes each to the binding's count, andflush()zeroes only the entriespending_used. An index past the count, whichBindlessSetnever queues, grows the vector, so even that case behaves as before.flush()'s in-placeVkWriteDescriptorSetarray was a newstd::vectoron every flush. It is now a member that is reused.allocate()looked for the first free index one byte at a time. It now callsmemchrfor the first zero byte, which returns the same index, marks it used and returns 0 when there is none.There is no behaviour change. The order of writes stays first-queued, the last info queued for a slot still wins, and the indices returned are the same.
Proof of equivalence
runtime/test/bindless_queue_test.cppis a new CPU-only ctest (bindless_queue, about 0.6 s, no GPU). It has three parts:BindlessSetwith random operations: add, update and remove images in all six dimensions, with and without storage views and MS classes; add and remove samplers; insert and erase keys, so both the in-place and the replace-the-generationflush()paths run. It covers 30 configurations and seeds, 60 frames × 120 operations each. It checks every returned index against the old allocation steps,free_images()against the model, and that no in-place flush writes a slot twice. It also prints an FNV digest of everyvkUpdateDescriptorSetselement and every returned index. I built the same test file against theorigin/mainheader (-DLEONIDA_BINDLESS_HEADER=...), and the digest is identical (94e517cb5ed9a136) for the old and new header.queue/clearandallocate, compared with the new ones on fixed cases and random inputs: 200 rounds × 4 flushes of up to 4000 queues, and 300 rounds ofusedarrays up to 70 000 entries with random ranges. They must give the same pending list and the same index and array state each time.--benchruns a longer one. A globaloperator newcounter gives the allocation counts.Measurements
Windows 11, AMD Radeon RX 6800 machine (CPU-only test), llvm-mingw clang 20261117,
-O2(RelWithDebInfo),--bench, 3 runs:origin/mainheader)BindlessSetframe: 256 adds with storage views + 256 updates + 2 flushes, 65 536 2D images 7/8 fullallocate, 65 536 indices, free ones in the upper halfThe third run of each row was slower for both headers alike (machine load). The speedup holds within each run.
Tested
cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFFwith llvm-mingw clang. Everything builds without warnings.ctest -j8: 65 of 68 pass and 2 are skipped (shader_library_corpus,vk_sync_validation). The one failure isvk_queue_query_sync, atline 468: progress_loss_ok("progress counter device loss NOT propagated") on the RX 6800. Its sources do not includevulkan_bindless.h(checked withninja -t deps), so this change cannot affect it.bindless_sizingand the newbindless_queuepass.tests/semantic, because this does not touch the translator.It does not touch the lines of #4517, #4672 or #2756 (the other open PRs on this file), or
gfx10_descriptors.h,vulkan_backend.horimage_view_cache.h.AI-assisted (Claude Code). I reviewed the change and checked the measurements above on this machine.
🤖 Generated with Claude Code