diff --git a/README.md b/README.md index 5101579..7e1b379 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ void init_vulkan () { .use_default_debug_messenger () .build (); if (!inst_ret) { - // error + printf("Failed to create Vulkan instance. Cause %s\n", + instance_builder_return.error().message()); + return; } vkb::Instance vkb_inst = inst_ret.value (); @@ -41,14 +43,18 @@ void init_vulkan () { .require_dedicated_transfer_queue () .select (); if (!phys_ret) { - // error + printf("Failed to select Vulkan Physical Device. Cause %s\n", + phys_ret.error().message()); + return; } vkb::DeviceBuilder device_builder{ phys_ret.value () }; // automatically propagate needed data from instance & physical device auto dev_ret = device_builder.build (); if (!dev_ret) { - // error + printf("Failed to create Vulkan device. Cause %s\n", + dev_ret.error().message()); + return; } vkb::Device vkb_device = dev_ret.value (); @@ -58,7 +64,9 @@ void init_vulkan () { // Get the graphics queue with a helper function auto graphics_queue_ret = vkb_device.get_queue (vkb::QueueType::graphics); if (!graphics_queue_ret) { - // error + printf("Failed to get graphics queue. Cause %s\n", + graphics_queue_ret.error().message()); + return; } VkQueue graphics_queue = graphics_queue_ret.value (); diff --git a/docs/getting_started.md b/docs/getting_started.md index a073223..5312327 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -15,7 +15,7 @@ Because creating an instance may fail, the builder returns an 'Result' type. Thi ```cpp if (!instance_builder_return) { printf("Failed to create Vulkan instance. Cause %s\n", - vkb::to_string(instance_builder_return.error().type)); + instance_builder_return.error().message()); return -1; } ``` @@ -57,6 +57,18 @@ auto inst_builder_ret = instance_builder .build(); ``` +To query the available layers and extensions, use the `get_system_info()` function of `vkb::InstanceBuilder` to get a `SystemInfo` struct. It contains a `is_layer_available()` and `is_extension_available()` function to check for a layer or extensions before enabling it. It also has booleans for if the validation layers are present and if the VK_EXT_debug_utils extension is available. + +```cpp +auto system_info = instance_builder.get_system_info(); +if (system_info.is_layer_available("VK_LAYER_LUNARG_api_dump")) { + instance_builder.enable_layer("VK_LAYER_LUNARG_api_dump"); +} +if (system_info.validation_layers_available){ + instance_builder.enable_validation_layers(); +} +``` + The `vkb::Instance` struct is meant to hold all the necessary instance level data to enable proper Physical Device selection. It also is meant for easy destructuring into custom classes if so desired. ```cpp struct CustomVulkanWrapper { @@ -191,7 +203,7 @@ Queue families represent a set of queues with similar operations, such as graphi #### Custom queue setup -If an application wishes to have more fine grained control over their queue setup, they should create a `std::vector` of `vkb::CustomQueueDescription` which describe the index, count and a `std::vector` of priorities. To build up such a vector, use the `get_queue_familties` function in `vkb::PhysicalDevice` to get a `std::vector` +If an application wishes to have more fine grained control over their queue setup, they should create a `std::vector` of `vkb::CustomQueueDescription` which describe the index, count and a `std::vector` of priorities. To build up such a vector, use the `get_queue_families` function in `vkb::PhysicalDevice` to get a `std::vector` For example ```cpp diff --git a/example/triangle.cpp b/example/triangle.cpp index 17971f3..abd26c0 100644 --- a/example/triangle.cpp +++ b/example/triangle.cpp @@ -44,7 +44,7 @@ int device_initialization (Init& init) { vkb::InstanceBuilder instance_builder; auto instance_ret = instance_builder.use_default_debug_messenger ().request_validation_layers ().build (); if (!instance_ret) { - std::cout << instance_ret.error () << "\n"; + std::cout << instance_ret.error ().message () << "\n"; return -1; } init.instance = instance_ret.value (); @@ -54,7 +54,7 @@ int device_initialization (Init& init) { vkb::PhysicalDeviceSelector phys_device_selector (init.instance); auto phys_device_ret = phys_device_selector.set_surface (init.surface).select (); if (!phys_device_ret) { - std::cout << phys_device_ret.error () << "\n"; + std::cout << phys_device_ret.error ().message () << "\n"; return -1; } vkb::PhysicalDevice physical_device = phys_device_ret.value (); @@ -62,7 +62,7 @@ int device_initialization (Init& init) { vkb::DeviceBuilder device_builder{ physical_device }; auto device_ret = device_builder.build (); if (!device_ret) { - std::cout << device_ret.error () << "\n"; + std::cout << device_ret.error ().message () << "\n"; return -1; } init.device = device_ret.value (); @@ -71,7 +71,7 @@ int device_initialization (Init& init) { auto swap_ret = swapchain_builder.use_default_format_selection ().use_default_present_mode_selection ().build (); if (!swap_ret) { - std::cout << swap_ret.error () << "\n"; + std::cout << swap_ret.error ().message () << "\n"; return -1; } init.swapchain = swap_ret.value (); @@ -81,14 +81,14 @@ int device_initialization (Init& init) { int get_queues (Init& init, RenderData& data) { auto gq = init.device.get_queue (vkb::QueueType::graphics); if (!gq.has_value ()) { - std::cout << "failed to get graphics queue: " << gq.error () << "\n"; + std::cout << "failed to get graphics queue: " << gq.error ().message () << "\n"; return -1; } data.graphics_queue = gq.value (); auto pq = init.device.get_queue (vkb::QueueType::present); if (!pq.has_value ()) { - std::cout << "failed to get present queue: " << pq.error () << "\n"; + std::cout << "failed to get present queue: " << pq.error ().message () << "\n"; return -1; } data.present_queue = pq.value (); diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index bb13b40..a89d568 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -113,7 +113,7 @@ VkBool32 default_debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageS } namespace detail { -bool check_layer_supported (std::vector available_layers, const char* layer_name) { +bool check_layer_supported (std::vector const& available_layers, const char* layer_name) { if (!layer_name) return false; for (const auto& layer_properties : available_layers) { if (strcmp (layer_name, layer_properties.layerName) == 0) { @@ -123,7 +123,8 @@ bool check_layer_supported (std::vector available_layers, con return false; } -bool check_layers_supported (std::vector available_layers, std::vector layer_names) { +bool check_layers_supported (std::vector const& available_layers, + std::vector const& layer_names) { bool all_found = true; for (const auto& layer_name : layer_names) { bool found = check_layer_supported (available_layers, layer_name); @@ -132,18 +133,19 @@ bool check_layers_supported (std::vector available_layers, st return all_found; } -bool check_extension_supported (std::vector available_extensions, const char* extension_name) { +bool check_extension_supported ( + std::vector const& available_extensions, const char* extension_name) { if (!extension_name) return false; - for (const auto& layer_properties : available_extensions) { - if (strcmp (extension_name, layer_properties.extensionName) == 0) { + for (const auto& extension_properties : available_extensions) { + if (strcmp (extension_name, extension_properties.extensionName) == 0) { return true; } } return false; } -bool check_extensions_supported (std::vector available_extensions, - std::vector extension_names) { +bool check_extensions_supported (std::vector const& available_extensions, + std::vector const& extension_names) { bool all_found = true; for (const auto& extension_name : extension_names) { bool found = check_extension_supported (available_extensions, extension_name); @@ -301,16 +303,6 @@ const char* to_string (SwapchainError err) { } SystemInfo::SystemInfo () { - auto available_extensions_ret = detail::get_vector ( - this->available_extensions, vkEnumerateInstanceExtensionProperties, nullptr); - if (available_extensions_ret != VK_SUCCESS) { - this->available_extensions.clear (); - } - - for (auto& ext : this->available_extensions) - if (strcmp (ext.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) - debug_messenger_available = true; - auto available_layers_ret = detail::get_vector (this->available_layers, vkEnumerateInstanceLayerProperties); if (available_layers_ret != VK_SUCCESS) { @@ -320,6 +312,27 @@ SystemInfo::SystemInfo () { for (auto& layer : this->available_layers) if (strcmp (layer.layerName, detail::validation_layer_name) == 0) validation_layers_available = true; + + auto available_extensions_ret = detail::get_vector ( + this->available_extensions, vkEnumerateInstanceExtensionProperties, nullptr); + if (available_extensions_ret != VK_SUCCESS) { + this->available_extensions.clear (); + } + + for (auto& ext : this->available_extensions) + if (strcmp (ext.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) + debug_utils_available = true; + + for (auto& layer : this->available_layers) { + std::vector layer_extensions; + auto layer_extensions_ret = detail::get_vector ( + layer_extensions, vkEnumerateInstanceExtensionProperties, layer.layerName); + if (layer_extensions_ret != VK_SUCCESS) { + for (auto& ext : layer_extensions) + if (strcmp (ext.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0) + debug_utils_available = true; + } + } } bool SystemInfo::is_extension_available (const char* extension_name) const { if (!extension_name) return false; diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 3218379..c3b2858 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -159,7 +159,7 @@ struct SystemInfo { std::vector available_layers; std::vector available_extensions; bool validation_layers_available = false; - bool debug_messenger_available = false; + bool debug_utils_available = false; }; class InstanceBuilder;