Commit Graph

8 Commits

Author SHA1 Message Date
959cda8e2c Stop unresolvable descriptor collisions from growing without bound 2026-11-22 18:03:12 +01:00
85aea5ad8a Reject descriptor table capacities that overflow slot indices 2026-11-22 18:03:12 +01:00
1df4c3b0f1 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.
2026-11-22 15:19:11 +01:00
05e2e39db9 perf(vulkan): zero-copy DescriptorTable staging upload and uint32 wrap guard in read_slots 2026-11-22 08:33:44 -03:00
e6eaecd05a Runtime: the descriptor table lives in device-local memory (D3D-76)
AI-assisted. Set 0 binding 2 is the table every T#/S# lookup probes.
BindlessSet allocated it HOST_VISIBLE | HOST_COHERENT and flush() memcpy'd into
the mapping, so a divergent lookup read it over PCIe: 19.5x slower for T#+S#
pairs and 46.2x for a divergent miss at 100k entries on an RTX 2060 SUPER
(vk_descriptor_bench, #639; 58-796x on the 5080).

The table now lives in DEVICE_LOCAL (HOST_VISIBLE kept as a fallback for a device
without it). flush() takes the command buffer that will use the set and uploads
only what changed: the whole table from a mapped staging buffer when the buffers
were just created (first use or growth), and the changed slots with
vkCmdUpdateBuffer otherwise, which copies the data into the command buffer while
recording so no staging bytes are read at execution. A TRANSFER_WRITE ->
SHADER_READ barrier follows, before the draws. DescriptorTable tracks the slots
that insert, replace, erase, clear and grow touched, including both slots of a
relocation, so a flush no longer rebuilds an 80 MiB table for one descriptor.

A command buffer whose vkQueueSubmit is rejected never runs the upload, so the
set keeps the obligation: VulkanQueue::execute reports the submit result through
a commit callback, and the set rebuilds the table on the next flush, which also
reports flush_needs_idle() and makes the device wait before it. The same wait now
honours the pre-existing contract for replaced/erased entries and for growth
(the device ignored flush_needs_idle() before), and frees the retired buffers
once the queue is idle instead of at teardown.

Verified on an NVIDIA RTX 2060 SUPER, Linux 620.73.04, Vulkan 1.4.357:
- ctest 10/10, including descriptor_table cases for the change list, relocation
  marking and consume-once reads.
- vk_bindless_test with LEONIDA_VK_VALIDATION=1: 14 draws (probe depth, erase,
  relocation, growth 64 -> 512 slots, rebind, failed-submit retry, other view,
  removal) read back exact, table in device-local memory in both
  descriptor-indexing configurations. With the retry disabled the test is red.
- GPU suite 64/91 with the same 27 64-wide skips as main, 0 failures; 91/91 with
  LEONIDA_W64_EMULATE=1.

No game data; synthetic fixtures only.
2026-11-21 23:30:46 -03:00
bb65ea6c35 runtime: require idle for bindless key replacements 2026-11-22 00:21:48 +01:00
9eb04373fa Runtime: add DescriptorTable::erase() and autonomous vk_texture_test with synthetic shader 2026-11-21 22:26:49 +01:00
82a1e229c9 Runtime: implement FNV-1a descriptor hash table for shader contract (set 0, binding 2) 2026-11-21 21:37:24 +01:00