diff --git a/base/vulkandevice.hpp b/base/vulkandevice.hpp index b0e30863..60eb32c3 100644 --- a/base/vulkandevice.hpp +++ b/base/vulkandevice.hpp @@ -50,6 +50,9 @@ namespace vk uint32_t transfer; } queueFamilyIndices; + /** @brief Typecast to VkDevice */ + operator VkDevice() { return logicalDevice; }; + /** * Default constructor * @@ -222,7 +225,7 @@ namespace vk * * @return VkResult of the device creation call */ - VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, bool useSwapChain = true, VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT) + VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector enabledExtensions, bool useSwapChain = true, VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT) { // Desired queues need to be requested upon logical device creation // Due to differing queue family configurations of Vulkan implementations this can be a bit tricky, especially if the application @@ -294,7 +297,7 @@ namespace vk } // Create the logical device representation - std::vector deviceExtensions; + std::vector deviceExtensions(enabledExtensions); if (useSwapChain) { // If the device will be used for presenting to a display via a swapchain we need to request the swapchain extension diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 2e6a1c0e..e324ea35 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -20,33 +20,33 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) appInfo.pEngineName = name.c_str(); appInfo.apiVersion = VK_API_VERSION_1_0; - std::vector enabledExtensions = { VK_KHR_SURFACE_EXTENSION_NAME }; + std::vector instanceExtensions = { VK_KHR_SURFACE_EXTENSION_NAME }; // Enable surface extensions depending on os #if defined(_WIN32) - enabledExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); + instanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); #elif defined(__ANDROID__) - enabledExtensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); + instanceExtensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); #elif defined(_DIRECT2DISPLAY) - enabledExtensions.push_back(VK_KHR_DISPLAY_EXTENSION_NAME); + instanceExtensions.push_back(VK_KHR_DISPLAY_EXTENSION_NAME); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) - enabledExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); + instanceExtensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); #elif defined(__linux__) - enabledExtensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); + instanceExtensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); #endif VkInstanceCreateInfo instanceCreateInfo = {}; instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instanceCreateInfo.pNext = NULL; instanceCreateInfo.pApplicationInfo = &appInfo; - if (enabledExtensions.size() > 0) + if (instanceExtensions.size() > 0) { if (settings.validation) { - enabledExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + instanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } - instanceCreateInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size(); - instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data(); + instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size(); + instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data(); } if (settings.validation) { @@ -851,7 +851,10 @@ void VulkanExampleBase::initVulkan() // This is handled by a separate class that gets a logical device representation // and encapsulates functions related to a device vulkanDevice = new vk::VulkanDevice(physicalDevice); - VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(enabledFeatures)); + VkResult res = vulkanDevice->createLogicalDevice(enabledFeatures, enabledExtensions); + if (res != VK_SUCCESS) { + vkTools::exitFatal("Could not create Vulkan device: \n" + vkTools::errorString(res), "Fatal error"); + } device = vulkanDevice->logicalDevice; // todo: remove diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 6d3c2e19..342984a1 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -85,6 +85,8 @@ protected: * @note By default no phyiscal device features are enabled */ VkPhysicalDeviceFeatures enabledFeatures{}; + /** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */ + std::vector enabledExtensions; /** @brief Logical device, application's view of the physical device (GPU) */ // todo: getter? should always point to VulkanDevice->device VkDevice device;