1 // 2 // VkhInfo 3 // Version: 1.3.2 4 // 5 // Copyright (c) 2019-2021 past-due 6 // 7 // https://github.com/past-due/vulkan-helpers 8 // 9 // Distributed under the MIT License. 10 // See accompanying file LICENSE or copy at https://opensource.org/licenses/MIT 11 // 12 13 #pragma once 14 15 #if defined( _MSC_VER ) 16 #pragma warning( push ) 17 #pragma warning( disable : 4191 ) // warning C4191: '<function-style-cast>': unsafe conversion from 'PFN_vkVoidFunction' to 'PFN_vk<...>' 18 #endif 19 #define VULKAN_HPP_TYPESAFE_CONVERSION 1 20 #ifndef NOMINMAX 21 #define NOMINMAX // For windows.h 22 #endif 23 #if defined(__clang__) 24 #pragma clang diagnostic push 25 #pragma clang diagnostic ignored "-Wshadow" 26 #endif 27 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 9 28 #pragma GCC diagnostic push 29 #pragma GCC diagnostic ignored "-Wdeprecated-copy" // Ignore warnings caused by vulkan.hpp 148 30 #pragma GCC diagnostic ignored "-Wshadow" 31 #endif 32 #include <vulkan/vulkan.hpp> 33 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 9 34 #pragma GCC diagnostic pop 35 #endif 36 #if defined( _MSC_VER ) 37 #pragma warning( pop ) 38 #endif 39 40 #include <string> 41 #include <functional> 42 #include <vector> 43 44 class VkhInfo 45 { 46 public: 47 typedef std::function<void (const std::string& output)> outputHandlerFuncType; 48 VkhInfo()49 VkhInfo() {} 50 VkhInfo(const outputHandlerFuncType& outputHandler); 51 52 void setOutputHandler(const outputHandlerFuncType& outputHandler); 53 54 public: 55 56 void Output_GlobalInstanceExtensions(PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr); 57 void Output_InstanceLayerProperties(PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr); 58 59 void Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice, const vk::SurfaceKHR& surface, const vk::DispatchLoaderDynamic& vkDynLoader); 60 61 // If `getProperties2` is true, the instance `inst` *must* have been created with the "VK_KHR_get_physical_device_properties2" extension enabled 62 void Output_PhysicalDevices(const vk::Instance& inst, const vk::ApplicationInfo& appInfo, std::vector<const char*> instanceExtensions, const vk::DispatchLoaderDynamic& vkDynLoader); 63 64 public: 65 vulkan_apiversion_to_string(uint32_t apiVersion)66 static inline std::string vulkan_apiversion_to_string(uint32_t apiVersion) 67 { 68 return std::to_string(VK_VERSION_MAJOR(apiVersion)) + "." + std::to_string(VK_VERSION_MINOR(apiVersion)) + "." + std::to_string(VK_VERSION_PATCH(apiVersion)); 69 } 70 static bool getInstanceLayerProperties(std::vector<VkLayerProperties> &output, PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr); 71 static bool getInstanceExtensions(const char * layerName, std::vector<VkExtensionProperties> &output, PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr); 72 static bool supportsInstanceExtension(const char * layerName, const char * extensionName, PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr); 73 74 private: 75 outputHandlerFuncType outputHandler; 76 }; 77