Enabled device extensions can now be set, display error message if device cannot be created
This commit is contained in:
parent
b30fd58557
commit
1c595c61e8
3 changed files with 21 additions and 13 deletions
|
|
@ -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<const char*> 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<const char*> deviceExtensions;
|
||||
std::vector<const char*> 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
|
||||
|
|
|
|||
|
|
@ -20,33 +20,33 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
|||
appInfo.pEngineName = name.c_str();
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
std::vector<const char*> enabledExtensions = { VK_KHR_SURFACE_EXTENSION_NAME };
|
||||
std::vector<const char*> 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
|
||||
|
|
|
|||
|
|
@ -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<const char*> enabledExtensions;
|
||||
/** @brief Logical device, application's view of the physical device (GPU) */
|
||||
// todo: getter? should always point to VulkanDevice->device
|
||||
VkDevice device;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue