mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 15:24:34 +00:00
Updated docs for error_code usage
Updated the documentation for using the new <error_code> based errors. Also fixed an issue where SystemInfo wouldn't check if layers had a debug_utils extension.
This commit is contained in:
parent
ef59478aa4
commit
3bbc4831f5
16
README.md
16
README.md
@ -31,7 +31,9 @@ void init_vulkan () {
|
|||||||
.use_default_debug_messenger ()
|
.use_default_debug_messenger ()
|
||||||
.build ();
|
.build ();
|
||||||
if (!inst_ret) {
|
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 ();
|
vkb::Instance vkb_inst = inst_ret.value ();
|
||||||
|
|
||||||
@ -41,14 +43,18 @@ void init_vulkan () {
|
|||||||
.require_dedicated_transfer_queue ()
|
.require_dedicated_transfer_queue ()
|
||||||
.select ();
|
.select ();
|
||||||
if (!phys_ret) {
|
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 () };
|
vkb::DeviceBuilder device_builder{ phys_ret.value () };
|
||||||
// automatically propagate needed data from instance & physical device
|
// automatically propagate needed data from instance & physical device
|
||||||
auto dev_ret = device_builder.build ();
|
auto dev_ret = device_builder.build ();
|
||||||
if (!dev_ret) {
|
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 ();
|
vkb::Device vkb_device = dev_ret.value ();
|
||||||
|
|
||||||
@ -58,7 +64,9 @@ void init_vulkan () {
|
|||||||
// Get the graphics queue with a helper function
|
// Get the graphics queue with a helper function
|
||||||
auto graphics_queue_ret = vkb_device.get_queue (vkb::QueueType::graphics);
|
auto graphics_queue_ret = vkb_device.get_queue (vkb::QueueType::graphics);
|
||||||
if (!graphics_queue_ret) {
|
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 ();
|
VkQueue graphics_queue = graphics_queue_ret.value ();
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ Because creating an instance may fail, the builder returns an 'Result' type. Thi
|
|||||||
```cpp
|
```cpp
|
||||||
if (!instance_builder_return) {
|
if (!instance_builder_return) {
|
||||||
printf("Failed to create Vulkan instance. Cause %s\n",
|
printf("Failed to create Vulkan instance. Cause %s\n",
|
||||||
vkb::to_string(instance_builder_return.error().type));
|
instance_builder_return.error().message());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -57,6 +57,18 @@ auto inst_builder_ret = instance_builder
|
|||||||
.build();
|
.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.
|
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
|
```cpp
|
||||||
struct CustomVulkanWrapper {
|
struct CustomVulkanWrapper {
|
||||||
@ -191,7 +203,7 @@ Queue families represent a set of queues with similar operations, such as graphi
|
|||||||
|
|
||||||
#### Custom queue setup
|
#### 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<float>` of priorities. To build up such a vector, use the `get_queue_familties` function in `vkb::PhysicalDevice` to get a `std::vector<VkQueueFamilyProperties>`
|
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<float>` of priorities. To build up such a vector, use the `get_queue_families` function in `vkb::PhysicalDevice` to get a `std::vector<VkQueueFamilyProperties>`
|
||||||
|
|
||||||
For example
|
For example
|
||||||
```cpp
|
```cpp
|
||||||
|
@ -44,7 +44,7 @@ int device_initialization (Init& init) {
|
|||||||
vkb::InstanceBuilder instance_builder;
|
vkb::InstanceBuilder instance_builder;
|
||||||
auto instance_ret = instance_builder.use_default_debug_messenger ().request_validation_layers ().build ();
|
auto instance_ret = instance_builder.use_default_debug_messenger ().request_validation_layers ().build ();
|
||||||
if (!instance_ret) {
|
if (!instance_ret) {
|
||||||
std::cout << instance_ret.error () << "\n";
|
std::cout << instance_ret.error ().message () << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
init.instance = instance_ret.value ();
|
init.instance = instance_ret.value ();
|
||||||
@ -54,7 +54,7 @@ int device_initialization (Init& init) {
|
|||||||
vkb::PhysicalDeviceSelector phys_device_selector (init.instance);
|
vkb::PhysicalDeviceSelector phys_device_selector (init.instance);
|
||||||
auto phys_device_ret = phys_device_selector.set_surface (init.surface).select ();
|
auto phys_device_ret = phys_device_selector.set_surface (init.surface).select ();
|
||||||
if (!phys_device_ret) {
|
if (!phys_device_ret) {
|
||||||
std::cout << phys_device_ret.error () << "\n";
|
std::cout << phys_device_ret.error ().message () << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vkb::PhysicalDevice physical_device = phys_device_ret.value ();
|
vkb::PhysicalDevice physical_device = phys_device_ret.value ();
|
||||||
@ -62,7 +62,7 @@ int device_initialization (Init& init) {
|
|||||||
vkb::DeviceBuilder device_builder{ physical_device };
|
vkb::DeviceBuilder device_builder{ physical_device };
|
||||||
auto device_ret = device_builder.build ();
|
auto device_ret = device_builder.build ();
|
||||||
if (!device_ret) {
|
if (!device_ret) {
|
||||||
std::cout << device_ret.error () << "\n";
|
std::cout << device_ret.error ().message () << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
init.device = device_ret.value ();
|
init.device = device_ret.value ();
|
||||||
@ -71,7 +71,7 @@ int device_initialization (Init& init) {
|
|||||||
auto swap_ret =
|
auto swap_ret =
|
||||||
swapchain_builder.use_default_format_selection ().use_default_present_mode_selection ().build ();
|
swapchain_builder.use_default_format_selection ().use_default_present_mode_selection ().build ();
|
||||||
if (!swap_ret) {
|
if (!swap_ret) {
|
||||||
std::cout << swap_ret.error () << "\n";
|
std::cout << swap_ret.error ().message () << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
init.swapchain = swap_ret.value ();
|
init.swapchain = swap_ret.value ();
|
||||||
@ -81,14 +81,14 @@ int device_initialization (Init& init) {
|
|||||||
int get_queues (Init& init, RenderData& data) {
|
int get_queues (Init& init, RenderData& data) {
|
||||||
auto gq = init.device.get_queue (vkb::QueueType::graphics);
|
auto gq = init.device.get_queue (vkb::QueueType::graphics);
|
||||||
if (!gq.has_value ()) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
data.graphics_queue = gq.value ();
|
data.graphics_queue = gq.value ();
|
||||||
|
|
||||||
auto pq = init.device.get_queue (vkb::QueueType::present);
|
auto pq = init.device.get_queue (vkb::QueueType::present);
|
||||||
if (!pq.has_value ()) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
data.present_queue = pq.value ();
|
data.present_queue = pq.value ();
|
||||||
|
@ -113,7 +113,7 @@ VkBool32 default_debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageS
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
bool check_layer_supported (std::vector<VkLayerProperties> available_layers, const char* layer_name) {
|
bool check_layer_supported (std::vector<VkLayerProperties> const& available_layers, const char* layer_name) {
|
||||||
if (!layer_name) return false;
|
if (!layer_name) return false;
|
||||||
for (const auto& layer_properties : available_layers) {
|
for (const auto& layer_properties : available_layers) {
|
||||||
if (strcmp (layer_name, layer_properties.layerName) == 0) {
|
if (strcmp (layer_name, layer_properties.layerName) == 0) {
|
||||||
@ -123,7 +123,8 @@ bool check_layer_supported (std::vector<VkLayerProperties> available_layers, con
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_layers_supported (std::vector<VkLayerProperties> available_layers, std::vector<const char*> layer_names) {
|
bool check_layers_supported (std::vector<VkLayerProperties> const& available_layers,
|
||||||
|
std::vector<const char*> const& layer_names) {
|
||||||
bool all_found = true;
|
bool all_found = true;
|
||||||
for (const auto& layer_name : layer_names) {
|
for (const auto& layer_name : layer_names) {
|
||||||
bool found = check_layer_supported (available_layers, layer_name);
|
bool found = check_layer_supported (available_layers, layer_name);
|
||||||
@ -132,18 +133,19 @@ bool check_layers_supported (std::vector<VkLayerProperties> available_layers, st
|
|||||||
return all_found;
|
return all_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_extension_supported (std::vector<VkExtensionProperties> available_extensions, const char* extension_name) {
|
bool check_extension_supported (
|
||||||
|
std::vector<VkExtensionProperties> const& available_extensions, const char* extension_name) {
|
||||||
if (!extension_name) return false;
|
if (!extension_name) return false;
|
||||||
for (const auto& layer_properties : available_extensions) {
|
for (const auto& extension_properties : available_extensions) {
|
||||||
if (strcmp (extension_name, layer_properties.extensionName) == 0) {
|
if (strcmp (extension_name, extension_properties.extensionName) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_extensions_supported (std::vector<VkExtensionProperties> available_extensions,
|
bool check_extensions_supported (std::vector<VkExtensionProperties> const& available_extensions,
|
||||||
std::vector<const char*> extension_names) {
|
std::vector<const char*> const& extension_names) {
|
||||||
bool all_found = true;
|
bool all_found = true;
|
||||||
for (const auto& extension_name : extension_names) {
|
for (const auto& extension_name : extension_names) {
|
||||||
bool found = check_extension_supported (available_extensions, extension_name);
|
bool found = check_extension_supported (available_extensions, extension_name);
|
||||||
@ -301,16 +303,6 @@ const char* to_string (SwapchainError err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SystemInfo::SystemInfo () {
|
SystemInfo::SystemInfo () {
|
||||||
auto available_extensions_ret = detail::get_vector<VkExtensionProperties> (
|
|
||||||
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 =
|
auto available_layers_ret =
|
||||||
detail::get_vector<VkLayerProperties> (this->available_layers, vkEnumerateInstanceLayerProperties);
|
detail::get_vector<VkLayerProperties> (this->available_layers, vkEnumerateInstanceLayerProperties);
|
||||||
if (available_layers_ret != VK_SUCCESS) {
|
if (available_layers_ret != VK_SUCCESS) {
|
||||||
@ -320,6 +312,27 @@ SystemInfo::SystemInfo () {
|
|||||||
for (auto& layer : this->available_layers)
|
for (auto& layer : this->available_layers)
|
||||||
if (strcmp (layer.layerName, detail::validation_layer_name) == 0)
|
if (strcmp (layer.layerName, detail::validation_layer_name) == 0)
|
||||||
validation_layers_available = true;
|
validation_layers_available = true;
|
||||||
|
|
||||||
|
auto available_extensions_ret = detail::get_vector<VkExtensionProperties> (
|
||||||
|
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<VkExtensionProperties> layer_extensions;
|
||||||
|
auto layer_extensions_ret = detail::get_vector<VkExtensionProperties> (
|
||||||
|
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 {
|
bool SystemInfo::is_extension_available (const char* extension_name) const {
|
||||||
if (!extension_name) return false;
|
if (!extension_name) return false;
|
||||||
|
@ -159,7 +159,7 @@ struct SystemInfo {
|
|||||||
std::vector<VkLayerProperties> available_layers;
|
std::vector<VkLayerProperties> available_layers;
|
||||||
std::vector<VkExtensionProperties> available_extensions;
|
std::vector<VkExtensionProperties> available_extensions;
|
||||||
bool validation_layers_available = false;
|
bool validation_layers_available = false;
|
||||||
bool debug_messenger_available = false;
|
bool debug_utils_available = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InstanceBuilder;
|
class InstanceBuilder;
|
||||||
|
Loading…
Reference in New Issue
Block a user