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/vk_bindless_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/vk_bindless_test.cpp')
| -rw-r--r-- | runtime/test/vk_bindless_test.cpp | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp index ea1ee5f24..8b6118118 100644 --- a/runtime/test/vk_bindless_test.cpp +++ b/runtime/test/vk_bindless_test.cpp | |||
| @@ -4,15 +4,17 @@ | |||
| 4 | // | 4 | // |
| 5 | // vk_bindless_test <vs_ids.spv> <ps_tex.spv> | 5 | // vk_bindless_test <vs_ids.spv> <ps_tex.spv> |
| 6 | // | 6 | // |
| 7 | // A full-screen triangle is drawn into 64x64 RGBA32F and read back, seven times: | 7 | // A full-screen triangle is drawn into 64x64 RGBA32F and read back, eight times: |
| 8 | // 1. the T# and S# are in the table behind keys that share the T#'s first slot, so the shader has to probe: | 8 | // 1. the T# and S# are in the table behind keys that share the T#'s first slot, so the shader has to probe: |
| 9 | // every pixel is the texel of an 8x8 gradient under it; | 9 | // every pixel is the texel of an 8x8 gradient under it; |
| 10 | // 2. the T# is erased: every pixel is the fallback at index 0 (zeros); | 10 | // 2. the T# is erased: every pixel is the fallback at index 0 (zeros); |
| 11 | // 3. the T# is back among 200 more keys and the table has grown into a new buffer: the gradient again; | 11 | // 3. the T# is back among 200 more keys and the table has grown into a new buffer: the gradient again; |
| 12 | // 4. the T# is rebound to the decoy index: that image's colour; | 12 | // 4. the T# is rebound to the decoy index: that image's colour; |
| 13 | // 5. the T# is rebound to the original index: the gradient again; | 13 | // 5. the T# is rebound to the original index: the gradient again; |
| 14 | // 6. the original index is given another view: the decoy image's colour; | 14 | // 6. the T# is rebound again, but the command buffer that carried the upload is never submitted and the set is |
| 15 | // 7. the original index is removed: the fallback. | 15 | // told so: the retry still has to show the decoy's colour, not the old mapping; |
| 16 | // 7. the original index is given another view: the decoy image's colour; | ||
| 17 | // 8. the original index is removed: the fallback. | ||
| 16 | // This runs with the descriptor-indexing flags the device has (update after bind, partially bound) and again | 18 | // This runs with the descriptor-indexing flags the device has (update after bind, partially bound) and again |
| 17 | // without any. Exit 77 with "unsupported: ..." when the device lacks a feature the shaders need. | 19 | // without any. Exit 77 with "unsupported: ..." when the device lacks a feature the shaders need. |
| 18 | // LEONIDA_VK_VALIDATION=1 runs under VK_LAYER_KHRONOS_validation; a validation error fails the test. | 20 | // LEONIDA_VK_VALIDATION=1 runs under VK_LAYER_KHRONOS_validation; a validation error fails the test. |
| @@ -565,6 +567,15 @@ int main(int argc, char** argv) { | |||
| 565 | return submit(); | 567 | return submit(); |
| 566 | }; | 568 | }; |
| 567 | 569 | ||
| 570 | // Uploads the table where the device does: the copy and its barrier are recorded in a command buffer that | ||
| 571 | // runs before the draws that read binding 2. | ||
| 572 | const auto flush = [&]() { | ||
| 573 | vkResetCommandBuffer(cmd, 0); | ||
| 574 | if (const VkResult r = vkBeginCommandBuffer(cmd, &begin); r != VK_SUCCESS) return false; | ||
| 575 | const bool ok = set.flush(cmd); | ||
| 576 | return submit() == VK_SUCCESS && ok; | ||
| 577 | }; | ||
| 578 | |||
| 568 | // Index spaces. An image with storage views gets an index the storage arrays hold; one without goes above | 579 | // Index spaces. An image with storage views gets an index the storage arrays hold; one without goes above |
| 569 | // them where the dimension has room. A dimension that is full gives 0, and removed indices come back. | 580 | // them where the dimension has room. A dimension that is full gives 0, and removed indices come back. |
| 570 | StorageViews as_storage; | 581 | StorageViews as_storage; |
| @@ -620,15 +631,15 @@ int main(int argc, char** argv) { | |||
| 620 | while ((hash_descriptor_key(key) & (slots - 1)) != target) ++key[7]; | 631 | while ((hash_descriptor_key(key) & (slots - 1)) != target) ++key[7]; |
| 621 | } | 632 | } |
| 622 | for (std::uint32_t i = 0; i < kDescriptorProbes; ++i) set.insert_key(keys[i], decoy_index); | 633 | for (std::uint32_t i = 0; i < kDescriptorProbes; ++i) set.insert_key(keys[i], decoy_index); |
| 623 | EXPECT(!set.flush_needs_idle() && set.flush()); | 634 | EXPECT(!set.flush_needs_idle() && flush()); |
| 624 | EXPECT(set.insert_key(keys.back(), gradient_index)); | 635 | EXPECT(set.insert_key(keys.back(), gradient_index)); |
| 625 | EXPECT(slot_count() == slots && set.flush_needs_idle()); | 636 | EXPECT(slot_count() == slots && set.flush_needs_idle()); |
| 626 | EXPECT(set.flush() && !set.flush_needs_idle()); | 637 | EXPECT(flush() && !set.flush_needs_idle()); |
| 627 | for (const auto& key : keys) { | 638 | for (const auto& key : keys) { |
| 628 | EXPECT(table.lookup(key) == (key == keys.back() ? gradient_index : decoy_index)); | 639 | EXPECT(table.lookup(key) == (key == keys.back() ? gradient_index : decoy_index)); |
| 629 | EXPECT(set.erase_key(key)); | 640 | EXPECT(set.erase_key(key)); |
| 630 | } | 641 | } |
| 631 | EXPECT(table.size() == 0 && set.flush()); | 642 | EXPECT(table.size() == 0 && flush()); |
| 632 | } | 643 | } |
| 633 | 644 | ||
| 634 | // 1. The T# behind three keys that share its first slot, the S#, and other keys that name the decoy. | 645 | // 1. The T# behind three keys that share its first slot, the S#, and other keys that name the decoy. |
| @@ -643,7 +654,7 @@ int main(int argc, char** argv) { | |||
| 643 | for (std::uint32_t k = 100000; k < 100006; ++k) set.insert_key(numbered(k), decoy_index); | 654 | for (std::uint32_t k = 100000; k < 100006; ++k) set.insert_key(numbered(k), decoy_index); |
| 644 | const std::uint32_t depth = probe_depth(table.build_gpu_buffer(), tsharp); | 655 | const std::uint32_t depth = probe_depth(table.build_gpu_buffer(), tsharp); |
| 645 | EXPECT(slot_count() == slots && depth == 3 && !set.flush_needs_idle()); | 656 | EXPECT(slot_count() == slots && depth == 3 && !set.flush_needs_idle()); |
| 646 | EXPECT(set.flush()); | 657 | EXPECT(flush()); |
| 647 | CHECK(draw()); | 658 | CHECK(draw()); |
| 648 | compare("1 gradient", nullptr); | 659 | compare("1 gradient", nullptr); |
| 649 | 660 | ||
| @@ -651,7 +662,7 @@ int main(int argc, char** argv) { | |||
| 651 | const float zeros[4] = {0, 0, 0, 0}; | 662 | const float zeros[4] = {0, 0, 0, 0}; |
| 652 | EXPECT(set.erase_key(tsharp) && !set.erase_key(tsharp)); | 663 | EXPECT(set.erase_key(tsharp) && !set.erase_key(tsharp)); |
| 653 | EXPECT(set.flush_needs_idle()); // erasing may move the keys behind it; nothing is running here | 664 | EXPECT(set.flush_needs_idle()); // erasing may move the keys behind it; nothing is running here |
| 654 | EXPECT(set.flush() && !set.flush_needs_idle()); | 665 | EXPECT(flush() && !set.flush_needs_idle()); |
| 655 | CHECK(draw()); | 666 | CHECK(draw()); |
| 656 | compare("2 miss", zeros); | 667 | compare("2 miss", zeros); |
| 657 | 668 | ||
| @@ -660,7 +671,7 @@ int main(int argc, char** argv) { | |||
| 660 | EXPECT(!set.flush_needs_idle()); // one more entry, in place | 671 | EXPECT(!set.flush_needs_idle()); // one more entry, in place |
| 661 | for (std::uint32_t k = 200000; k < 200200; ++k) set.insert_key(numbered(k), decoy_index); | 672 | for (std::uint32_t k = 200000; k < 200200; ++k) set.insert_key(numbered(k), decoy_index); |
| 662 | EXPECT(slot_count() > slots && table.lookup(tsharp) == gradient_index && set.flush_needs_idle()); | 673 | EXPECT(slot_count() > slots && table.lookup(tsharp) == gradient_index && set.flush_needs_idle()); |
| 663 | EXPECT(set.flush()); | 674 | EXPECT(flush()); |
| 664 | CHECK(draw()); | 675 | CHECK(draw()); |
| 665 | compare("3 grown", nullptr); | 676 | compare("3 grown", nullptr); |
| 666 | set.release_retired(); | 677 | set.release_retired(); |
| @@ -670,25 +681,43 @@ int main(int argc, char** argv) { | |||
| 670 | const std::uint32_t grown_slots = slot_count(); | 681 | const std::uint32_t grown_slots = slot_count(); |
| 671 | EXPECT(set.insert_key(tsharp, gradient_index) && !set.flush_needs_idle()); | 682 | EXPECT(set.insert_key(tsharp, gradient_index) && !set.flush_needs_idle()); |
| 672 | EXPECT(set.insert_key(tsharp, decoy_index) && slot_count() == grown_slots && set.flush_needs_idle()); | 683 | EXPECT(set.insert_key(tsharp, decoy_index) && slot_count() == grown_slots && set.flush_needs_idle()); |
| 673 | EXPECT(set.flush() && !set.flush_needs_idle()); | 684 | EXPECT(flush() && !set.flush_needs_idle()); |
| 674 | CHECK(draw()); | 685 | CHECK(draw()); |
| 675 | compare("4 rebound", orange_colour); | 686 | compare("4 rebound", orange_colour); |
| 676 | EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_needs_idle()); | 687 | EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_needs_idle()); |
| 677 | EXPECT(set.flush()); | 688 | EXPECT(flush()); |
| 678 | CHECK(draw()); | 689 | CHECK(draw()); |
| 679 | compare("5 restored", nullptr); | 690 | compare("5 restored", nullptr); |
| 680 | 691 | ||
| 692 | // A submit that never reached the queue must keep the table upload pending: the retry has to see the new | ||
| 693 | // mapping instead of the fallback or the old index (a recovered submit failure, the case a device reports | ||
| 694 | // through table_upload_result(false)). | ||
| 695 | EXPECT(set.insert_key(tsharp, decoy_index) && set.flush_needs_idle()); | ||
| 696 | vkResetCommandBuffer(cmd, 0); | ||
| 697 | CHECK(vkBeginCommandBuffer(cmd, &begin)); | ||
| 698 | EXPECT(set.flush(cmd)); // recorded in a command buffer that is never submitted | ||
| 699 | CHECK(vkEndCommandBuffer(cmd)); | ||
| 700 | set.table_upload_result(false); | ||
| 701 | EXPECT(set.flush_needs_idle()); // the retry rewrites the whole table: the device must idle first | ||
| 702 | EXPECT(flush()); | ||
| 703 | CHECK(draw()); | ||
| 704 | compare("6 rebound after a failed submit", orange_colour); | ||
| 705 | EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_needs_idle()); | ||
| 706 | EXPECT(flush()); | ||
| 707 | |||
| 681 | // Another view at the same index, then removal of the index. | 708 | // Another view at the same index, then removal of the index. |
| 682 | set.update_image(ImageDimension::dim_2d, gradient_index, decoy_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); | 709 | set.update_image(ImageDimension::dim_2d, gradient_index, decoy_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); |
| 683 | EXPECT(set.flush()); | 710 | EXPECT(flush()); |
| 684 | CHECK(draw()); | 711 | CHECK(draw()); |
| 685 | compare("6 other view", orange_colour); | 712 | compare("7 other view", orange_colour); |
| 686 | set.remove_image(ImageDimension::dim_2d, gradient_index); | 713 | set.remove_image(ImageDimension::dim_2d, gradient_index); |
| 687 | EXPECT(set.flush()); | 714 | EXPECT(flush()); |
| 688 | CHECK(draw()); | 715 | CHECK(draw()); |
| 689 | compare("7 removed", zeros); | 716 | compare("8 removed", zeros); |
| 690 | EXPECT(set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) == gradient_index); | 717 | EXPECT(set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) == gradient_index); |
| 691 | 718 | ||
| 719 | std::printf("%s: descriptor table in %s memory\n", name, | ||
| 720 | set.table_in_device_local_memory() ? "device-local" : "host-visible"); | ||
| 692 | std::printf("%s: gradient at the %uth slot probed, miss, table grown %u -> %u slots, rebound, restored, other view, removed\n", name, | 721 | std::printf("%s: gradient at the %uth slot probed, miss, table grown %u -> %u slots, rebound, restored, other view, removed\n", name, |
| 693 | depth + 1, slots, slot_count()); | 722 | depth + 1, slots, slot_count()); |
| 694 | ++runs; | 723 | ++runs; |