upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorjsthope <68657498+jsthope@users.noreply.github.com>2026-11-22 15:19:11 +0100
committerjsthope <68657498+jsthope@users.noreply.github.com>2026-11-22 15:19:11 +0100
commit1df4c3b0f16fd580837ff184904d2aba62d4eb5c (patch)
tree595f7d52fb1b9fa5431dae7e24d6150ef812dce2 /runtime/src
parent89b047cd8fab50675a43d76722a6a8a881f55dc2 (diff)
runtime: erasing a bindless descriptor key no longer idles the GPU
DescriptorTable::erase backward-shifted the key's probe cluster, which moved other live entries, so BindlessSet::erase_key flagged the next flush as needing idle and every texture release ended in vkDeviceWaitIdle on the next submit. The shift is not needed: every lookup, on the CPU and in the translated shaders (rdna2spirv.py desc_probe), compares all eight probe slots and never stops at an empty one. Erase now empties only the key's own slot, and inserts reuse the hole. An erase uploads like an add (one slot, no idle). Replacing a live key's index, a relocating insert and table growth still require idle. Tests: descriptor_table_test checks that an erase in the middle of a cluster leaves every other slot byte-identical and marks one changed slot (it fails on the old erase); vk_bindless_test now expects no idle after an erase.
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/descriptor_table.h24
-rw-r--r--runtime/src/vulkan_bindless.h16
2 files changed, 15 insertions, 25 deletions
diff --git a/runtime/src/descriptor_table.h b/runtime/src/descriptor_table.h
index 59f96fd4f..2b5b111f7 100644
--- a/runtime/src/descriptor_table.h
+++ b/runtime/src/descriptor_table.h
@@ -129,7 +129,10 @@ public:
129 } 129 }
130 130
131 // Erases a key from the table. Returns true if the key was found and erased, false otherwise. 131 // Erases a key from the table. Returns true if the key was found and erased, false otherwise.
132 // Backward-shifts downstream entries in the probe cluster so probe chains remain intact and compact. 132 // Only the key's own slot changes (it becomes empty): no other entry moves. Every lookup, here and in the
133 // shaders (rdna2spirv.py desc_probe), compares all kDescriptorProbes slots and never stops at an empty one, so
134 // a hole breaks no probe chain and inserts reuse it. Keeping the other entries in place is what lets the GPU
135 // copy of the table take an erase while shaders still probe it (BindlessSet::flush_needs_idle).
133 bool erase(const std::uint32_t key[8]) { 136 bool erase(const std::uint32_t key[8]) {
134 std::lock_guard lock(mutex_); 137 std::lock_guard lock(mutex_);
135 return erase_locked(key); 138 return erase_locked(key);
@@ -321,24 +324,9 @@ private:
321 } 324 }
322 if (!found) return false; 325 if (!found) return false;
323 326
324 // Backward-shift entries in the probe cluster to maintain probe chains 327 // No backward shift: see erase().
325 std::uint32_t i = found_slot; 328 entries_[found_slot] = DescriptorEntry{};
326 std::uint32_t j = i;
327 mark(found_slot); 329 mark(found_slot);
328 while (true) {
329 j = (j + 1) & mask_;
330 if (entries_[j].pad != kSlotOccupiedMarker) break;
331 const std::uint32_t r = hash_descriptor_key(entries_[j].key);
332 const std::uint32_t dist_r_to_i = (i - r) & mask_;
333 const std::uint32_t dist_r_to_j = (j - r) & mask_;
334 if (dist_r_to_i < dist_r_to_j && dist_r_to_i < kDescriptorProbes) {
335 entries_[i] = entries_[j];
336 mark(i);
337 i = j;
338 }
339 }
340 entries_[i] = DescriptorEntry{};
341 mark(i);
342 --occupied_count_; 330 --occupied_count_;
343 return true; 331 return true;
344 } 332 }
diff --git a/runtime/src/vulkan_bindless.h b/runtime/src/vulkan_bindless.h
index c599eb7c2..965a21c1c 100644
--- a/runtime/src/vulkan_bindless.h
+++ b/runtime/src/vulkan_bindless.h
@@ -400,19 +400,21 @@ public:
400 result == DescriptorTable::InsertResult::added_with_relocation; 400 result == DescriptorTable::InsertResult::added_with_relocation;
401 return true; 401 return true;
402 } 402 }
403 // Erasing compacts the key's probe cluster, so other keys' entries may change slots. 403 // Erasing empties only the key's own slot; no other entry moves (DescriptorTable::erase), so it needs no idle.
404 // The caller erases a key once no submitted work uses it (its texture is gone), like D3D12 requires.
404 bool erase_key(const DescriptorKey& key) { 405 bool erase_key(const DescriptorKey& key) {
405 if (!table_.erase(key)) return false; 406 if (!table_.erase(key)) return false;
406 table_dirty_ = existing_entries_changed_ = true; 407 table_dirty_ = true;
407 return true; 408 return true;
408 } 409 }
409 const DescriptorTable& table() const { return table_; } 410 const DescriptorTable& table() const { return table_; }
410 411
411 // True when the next flush() will change entries a running shader may be probing, or replace the table's 412 // True when the next flush() will change entries a running shader may be probing (a live key's index replaced
412 // buffer: the caller then flushes only once no command buffer that uses the set is still executing. Without 413 // or a live key moved by a relocating insert), or replace the table's buffer: the caller then flushes only once
413 // it the flush only adds entries, and the copy of an entry is not atomic: a shader probing a different key 414 // no command buffer that uses the set is still executing. Without it the flush only adds entries or empties the
414 // could in principle see a torn entry that matches it, which is accepted as vanishingly unlikely because the 415 // slots of erased keys, and the copy of an entry is not atomic: a shader probing a different key could in
415 // added key is new (there is no live key equal to it). 416 // principle see a torn entry that matches it, which is accepted as vanishingly unlikely because the added or
417 // erased key is not live (no running work uses it).
416 bool flush_needs_idle() const { 418 bool flush_needs_idle() const {
417 return table_dirty_ && (existing_entries_changed_ || force_full_upload_ || 419 return table_dirty_ && (existing_entries_changed_ || force_full_upload_ ||
418 table_.size_bytes() > table_buffers_.table.size); 420 table_.size_bytes() > table_buffers_.table.size);