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_harness.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_harness.cpp')
| -rw-r--r-- | runtime/test/vk_harness.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp index a2491b64b..d7b6597e4 100644 --- a/runtime/test/vk_harness.cpp +++ b/runtime/test/vk_harness.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "vulkan_loader.h" | 23 | #include "vulkan_loader.h" |
| 24 | #include "vk_device_pick.h" | 24 | #include "vk_device_pick.h" |
| 25 | #include "vk_shader_fma.h" | 25 | #include "vk_shader_fma.h" |
| 26 | #include "vk_pc_tail.h" | ||
| 26 | 27 | ||
| 27 | #include <cctype> | 28 | #include <cctype> |
| 28 | #include <cstddef> | 29 | #include <cstddef> |
| @@ -296,7 +297,16 @@ int main(int argc, char** argv) { | |||
| 296 | // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs) | 297 | // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs) |
| 297 | // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or | 298 | // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or |
| 298 | // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14). | 299 | // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14). |
| 299 | const uint32_t pc_bytes = mesh_compute ? 152u : 144u; | 300 | // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes, which every device has; the |
| 301 | // tail is a uniform block at set 1 (vk_pc_tail.h). tools/mesh_compute_vs.py's vertex shader still reads the | ||
| 302 | // --mesh-compute output address from push constants, so that combination isn't run. | ||
| 303 | const bool pc_tail = leonida::vk_test::pc_tail_requested(); | ||
| 304 | if (pc_tail && mesh_compute) { | ||
| 305 | std::fprintf(stderr, "unsupported: --mesh-compute's vertex shader reads the output address from push " | ||
| 306 | "constants, not from the --pc-tail-ubo block\n"); | ||
| 307 | return 77; | ||
| 308 | } | ||
| 309 | const uint32_t pc_bytes = pc_tail ? 128u : mesh_compute ? 152u : 144u; | ||
| 300 | if (props.limits.maxPushConstantsSize < pc_bytes) { | 310 | if (props.limits.maxPushConstantsSize < pc_bytes) { |
| 301 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes, | 311 | std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes, |
| 302 | props.limits.maxPushConstantsSize); | 312 | props.limits.maxPushConstantsSize); |
| @@ -462,8 +472,11 @@ int main(int argc, char** argv) { | |||
| 462 | VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; | 472 | VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; |
| 463 | fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1; | 473 | fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1; |
| 464 | VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb)); | 474 | VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb)); |
| 475 | bool tail_block = false; // some stage reads the --pc-tail-ubo block (declares set 1) | ||
| 465 | auto module = [&](const char* p, VkShaderModule* m) { | 476 | auto module = [&](const char* p, VkShaderModule* m) { |
| 466 | auto code = read_spv(p); | 477 | auto code = read_spv(p); |
| 478 | if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set)) | ||
| 479 | tail_block = true; | ||
| 467 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 480 | VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 468 | smi.codeSize = code.size() * 4; smi.pCode = code.data(); | 481 | smi.codeSize = code.size() * 4; smi.pCode = code.data(); |
| 469 | return vkCreateShaderModule(dev, &smi, nullptr, m); | 482 | return vkCreateShaderModule(dev, &smi, nullptr, m); |
| @@ -534,6 +547,14 @@ int main(int argc, char** argv) { | |||
| 534 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; | 547 | VkPushConstantRange pcr{pcs, 0, pc_bytes}; |
| 535 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; | 548 | VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; |
| 536 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; | 549 | pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; |
| 550 | // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw. | ||
| 551 | leonida::vk_test::PcTail tail; | ||
| 552 | if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, pcs, 1)) { | ||
| 553 | std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n"); | ||
| 554 | return 1; | ||
| 555 | } | ||
| 556 | const VkDescriptorSetLayout tail_layouts[] = {tail.empty_layout, tail.set_layout}; | ||
| 557 | if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = tail_layouts; } | ||
| 537 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); | 558 | VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); |
| 538 | VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; | 559 | VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; |
| 539 | gpi.stageCount = nstages; gpi.pStages = stages; | 560 | gpi.stageCount = nstages; gpi.pStages = stages; |
| @@ -695,6 +716,13 @@ int main(int argc, char** argv) { | |||
| 695 | } | 716 | } |
| 696 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); | 717 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); |
| 697 | push(cmd, pl, pcs, 0, pc_bytes, pc); | 718 | push(cmd, pl, pcs, 0, pc_bytes, pc); |
| 719 | if (tail_block) { | ||
| 720 | LOADD(vkCmdBindDescriptorSets); | ||
| 721 | tail.write(0, pc, 4); // heap base (VKH_HEAP) and code base, as pc[32..35] are without the flag | ||
| 722 | const uint32_t offset = tail.offset(0); | ||
| 723 | vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, leonida::vk_test::pc_tail_set, 1, &tail.set, | ||
| 724 | 1, &offset); | ||
| 725 | } | ||
| 698 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). | 726 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). |
| 699 | const char* vertices_env = std::getenv("VKH_VERTICES"); | 727 | const char* vertices_env = std::getenv("VKH_VERTICES"); |
| 700 | if (draw_mesh_path) { | 728 | if (draw_mesh_path) { |