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:
authorKacper Serewiś <kacper@serewis.nl>2026-11-23 15:21:47 +0100
committerGitHub <noreply@github.com>2026-11-23 08:21:47 -0600
commit57aafb761bc229b87334068b2f98b231c8d0ba75 (patch)
tree1f577373fbce3a612dfd703e5dde043a46eac158 /runtime/test/vk_harness.cpp
parent05961f0eeb24486ce25ddc7dfb453ca87db2be5f (diff)
Measure emitted geometry primitives in synthetic Vulkan draws (#6316)
Squash-merged after diff review of PR #6316 - TEST-GS-PRIMITIVE-READBACK: count emitted primitives in synthetic geometry draws
Diffstat (limited to 'runtime/test/vk_harness.cpp')
-rw-r--r--runtime/test/vk_harness.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp
index fc1f352b8..836b198e6 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
@@ -476,11 +477,22 @@ int main(int argc, char** argv) {
476 // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then 477 // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then
477 // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test. 478 // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test.
478 const char* gs_path = std::getenv("VKH_GS"); 479 const char* gs_path = std::getenv("VKH_GS");
480 const char* count_opt = std::getenv("VKH_GS_PRIMITIVES");
481 const bool count_gs = count_opt && std::strcmp(count_opt, "1") == 0;
482 if (count_gs && (!gs_path || !*gs_path || mesh || mesh_compute)) {
483 std::fprintf(stderr, "VKH_GS_PRIMITIVES=1 requires a VS/GS/FS draw with VKH_GS\n");
484 return 1;
485 }
479 if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage 486 if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage
480 std::fprintf(stderr, "unsupported: no geometryShader\n"); 487 std::fprintf(stderr, "unsupported: no geometryShader\n");
481 return 77; 488 return 77;
482 } 489 }
483 VkPhysicalDeviceFeatures feats{}; 490 VkPhysicalDeviceFeatures feats{};
491 if (count_gs && !f2q.features.pipelineStatisticsQuery) {
492 std::fprintf(stderr, "unsupported: no pipelineStatisticsQuery\n");
493 return 77;
494 }
495 feats.pipelineStatisticsQuery = count_gs;
484 if (clip_shifts && !f2q.features.shaderClipDistance) { 496 if (clip_shifts && !f2q.features.shaderClipDistance) {
485 std::fprintf(stderr, "unsupported: shaderClipDistance\n"); 497 std::fprintf(stderr, "unsupported: shaderClipDistance\n");
486 return 77; 498 return 77;
@@ -1010,6 +1022,17 @@ int main(int argc, char** argv) {
1010 VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd)); 1022 VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd));
1011 VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; 1023 VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
1012 CHECK(vkBeginCommandBuffer(cmd, &cbi)); 1024 CHECK(vkBeginCommandBuffer(cmd, &cbi));
1025 VkQueryPool gs_query = VK_NULL_HANDLE;
1026 if (count_gs) {
1027 LOADD(vkCreateQueryPool);
1028 LOADD(vkCmdResetQueryPool);
1029 VkQueryPoolCreateInfo info{VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO};
1030 info.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
1031 info.queryCount = 1;
1032 info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT;
1033 CHECK(vkCreateQueryPool(dev, &info, nullptr, &gs_query));
1034 vkCmdResetQueryPool(cmd, gs_query, 0, 1);
1035 }
1013 VkClearValue clears[2]{}; 1036 VkClearValue clears[2]{};
1014 for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels 1037 for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels
1015 if (clip_shifts) { 1038 if (clip_shifts) {
@@ -1088,6 +1111,10 @@ int main(int argc, char** argv) {
1088 } 1111 }
1089 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). 1112 // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251).
1090 const char* vertices_env = std::getenv("VKH_VERTICES"); 1113 const char* vertices_env = std::getenv("VKH_VERTICES");
1114 if (count_gs) {
1115 LOADD(vkCmdBeginQuery);
1116 vkCmdBeginQuery(cmd, gs_query, 0, 0);
1117 }
1091 if (draw_mesh_path) { 1118 if (draw_mesh_path) {
1092 VkDeviceSize offset = 0; 1119 VkDeviceSize offset = 0;
1093 vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset); 1120 vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset);
@@ -1106,6 +1133,10 @@ int main(int argc, char** argv) {
1106 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance); 1133 if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance);
1107 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance); 1134 vkCmdDraw(cmd, 3, 1, first_vertex, first_instance);
1108 } 1135 }
1136 if (count_gs) {
1137 LOADD(vkCmdEndQuery);
1138 vkCmdEndQuery(cmd, gs_query, 0);
1139 }
1109 vkCmdEndRenderPass(cmd); 1140 vkCmdEndRenderPass(cmd);
1110 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; 1141 VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1};
1111 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg); 1142 vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, &reg);
@@ -1119,6 +1150,15 @@ int main(int argc, char** argv) {
1119 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; 1150 VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd;
1120 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); 1151 CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE));
1121 CHECK(vkQueueWaitIdle(q)); 1152 CHECK(vkQueueWaitIdle(q));
1153 if (count_gs) {
1154 LOADD(vkGetQueryPoolResults);
1155 LOADD(vkDestroyQueryPool);
1156 uint64_t primitives = 0;
1157 CHECK(vkGetQueryPoolResults(dev, gs_query, 0, 1, sizeof(primitives), &primitives,
1158 sizeof(primitives), VK_QUERY_RESULT_64_BIT));
1159 vkDestroyQueryPool(dev, gs_query, nullptr);
1160 std::fprintf(stderr, "gs_primitives=%llu\n", static_cast<unsigned long long>(primitives));
1161 }
1122 void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p)); 1162 void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p));
1123 std::ofstream output(argv[3], std::ios::binary); 1163 std::ofstream output(argv[3], std::ios::binary);
1124 output.write(static_cast<const char*>(p), std::streamsize(bi.size)); 1164 output.write(static_cast<const char*>(p), std::streamsize(bi.size));