|
| 1 | +// compat.vulkan-validation-layers — behavioral test, no GPU needed. |
| 2 | +// |
| 3 | +// Two questions, both answered by the loader before any driver is involved: |
| 4 | +// |
| 5 | +// 1. Is VK_LAYER_KHRONOS_validation enumerated? That is the manifest being |
| 6 | +// found -- the subos share reached XDG_DATA_DIRS and the manifest reached |
| 7 | +// share/vulkan/explicit_layer.d, and mcpp carried the variable into this |
| 8 | +// process. |
| 9 | +// 2. Can the layer's library be loaded? vkEnumerateInstanceExtensionProperties |
| 10 | +// with the layer's name makes the loader dlopen the library and call into |
| 11 | +// it. That is the very step that fails against a host copy of the layer |
| 12 | +// (bare soname, no /usr/lib on this loader's path), and it is what the |
| 13 | +// absolute library_path plus a self-contained .so make succeed. |
| 14 | +// |
| 15 | +// No vkCreateInstance: on a driverless runner that is VK_ERROR_INCOMPATIBLE_DRIVER |
| 16 | +// and says nothing about the layer. |
| 17 | +#if defined(HAVE_VULKAN_LOADER) |
| 18 | +#include <vulkan/vulkan.h> |
| 19 | +#endif |
| 20 | +import std; |
| 21 | + |
| 22 | +#if !defined(HAVE_VULKAN_LOADER) |
| 23 | +int main() { |
| 24 | + std::println("compat.vulkan-validation-layers: skipped (linux only)"); |
| 25 | + return 0; |
| 26 | +} |
| 27 | +#else |
| 28 | +int main() { |
| 29 | + constexpr const char* layer = "VK_LAYER_KHRONOS_validation"; |
| 30 | + |
| 31 | + std::uint32_t count = 0; |
| 32 | + if (vkEnumerateInstanceLayerProperties(&count, nullptr) != VK_SUCCESS) { |
| 33 | + std::println("vkEnumerateInstanceLayerProperties failed"); |
| 34 | + return 1; |
| 35 | + } |
| 36 | + std::vector<VkLayerProperties> layers(count); |
| 37 | + if (count && vkEnumerateInstanceLayerProperties(&count, layers.data()) != VK_SUCCESS) { |
| 38 | + std::println("vkEnumerateInstanceLayerProperties (fill) failed"); |
| 39 | + return 1; |
| 40 | + } |
| 41 | + bool found = false; |
| 42 | + for (const auto& l : layers) { |
| 43 | + std::println("layer: {} ({})", l.layerName, l.description); |
| 44 | + if (std::string_view{l.layerName} == layer) found = true; |
| 45 | + } |
| 46 | + if (!found) { |
| 47 | + std::println("{} is not enumerated: the manifest did not reach the loader", layer); |
| 48 | + return 1; |
| 49 | + } |
| 50 | + |
| 51 | + // Loads the library. A stale or unreachable library_path fails here with |
| 52 | + // VK_ERROR_LAYER_NOT_PRESENT; a library that cannot resolve its own |
| 53 | + // dependencies fails the same way. |
| 54 | + std::uint32_t ext_count = 0; |
| 55 | + const auto rst = vkEnumerateInstanceExtensionProperties(layer, &ext_count, nullptr); |
| 56 | + if (rst != VK_SUCCESS) { |
| 57 | + std::println("vkEnumerateInstanceExtensionProperties({}) = {}: the layer library did not load", layer, static_cast<int>(rst)); |
| 58 | + return 1; |
| 59 | + } |
| 60 | + std::vector<VkExtensionProperties> exts(ext_count); |
| 61 | + if (ext_count && vkEnumerateInstanceExtensionProperties(layer, &ext_count, exts.data()) != VK_SUCCESS) { |
| 62 | + std::println("vkEnumerateInstanceExtensionProperties (fill) failed"); |
| 63 | + return 1; |
| 64 | + } |
| 65 | + bool debug_utils = false; |
| 66 | + for (const auto& e : exts) { |
| 67 | + std::println(" {} v{}", e.extensionName, e.specVersion); |
| 68 | + if (std::string_view{e.extensionName} == "VK_EXT_debug_utils") debug_utils = true; |
| 69 | + } |
| 70 | + // The validation layer implements VK_EXT_debug_utils, which is how a |
| 71 | + // program receives its messages; a layer that loaded but lists nothing |
| 72 | + // is not the one asked for. |
| 73 | + if (!debug_utils) { |
| 74 | + std::println("{} loaded but does not provide VK_EXT_debug_utils", layer); |
| 75 | + return 1; |
| 76 | + } |
| 77 | + std::println("ok: {} enumerated and loaded", layer); |
| 78 | + return 0; |
| 79 | +} |
| 80 | +#endif |
0 commit comments