diff options
| author | whoalin1 <207920491+whoalin1@users.noreply.github.com> | 2026-11-22 17:42:20 +0200 |
|---|---|---|
| committer | whoalin1 <207920491+whoalin1@users.noreply.github.com> | 2026-11-22 18:48:05 +0200 |
| commit | 0ec464b0e11fb5c945cd7e9edba52d4cd330df7a (patch) | |
| tree | cced16a943ce8cb55785276ac2e3354bc3ac9398 /runtime/test/vk_bindless_test.cpp | |
| parent | 8d89bfa6471a8a95d8ef65fa8b458dc4701129f6 (diff) | |
GPU tests: bind the --pc-tail-ubo block, so 128-byte push-constant devices run the tests
With LEONIDA_PC_TAIL_UBO=1, build.py and run_gpu_tests.py translate with --pc-tail-ubo, and the test
programs (vk_compute_test, vk_store_test, vk_harness, vk_texture_test, vk_sampler_test, vk_bindless_test)
declare and push 128 bytes and, when a stage declares set 1, bind the tail block there
(runtime/test/vk_pc_tail.h: a host-visible buffer with one slot per dispatch or draw, bound as a dynamic
uniform buffer). vk_harness refuses --mesh-compute with the flag (exit 77): mesh_compute_vs.py's vertex
shader still reads its address from push constants. Without the variable nothing changes.
Step 2 of the uniform-buffer tail claimed in #1902.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/vk_bindless_test.cpp')
| -rw-r--r-- | runtime/test/vk_bindless_test.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp index 041f6f648..09c0baf2b 100644 --- a/runtime/test/vk_bindless_test.cpp +++ b/runtime/test/vk_bindless_test.cpp | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "vulkan_loader.h" | 22 | #include "vulkan_loader.h" |
| 23 | #include "vk_device_pick.h" | 23 | #include "vk_device_pick.h" |
| 24 | #include "vk_shader_fma.h" | 24 | #include "vk_shader_fma.h" |
| 25 | #include "vk_pc_tail.h" | ||
| 25 | #include "../src/vulkan_bindless.h" | 26 | #include "../src/vulkan_bindless.h" |
| 26 | 27 | ||
| 27 | #include <algorithm> | 28 | #include <algorithm> |
| @@ -192,7 +193,10 @@ int main(int argc, char** argv) { | |||
| 192 | std::printf("device: %s%s\n", props.properties.deviceName, validation ? " (validation on)" : ""); | 193 | std::printf("device: %s%s\n", props.properties.deviceName, validation ? " (validation on)" : ""); |
| 193 | // The pipeline layout pushes the 144-byte translated user-data block. A device with fewer push constant bytes | 194 | // The pipeline layout pushes the 144-byte translated user-data block. A device with fewer push constant bytes |
| 194 | // (128 on Intel Arc and some AMD drivers) can't create it: a device limit, not a wrong result (TEST-149). | 195 | // (128 on Intel Arc and some AMD drivers) can't create it: a device limit, not a wrong result (TEST-149). |
| 195 | constexpr std::uint32_t push_bytes = 144; | 196 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes; the heap base, if a stage reads |
| 197 | // it, is in a uniform block at set 1 (vk_pc_tail.h). | ||
| 198 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 199 | const std::uint32_t push_bytes = pc_tail ? 128u : 144u; | ||
| 196 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { | 200 | if (props.properties.limits.maxPushConstantsSize < push_bytes) { |
| 197 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, | 201 | std::printf("unsupported: need %u push constant bytes, device has %u\n", push_bytes, |
| 198 | props.properties.limits.maxPushConstantsSize); | 202 | props.properties.limits.maxPushConstantsSize); |
| @@ -419,17 +423,34 @@ int main(int argc, char** argv) { | |||
| 419 | CHECK(make_buffer(VkDeviceSize(W) * H * 16, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &readback, &readback_map)); | 423 | CHECK(make_buffer(VkDeviceSize(W) * H * 16, VK_BUFFER_USAGE_TRANSFER_DST_BIT, &readback, &readback_map)); |
| 420 | 424 | ||
| 421 | VkShaderModule vs, fs; | 425 | VkShaderModule vs, fs; |
| 426 | bool tail_block = false; | ||
| 422 | for (int stage = 0; stage < 2; ++stage) { | 427 | for (int stage = 0; stage < 2; ++stage) { |
| 423 | const auto code = read_spv(argv[1 + stage]); | 428 | const auto code = read_spv(argv[1 + stage]); |
| 424 | if (code.empty()) { | 429 | if (code.empty()) { |
| 425 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); | 430 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); |
| 426 | return 1; | 431 | return 1; |
| 427 | } | 432 | } |
| 433 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 434 | tail_block = true; | ||
| 428 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 435 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 429 | smi.codeSize = code.size() * 4; | 436 | smi.codeSize = code.size() * 4; |
| 430 | smi.pCode = code.data(); | 437 | smi.pCode = code.data(); |
| 431 | CHECK(vkCreateShaderModule(dev, &smi, nullptr, stage ? &fs : &vs)); | 438 | CHECK(vkCreateShaderModule(dev, &smi, nullptr, stage ? &fs : &vs)); |
| 432 | } | 439 | } |
| 440 | // One tail block for every variant below: each draw's tail is the same heap base. | ||
| 441 | leonida::vk_test::PcTail tail; | ||
| 442 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.properties.limits.minUniformBufferOffsetAlignment, | ||
| 443 | VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1)) { | ||
| 444 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 445 | return 1; | ||
| 446 | } | ||
| 447 | auto bind_tail = [&](VkCommandBuffer cb, VkPipelineLayout layout, const std::uint32_t* block) { | ||
| 448 | if (!tail_block) return; | ||
| 449 | tail.write(0, block, 4); | ||
| 450 | const std::uint32_t offset = tail.offset(0); | ||
| 451 | vkCmdBindDescriptorSets(cb, VK_PIPELINE_BIND_POINT_GRAPHICS, layout, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 452 | 1, &offset); | ||
| 453 | }; | ||
| 433 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; | 454 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; |
| 434 | cpi.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; | 455 | cpi.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 435 | cpi.queueFamilyIndex = qi; | 456 | cpi.queueFamilyIndex = qi; |
| @@ -566,6 +587,8 @@ int main(int argc, char** argv) { | |||
| 566 | pli.pSetLayouts = &set_layout; | 587 | pli.pSetLayouts = &set_layout; |
| 567 | pli.pushConstantRangeCount = 1; | 588 | pli.pushConstantRangeCount = 1; |
| 568 | pli.pPushConstantRanges = &push; | 589 | pli.pPushConstantRanges = &push; |
| 590 | const VkDescriptorSetLayout set_layouts[] = {set_layout, tail.set_layout}; | ||
| 591 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = set_layouts; } | ||
| 569 | VkPipelineLayout pipeline_layout; | 592 | VkPipelineLayout pipeline_layout; |
| 570 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); | 593 | CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pipeline_layout)); |
| 571 | VkPipelineShaderStageCreateInfo stages[2]{{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}, | 594 | VkPipelineShaderStageCreateInfo stages[2]{{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}, |
| @@ -632,7 +655,8 @@ int main(int argc, char** argv) { | |||
| 632 | block[2] = table_va; // s2:s3 = console VA of the descriptor table | 655 | block[2] = table_va; // s2:s3 = console VA of the descriptor table |
| 633 | block[32] = std::uint32_t(heap_base); | 656 | block[32] = std::uint32_t(heap_base); |
| 634 | block[33] = std::uint32_t(heap_base >> 32); | 657 | block[33] = std::uint32_t(heap_base >> 32); |
| 635 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(block), block); | 658 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, push_bytes, block); |
| 659 | bind_tail(cmd, pipeline_layout, block); | ||
| 636 | vkCmdDraw(cmd, 3, 1, 0, 0); | 660 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 637 | vkCmdEndRenderPass(cmd); | 661 | vkCmdEndRenderPass(cmd); |
| 638 | VkBufferImageCopy rc{}; | 662 | VkBufferImageCopy rc{}; |
| @@ -777,7 +801,8 @@ int main(int argc, char** argv) { | |||
| 777 | block[32] = std::uint32_t(heap_base); | 801 | block[32] = std::uint32_t(heap_base); |
| 778 | block[33] = std::uint32_t(heap_base >> 32); | 802 | block[33] = std::uint32_t(heap_base >> 32); |
| 779 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, | 803 | vkCmdPushConstants(cmd, pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, |
| 780 | sizeof(block), block); | 804 | push_bytes, block); |
| 805 | bind_tail(cmd, pipeline_layout, block); | ||
| 781 | vkCmdDraw(cmd, 3, 1, 0, 0); | 806 | vkCmdDraw(cmd, 3, 1, 0, 0); |
| 782 | vkCmdEndRenderPass(cmd); | 807 | vkCmdEndRenderPass(cmd); |
| 783 | VkMemoryBarrier after{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; | 808 | VkMemoryBarrier after{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; |