diff options
| author | Charles Giessen <charles@lunarg.com> | 2023-11-08 17:47:07 -0700 |
|---|---|---|
| committer | Juan Ramos <114601453+juan-lunarg@users.noreply.github.com> | 2023-11-16 18:28:56 -0700 |
| commit | 62c4f8f7c546662aa5d43ca185e7d478d1224fb1 (patch) | |
| tree | 5046aef3adc2f19d2a1c2d6d539ced61ffeb4fb0 /cube/cube.cpp | |
| parent | 5093613de741e02f0fc0efae6796bf87e0615ee8 (diff) | |
| download | usermoji-62c4f8f7c546662aa5d43ca185e7d478d1224fb1.tar.xz | |
cube: Use volk to load functions
Add volk as a repo dependency to replace the dependency on the Vulkan-Loader.
This makes it easier to build the repo as the vulkan-loader has a much more
complex build than volk does. It also allows vkcube to launch without vulkan
being installed on the system, allowing for better error handling.
Because volk can be used on all platforms, there is no longer a need for
android_wrapper. Thus it has been removed.
Diffstat (limited to 'cube/cube.cpp')
| -rw-r--r-- | cube/cube.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/cube/cube.cpp b/cube/cube.cpp index c67242ae..1d594b32 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -43,6 +43,9 @@ #define VULKAN_HPP_TYPESAFE_CONVERSION #include <vulkan/vulkan.hpp> +#define VOLK_IMPLEMENTATION +#include "volk.h" + VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE #include "linmath.h" @@ -73,21 +76,6 @@ constexpr uint32_t FRAME_LAG = 2; } while (0) #endif -// easier to use the C function for extension functions -PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT; -PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT; -VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, - const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, - const VkAllocationCallbacks *pAllocator, - VkDebugUtilsMessengerEXT *pMessenger) { - return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger); -} - -VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, - VkAllocationCallbacks const *pAllocator) { - return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); -} - struct texture_object { vk::Sampler sampler; @@ -1132,7 +1120,16 @@ VKAPI_ATTR VkBool32 VKAPI_CALL Demo::debug_messenger_callback(VkDebugUtilsMessag } void Demo::init_vk() { - VULKAN_HPP_DEFAULT_DISPATCHER.init(); + // Vulkan-hpp doesn't load moltenkVK, so we use volk to do that for us, then pass vkGetInstanceProcAddr along + VkResult err = volkInitialize(); + if (err != VK_SUCCESS) { + ERR_EXIT( + "Unable to find the Vulkan runtime on the system.\n\n" + "This likely indicates that no Vulkan capable drivers are installed.", + "Installation Failure"); + } + + VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); std::vector<char const *> instance_validation_layers = {"VK_LAYER_KHRONOS_validation"}; @@ -1327,11 +1324,6 @@ void Demo::init_vk() { VULKAN_HPP_DEFAULT_DISPATCHER.init(inst); if (use_debug_messenger) { - pfnVkCreateDebugUtilsMessengerEXT = - reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(inst.getProcAddr("vkCreateDebugUtilsMessengerEXT")); - pfnVkDestroyDebugUtilsMessengerEXT = - reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(inst.getProcAddr("vkDestroyDebugUtilsMessengerEXT")); - VERIFY(pfnVkCreateDebugUtilsMessengerEXT != nullptr && pfnVkDestroyDebugUtilsMessengerEXT != nullptr); auto create_debug_messenger_return = inst.createDebugUtilsMessengerEXT(debug_utils_create_info); VERIFY(create_debug_messenger_return.result == vk::Result::eSuccess); debug_messenger = create_debug_messenger_return.value; |
