upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/vk_harness.cpp
diff options
context:
space:
mode:
authorlumenpearson <139921639+lumenpearson@users.noreply.github.com>2026-11-22 23:25:25 +0300
committerlumenpearson <139921639+lumenpearson@users.noreply.github.com>2026-11-22 23:25:25 +0300
commitf324bfbc71f0eabf9515bcd7c8b7c9e4b89448bf (patch)
tree2db4ae6fd5412abbbc3e1894f8bc7ed88c8ae514 /runtime/test/vk_harness.cpp
parent18380c6d2baf1422109b369860a6e8be5e185b05 (diff)
parentf847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff)
Merge upstream main into SHADER-537
Diffstat (limited to 'runtime/test/vk_harness.cpp')
-rw-r--r--runtime/test/vk_harness.cpp57
1 files changed, 53 insertions, 4 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp
index fe9ae194a..abaacb348 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);
@@ -326,12 +336,22 @@ int main(int argc, char** argv) {
326 m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; 336 m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8;
327 } 337 }
328#endif 338#endif
339 VkPhysicalDeviceVulkan11Features f11q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES};
329 VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; 340 VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
341 f12q.pNext = &f11q;
330 VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 342 VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
331 f13q.pNext = &f12q; 343 f13q.pNext = &f12q;
332 VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 344 VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
333 f2q.pNext = &f13q; 345 f2q.pNext = &f13q;
334 vkGetPhysicalDeviceFeatures2(pd, &f2q); 346 vkGetPhysicalDeviceFeatures2(pd, &f2q);
347 // Translated vertex shaders read BaseVertex / BaseInstance (DrawParameters) to give v0 / v3 the hardware's
348 // zero-based ids.
349 VkPhysicalDeviceVulkan11Features f11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES};
350 if (f11q.shaderDrawParameters) {
351 f11.shaderDrawParameters = VK_TRUE;
352 f11.pNext = chain;
353 chain = &f11;
354 }
335 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 355 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
336 if (f13q.subgroupSizeControl) { 356 if (f13q.subgroupSizeControl) {
337 f13.subgroupSizeControl = VK_TRUE; 357 f13.subgroupSizeControl = VK_TRUE;
@@ -390,6 +410,7 @@ int main(int argc, char** argv) {
390 LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); 410 LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer);
391 LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass); 411 LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass);
392 LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed); 412 LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed);
413 LOADD(vkCmdPipelineBarrier);
393 LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle); 414 LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle);
394 LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory); 415 LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory);
395 VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); 416 VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q);
@@ -462,8 +483,11 @@ int main(int argc, char** argv) {
462 VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; 483 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; 484 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)); 485 VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb));
486 bool tail_block = false; // some stage reads the --pc-tail-ubo block (declares set 1)
465 auto module = [&](const char* p, VkShaderModule* m) { 487 auto module = [&](const char* p, VkShaderModule* m) {
466 auto code = read_spv(p); 488 auto code = read_spv(p);
489 if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set))
490 tail_block = true;
467 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; 491 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
468 smi.codeSize = code.size() * 4; smi.pCode = code.data(); 492 smi.codeSize = code.size() * 4; smi.pCode = code.data();
469 return vkCreateShaderModule(dev, &smi, nullptr, m); 493 return vkCreateShaderModule(dev, &smi, nullptr, m);
@@ -537,6 +561,14 @@ int main(int argc, char** argv) {
537 VkPushConstantRange pcr{pcs, 0, pc_bytes}; 561 VkPushConstantRange pcr{pcs, 0, pc_bytes};
538 VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; 562 VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
539 pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; 563 pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr;
564 // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw.
565 leonida::vk_test::PcTail tail;
566 if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, pcs, 1)) {
567 std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n");
568 return 1;
569 }
570 const VkDescriptorSetLayout tail_layouts[] = {tail.empty_layout, tail.set_layout};
571 if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = tail_layouts; }
540 VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); 572 VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl));
541 VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; 573 VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO};
542 gpi.stageCount = nstages; gpi.pStages = stages; 574 gpi.stageCount = nstages; gpi.pStages = stages;
@@ -674,7 +706,7 @@ int main(int argc, char** argv) {
674 auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); 706 auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants"));
675 if (mesh_compute) { 707 if (mesh_compute) {
676 // The mesh shader as compute, then make its stores visible to the vertex shader's reads. 708 // The mesh shader as compute, then make its stores visible to the vertex shader's reads.
677 LOADD(vkCmdDispatch); LOADD(vkCmdPipelineBarrier); 709 LOADD(vkCmdDispatch);
678 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe); 710 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe);
679 push(cmd, pl, pcs, 0, pc_bytes, pc); 711 push(cmd, pl, pcs, 0, pc_bytes, pc);
680 vkCmdDispatch(cmd, groups[0], groups[1], groups[2]); 712 vkCmdDispatch(cmd, groups[0], groups[1], groups[2]);
@@ -698,6 +730,13 @@ int main(int argc, char** argv) {
698 } 730 }
699 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); 731 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
700 push(cmd, pl, pcs, 0, pc_bytes, pc); 732 push(cmd, pl, pcs, 0, pc_bytes, pc);
733 if (tail_block) {
734 LOADD(vkCmdBindDescriptorSets);
735 tail.write(0, pc, 4); // heap base (VKH_HEAP) and code base, as pc[32..35] are without the flag
736 const uint32_t offset = tail.offset(0);
737 vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, leonida::vk_test::pc_tail_set, 1, &tail.set,
738 1, &offset);
739 }
701 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). 740 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251).
702 const char* vertices_env = std::getenv("VKH_VERTICES"); 741 const char* vertices_env = std::getenv("VKH_VERTICES");
703 if (draw_mesh_path) { 742 if (draw_mesh_path) {
@@ -712,11 +751,21 @@ int main(int argc, char** argv) {
712 vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0); 751 vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0);
713 else if (mesh) 752 else if (mesh)
714 reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]); 753 reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]);
715 else 754 else {
716 vkCmdDraw(cmd, 3, 1, 0, 0); 755 // VKH_DRAW=<firstVertex>,<firstInstance>: draw the triangle with non-zero bases (vs_base_ids).
756 unsigned first_vertex = 0, first_instance = 0;
757 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance);
758 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance);
759 }
717 vkCmdEndRenderPass(cmd); 760 vkCmdEndRenderPass(cmd);
718 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; 761 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1};
719 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg); 762 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg);
763 // Make the image copy and any shader writes to the heap visible to the host after the queue wait.
764 VkMemoryBarrier readback{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
765 readback.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
766 readback.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
767 vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0,
768 1, &readback, 0, nullptr, 0, nullptr);
720 CHECK(vkEndCommandBuffer(cmd)); 769 CHECK(vkEndCommandBuffer(cmd));
721 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; 770 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd;
722 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); 771 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE));