diff options
| author | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 16:10:41 +0000 |
|---|---|---|
| committer | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 16:10:41 +0000 |
| commit | fc7d1f514d9d73c7366336c1e7adbdf5c689dfa0 (patch) | |
| tree | e46dc95057c9b935804d172c132e5ea4976a373d /runtime/test/vk_harness.cpp | |
| parent | 279898ee6ce736d77e03ca81eeeacde31f4f4f9f (diff) | |
| parent | 8575d36edc479218972497a7bded8651a42856c0 (diff) | |
Merge origin/main into test/877b-shader-programs-validation
Conflicts in vk_store_test.cpp and vk_texture_test.cpp: both new includes (vk_validation.h and spirv_capability.h) are kept.
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 | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp index 53a39b2e0..d20c9d2c1 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 |
| @@ -37,6 +38,7 @@ | |||
| 37 | #include "vk_validation.h" | 38 | #include "vk_validation.h" |
| 38 | #include "../src/descriptor_table.h" | 39 | #include "../src/descriptor_table.h" |
| 39 | #include "../src/gfx10_descriptors.h" | 40 | #include "../src/gfx10_descriptors.h" |
| 41 | #include "spirv_capability.h" | ||
| 40 | 42 | ||
| 41 | #include <cctype> | 43 | #include <cctype> |
| 42 | #include <cstddef> | 44 | #include <cstddef> |
| @@ -481,11 +483,22 @@ static int run(int argc, char** argv) { | |||
| 481 | // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then | 483 | // VKH_GS=<geometry.spv>: insert a geometry stage between the vertex and fragment shaders. VKH_SUBGROUP_SIZE then |
| 482 | // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test. | 484 | // applies to it, unless VKH_GS_HELPER=1 says the GS only feeds the pixel shader under test. |
| 483 | const char* gs_path = std::getenv("VKH_GS"); | 485 | const char* gs_path = std::getenv("VKH_GS"); |
| 486 | const char* count_opt = std::getenv("VKH_GS_PRIMITIVES"); | ||
| 487 | const bool count_gs = count_opt && std::strcmp(count_opt, "1") == 0; | ||
| 488 | if (count_gs && (!gs_path || !*gs_path || mesh || mesh_compute)) { | ||
| 489 | std::fprintf(stderr, "VKH_GS_PRIMITIVES=1 requires a VS/GS/FS draw with VKH_GS\n"); | ||
| 490 | return 1; | ||
| 491 | } | ||
| 484 | if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage | 492 | if (gs_path && !f2q.features.geometryShader) { // MoltenVK: Metal has no geometry stage |
| 485 | std::fprintf(stderr, "unsupported: no geometryShader\n"); | 493 | std::fprintf(stderr, "unsupported: no geometryShader\n"); |
| 486 | return 77; | 494 | return 77; |
| 487 | } | 495 | } |
| 488 | VkPhysicalDeviceFeatures feats{}; | 496 | VkPhysicalDeviceFeatures feats{}; |
| 497 | if (count_gs && !f2q.features.pipelineStatisticsQuery) { | ||
| 498 | std::fprintf(stderr, "unsupported: no pipelineStatisticsQuery\n"); | ||
| 499 | return 77; | ||
| 500 | } | ||
| 501 | feats.pipelineStatisticsQuery = count_gs; | ||
| 489 | if (clip_shifts && !f2q.features.shaderClipDistance) { | 502 | if (clip_shifts && !f2q.features.shaderClipDistance) { |
| 490 | std::fprintf(stderr, "unsupported: shaderClipDistance\n"); | 503 | std::fprintf(stderr, "unsupported: shaderClipDistance\n"); |
| 491 | return 77; | 504 | return 77; |
| @@ -500,9 +513,18 @@ static int run(int argc, char** argv) { | |||
| 500 | } | 513 | } |
| 501 | feats.shaderFloat64 = VK_TRUE; | 514 | feats.shaderFloat64 = VK_TRUE; |
| 502 | } | 515 | } |
| 503 | if (need_heap || mesh_compute) { | 516 | // shaderInt64 only when a stage has 64-bit integers. Heap and --mesh-compute addresses are 64-bit, but rdna2spirv.py |
| 504 | if (!f2q.features.shaderInt64) { std::fprintf(stderr, "unsupported: 64-bit addresses need shaderInt64\n"); return 77; } | 517 | // builds them from 32-bit pairs unless the shader also does 64-bit arithmetic (SHADER-423), so the module decides, |
| 505 | feats.shaderInt64 = VK_TRUE; // heap and --mesh-compute output addresses are 64-bit | 518 | // not VKH_HEAP (TEST-468). |
| 519 | bool needs_int64 = leonida::vk_test::needs_shader_int64(fs_code); | ||
| 520 | for (const char* p : std::initializer_list<const char*>{argv[1], mesh_vs_path, gs_path}) | ||
| 521 | if (p && !needs_int64) needs_int64 = leonida::vk_test::needs_shader_int64(read_spv(p)); | ||
| 522 | if (needs_int64) { | ||
| 523 | if (!f2q.features.shaderInt64) { | ||
| 524 | std::fprintf(stderr, "unsupported: a stage declares Int64 and the device has no shaderInt64\n"); | ||
| 525 | return 77; | ||
| 526 | } | ||
| 527 | feats.shaderInt64 = VK_TRUE; | ||
| 506 | } | 528 | } |
| 507 | if (tex_rgba_path) { | 529 | if (tex_rgba_path) { |
| 508 | if (!f2q.features.shaderSampledImageArrayDynamicIndexing) { | 530 | if (!f2q.features.shaderSampledImageArrayDynamicIndexing) { |
| @@ -1015,6 +1037,17 @@ static int run(int argc, char** argv) { | |||
| 1015 | VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd)); | 1037 | VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(dev, &cai, &cmd)); |
| 1016 | VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; | 1038 | VkCommandBufferBeginInfo cbi{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; |
| 1017 | CHECK(vkBeginCommandBuffer(cmd, &cbi)); | 1039 | CHECK(vkBeginCommandBuffer(cmd, &cbi)); |
| 1040 | VkQueryPool gs_query = VK_NULL_HANDLE; | ||
| 1041 | if (count_gs) { | ||
| 1042 | LOADD(vkCreateQueryPool); | ||
| 1043 | LOADD(vkCmdResetQueryPool); | ||
| 1044 | VkQueryPoolCreateInfo info{VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO}; | ||
| 1045 | info.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS; | ||
| 1046 | info.queryCount = 1; | ||
| 1047 | info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT; | ||
| 1048 | CHECK(vkCreateQueryPool(dev, &info, nullptr, &gs_query)); | ||
| 1049 | vkCmdResetQueryPool(cmd, gs_query, 0, 1); | ||
| 1050 | } | ||
| 1018 | VkClearValue clears[2]{}; | 1051 | VkClearValue clears[2]{}; |
| 1019 | for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels | 1052 | for (float& c : clears[0].color.float32) c = -1; // marks untouched pixels |
| 1020 | if (clip_shifts) { | 1053 | if (clip_shifts) { |
| @@ -1093,6 +1126,10 @@ static int run(int argc, char** argv) { | |||
| 1093 | } | 1126 | } |
| 1094 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). | 1127 | // VKH_VERTICES=<n>: draw n vertices instead of one triangle, so a vertex shader fills whole waves (TEST-251). |
| 1095 | const char* vertices_env = std::getenv("VKH_VERTICES"); | 1128 | const char* vertices_env = std::getenv("VKH_VERTICES"); |
| 1129 | if (count_gs) { | ||
| 1130 | LOADD(vkCmdBeginQuery); | ||
| 1131 | vkCmdBeginQuery(cmd, gs_query, 0, 0); | ||
| 1132 | } | ||
| 1096 | if (draw_mesh_path) { | 1133 | if (draw_mesh_path) { |
| 1097 | VkDeviceSize offset = 0; | 1134 | VkDeviceSize offset = 0; |
| 1098 | vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset); | 1135 | vkCmdBindVertexBuffers(cmd, 0, 1, &vbo, &offset); |
| @@ -1111,6 +1148,10 @@ static int run(int argc, char** argv) { | |||
| 1111 | if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance); | 1148 | if (const char* d = std::getenv("VKH_DRAW")) std::sscanf(d, "%u,%u", &first_vertex, &first_instance); |
| 1112 | vkCmdDraw(cmd, 3, 1, first_vertex, first_instance); | 1149 | vkCmdDraw(cmd, 3, 1, first_vertex, first_instance); |
| 1113 | } | 1150 | } |
| 1151 | if (count_gs) { | ||
| 1152 | LOADD(vkCmdEndQuery); | ||
| 1153 | vkCmdEndQuery(cmd, gs_query, 0); | ||
| 1154 | } | ||
| 1114 | vkCmdEndRenderPass(cmd); | 1155 | vkCmdEndRenderPass(cmd); |
| 1115 | VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; | 1156 | VkBufferImageCopy reg{}; reg.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; reg.imageExtent = {W, H, 1}; |
| 1116 | vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, ®); | 1157 | vkCmdCopyImageToBuffer(cmd, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buf, 1, ®); |
| @@ -1124,6 +1165,15 @@ static int run(int argc, char** argv) { | |||
| 1124 | VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; | 1165 | VkSubmitInfo si{VK_STRUCTURE_TYPE_SUBMIT_INFO}; si.commandBufferCount = 1; si.pCommandBuffers = &cmd; |
| 1125 | CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); | 1166 | CHECK(vkQueueSubmit(q, 1, &si, VK_NULL_HANDLE)); |
| 1126 | CHECK(vkQueueWaitIdle(q)); | 1167 | CHECK(vkQueueWaitIdle(q)); |
| 1168 | if (count_gs) { | ||
| 1169 | LOADD(vkGetQueryPoolResults); | ||
| 1170 | LOADD(vkDestroyQueryPool); | ||
| 1171 | uint64_t primitives = 0; | ||
| 1172 | CHECK(vkGetQueryPoolResults(dev, gs_query, 0, 1, sizeof(primitives), &primitives, | ||
| 1173 | sizeof(primitives), VK_QUERY_RESULT_64_BIT)); | ||
| 1174 | vkDestroyQueryPool(dev, gs_query, nullptr); | ||
| 1175 | std::fprintf(stderr, "gs_primitives=%llu\n", static_cast<unsigned long long>(primitives)); | ||
| 1176 | } | ||
| 1127 | void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p)); | 1177 | void* p; CHECK(vkMapMemory(dev, bmem, 0, bi.size, 0, &p)); |
| 1128 | std::ofstream output(argv[3], std::ios::binary); | 1178 | std::ofstream output(argv[3], std::ios::binary); |
| 1129 | output.write(static_cast<const char*>(p), std::streamsize(bi.size)); | 1179 | output.write(static_cast<const char*>(p), std::streamsize(bi.size)); |