Added new functionality for passing extension structures to device creation

This commit is contained in:
Sascha Willems 2019-06-10 08:46:11 +02:00
parent b2add91d2c
commit 4318c6d43e
3 changed files with 18 additions and 10 deletions

View file

@ -3,7 +3,7 @@
* *
* Encapsulates a physical Vulkan device and it's logical representation * 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) * 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 * 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 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 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 * @param requestedQueueTypes Bit flags specifying the queue types to be requested from the device
* *
* @return VkResult of the device creation call * @return VkResult of the device creation call
*/ */
VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector<const char*> enabledExtensions, bool useSwapChain = true, VkQueueFlags requestedQueueTypes = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT) VkResult createLogicalDevice(VkPhysicalDeviceFeatures enabledFeatures, std::vector<const char*> 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 // 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 // Due to differing queue family configurations of Vulkan implementations this can be a bit tricky, especially if the application
@ -298,6 +299,16 @@ namespace vks
deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data(); deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data();
deviceCreateInfo.pEnabledFeatures = &enabledFeatures; 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) // Enable the debug marker extension if it is present (likely meaning a debugging tool is present)
if (extensionSupported(VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) if (extensionSupported(VK_EXT_DEBUG_MARKER_EXTENSION_NAME))
{ {

View file

@ -931,7 +931,7 @@ bool VulkanExampleBase::initVulkan()
// This is handled by a separate class that gets a logical device representation // This is handled by a separate class that gets a logical device representation
// and encapsulates functions related to a device // and encapsulates functions related to a device
vulkanDevice = new vks::VulkanDevice(physicalDevice); vulkanDevice = new vks::VulkanDevice(physicalDevice);
VkResult res = vulkanDevice->createLogicalDevice(enabledFeatures, enabledDeviceExtensions); VkResult res = vulkanDevice->createLogicalDevice(enabledFeatures, enabledDeviceExtensions, deviceCreatepNextChain);
if (res != VK_SUCCESS) { if (res != VK_SUCCESS) {
vks::tools::exitFatal("Could not create Vulkan device: \n" + vks::tools::errorString(res), res); vks::tools::exitFatal("Could not create Vulkan device: \n" + vks::tools::errorString(res), res);
return false; return false;

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example base class * 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) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -83,17 +83,14 @@ protected:
VkPhysicalDeviceFeatures deviceFeatures; VkPhysicalDeviceFeatures deviceFeatures;
// Stores all available memory (type) properties for the physical device // Stores all available memory (type) properties for the physical device
VkPhysicalDeviceMemoryProperties deviceMemoryProperties; VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
/** /** @brief Set of physical device features to be enabled for this example (must be set in the derived constructor) */
* 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
*/
VkPhysicalDeviceFeatures enabledFeatures{}; VkPhysicalDeviceFeatures enabledFeatures{};
/** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */ /** @brief Set of device extensions to be enabled for this example (must be set in the derived constructor) */
std::vector<const char*> enabledDeviceExtensions; std::vector<const char*> enabledDeviceExtensions;
std::vector<const char*> enabledInstanceExtensions; std::vector<const char*> 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) */ /** @brief Logical device, application's view of the physical device (GPU) */
// todo: getter? should always point to VulkanDevice->device
VkDevice device; VkDevice device;
// Handle to the device graphics queue that command buffers are submitted to // Handle to the device graphics queue that command buffers are submitted to
VkQueue queue; VkQueue queue;