diff options
| author | SuarezPM <SuarezPM@users.noreply.github.com> | 2026-11-21 23:02:36 -0300 |
|---|---|---|
| committer | SuarezPM <SuarezPM@users.noreply.github.com> | 2026-11-21 23:30:46 -0300 |
| commit | e6eaecd05a7d5d332ce8b84191c1d383ae7be18e (patch) | |
| tree | 8d783e7d636881633dbf256a67ff47d5283518f8 /runtime/test/descriptor_table_test.cpp | |
| parent | 67204bf8c0471335d9046890288b33e8d5e2875b (diff) | |
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.
Diffstat (limited to 'runtime/test/descriptor_table_test.cpp')
| -rw-r--r-- | runtime/test/descriptor_table_test.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/runtime/test/descriptor_table_test.cpp b/runtime/test/descriptor_table_test.cpp index eb8d884d5..cda355a3f 100644 --- a/runtime/test/descriptor_table_test.cpp +++ b/runtime/test/descriptor_table_test.cpp | |||
| @@ -283,6 +283,77 @@ int test_erase_and_cluster_compact() { | |||
| 283 | return 0; | 283 | return 0; |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | int test_change_tracking() { | ||
| 287 | DescriptorTable table(16); | ||
| 288 | const std::uint32_t k1[8] = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| 289 | const std::uint32_t k2[8] = {9, 10, 11, 12, 13, 14, 15, 16}; | ||
| 290 | |||
| 291 | // A fresh table has nothing to upload. | ||
| 292 | DescriptorTable::Changes changes = table.take_changes(); | ||
| 293 | EXPECT(!changes.all && changes.slots.empty()); | ||
| 294 | |||
| 295 | // An insert marks exactly the slot it landed in, and read_slot agrees with build_gpu_buffer. | ||
| 296 | EXPECT(table.insert(k1, 42)); | ||
| 297 | changes = table.take_changes(); | ||
| 298 | EXPECT(!changes.all && changes.slots.size() == 1); | ||
| 299 | const std::uint32_t slot = changes.slots.front(); | ||
| 300 | const auto words = table.build_gpu_buffer(); | ||
| 301 | std::uint32_t read[10] = {}; | ||
| 302 | EXPECT(table.read_slot(slot, read)); | ||
| 303 | EXPECT(std::memcmp(read, &words[1 + slot * 10], sizeof(read)) == 0); | ||
| 304 | EXPECT(read[8] == 42 && read[9] == kSlotOccupiedMarker); | ||
| 305 | EXPECT(table.take_changes().slots.empty()); // taking consumes the list | ||
| 306 | |||
| 307 | // Replacing an index marks the same slot; read_slot sees the new index. | ||
| 308 | EXPECT(table.insert_or_update(k1, 43) == DescriptorTable::InsertResult::replaced); | ||
| 309 | changes = table.take_changes(); | ||
| 310 | EXPECT(!changes.all && changes.slots.size() == 1 && changes.slots.front() == slot); | ||
| 311 | EXPECT(table.read_slot(slot, read) && read[8] == 43); | ||
| 312 | |||
| 313 | // Erasing marks the slot it was in and the ones the cluster compaction moved. | ||
| 314 | EXPECT(table.insert(k2, 7)); | ||
| 315 | table.take_changes(); | ||
| 316 | EXPECT(table.erase(k1)); | ||
| 317 | changes = table.take_changes(); | ||
| 318 | EXPECT(!changes.all && !changes.slots.empty() && changes.slots.front() == slot); | ||
| 319 | |||
| 320 | // Growth changes the mask, so everything re-uploads. | ||
| 321 | const std::size_t before = table.capacity(); | ||
| 322 | for (std::uint32_t i = 0; i < 200 && table.capacity() == before; ++i) { | ||
| 323 | const std::uint32_t key[8] = {i, i * 2, i * 3, i * 4, i * 5, i * 6, i * 7, i * 8}; | ||
| 324 | table.insert(key, 1000 + i); | ||
| 325 | } | ||
| 326 | EXPECT(table.capacity() > before); | ||
| 327 | EXPECT(table.take_changes().all); | ||
| 328 | |||
| 329 | // Out-of-range slots are refused rather than read past the table. | ||
| 330 | EXPECT(!table.read_slot(std::uint32_t(table.capacity()), read)); | ||
| 331 | return 0; | ||
| 332 | } | ||
| 333 | |||
| 334 | int test_relocation_marks_both_slots() { | ||
| 335 | DescriptorTable table(64); | ||
| 336 | const std::uint32_t slots = std::uint32_t(table.capacity()); | ||
| 337 | // Eight keys in eight adjacent home slots across the end of the table; the ninth shares the first home and can | ||
| 338 | // only fit by moving a resident (make_probe_slot), which changes two slots. | ||
| 339 | std::array<DescriptorKey, kDescriptorProbes + 1> keys{}; | ||
| 340 | for (std::uint32_t i = 0; i < keys.size(); ++i) { | ||
| 341 | auto& key = keys[i]; | ||
| 342 | key[0] = i + 1; | ||
| 343 | const std::uint32_t target = (slots - 4 + i % kDescriptorProbes) & (slots - 1); | ||
| 344 | while ((hash_descriptor_key(key) & (slots - 1)) != target) ++key[7]; | ||
| 345 | } | ||
| 346 | for (std::uint32_t i = 0; i < kDescriptorProbes; ++i) EXPECT(table.insert(keys[i].data(), 100 + i)); | ||
| 347 | table.take_changes(); | ||
| 348 | EXPECT(table.insert_or_update(keys.back().data(), 999) == DescriptorTable::InsertResult::added_with_relocation); | ||
| 349 | const DescriptorTable::Changes changes = table.take_changes(); | ||
| 350 | EXPECT(!changes.all); | ||
| 351 | EXPECT(changes.slots.size() >= 2); // the hole a resident moved into and the slot the new key took | ||
| 352 | for (std::uint32_t i = 0; i < kDescriptorProbes; ++i) EXPECT(table.lookup(keys[i]) == 100 + i); | ||
| 353 | EXPECT(table.lookup(keys.back()) == 999); | ||
| 354 | return 0; | ||
| 355 | } | ||
| 356 | |||
| 286 | int main() { | 357 | int main() { |
| 287 | EXPECT(test_fnv1a_hash_matches_contract() == 0); | 358 | EXPECT(test_fnv1a_hash_matches_contract() == 0); |
| 288 | EXPECT(test_ssharp_key_padding() == 0); | 359 | EXPECT(test_ssharp_key_padding() == 0); |
| @@ -291,6 +362,8 @@ int main() { | |||
| 291 | EXPECT(test_load_factor_and_growth() == 0); | 362 | EXPECT(test_load_factor_and_growth() == 0); |
| 292 | EXPECT(test_probe_collision_resolution() == 0); | 363 | EXPECT(test_probe_collision_resolution() == 0); |
| 293 | EXPECT(test_gpu_buffer_serialization() == 0); | 364 | EXPECT(test_gpu_buffer_serialization() == 0); |
| 365 | EXPECT(test_change_tracking() == 0); | ||
| 366 | EXPECT(test_relocation_marks_both_slots() == 0); | ||
| 294 | EXPECT(test_multithreaded_insert_and_lookup() == 0); | 367 | EXPECT(test_multithreaded_insert_and_lookup() == 0); |
| 295 | EXPECT(test_clear_resets_table() == 0); | 368 | EXPECT(test_clear_resets_table() == 0); |
| 296 | EXPECT(test_erase_and_cluster_compact() == 0); | 369 | EXPECT(test_erase_and_cluster_compact() == 0); |