diff options
| author | 给伊莉雅补魔 <98532177+geiyiliyabumo@users.noreply.github.com> | 2026-11-24 06:09:24 +0800 |
|---|---|---|
| committer | 给伊莉雅补魔 <98532177+geiyiliyabumo@users.noreply.github.com> | 2026-11-24 06:09:24 +0800 |
| commit | de17f980aeebbb89d8e8dbe377f4b376d04998be (patch) | |
| tree | 7caf33f282fa4bac9917541c2cbff8f0b08e563f /runtime/test/vk_bindless_test.cpp | |
| parent | 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff) | |
vk_bindless_test: validate SPIR-V framing via read_spirv_words before Vulkan init
Diffstat (limited to 'runtime/test/vk_bindless_test.cpp')
| -rw-r--r-- | runtime/test/vk_bindless_test.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/runtime/test/vk_bindless_test.cpp b/runtime/test/vk_bindless_test.cpp index 1b3a609ef..d6276d8ad 100644 --- a/runtime/test/vk_bindless_test.cpp +++ b/runtime/test/vk_bindless_test.cpp | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include "vk_shader_fma.h" | 24 | #include "vk_shader_fma.h" |
| 25 | #include "vk_pc_tail.h" | 25 | #include "vk_pc_tail.h" |
| 26 | #include "spirv_capability.h" | 26 | #include "spirv_capability.h" |
| 27 | #include "../src/spirv_words.h" | ||
| 27 | #include "../src/vulkan_bindless.h" | 28 | #include "../src/vulkan_bindless.h" |
| 28 | 29 | ||
| 29 | #include <algorithm> | 30 | #include <algorithm> |
| @@ -71,11 +72,9 @@ VKAPI_ATTR VkBool32 VKAPI_CALL on_message(VkDebugUtilsMessageSeverityFlagBitsEXT | |||
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | std::vector<std::uint32_t> read_spv(const char* path) { | 74 | std::vector<std::uint32_t> read_spv(const char* path) { |
| 74 | std::ifstream f(path, std::ios::binary); | 75 | std::ifstream f(path, std::ios::binary | std::ios::ate); |
| 75 | std::vector<char> bytes((std::istreambuf_iterator<char>(f)), {}); | 76 | if (!f) return {}; |
| 76 | std::vector<std::uint32_t> words(bytes.size() / 4); | 77 | return leonida::read_spirv_words(f, f.tellg()); |
| 77 | std::memcpy(words.data(), bytes.data(), words.size() * 4); | ||
| 78 | return words; | ||
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | // Expected RGBA values in this test are finite. Report the worst channel error per pixel. | 80 | // Expected RGBA values in this test are finite. Report the worst channel error per pixel. |
| @@ -118,6 +117,13 @@ int main(int argc, char** argv) { | |||
| 118 | pixel[c] = std::numeric_limits<float>::quiet_NaN(); | 117 | pixel[c] = std::numeric_limits<float>::quiet_NaN(); |
| 119 | EXPECT(std::isinf(pixel_error(pixel, black))); | 118 | EXPECT(std::isinf(pixel_error(pixel, black))); |
| 120 | } | 119 | } |
| 120 | const std::vector<std::uint32_t> shader_code[] = {read_spv(argv[1]), read_spv(argv[2])}; | ||
| 121 | for (int stage = 0; stage < 2; ++stage) { | ||
| 122 | if (shader_code[stage].empty()) { | ||
| 123 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); | ||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | } | ||
| 121 | constexpr std::uint32_t W = 64, H = 64, TW = 8; | 127 | constexpr std::uint32_t W = 64, H = 64, TW = 8; |
| 122 | constexpr std::uint32_t table_va = 256; // console VA of the descriptor table: T# at +0, S# at +32 | 128 | constexpr std::uint32_t table_va = 256; // console VA of the descriptor table: T# at +0, S# at +32 |
| 123 | // Any 8 dwords as the lookup key, except FORMAT (word 1 [28:20]): the translator picks the float, uint or sint | 129 | // Any 8 dwords as the lookup key, except FORMAT (word 1 [28:20]): the translator picks the float, uint or sint |
| @@ -251,14 +257,9 @@ int main(int argc, char** argv) { | |||
| 251 | VkPhysicalDeviceFeatures2 enable{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &enable12}; | 257 | VkPhysicalDeviceFeatures2 enable{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &enable12}; |
| 252 | enable.features.shaderInt64 = int64 ? VK_TRUE : VK_FALSE; | 258 | enable.features.shaderInt64 = int64 ? VK_TRUE : VK_FALSE; |
| 253 | enable.features.shaderSampledImageArrayDynamicIndexing = VK_TRUE; | 259 | enable.features.shaderSampledImageArrayDynamicIndexing = VK_TRUE; |
| 254 | const std::vector<std::uint32_t> shader_code[] = {read_spv(argv[1]), read_spv(argv[2])}; | ||
| 255 | bool dynamic_storage = false; | 260 | bool dynamic_storage = false; |
| 256 | for (int stage = 0; stage < 2; ++stage) { | 261 | for (int stage = 0; stage < 2; ++stage) { |
| 257 | const auto& code = shader_code[stage]; | 262 | const auto& code = shader_code[stage]; |
| 258 | if (code.empty()) { | ||
| 259 | std::fprintf(stderr, "cannot read %s\n", argv[1 + stage]); | ||
| 260 | return 1; | ||
| 261 | } | ||
| 262 | dynamic_storage = dynamic_storage || leonida::vk_test::spirv_declares_capability( | 263 | dynamic_storage = dynamic_storage || leonida::vk_test::spirv_declares_capability( |
| 263 | code.data(), code.size() * sizeof(code[0]), leonida::vk_test::spv_storage_image_array_dynamic_indexing); | 264 | code.data(), code.size() * sizeof(code[0]), leonida::vk_test::spv_storage_image_array_dynamic_indexing); |
| 264 | } | 265 | } |