This sample overrides the device creation part of the framework Instead of manually setting up all extensions, features, etc. we use the Vulkan Profiles library to simplify device setup
| 65 | // This sample overrides the device creation part of the framework |
| 66 | // Instead of manually setting up all extensions, features, etc. we use the Vulkan Profiles library to simplify device setup |
| 67 | std::unique_ptr<vkb::core::DeviceC> Profiles::create_device(vkb::core::PhysicalDeviceC &gpu) |
| 68 | { |
| 69 | // Check if the profile is supported at device level |
| 70 | VkBool32 profile_supported; |
| 71 | vpGetPhysicalDeviceProfileSupport(get_instance().get_handle(), gpu.get_handle(), &profile_properties, &profile_supported); |
| 72 | if (!profile_supported) |
| 73 | { |
| 74 | throw std::runtime_error{"The selected profile is not supported (error at creating the device)!"}; |
| 75 | } |
| 76 | |
| 77 | // If the profile is supported, we can start setting things up and use the profiles library for that |
| 78 | |
| 79 | // Simplified queue setup (only graphics) |
| 80 | uint32_t selected_queue_family = 0; |
| 81 | const auto &queue_family_properties = gpu.get_queue_family_properties(); |
| 82 | const float default_queue_priority{0.5f}; |
| 83 | VkDeviceQueueCreateInfo queue_create_info{}; |
| 84 | queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 85 | queue_create_info.queueCount = 1; |
| 86 | queue_create_info.pQueuePriorities = &default_queue_priority; |
| 87 | for (uint32_t i = 0; i < static_cast<uint32_t>(queue_family_properties.size()); i++) |
| 88 | { |
| 89 | if (queue_family_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) |
| 90 | { |
| 91 | queue_create_info.queueFamilyIndex = i; |
| 92 | selected_queue_family = i; |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | std::vector<const char *> enabled_extensions; |
| 98 | enabled_extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 99 | |
| 100 | #if (defined(VKB_ENABLE_PORTABILITY)) |
| 101 | // VK_KHR_portability_subset must be enabled if present in the implementation (e.g on macOS/iOS using MoltenVK with beta extensions enabled) |
| 102 | if (gpu.is_extension_supported(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME)) |
| 103 | { |
| 104 | enabled_extensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME); |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | VkDeviceCreateInfo create_info{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO}; |
| 109 | create_info.pNext = gpu.get_extension_feature_chain(); |
| 110 | create_info.pQueueCreateInfos = &queue_create_info; |
| 111 | create_info.queueCreateInfoCount = 1; |
| 112 | create_info.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions.size()); |
| 113 | create_info.ppEnabledExtensionNames = enabled_extensions.data(); |
| 114 | |
| 115 | // Create the device using the profiles library |
| 116 | VpDeviceCreateInfo deviceCreateInfo{}; |
| 117 | deviceCreateInfo.pCreateInfo = &create_info; |
| 118 | deviceCreateInfo.pEnabledFullProfiles = &profile_properties; |
| 119 | deviceCreateInfo.enabledFullProfileCount = 1; |
| 120 | VkDevice vulkan_device; |
| 121 | VkResult result = vpCreateDevice(gpu.get_handle(), &deviceCreateInfo, nullptr, &vulkan_device); |
| 122 | |
| 123 | if (result != VK_SUCCESS) |
| 124 | { |
nothing calls this directly
no test coverage detected