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:
authorVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 22:01:03 +0100
committerVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 22:01:03 +0100
commit3a1ed28bebf374321149bc4bbffc005ea6f691c4 (patch)
tree8884d5f8c45eef1e8f4d3a806790418de278ae55 /runtime/test/vk_harness.cpp
parent0d58747e0da27dcb44b0127831260b763913fc2f (diff)
parentf847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff)
Merge main into hw4-ps-formats (#3499)
docs/shader_validation.md AI-assisted.
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 f906bc4f2..89505eab3 100644
--- a/runtime/test/vk_harness.cpp
+++ b/runtime/test/vk_harness.cpp
@@ -28,6 +28,7 @@
28#include "vulkan_loader.h" 28#include "vulkan_loader.h"
29#include "vk_device_pick.h" 29#include "vk_device_pick.h"
30#include "vk_shader_fma.h" 30#include "vk_shader_fma.h"
31#include "vk_pc_tail.h"
31 32
32#include <cctype> 33#include <cctype>
33#include <cstddef> 34#include <cstddef>
@@ -302,7 +303,16 @@ int main(int argc, char** argv) {
302 // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs) 303 // fewer bytes (128, the Vulkan minimum, as on some Intel Arc drivers and AMD's Windows driver for RDNA2 iGPUs)
303 // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or 304 // cannot take that range: declaring it anyway is invalid, and there a shader reading past the limit crashed or
304 // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14). 305 // hung the device. 77, as vk_texture_test and vk_bindless_test: a device limit, not a wrong result (D3D-14).
305 const uint32_t pc_bytes = mesh_compute ? 152u : 144u; 306 // LEONIDA_PC_TAIL_UBO=1 (rdna2spirv.py --pc-tail-ubo): s0..s31 only, 128 bytes, which every device has; the
307 // tail is a uniform block at set 1 (vk_pc_tail.h). tools/mesh_compute_vs.py's vertex shader still reads the
308 // --mesh-compute output address from push constants, so that combination isn't run.
309 const bool pc_tail = leonida::vk_test::pc_tail_requested();
310 if (pc_tail && mesh_compute) {
311 std::fprintf(stderr, "unsupported: --mesh-compute's vertex shader reads the output address from push "
312 "constants, not from the --pc-tail-ubo block\n");
313 return 77;
314 }
315 const uint32_t pc_bytes = pc_tail ? 128u : mesh_compute ? 152u : 144u;
306 if (props.limits.maxPushConstantsSize < pc_bytes) { 316 if (props.limits.maxPushConstantsSize < pc_bytes) {
307 std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes, 317 std::fprintf(stderr, "unsupported: need %u push constant bytes, device has %u\n", pc_bytes,
308 props.limits.maxPushConstantsSize); 318 props.limits.maxPushConstantsSize);
@@ -332,12 +342,22 @@ int main(int argc, char** argv) {
332 m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; 342 m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8;
333 } 343 }
334#endif 344#endif
345 VkPhysicalDeviceVulkan11Features f11q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES};
335 VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; 346 VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
347 f12q.pNext = &f11q;
336 VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 348 VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
337 f13q.pNext = &f12q; 349 f13q.pNext = &f12q;
338 VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 350 VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
339 f2q.pNext = &f13q; 351 f2q.pNext = &f13q;
340 vkGetPhysicalDeviceFeatures2(pd, &f2q); 352 vkGetPhysicalDeviceFeatures2(pd, &f2q);
353 // Translated vertex shaders read BaseVertex / BaseInstance (DrawParameters) to give v0 / v3 the hardware's
354 // zero-based ids.
355 VkPhysicalDeviceVulkan11Features f11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES};
356 if (f11q.shaderDrawParameters) {
357 f11.shaderDrawParameters = VK_TRUE;
358 f11.pNext = chain;
359 chain = &f11;
360 }
341 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 361 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
342 if (f13q.subgroupSizeControl) { 362 if (f13q.subgroupSizeControl) {
343 f13.subgroupSizeControl = VK_TRUE; 363 f13.subgroupSizeControl = VK_TRUE;
@@ -419,6 +439,7 @@ int main(int argc, char** argv) {
419 LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer); 439 LOADD(vkCreateCommandPool); LOADD(vkAllocateCommandBuffers); LOADD(vkBeginCommandBuffer);
420 LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass); 440 LOADD(vkCmdBeginRenderPass); LOADD(vkCmdBindPipeline); LOADD(vkCmdDraw); LOADD(vkCmdEndRenderPass);
421 LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed); 441 LOADD(vkCmdBindVertexBuffers); LOADD(vkCmdBindIndexBuffer); LOADD(vkCmdDrawIndexed);
442 LOADD(vkCmdPipelineBarrier);
422 LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle); 443 LOADD(vkCmdCopyImageToBuffer); LOADD(vkEndCommandBuffer); LOADD(vkQueueSubmit); LOADD(vkQueueWaitIdle);
423 LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory); 444 LOADD(vkCreateBuffer); LOADD(vkGetBufferMemoryRequirements); LOADD(vkBindBufferMemory); LOADD(vkMapMemory);
424 VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q); 445 VkQueue q; vkGetDeviceQueue(dev, qi, 0, &q);
@@ -507,8 +528,11 @@ int main(int argc, char** argv) {
507 VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO}; 528 VkFramebufferCreateInfo fbi{VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};
508 fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1; 529 fbi.renderPass = rp; fbi.attachmentCount = rpi.attachmentCount; fbi.pAttachments = views; fbi.width = W; fbi.height = H; fbi.layers = 1;
509 VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb)); 530 VkFramebuffer fb; CHECK(vkCreateFramebuffer(dev, &fbi, nullptr, &fb));
531 bool tail_block = false; // some stage reads the --pc-tail-ubo block (declares set 1)
510 auto module = [&](const char* p, VkShaderModule* m) { 532 auto module = [&](const char* p, VkShaderModule* m) {
511 auto code = read_spv(p); 533 auto code = read_spv(p);
534 if (pc_tail && leonida::vk_test::spirv_declares_set(code.data(), code.size() * 4, leonida::vk_test::pc_tail_set))
535 tail_block = true;
512 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; 536 VkShaderModuleCreateInfo smi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
513 smi.codeSize = code.size() * 4; smi.pCode = code.data(); 537 smi.codeSize = code.size() * 4; smi.pCode = code.data();
514 return vkCreateShaderModule(dev, &smi, nullptr, m); 538 return vkCreateShaderModule(dev, &smi, nullptr, m);
@@ -582,6 +606,14 @@ int main(int argc, char** argv) {
582 VkPushConstantRange pcr{pcs, 0, pc_bytes}; 606 VkPushConstantRange pcr{pcs, 0, pc_bytes};
583 VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; 607 VkPipelineLayoutCreateInfo pli{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
584 pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr; 608 pli.pushConstantRangeCount = 1; pli.pPushConstantRanges = &pcr;
609 // --pc-tail-ubo: the tail block at set 1 (set 0 stays empty here), one slot for the one draw.
610 leonida::vk_test::PcTail tail;
611 if (tail_block && !tail.create(vkGetDeviceProcAddr, dev, mp, props.limits.minUniformBufferOffsetAlignment, pcs, 1)) {
612 std::fprintf(stderr, "FAILED creating the --pc-tail-ubo block\n");
613 return 1;
614 }
615 const VkDescriptorSetLayout tail_layouts[] = {tail.empty_layout, tail.set_layout};
616 if (tail_block) { pli.setLayoutCount = 2; pli.pSetLayouts = tail_layouts; }
585 VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl)); 617 VkPipelineLayout pl; CHECK(vkCreatePipelineLayout(dev, &pli, nullptr, &pl));
586 VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; 618 VkGraphicsPipelineCreateInfo gpi{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO};
587 gpi.stageCount = nstages; gpi.pStages = stages; 619 gpi.stageCount = nstages; gpi.pStages = stages;
@@ -788,7 +820,7 @@ int main(int argc, char** argv) {
788 auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants")); 820 auto push = reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants"));
789 if (mesh_compute) { 821 if (mesh_compute) {
790 // The mesh shader as compute, then make its stores visible to the vertex shader's reads. 822 // The mesh shader as compute, then make its stores visible to the vertex shader's reads.
791 LOADD(vkCmdDispatch); LOADD(vkCmdPipelineBarrier); 823 LOADD(vkCmdDispatch);
792 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe); 824 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, cpipe);
793 push(cmd, pl, pcs, 0, pc_bytes, pc); 825 push(cmd, pl, pcs, 0, pc_bytes, pc);
794 vkCmdDispatch(cmd, groups[0], groups[1], groups[2]); 826 vkCmdDispatch(cmd, groups[0], groups[1], groups[2]);
@@ -812,6 +844,13 @@ int main(int argc, char** argv) {
812 } 844 }
813 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); 845 vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
814 push(cmd, pl, pcs, 0, pc_bytes, pc); 846 push(cmd, pl, pcs, 0, pc_bytes, pc);
847 if (tail_block) {
848 LOADD(vkCmdBindDescriptorSets);
849 tail.write(0, pc, 4); // heap base (VKH_HEAP) and code base, as pc[32..35] are without the flag
850 const uint32_t offset = tail.offset(0);
851 vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl, leonida::vk_test::pc_tail_set, 1, &tail.set,
852 1, &offset);
853 }
815 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). 854 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251).
816 const char* vertices_env = std::getenv("VKH_VERTICES"); 855 const char* vertices_env = std::getenv("VKH_VERTICES");
817 if (draw_mesh_path) { 856 if (draw_mesh_path) {
@@ -826,11 +865,21 @@ int main(int argc, char** argv) {
826 vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0); 865 vkCmdDraw(cmd, uint32_t(mesh_groups * mesh_prims * 3), 1, 0, 0);
827 else if (mesh) 866 else if (mesh)
828 reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]); 867 reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, groups[0], groups[1], groups[2]);
829 else 868 else {
830 vkCmdDraw(cmd, 3, 1, 0, 0); 869 // VKH_DRAW=<firstVertex>,<firstInstance>: draw the triangle with non-zero bases (vs_base_ids).
870 unsigned first_vertex = 0, first_instance = 0;
871 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance);
872 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance);
873 }
831 vkCmdEndRenderPass(cmd); 874 vkCmdEndRenderPass(cmd);
832 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; 875 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1};
833 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg); 876 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg);
877 // Make the image copy and any shader writes to the heap visible to the host after the queue wait.
878 VkMemoryBarrier readback{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
879 readback.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
880 readback.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
881 vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0,
882 1, &readback, 0, nullptr, 0, nullptr);
834 CHECK(vkEndCommandBuffer(cmd)); 883 CHECK(vkEndCommandBuffer(cmd));
835 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; 884 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd;
836 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); 885 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE));