| 156 | |
| 157 | template <vkb::BindingType bindingType> |
| 158 | inline Instance<bindingType>::Instance(std::string const &application_name, |
| 159 | uint32_t api_version, |
| 160 | std::unordered_map<std::string, vkb::RequestMode> const &requested_layers, |
| 161 | std::unordered_map<std::string, vkb::RequestMode> const &requested_extensions, |
| 162 | std::function<InstanceCreateFlagsType(std::vector<std::string> const &)> const &get_create_flags, |
| 163 | std::function<void(vkb::StructureChainBuilder<bindingType, InstanceCreateInfoType> &)> const &extend_instance_create_info) |
| 164 | { |
| 165 | // check API version |
| 166 | LOGI("Requesting Vulkan API version {}.{}", VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version)); |
| 167 | if (api_version < VK_API_VERSION_1_1) |
| 168 | { |
| 169 | LOGE("Vulkan API version {}.{} is requested but version 1.1 or higher is required.", VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version)); |
| 170 | throw std::runtime_error("Requested Vulkan API version is too low."); |
| 171 | } |
| 172 | uint32_t instance_api_version = vk::enumerateInstanceVersion(); |
| 173 | LOGI("Vulkan instance supports API version {}.{}", VK_VERSION_MAJOR(instance_api_version), VK_VERSION_MINOR(instance_api_version)); |
| 174 | if (instance_api_version < api_version) |
| 175 | { |
| 176 | LOGE("Vulkan API version {}.{} is requested but only version {}.{} is supported.", |
| 177 | VK_VERSION_MAJOR(api_version), |
| 178 | VK_VERSION_MINOR(api_version), |
| 179 | VK_VERSION_MAJOR(instance_api_version), |
| 180 | VK_VERSION_MINOR(instance_api_version)); |
| 181 | throw std::runtime_error("Requested Vulkan API version is too high."); |
| 182 | } |
| 183 | |
| 184 | // Check for optional and required layers |
| 185 | std::vector<vk::LayerProperties> available_layers = vk::enumerateInstanceLayerProperties(); |
| 186 | std::vector<std::string> enabled_layers; |
| 187 | for (auto const &requested_layer : requested_layers) |
| 188 | { |
| 189 | if (!enable_layer(requested_layer.first, available_layers, enabled_layers)) |
| 190 | { |
| 191 | if (requested_layer.second == vkb::RequestMode::Optional) |
| 192 | { |
| 193 | LOGW("Optional layer {} not available, some features may be disabled", requested_layer.first); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | LOGE("Required layer {} not available, cannot run", requested_layer.first); |
| 198 | throw std::runtime_error("Required layers are missing."); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | std::vector<char const *> enabled_layers_cstr; |
| 203 | for (auto &layer : enabled_layers) |
| 204 | { |
| 205 | enabled_layers_cstr.push_back(layer.c_str()); |
| 206 | } |
| 207 | |
| 208 | // Check for optional and required extensions |
| 209 | std::vector<vk::ExtensionProperties> available_extensions = vk::enumerateInstanceExtensionProperties(); |
| 210 | |
| 211 | if (contains(enabled_layers, "VK_LAYER_KHRONOS_validation")) |
| 212 | { |
| 213 | std::string const validation_layer_name = "VK_LAYER_KHRONOS_validation"; |
| 214 | std::vector<vk::ExtensionProperties> available_layer_instance_extensions = vk::enumerateInstanceExtensionProperties(validation_layer_name); |
| 215 | available_extensions.insert(available_extensions.end(), |
nothing calls this directly
no test coverage detected