From a535700b830b570146b7aa4f82c01373330629cd Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Tue, 16 Nov 2021 18:56:13 -0700 Subject: [PATCH] vulkaninfo: Simplify WSI macro defines Create a single macro define which is used everywhere rather than have 5 different places with the same giant macro if block. --- vulkaninfo/vulkaninfo.cpp | 20 +++++++++++++++----- vulkaninfo/vulkaninfo.h | 13 +++++++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/vulkaninfo/vulkaninfo.cpp b/vulkaninfo/vulkaninfo.cpp index 35fc62a..a2e8e77 100644 --- a/vulkaninfo/vulkaninfo.cpp +++ b/vulkaninfo/vulkaninfo.cpp @@ -189,6 +189,7 @@ bool operator==(AppSurface const &a, AppSurface const &b) { a.surface_capabilities2_khr == b.surface_capabilities2_khr && a.surface_capabilities2_ext == b.surface_capabilities2_ext; } +#if defined(VULKANINFO_WSI_ENABLED) void DumpPresentableSurfaces(Printer &p, AppInstance &inst, const std::vector> &gpus, const std::vector> &surfaces) { // Don't print anything if no surfaces are found @@ -225,6 +226,7 @@ void DumpPresentableSurfaces(Printer &p, AppInstance &inst, const std::vector> surfaces; +#if defined(VULKANINFO_WSI_ENABLED) for (auto &surface_extension : instance.surface_extensions) { surface_extension.create_window(instance); surface_extension.surface = surface_extension.create_surface(instance); @@ -1089,6 +1094,7 @@ int main(int argc, char **argv) { surfaces.push_back(std::unique_ptr(new AppSurface(instance, phys_device, surface_extension))); } } +#endif // defined(VULKANINFO_WSI_ENABLED) std::vector> gpus; @@ -1102,13 +1108,15 @@ int main(int argc, char **argv) { std::cout << "The selected gpu (" << parse_data.selected_gpu << ") is not a valid GPU index. "; if (gpus.size() == 0) { std::cout << "vulkaninfo could not find any GPU's.\n"; - } - if (gpus.size() == 1) { - std::cout << "The only available GPU selection is 0.\n"; + return 1; } else { - std::cout << "The available GPUs are in the range of 0 to " << gpus.size() - 1 << ".\n"; + if (gpus.size() == 1) { + std::cout << "The only available GPU selection is 0.\n"; + } else { + std::cout << "The available GPUs are in the range of 0 to " << gpus.size() - 1 << ".\n"; + } + return 1; } - return 1; } else if (parse_data.output_category == OutputCategory::devsim_json || parse_data.output_category == OutputCategory::portability_json) { std::cout << "vulkaninfo could not find any GPU's.\n"; @@ -1133,10 +1141,12 @@ int main(int argc, char **argv) { RunPrinter(*(printer.get()), parse_data, instance, gpus, surfaces); +#if defined(VULKANINFO_WSI_ENABLED) for (auto &surface_extension : instance.surface_extensions) { AppDestroySurface(instance, surface_extension.surface); surface_extension.destroy_window(instance); } +#endif // defined(VULKANINFO_WSI_ENABLED) } catch (std::exception &e) { // Print the error to stderr and leave all outputs in a valid state (mainly for json) std::cerr << "ERROR at " << e.what() << "\n"; diff --git a/vulkaninfo/vulkaninfo.h b/vulkaninfo/vulkaninfo.h index d49d301..e2ef653 100644 --- a/vulkaninfo/vulkaninfo.h +++ b/vulkaninfo/vulkaninfo.h @@ -620,10 +620,9 @@ struct AppInstance { if (err) THROW_VK_ERR("vkEnumerateInstanceVersion", err); } - // fallback to baked header version if loader returns 0 for the patch version - uint32_t patch_version = VK_VERSION_PATCH(instance_version); - if (patch_version == 0) patch_version = VK_VERSION_PATCH(VK_HEADER_VERSION); vk_version = make_vulkan_version(instance_version); + // fallback to baked header version if loader returns 0 for the patch version + if (VK_VERSION_PATCH(instance_version) == 0) vk_version.patch = VK_VERSION_PATCH(VK_HEADER_VERSION); AppGetInstanceExtensions(); @@ -708,6 +707,11 @@ struct AppInstance { // --------- Platform Specific Presentation Calls --------- // +#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \ + defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT) || defined(VK_USE_PLATFORM_WAYLAND_KHR) || \ + defined(VK_USE_PLATFORM_DIRECTFB_EXT) || defined(VK_USE_PLATFORM_ANDROID_KHR) +#define VULKANINFO_WSI_ENABLED +#endif //---------------------------Win32--------------------------- #ifdef VK_USE_PLATFORM_WIN32_KHR @@ -779,10 +783,11 @@ static void AppDestroyWin32Window(AppInstance &inst) { user32_handles->pfnDestro #endif // VK_USE_PLATFORM_WIN32_KHR //----------------------------------------------------------- +#if defined(VULKANINFO_WSI_ENABLED) static void AppDestroySurface(AppInstance &inst, VkSurfaceKHR surface) { // same for all platforms inst.dll.fp_vkDestroySurfaceKHR(inst.instance, surface, nullptr); } - +#endif // defined(VULKANINFO_WSI_ENABLED) //----------------------------XCB---------------------------- #ifdef VK_USE_PLATFORM_XCB_KHR -- 2.7.4