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:
authorRafael <rafaelalvesp2005@gmail.com>2026-11-23 15:36:26 -0300
committerRafael <rafaelalvesp2005@gmail.com>2026-11-23 15:36:26 -0300
commit63f0e0dea3a9d44201db408c4e2c3f2f5b2b94d6 (patch)
tree86f0dcad8070e2a3a693ef4897aa83950cfeb224 /runtime/test/vk_harness.cpp
parentf78f7d6a2a9364cb128c03ac539fe540d5c70df1 (diff)
parent6dda0630bd6fc0514baadb94fb98e36bd7d64c0b (diff)
Merge main into fix/walk-bink_names
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.cpp91
1 files changed, 85 insertions, 6 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp
index a9b97d31e..23d58bc70 100644
--- a/runtime/test/vk_harness.cpp
+++ b/runtime/test/vk_harness.cpp
@@ -7,6 +7,7 @@
7// 7//
8// Push constants follow the contract in docs/design.md: s0..s31, then the heap base lo/hi. They are zero unless 8// Push constants follow the contract in docs/design.md: s0..s31, then the heap base lo/hi. They are zero unless
9// VKH_SGPRS=w0,w1,... sets s0, s1, ... (decimal or 0x hex) 9// VKH_SGPRS=w0,w1,... sets s0, s1, ... (decimal or 0x hex)
10// VKH_GS_PRIMITIVES=1 reports "gs_primitives=N" on stderr for the VKH_GS draw (77 if unsupported)
10// VKH_HEAP=addr=word,... allocates a zeroed 64 KiB heap (Xbox VA 0 = its device address), writes each word at 11// VKH_HEAP=addr=word,... allocates a zeroed 64 KiB heap (Xbox VA 0 = its device address), writes each word at
11// its address and passes the heap base, so a V# in VKH_SGPRS can point into it. 12// its address and passes the heap base, so a V# in VKH_SGPRS can point into it.
12// VKH_HEAP_DUMP=<file> after the draw, writes the 64 KiB heap (needs VKH_HEAP, which may be empty-valued as 13// VKH_HEAP_DUMP=<file> after the draw, writes the 64 KiB heap (needs VKH_HEAP, which may be empty-valued as
@@ -18,6 +19,8 @@
18// VKH_BINARY_OUT=<file> writes the pipeline's VK_KHR_pipeline_binary data after building it 19// VKH_BINARY_OUT=<file> writes the pipeline's VK_KHR_pipeline_binary data after building it
19// VKH_BINARY_IN=<file> builds the pipeline from such a file instead (tools/ps_oracle.py patches the pixel 20// VKH_BINARY_IN=<file> builds the pipeline from such a file instead (tools/ps_oracle.py patches the pixel
20// shader in it); both exit 77 without VK_KHR_pipeline_binary 21// shader in it); both exit 77 without VK_KHR_pipeline_binary
22// VKH_COLOR_FORMAT=<VkFormat>:<bytes> the color target's format and texel size (default RGBA32F, 16); out.raw
23// holds the texels as stored; 77 when the format is no color attachment
21// VKH_SUBGROUP_SIZE=32|64 requires that subgroup size of the fragment shader (or of the compute or geometry 24// VKH_SUBGROUP_SIZE=32|64 requires that subgroup size of the fragment shader (or of the compute or geometry
22// stage under test); stderr says "fragment subgroup size: N" when it took effect and 25// stage under test); stderr says "fragment subgroup size: N" when it took effect and
23// "... not available" when the device cannot require it (exit code stays 0). 26// "... not available" when the device cannot require it (exit code stays 0).
@@ -33,6 +36,7 @@
33#include "vk_pc_tail.h" 36#include "vk_pc_tail.h"
34#include "../src/descriptor_table.h" 37#include "../src/descriptor_table.h"
35#include "../src/gfx10_descriptors.h" 38#include "../src/gfx10_descriptors.h"
39#include "spirv_capability.h"
36 40
37#include <cctype> 41#include <cctype>
38#include <cstddef> 42#include <cstddef>
@@ -265,10 +269,13 @@ int main(int argc, char** argv) {
265 } 269 }
266 VkPhysicalDeviceProperties props; vkGetPhysicalDeviceProperties(pd, &props); 270 VkPhysicalDeviceProperties props; vkGetPhysicalDeviceProperties(pd, &props);
267 VkPhysicalDeviceSubgroupSizeControlProperties sgProps{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES}; 271 VkPhysicalDeviceSubgroupSizeControlProperties sgProps{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES};
272 VkPhysicalDeviceDriverProperties driver{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES};
273 if (props.apiVersion >= VK_API_VERSION_1_2) sgProps.pNext = &driver;
268 VkPhysicalDeviceProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; 274 VkPhysicalDeviceProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
269 props2.pNext = &sgProps; 275 props2.pNext = &sgProps;
270 vkGetPhysicalDeviceProperties2(pd, &props2); 276 vkGetPhysicalDeviceProperties2(pd, &props2);
271 std::fprintf(stderr, "device: %s (subgroup %u..%u)\n", props.deviceName, sgProps.minSubgroupSize, sgProps.maxSubgroupSize); 277 std::fprintf(stderr, "device: %s (subgroup %u..%u)\n", props.deviceName, sgProps.minSubgroupSize, sgProps.maxSubgroupSize);
278 if (driver.driverName[0]) std::fprintf(stderr, "driver: %s\n", driver.driverName);
272 uint32_t qn = 0; 279 uint32_t qn = 0;
273 vkGetPhysicalDeviceQueueFamilyProperties(pd, &qn, nullptr); 280 vkGetPhysicalDeviceQueueFamilyProperties(pd, &qn, nullptr);
274 std::vector<VkQueueFamilyProperties> qf(qn); 281 std::vector<VkQueueFamilyProperties> qf(qn);
@@ -309,10 +316,13 @@ int main(int argc, char** argv) {
309 argv[2], VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME); 316 argv[2], VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);
310 return 77; 317 return 77;
311 } 318 }
312 // OpFmaKHR (rdna2spirv.py --fma khr) needs VK_KHR_shader_fma; the fragment shader decides whether it is refused. 319 // OpFmaKHR (rdna2spirv.py --fma khr) needs VK_KHR_shader_fma; a module of ANY stage that needs it is refused
320 // (argv[1] is the vertex shader, or the mesh shader run as compute under VKH_MESH_COMPUTE).
313 leonida::vk_test::ShaderFma fma; 321 leonida::vk_test::ShaderFma fma;
314 fma.query(gipa, inst, pd); 322 fma.query(gipa, inst, pd);
315 if (!fma.accepts(fs_code.data(), fs_code.size() * 4, argv[2])) return 77; 323 if (!fma.accepts(fs_code.data(), fs_code.size() * 4, argv[2])) return 77;
324 if (!fma.accepts_file(argv[1])) return 77;
325 if (!fma.accepts_file(std::getenv("VKH_MESH_COMPUTE"))) return 77;
316 std::vector<const char*> enable; 326 std::vector<const char*> enable;
317 void* chain = nullptr; 327 void* chain = nullptr;
318 if (fma.supported()) { 328 if (fma.supported()) {
@@ -468,11 +478,22 @@ int main(int argc, char** argv) {
468 // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then 478 // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then
469 // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test. 479 // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test.
470 const char* gs_path = std::getenv("VKH_GS"); 480 const char* gs_path = std::getenv("VKH_GS");
481 const char* count_opt = std::getenv("VKH_GS_PRIMITIVES");
482 const bool count_gs = count_opt && std::strcmp(count_opt, "1") == 0;
483 if (count_gs && (!gs_path || !*gs_path || mesh || mesh_compute)) {
484 std::fprintf(stderr, "VKH_GS_PRIMITIVES=1 requires a VS/GS/FS draw with VKH_GS\n");
485 return 1;
486 }
471 if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage 487 if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage
472 std::fprintf(stderr, "unsupported: no geometryShader\n"); 488 std::fprintf(stderr, "unsupported: no geometryShader\n");
473 return 77; 489 return 77;
474 } 490 }
475 VkPhysicalDeviceFeatures feats{}; 491 VkPhysicalDeviceFeatures feats{};
492 if (count_gs && !f2q.features.pipelineStatisticsQuery) {
493 std::fprintf(stderr, "unsupported: no pipelineStatisticsQuery\n");
494 return 77;
495 }
496 feats.pipelineStatisticsQuery = count_gs;
476 if (clip_shifts && !f2q.features.shaderClipDistance) { 497 if (clip_shifts && !f2q.features.shaderClipDistance) {
477 std::fprintf(stderr, "unsupported: shaderClipDistance\n"); 498 std::fprintf(stderr, "unsupported: shaderClipDistance\n");
478 return 77; 499 return 77;
@@ -487,9 +508,18 @@ int main(int argc, char** argv) {
487 } 508 }
488 feats.shaderFloat64 = VK_TRUE; 509 feats.shaderFloat64 = VK_TRUE;
489 } 510 }
490 if (need_heap || mesh_compute) { 511 // shaderInt64 only when a stage has 64-bit integers. Heap and --mesh-compute addresses are 64-bit, but rdna2spirv.py
491 if (!f2q.features.shaderInt64) { std::fprintf(stderr, "unsupported: 64-bit addresses need shaderInt64\n"); return 77; } 512 // builds them from 32-bit pairs unless the shader also does 64-bit arithmetic (SHADER-423), so the module decides,
492 feats.shaderInt64 = VK_TRUE; // heap and --mesh-compute output addresses are 64-bit 513 // not VKH_HEAP (TEST-468).
514 bool needs_int64 = leonida::vk_test::needs_shader_int64(fs_code);
515 for (const char* p : std::initializer_list<const char*>{argv[1], mesh_vs_path, gs_path})
516 if (p && !needs_int64) needs_int64 = leonida::vk_test::needs_shader_int64(read_spv(p));
517 if (needs_int64) {
518 if (!f2q.features.shaderInt64) {
519 std::fprintf(stderr, "unsupported: a stage declares Int64 and the device has no shaderInt64\n");
520 return 77;
521 }
522 feats.shaderInt64 = VK_TRUE;
493 } 523 }
494 if (tex_rgba_path) { 524 if (tex_rgba_path) {
495 if (!f2q.features.shaderSampledImageArrayDynamicIndexing) { 525 if (!f2q.features.shaderSampledImageArrayDynamicIndexing) {
@@ -535,7 +565,23 @@ int main(int argc, char** argv) {
535 CHECK(vkCreateImageView(dev, &vi, nullptr, &view)); 565 CHECK(vkCreateImageView(dev, &vi, nullptr, &view));
536 return 0; 566 return 0;
537 }; 567 };
538 const VkFormat fmt = VK_FORMAT_R32G32B32A32_SFLOAT; 568 // VKH_COLOR_FORMAT=<VkFormat number>:<bytes per texel>: the color target's format (default RGBA32F, 16 bytes);
569 // out.raw then holds the target's texels as they are (tools/ps_oracle.py --format).
570 VkFormat fmt = VK_FORMAT_R32G32B32A32_SFLOAT;
571 uint32_t texel_bytes = 16;
572 if (const char* cf = std::getenv("VKH_COLOR_FORMAT"); cf && *cf) {
573 char* end = nullptr;
574 fmt = VkFormat(std::strtoul(cf, &end, 0));
575 texel_bytes = (end && *end == ':') ? uint32_t(std::strtoul(end + 1, nullptr, 0)) : 0;
576 if (!texel_bytes || texel_bytes > 16) { std::fprintf(stderr, "VKH_COLOR_FORMAT: want <format>:<bytes>\n"); return 2; }
577 auto get_fp = reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(
578 gipa(inst, "vkGetPhysicalDeviceFormatProperties"));
579 VkFormatProperties cp; get_fp(pd, fmt, &cp);
580 if (!(cp.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) {
581 std::fprintf(stderr, "unsupported: format %u is not a color attachment\n", unsigned(fmt));
582 return 77;
583 }
584 }
539 VkImage img; 585 VkImage img;
540 VkImageView views[2]{}; 586 VkImageView views[2]{};
541 if (attachment(fmt, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 587 if (attachment(fmt, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
@@ -771,6 +817,11 @@ int main(int argc, char** argv) {
771 f.write(reinterpret_cast<const char*>(&n64), 8); 817 f.write(reinterpret_cast<const char*>(&n64), 8);
772 f.write(data.data(), std::streamsize(n)); 818 f.write(data.data(), std::streamsize(n));
773 } 819 }
820 f.close();
821 if (!f) {
822 std::fprintf(stderr, "failed to write pipeline binaries to %s\n", bin_out);
823 return 1;
824 }
774 std::fprintf(stderr, "wrote %u pipeline binaries to %s\n", count, bin_out); 825 std::fprintf(stderr, "wrote %u pipeline binaries to %s\n", count, bin_out);
775 } 826 }
776 VkPipeline cpipe = VK_NULL_HANDLE; 827 VkPipeline cpipe = VK_NULL_HANDLE;
@@ -787,7 +838,7 @@ int main(int argc, char** argv) {
787 CHECK(vkCreateComputePipelines(dev, VK_NULL_HANDLE, 1, &cpi, nullptr, &cpipe)); 838 CHECK(vkCreateComputePipelines(dev, VK_NULL_HANDLE, 1, &cpi, nullptr, &cpipe));
788 } 839 }
789 VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; 840 VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
790 bi.size = VkDeviceSize(W) * H * 16; bi.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; 841 bi.size = VkDeviceSize(W) * H * texel_bytes; bi.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
791 VkBuffer buf; CHECK(vkCreateBuffer(dev, &bi, nullptr, &buf)); 842 VkBuffer buf; CHECK(vkCreateBuffer(dev, &bi, nullptr, &buf));
792 VkMemoryRequirements br; vkGetBufferMemoryRequirements(dev, buf, &br); 843 VkMemoryRequirements br; vkGetBufferMemoryRequirements(dev, buf, &br);
793 VkMemoryAllocateInfo bai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; 844 VkMemoryAllocateInfo bai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
@@ -981,6 +1032,17 @@ int main(int argc, char** argv) {
981 VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd)); 1032 VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd));
982 VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; 1033 VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
983 CHECK(vkBeginCommandBuffer(cmd, &cbi)); 1034 CHECK(vkBeginCommandBuffer(cmd, &cbi));
1035 VkQueryPool gs_query = VK_NULL_HANDLE;
1036 if (count_gs) {
1037 LOADD(vkCreateQueryPool);
1038 LOADD(vkCmdResetQueryPool);
1039 VkQueryPoolCreateInfo info{VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO};
1040 info.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
1041 info.queryCount = 1;
1042 info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT;
1043 CHECK(vkCreateQueryPool(dev, &info, nullptr, &gs_query));
1044 vkCmdResetQueryPool(cmd, gs_query, 0, 1);
1045 }
984 VkClearValue clears[2]{}; 1046 VkClearValue clears[2]{};
985 for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels 1047 for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels
986 if (clip_shifts) { 1048 if (clip_shifts) {
@@ -1059,6 +1121,10 @@ int main(int argc, char** argv) {
1059 } 1121 }
1060 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). 1122 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251).
1061 const char* vertices_env = std::getenv("VKH_VERTICES"); 1123 const char* vertices_env = std::getenv("VKH_VERTICES");
1124 if (count_gs) {
1125 LOADD(vkCmdBeginQuery);
1126 vkCmdBeginQuery(cmd, gs_query, 0, 0);
1127 }
1062 if (draw_mesh_path) { 1128 if (draw_mesh_path) {
1063 VkDeviceSize offset = 0; 1129 VkDeviceSize offset = 0;
1064 vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset); 1130 vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset);
@@ -1077,6 +1143,10 @@ int main(int argc, char** argv) {
1077 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance); 1143 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance);
1078 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance); 1144 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance);
1079 } 1145 }
1146 if (count_gs) {
1147 LOADD(vkCmdEndQuery);
1148 vkCmdEndQuery(cmd, gs_query, 0);
1149 }
1080 vkCmdEndRenderPass(cmd); 1150 vkCmdEndRenderPass(cmd);
1081 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; 1151 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1};
1082 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg); 1152 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg);
@@ -1090,6 +1160,15 @@ int main(int argc, char** argv) {
1090 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; 1160 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd;
1091 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); 1161 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE));
1092 CHECK(vkQueueWaitIdle(q)); 1162 CHECK(vkQueueWaitIdle(q));
1163 if (count_gs) {
1164 LOADD(vkGetQueryPoolResults);
1165 LOADD(vkDestroyQueryPool);
1166 uint64_t primitives = 0;
1167 CHECK(vkGetQueryPoolResults(dev, gs_query, 0, 1, sizeof(primitives), &primitives,
1168 sizeof(primitives), VK_QUERY_RESULT_64_BIT));
1169 vkDestroyQueryPool(dev, gs_query, nullptr);
1170 std::fprintf(stderr, "gs_primitives=%llu\n", static_cast<unsigned long long>(primitives));
1171 }
1093 void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p)); 1172 void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p));
1094 std::ofstream output(argv[3], std::ios::binary); 1173 std::ofstream output(argv[3], std::ios::binary);
1095 output.write(static_cast<const char*>(p), std::streamsize(bi.size)); 1174 output.write(static_cast<const char*>(p), std::streamsize(bi.size));