diff options
| author | Codex <codex@localhost> | 2026-11-22 00:21:48 +0100 |
|---|---|---|
| committer | Codex <codex@localhost> | 2026-11-22 00:21:48 +0100 |
| commit | bb65ea6c35b9e67e7d6883a647a013fbc580c708 (patch) | |
| tree | e28d27caf360158aa68df38f3c33c0adf328185b /runtime/test/vk_bindless_test.cpp | |
| parent | 8bd0087d2d0e45fc18fa78fb40b70ecfc6648854 (diff) | |
runtime: require idle for bindless key replacements
Diffstat (limited to 'runtime/test/vk_bindless_test.cpp')
| -rw-r--r-- | runtime/test/vk_bindless_test.cpp | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp index a8b3e5a01..b5e5828a6 100644 --- a/runtime/test/vk_bindless_test.cpp +++ b/runtime/test/vk_bindless_test.cpp | |||
| @@ -4,13 +4,15 @@ | |||
| 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, five times: | 7 | // A full-screen triangle is drawn into 64x64 RGBA32F and read back, seven 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 index is given another view: that image's colour; | 12 | // 4. the T# is rebound to the decoy index: that image's colour; |
| 13 | // 5. the index is removed: the fallback. | 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; | ||
| 15 | // 7. the original index is removed: the fallback. | ||
| 14 | // This runs with the descriptor-indexing flags the device has (update after bind, partially bound) and again | 16 | // This runs with the descriptor-indexing flags the device has (update after bind, partially bound) and again |
| 15 | // without any. Exit 77 with "unsupported: ..." when the device lacks a feature the shaders need. | 17 | // without any. Exit 77 with "unsupported: ..." when the device lacks a feature the shaders need. |
| 16 | // LEONIDA_VK_VALIDATION=1 runs under VK_LAYER_KHRONOS_validation; a validation error fails the test. | 18 | // LEONIDA_VK_VALIDATION=1 runs under VK_LAYER_KHRONOS_validation; a validation error fails the test. |
| @@ -215,6 +217,9 @@ int main(int argc, char** argv) { | |||
| 215 | LD(vkGetBufferMemoryRequirements); LD(vkBindBufferMemory); LD(vkMapMemory); LD(vkGetBufferDeviceAddress); | 217 | LD(vkGetBufferMemoryRequirements); LD(vkBindBufferMemory); LD(vkMapMemory); LD(vkGetBufferDeviceAddress); |
| 216 | LD(vkCreateSampler); LD(vkCmdBindDescriptorSets); LD(vkCmdPushConstants); LD(vkCmdPipelineBarrier); | 218 | LD(vkCreateSampler); LD(vkCmdBindDescriptorSets); LD(vkCmdPushConstants); LD(vkCmdPipelineBarrier); |
| 217 | LD(vkDeviceWaitIdle); LD(vkDestroyPipeline); LD(vkDestroyPipelineLayout); | 219 | LD(vkDeviceWaitIdle); LD(vkDestroyPipeline); LD(vkDestroyPipelineLayout); |
| 220 | LD(vkDestroyCommandPool); LD(vkDestroyShaderModule); LD(vkDestroyFramebuffer); LD(vkDestroyRenderPass); | ||
| 221 | LD(vkDestroySampler); LD(vkDestroyImageView); LD(vkDestroyImage); LD(vkDestroyBuffer); | ||
| 222 | LD(vkFreeMemory); LD(vkDestroyDevice); | ||
| 218 | VkQueue queue = VK_NULL_HANDLE; | 223 | VkQueue queue = VK_NULL_HANDLE; |
| 219 | vkGetDeviceQueue(dev, qi, 0, &queue); | 224 | vkGetDeviceQueue(dev, qi, 0, &queue); |
| 220 | VkPhysicalDeviceMemoryProperties mp; | 225 | VkPhysicalDeviceMemoryProperties mp; |
| @@ -224,6 +229,7 @@ int main(int argc, char** argv) { | |||
| 224 | if ((bits & (1u << i)) && (mp.memoryTypes[i].propertyFlags & want) == want) return i; | 229 | if ((bits & (1u << i)) && (mp.memoryTypes[i].propertyFlags & want) == want) return i; |
| 225 | return 0u; | 230 | return 0u; |
| 226 | }; | 231 | }; |
| 232 | std::vector<VkDeviceMemory> allocations; | ||
| 227 | const auto make_buffer = [&](VkDeviceSize size, VkBufferUsageFlags usage, VkBuffer* b, void** map) { | 233 | const auto make_buffer = [&](VkDeviceSize size, VkBufferUsageFlags usage, VkBuffer* b, void** map) { |
| 228 | VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | 234 | VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; |
| 229 | bi.size = size; | 235 | bi.size = size; |
| @@ -241,6 +247,7 @@ int main(int argc, char** argv) { | |||
| 241 | VkDeviceMemory m; | 247 | VkDeviceMemory m; |
| 242 | r = vkAllocateMemory(dev, &ai, nullptr, &m); | 248 | r = vkAllocateMemory(dev, &ai, nullptr, &m); |
| 243 | if (r) return r; | 249 | if (r) return r; |
| 250 | allocations.push_back(m); | ||
| 244 | r = vkBindBufferMemory(dev, *b, m, 0); | 251 | r = vkBindBufferMemory(dev, *b, m, 0); |
| 245 | if (r) return r; | 252 | if (r) return r; |
| 246 | return vkMapMemory(dev, m, 0, size, 0, map); | 253 | return vkMapMemory(dev, m, 0, size, 0, map); |
| @@ -265,7 +272,9 @@ int main(int argc, char** argv) { | |||
| 265 | VkDeviceMemory m; | 272 | VkDeviceMemory m; |
| 266 | r = vkAllocateMemory(dev, &ai, nullptr, &m); | 273 | r = vkAllocateMemory(dev, &ai, nullptr, &m); |
| 267 | if (r) return r; | 274 | if (r) return r; |
| 268 | vkBindImageMemory(dev, *image, m, 0); | 275 | allocations.push_back(m); |
| 276 | r = vkBindImageMemory(dev, *image, m, 0); | ||
| 277 | if (r) return r; | ||
| 269 | VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; | 278 | VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; |
| 270 | vi.image = *image; | 279 | vi.image = *image; |
| 271 | vi.viewType = VK_IMAGE_VIEW_TYPE_2D; | 280 | vi.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| @@ -593,7 +602,7 @@ int main(int argc, char** argv) { | |||
| 593 | const std::uint32_t brief_index = set.add_image(ImageDimension::dim_2d, brief, VK_IMAGE_LAYOUT_GENERAL, brief_storage); | 602 | const std::uint32_t brief_index = set.add_image(ImageDimension::dim_2d, brief, VK_IMAGE_LAYOUT_GENERAL, brief_storage); |
| 594 | EXPECT(brief_index >= 1 && brief_index < bindless::storage_indices && brief_index != stored_index); | 603 | EXPECT(brief_index >= 1 && brief_index < bindless::storage_indices && brief_index != stored_index); |
| 595 | set.remove_image(ImageDimension::dim_2d, brief_index); | 604 | set.remove_image(ImageDimension::dim_2d, brief_index); |
| 596 | reinterpret_cast<PFN_vkDestroyImageView>(vkGetDeviceProcAddr(dev, "vkDestroyImageView"))(dev, brief, nullptr); | 605 | vkDestroyImageView(dev, brief, nullptr); |
| 597 | } | 606 | } |
| 598 | 607 | ||
| 599 | // 1. The T# behind three keys that share its first slot, the S#, and other keys that name the decoy. | 608 | // 1. The T# behind three keys that share its first slot, the S#, and other keys that name the decoy. |
| @@ -633,19 +642,31 @@ int main(int argc, char** argv) { | |||
| 633 | compare("3 grown", nullptr); | 642 | compare("3 grown", nullptr); |
| 634 | set.release_retired(); | 643 | set.release_retired(); |
| 635 | 644 | ||
| 636 | // 4. Another view at the same index, then 5. the index removed. | ||
| 637 | const float orange_colour[4] = {1.0f, 128.0f / 255.0f, 0.0f, 1.0f}; | 645 | const float orange_colour[4] = {1.0f, 128.0f / 255.0f, 0.0f, 1.0f}; |
| 646 | // Rewriting the same mapping is a no-op. Changing it needs idle even with no table growth. | ||
| 647 | const std::uint32_t grown_slots = slot_count(); | ||
| 648 | EXPECT(set.insert_key(tsharp, gradient_index) && !set.flush_needs_idle()); | ||
| 649 | EXPECT(set.insert_key(tsharp, decoy_index) && slot_count() == grown_slots && set.flush_needs_idle()); | ||
| 650 | EXPECT(set.flush() && !set.flush_needs_idle()); | ||
| 651 | CHECK(draw()); | ||
| 652 | compare("4 rebound", orange_colour); | ||
| 653 | EXPECT(set.insert_key(tsharp, gradient_index) && set.flush_needs_idle()); | ||
| 654 | EXPECT(set.flush()); | ||
| 655 | CHECK(draw()); | ||
| 656 | compare("5 restored", nullptr); | ||
| 657 | |||
| 658 | // Another view at the same index, then removal of the index. | ||
| 638 | set.update_image(ImageDimension::dim_2d, gradient_index, decoy_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); | 659 | set.update_image(ImageDimension::dim_2d, gradient_index, decoy_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); |
| 639 | EXPECT(set.flush()); | 660 | EXPECT(set.flush()); |
| 640 | CHECK(draw()); | 661 | CHECK(draw()); |
| 641 | compare("4 other view", orange_colour); | 662 | compare("6 other view", orange_colour); |
| 642 | set.remove_image(ImageDimension::dim_2d, gradient_index); | 663 | set.remove_image(ImageDimension::dim_2d, gradient_index); |
| 643 | EXPECT(set.flush()); | 664 | EXPECT(set.flush()); |
| 644 | CHECK(draw()); | 665 | CHECK(draw()); |
| 645 | compare("5 removed", zeros); | 666 | compare("7 removed", zeros); |
| 646 | EXPECT(set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) == gradient_index); | 667 | EXPECT(set.add_image(ImageDimension::dim_2d, gradient_view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) == gradient_index); |
| 647 | 668 | ||
| 648 | std::printf("%s: gradient at the %uth slot probed, miss, table grown %u -> %u slots, other view, removed\n", name, | 669 | std::printf("%s: gradient at the %uth slot probed, miss, table grown %u -> %u slots, rebound, restored, other view, removed\n", name, |
| 649 | depth + 1, slots, slot_count()); | 670 | depth + 1, slots, slot_count()); |
| 650 | ++runs; | 671 | ++runs; |
| 651 | vkDeviceWaitIdle(dev); | 672 | vkDeviceWaitIdle(dev); |
| @@ -653,11 +674,31 @@ int main(int argc, char** argv) { | |||
| 653 | vkDestroyPipelineLayout(dev, pipeline_layout, nullptr); | 674 | vkDestroyPipelineLayout(dev, pipeline_layout, nullptr); |
| 654 | } | 675 | } |
| 655 | 676 | ||
| 677 | // Let validation observe resource and device destruction before reporting its final error count. | ||
| 678 | vkDestroyCommandPool(dev, pool, nullptr); | ||
| 679 | vkDestroyFramebuffer(dev, framebuffer, nullptr); | ||
| 680 | vkDestroyRenderPass(dev, pass, nullptr); | ||
| 681 | vkDestroyShaderModule(dev, fs, nullptr); | ||
| 682 | vkDestroyShaderModule(dev, vs, nullptr); | ||
| 683 | vkDestroySampler(dev, nearest, nullptr); | ||
| 684 | for (const auto view : {target_view, stored_view, decoy_view, gradient_view}) | ||
| 685 | vkDestroyImageView(dev, view, nullptr); | ||
| 686 | for (const auto image : {target, stored, decoy, gradient}) vkDestroyImage(dev, image, nullptr); | ||
| 687 | for (const auto buffer : {readback, upload, heap}) vkDestroyBuffer(dev, buffer, nullptr); | ||
| 688 | for (const auto memory : allocations) vkFreeMemory(dev, memory, nullptr); | ||
| 689 | vkDestroyDevice(dev, nullptr); | ||
| 690 | if (messenger) { | ||
| 691 | LI(vkDestroyDebugUtilsMessengerEXT); | ||
| 692 | vkDestroyDebugUtilsMessengerEXT(inst, messenger, nullptr); | ||
| 693 | } | ||
| 694 | LI(vkDestroyInstance); | ||
| 695 | vkDestroyInstance(inst, nullptr); | ||
| 696 | |||
| 656 | if (!runs) { | 697 | if (!runs) { |
| 657 | std::printf("unsupported: the bindless set does not fit this device's descriptor limits\n"); | 698 | std::printf("unsupported: the bindless set does not fit this device's descriptor limits\n"); |
| 658 | return unsupported; | 699 | return unsupported; |
| 659 | } | 700 | } |
| 660 | std::printf("bindless: %u draws read back, %u bad pixels, largest error %g\n", runs * 5, mismatches, double(worst)); | 701 | std::printf("bindless: %u draws read back, %u bad pixels, largest error %g\n", runs * 7, mismatches, double(worst)); |
| 661 | if (g_validation_errors) { | 702 | if (g_validation_errors) { |
| 662 | std::fprintf(stderr, "%u validation errors\n", g_validation_errors); | 703 | std::fprintf(stderr, "%u validation errors\n", g_validation_errors); |
| 663 | return 1; | 704 | return 1; |