diff --git a/base/VulkanDevice.hpp b/base/VulkanDevice.hpp index 9289ec9a..76c6655d 100644 --- a/base/VulkanDevice.hpp +++ b/base/VulkanDevice.hpp @@ -3,7 +3,7 @@ * * Encapsulates a physical Vulkan device and it's logical representation * -* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de +* Copyright (C) by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -208,12 +208,13 @@ namespace vks * Create the logical device based on the assigned physical device, also gets default queue family indices * * @param enabledFeatures Can be used to enable certain features upon device creation + * @param pNextChain Optional chain of pointer to extension structures * @param useSwapChain Set to false for headless rendering to omit the swapchain device extensions * @param requestedQueueTypes Bit flags specifying the queue types to be requested from the device * * @return VkResult of the device creation call */ - VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector enabledExtensions, bool useSwapChain = true, VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT) + VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector enabledExtensions, void* pNextChain, 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 @@ -297,6 +298,16 @@ namespace vks deviceCreateInfo.queueCreateInfoCount = static_cast(queueCreateInfos.size());; deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data(); deviceCreateInfo.pEnabledFeatures = &enabledFeatures; + + // If a pNext(Chain) has been passed, we need to add it to the device creation info + if (pNextChain) { + VkPhysicalDeviceFeatures2 physicalDeviceFeatures2{}; + physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + physicalDeviceFeatures2.features = enabledFeatures; + physicalDeviceFeatures2.pNext = pNextChain; + deviceCreateInfo.pEnabledFeatures = nullptr; + deviceCreateInfo.pNext = &physicalDeviceFeatures2; + } // Enable the debug marker extension if it is present (likely meaning a debugging tool is present) if (extensionSupported(VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 552817e1..97dbcae3 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -931,7 +931,7 @@ bool VulkanExampleBase::initVulkan() // This is handled by a separate class that gets a logical device representation // and encapsulates functions related to a device vulkanDevice = new vks::VulkanDevice(physicalDevice); - VkResult res = vulkanDevice->createLogicalDevice(enabledFeatures, enabledDeviceExtensions); + VkResult res = vulkanDevice->createLogicalDevice(enabledFeatures, enabledDeviceExtensions, deviceCreatepNextChain); if (res != VK_SUCCESS) { vks::tools::exitFatal("Could not create Vulkan device: \n" + vks::tools::errorString(res), res); return false; diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index fc78591c..e84f4c98 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -1,7 +1,7 @@ /* * Vulkan Example base class * -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +* Copyright (C) by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -83,17 +83,14 @@ protected: VkPhysicalDeviceFeatures deviceFeatures; // Stores all available memory (type) properties for the physical device VkPhysicalDeviceMemoryProperties deviceMemoryProperties; - /** - * Set of physical device features to be enabled for this example (must be set in the derived constructor) - * - * @note By default no phyiscal device features are enabled - */ + /** @brief Set of physical device features to be enabled for this example (must be set in the derived constructor) */ VkPhysicalDeviceFeatures enabledFeatures{}; /** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */ std::vector enabledDeviceExtensions; std::vector enabledInstanceExtensions; + /** @brief Optional pNext structure for passing extension structures to device creation */ + void* deviceCreatepNextChain = nullptr; /** @brief Logical device, application's view of the physical device (GPU) */ - // todo: getter? should always point to VulkanDevice->device VkDevice device; // Handle to the device graphics queue that command buffers are submitted to VkQueue queue;