diff options
| author | crastinator <qvaras@proton.me> | 2026-11-21 23:51:16 +0200 |
|---|---|---|
| committer | crastinator <qvaras@proton.me> | 2026-11-21 23:51:16 +0200 |
| commit | 58f3fe8f6b577a975423c46e4b8302d36c7111a9 (patch) | |
| tree | ff41601181156c9cb1ec1c7ec79d804ab85f2ad4 /runtime/test/vk_harness.cpp | |
| parent | 4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff) | |
GPU tests: run ps_vcc_x2 on the GPU with a seeded V# and heap in vk_harness (TEST-19)
ps_vcc_x2 reads two dwords through the V# in s[0:3], but vk_harness pushed zeros and bound no memory, so on the
GPU it read address 0 and lost the device; run_gpu_tests.py skipped it and check.py left it out. vk_harness now
takes VKH_SGPRS (user SGPRs) and VKH_HEAP (addr=word seeds in a 64 KiB device-address heap, passed as the heap
base, with bufferDeviceAddress and shaderInt64 enabled only then). Both runners give ps_vcc_x2 the V# and words
tests/semantic uses and expect 0x11223344 0x55667788 0 0.
Diffstat (limited to 'runtime/test/vk_harness.cpp')
| -rw-r--r-- | runtime/test/vk_harness.cpp | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/runtime/test/vk_harness.cpp b/runtime/test/vk_harness.cpp index 1c29cce86..9b9e065bd 100644 --- a/runtime/test/vk_harness.cpp +++ b/runtime/test/vk_harness.cpp | |||
| @@ -3,6 +3,11 @@ | |||
| 3 | // | 3 | // |
| 4 | // vk_harness <vs.spv> <fs.spv> <out.raw> [width height] | 4 | // vk_harness <vs.spv> <fs.spv> <out.raw> [width height] |
| 5 | // | 5 | // |
| 6 | // Push constants follow the contract in docs/design.md: s0..s31, then the heap base lo/hi. They are zero unless | ||
| 7 | // VKH_SGPRS=w0,w1,... sets s0, s1, ... (decimal or 0x hex) | ||
| 8 | // VKH_HEAP=addr=word,... allocates a zeroed 64 KiB heap (Xbox VA 0 = its device address), writes each word at | ||
| 9 | // its address and passes the heap base, so a V# in VKH_SGPRS can point into it. | ||
| 10 | // | ||
| 6 | #define VK_NO_PROTOTYPES | 11 | #define VK_NO_PROTOTYPES |
| 7 | #include "vulkan_loader.h" | 12 | #include "vulkan_loader.h" |
| 8 | 13 | ||
| @@ -10,6 +15,7 @@ | |||
| 10 | #include <cstdlib> | 15 | #include <cstdlib> |
| 11 | #include <cstring> | 16 | #include <cstring> |
| 12 | #include <fstream> | 17 | #include <fstream> |
| 18 | #include <utility> | ||
| 13 | #include <vector> | 19 | #include <vector> |
| 14 | 20 | ||
| 15 | static PFN_vkGetInstanceProcAddr gipa; | 21 | static PFN_vkGetInstanceProcAddr gipa; |
| @@ -31,12 +37,51 @@ static std::vector<uint32_t> read_spv(const char* path) { | |||
| 31 | return w; | 37 | return w; |
| 32 | } | 38 | } |
| 33 | 39 | ||
| 40 | static bool parse_u32(const char*& s, uint32_t& v) { | ||
| 41 | char* end; | ||
| 42 | unsigned long long x = std::strtoull(s, &end, 0); | ||
| 43 | if (end == s || x > 0xFFFFFFFFull) return false; | ||
| 44 | v = uint32_t(x); s = end; | ||
| 45 | return true; | ||
| 46 | } | ||
| 47 | |||
| 48 | static bool parse_sgprs(const char* s, uint32_t* sgprs) { | ||
| 49 | for (uint32_t i = 0; *s; i++) { | ||
| 50 | if (i == 32 || !parse_u32(s, sgprs[i]) || (*s && *s++ != ',')) return false; | ||
| 51 | } | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | |||
| 55 | static bool parse_heap(const char* s, std::vector<std::pair<uint32_t, uint32_t>>& words, uint32_t heap_bytes) { | ||
| 56 | while (*s) { | ||
| 57 | uint32_t addr, word; | ||
| 58 | if (!parse_u32(s, addr) || *s++ != '=' || !parse_u32(s, word) || (*s && *s++ != ',')) return false; | ||
| 59 | if (addr % 4 || addr > heap_bytes - 4) return false; | ||
| 60 | words.emplace_back(addr, word); | ||
| 61 | } | ||
| 62 | return true; | ||
| 63 | } | ||
| 64 | |||
| 34 | int main(int argc, char** argv) { | 65 | int main(int argc, char** argv) { |
| 35 | if (argc < 4) { | 66 | if (argc < 4) { |
| 36 | std::fprintf(stderr, "usage: vk_harness vs.spv fs.spv out.raw [w h]\n"); | 67 | std::fprintf(stderr, "usage: vk_harness vs.spv fs.spv out.raw [w h]\n"); |
| 37 | return 2; | 68 | return 2; |
| 38 | } | 69 | } |
| 39 | uint32_t W = argc > 5 ? atoi(argv[4]) : 64, H = argc > 5 ? atoi(argv[5]) : 64; | 70 | uint32_t W = argc > 5 ? atoi(argv[4]) : 64, H = argc > 5 ? atoi(argv[5]) : 64; |
| 71 | uint32_t pc[36] = {}; | ||
| 72 | const char* sgprs_env = std::getenv("VKH_SGPRS"); | ||
| 73 | if (sgprs_env && !parse_sgprs(sgprs_env, pc)) { | ||
| 74 | std::fprintf(stderr, "VKH_SGPRS: expected up to 32 comma-separated words, got \"%s\"\n", sgprs_env); | ||
| 75 | return 2; | ||
| 76 | } | ||
| 77 | const uint32_t heap_bytes = 64 * 1024; | ||
| 78 | const char* heap_env = std::getenv("VKH_HEAP"); | ||
| 79 | std::vector<std::pair<uint32_t, uint32_t>> heap_words; | ||
| 80 | if (heap_env && !parse_heap(heap_env, heap_words, heap_bytes)) { | ||
| 81 | std::fprintf(stderr, "VKH_HEAP: expected addr=word pairs, 4-byte aligned below 0x%x, got \"%s\"\n", | ||
| 82 | heap_bytes, heap_env); | ||
| 83 | return 2; | ||
| 84 | } | ||
| 40 | gipa = load_vulkan(); | 85 | gipa = load_vulkan(); |
| 41 | if (!gipa) return 1; | 86 | if (!gipa) return 1; |
| 42 | VkInstance inst = VK_NULL_HANDLE; | 87 | VkInstance inst = VK_NULL_HANDLE; |
| @@ -116,7 +161,9 @@ int main(int argc, char** argv) { | |||
| 116 | m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; | 161 | m8.maintenance8 = VK_TRUE; m8.pNext = chain; chain = &m8; |
| 117 | } | 162 | } |
| 118 | #endif | 163 | #endif |
| 164 | VkPhysicalDeviceVulkan12Features f12q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | ||
| 119 | VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | 165 | VkPhysicalDeviceVulkan13Features f13q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; |
| 166 | f13q.pNext = &f12q; | ||
| 120 | VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; | 167 | VkPhysicalDeviceFeatures2 f2q{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; |
| 121 | f2q.pNext = &f13q; | 168 | f2q.pNext = &f13q; |
| 122 | vkGetPhysicalDeviceFeatures2(pd, &f2q); | 169 | vkGetPhysicalDeviceFeatures2(pd, &f2q); |
| @@ -126,6 +173,13 @@ int main(int argc, char** argv) { | |||
| 126 | f13.pNext = chain; | 173 | f13.pNext = chain; |
| 127 | chain = &f13; | 174 | chain = &f13; |
| 128 | } | 175 | } |
| 176 | VkPhysicalDeviceVulkan12Features f12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; | ||
| 177 | if (heap_env) { | ||
| 178 | if (!f12q.bufferDeviceAddress) { std::fprintf(stderr, "VKH_HEAP: no bufferDeviceAddress\n"); return 1; } | ||
| 179 | f12.bufferDeviceAddress = VK_TRUE; | ||
| 180 | f12.pNext = chain; | ||
| 181 | chain = &f12; | ||
| 182 | } | ||
| 129 | for (auto e : enable) std::fprintf(stderr, "enabled %s\n", e); | 183 | for (auto e : enable) std::fprintf(stderr, "enabled %s\n", e); |
| 130 | VkDeviceCreateInfo dci{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO}; | 184 | VkDeviceCreateInfo dci{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO}; |
| 131 | dci.queueCreateInfoCount = 1; dci.pQueueCreateInfos = &qci; | 185 | dci.queueCreateInfoCount = 1; dci.pQueueCreateInfos = &qci; |
| @@ -137,6 +191,10 @@ int main(int argc, char** argv) { | |||
| 137 | feats.geometryShader = gs_path ? VK_TRUE : VK_FALSE; | 191 | feats.geometryShader = gs_path ? VK_TRUE : VK_FALSE; |
| 138 | feats.shaderClipDistance = f2q.features.shaderClipDistance; | 192 | feats.shaderClipDistance = f2q.features.shaderClipDistance; |
| 139 | feats.shaderCullDistance = f2q.features.shaderCullDistance; | 193 | feats.shaderCullDistance = f2q.features.shaderCullDistance; |
| 194 | if (heap_env) { | ||
| 195 | if (!f2q.features.shaderInt64) { std::fprintf(stderr, "VKH_HEAP: no shaderInt64\n"); return 1; } | ||
| 196 | feats.shaderInt64 = VK_TRUE; // heap addresses are 64-bit | ||
| 197 | } | ||
| 140 | dci.pEnabledFeatures = &feats; | 198 | dci.pEnabledFeatures = &feats; |
| 141 | VkDevice dev; | 199 | VkDevice dev; |
| 142 | CHECK(vkCreateDevice(pd, &dci, nullptr, &dev)); | 200 | CHECK(vkCreateDevice(pd, &dci, nullptr, &dev)); |
| @@ -232,7 +290,7 @@ int main(int argc, char** argv) { | |||
| 232 | VkPipelineColorBlendAttachmentState cba{}; cba.colorWriteMask = 0xF; | 290 | VkPipelineColorBlendAttachmentState cba{}; cba.colorWriteMask = 0xF; |
| 233 | VkPipelineColorBlendStateCreateInfo cb{VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO}; | 291 | VkPipelineColorBlendStateCreateInfo cb{VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO}; |
| 234 | cb.attachmentCount = 1; cb.pAttachments = &cba; | 292 | cb.attachmentCount = 1; cb.pAttachments = &cba; |
| 235 | // Translated shaders declare a 136-byte push-constant block (user SGPRs + heap base); zeros here. | 293 | // Translated shaders declare a 136-byte push-constant block (user SGPRs + heap base); see VKH_SGPRS / VKH_HEAP. |
| 236 | const VkShaderStageFlags pcs = (mesh ? VK_SHADER_STAGE_MESH_BIT_EXT : VK_SHADER_STAGE_VERTEX_BIT) | | 294 | const VkShaderStageFlags pcs = (mesh ? VK_SHADER_STAGE_MESH_BIT_EXT : VK_SHADER_STAGE_VERTEX_BIT) | |
| 237 | VK_SHADER_STAGE_FRAGMENT_BIT | (gs_path ? VK_SHADER_STAGE_GEOMETRY_BIT : 0); | 295 | VK_SHADER_STAGE_FRAGMENT_BIT | (gs_path ? VK_SHADER_STAGE_GEOMETRY_BIT : 0); |
| 238 | VkPushConstantRange pcr{pcs, 0, 144}; | 296 | VkPushConstantRange pcr{pcs, 0, 144}; |
| @@ -254,6 +312,28 @@ int main(int argc, char** argv) { | |||
| 254 | bai.memoryTypeIndex = memtype(br.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); | 312 | bai.memoryTypeIndex = memtype(br.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 255 | VkDeviceMemory bmem; CHECK(vkAllocateMemory(dev, &bai, nullptr, &bmem)); | 313 | VkDeviceMemory bmem; CHECK(vkAllocateMemory(dev, &bai, nullptr, &bmem)); |
| 256 | CHECK(vkBindBufferMemory(dev, buf, bmem, 0)); | 314 | CHECK(vkBindBufferMemory(dev, buf, bmem, 0)); |
| 315 | if (heap_env) { | ||
| 316 | LOADD(vkGetBufferDeviceAddress); | ||
| 317 | VkBufferCreateInfo hbi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; | ||
| 318 | hbi.size = heap_bytes; | ||
| 319 | hbi.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT; | ||
| 320 | VkBuffer heap; CHECK(vkCreateBuffer(dev, &hbi, nullptr, &heap)); | ||
| 321 | VkMemoryRequirements hr; vkGetBufferMemoryRequirements(dev, heap, &hr); | ||
| 322 | VkMemoryAllocateFlagsInfo haf{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO}; | ||
| 323 | haf.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT; | ||
| 324 | VkMemoryAllocateInfo hai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; | ||
| 325 | hai.pNext = &haf; hai.allocationSize = hr.size; | ||
| 326 | hai.memoryTypeIndex = memtype(hr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); | ||
| 327 | VkDeviceMemory hmem; CHECK(vkAllocateMemory(dev, &hai, nullptr, &hmem)); | ||
| 328 | CHECK(vkBindBufferMemory(dev, heap, hmem, 0)); | ||
| 329 | void* hp; CHECK(vkMapMemory(dev, hmem, 0, heap_bytes, 0, &hp)); | ||
| 330 | std::memset(hp, 0, heap_bytes); | ||
| 331 | for (auto [addr, word] : heap_words) std::memcpy(static_cast<char*>(hp) + addr, &word, 4); | ||
| 332 | VkBufferDeviceAddressInfo hda{VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; | ||
| 333 | hda.buffer = heap; | ||
| 334 | const uint64_t base = vkGetBufferDeviceAddress(dev, &hda); | ||
| 335 | pc[32] = uint32_t(base); pc[33] = uint32_t(base >> 32); | ||
| 336 | } | ||
| 257 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; cpi.queueFamilyIndex = qi; | 337 | VkCommandPoolCreateInfo cpi{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; cpi.queueFamilyIndex = qi; |
| 258 | VkCommandPool pool; CHECK(vkCreateCommandPool(dev, &cpi, nullptr, &pool)); | 338 | VkCommandPool pool; CHECK(vkCreateCommandPool(dev, &cpi, nullptr, &pool)); |
| 259 | VkCommandBufferAllocateInfo cai{VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO}; | 339 | VkCommandBufferAllocateInfo cai{VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO}; |
| @@ -267,9 +347,8 @@ int main(int argc, char** argv) { | |||
| 267 | rbi.renderPass = rp; rbi.framebuffer = fb; rbi.renderArea = sc; rbi.clearValueCount = 1; rbi.pClearValues = &clear; | 347 | rbi.renderPass = rp; rbi.framebuffer = fb; rbi.renderArea = sc; rbi.clearValueCount = 1; rbi.pClearValues = &clear; |
| 268 | vkCmdBeginRenderPass(cmd, &rbi, VK_SUBPASS_CONTENTS_INLINE); | 348 | vkCmdBeginRenderPass(cmd, &rbi, VK_SUBPASS_CONTENTS_INLINE); |
| 269 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); | 349 | vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe); |
| 270 | uint32_t zeros[36] = {}; | ||
| 271 | reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants"))( | 350 | reinterpret_cast<PFN_vkCmdPushConstants>(vkGetDeviceProcAddr(dev, "vkCmdPushConstants"))( |
| 272 | cmd, pl, pcs, 0, sizeof(zeros), zeros); | 351 | cmd, pl, pcs, 0, sizeof(pc), pc); |
| 273 | if (mesh) | 352 | if (mesh) |
| 274 | reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, 1, 1, 1); | 353 | reinterpret_cast<PFN_vkCmdDrawMeshTasksEXT>(vkGetDeviceProcAddr(dev, "vkCmdDrawMeshTasksEXT"))(cmd, 1, 1, 1); |
| 275 | else | 354 | else |