mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 15:24:34 +00:00
Updated docs to include device and swapchain deletion.
Fix example triangle to properly exit if swapchain recreation fails.
This commit is contained in:
parent
8a053cadc3
commit
d169f3e32d
@ -185,6 +185,11 @@ auto dev_ret = device_builder.add_pNext(&descriptor_indexing_features)
|
|||||||
.build ();
|
.build ();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To destroy a `vkb::Device`, call `vkb::destroy_device()`.
|
||||||
|
```cpp
|
||||||
|
vkb::destroy_device(vkb_device);
|
||||||
|
```
|
||||||
|
|
||||||
### Queues
|
### Queues
|
||||||
|
|
||||||
By default, `vkb::DeviceBuilder` will enable one queue from each queue family available on the `VkPhysicalDevice`. This is done because in practice, most use cases only need a single queue from each family.
|
By default, `vkb::DeviceBuilder` will enable one queue from each queue family available on the `VkPhysicalDevice`. This is done because in practice, most use cases only need a single queue from each family.
|
||||||
@ -245,3 +250,9 @@ if !(swap_ret){
|
|||||||
// Note that this is the same vkb::Swapchain which was fed into vkb::SwapchainBuilder
|
// Note that this is the same vkb::Swapchain which was fed into vkb::SwapchainBuilder
|
||||||
vkb_swapchain = swap_ret.value();
|
vkb_swapchain = swap_ret.value();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To destroy the swapchain, call `vkb::destroy_swapchain()`. This is null out the VkSwapchainHandle inside of it.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
vkb::destroy_swapchain(vkb_swapchain);
|
||||||
|
```
|
@ -71,20 +71,23 @@ int device_initialization (Init& init) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int create_swapchain (Init& init) {
|
int create_swapchain (Init& init) {
|
||||||
|
|
||||||
vkb::SwapchainBuilder swapchain_builder{ init.device };
|
vkb::SwapchainBuilder swapchain_builder{ init.device };
|
||||||
auto swap_ret = swapchain_builder.use_default_format_selection ()
|
auto swap_ret = swapchain_builder
|
||||||
.use_default_present_mode_selection ()
|
|
||||||
.set_old_swapchain (init.swapchain)
|
.set_old_swapchain (init.swapchain)
|
||||||
.build ();
|
.build ();
|
||||||
|
static int count = 0;
|
||||||
|
count++;
|
||||||
|
std::cout << count << '\n';
|
||||||
if (!swap_ret) {
|
if (!swap_ret) {
|
||||||
std::cout << swap_ret.error ().message () << " " << swap_ret.vk_result () << "\n";
|
std::cout << swap_ret.error ().message () << " " << swap_ret.vk_result () << "\n";
|
||||||
|
init.swapchain.swapchain = VK_NULL_HANDLE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
init.swapchain = swap_ret.value ();
|
init.swapchain = swap_ret.value ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 ()) {
|
||||||
@ -442,11 +445,7 @@ int recreate_swapchain (Init& init, RenderData& data) {
|
|||||||
|
|
||||||
init.swapchain.destroy_image_views (data.swapchain_image_views);
|
init.swapchain.destroy_image_views (data.swapchain_image_views);
|
||||||
|
|
||||||
int created_swapchain = create_swapchain (init);
|
if (0 != create_swapchain (init)) return -1;
|
||||||
while (created_swapchain != 0) {
|
|
||||||
init.swapchain.swapchain = VK_NULL_HANDLE;
|
|
||||||
created_swapchain = create_swapchain (init);
|
|
||||||
}
|
|
||||||
if (0 != create_framebuffers (init, data)) return -1;
|
if (0 != create_framebuffers (init, data)) return -1;
|
||||||
if (0 != create_command_pool (init, data)) return -1;
|
if (0 != create_command_pool (init, data)) return -1;
|
||||||
if (0 != create_command_buffers (init, data)) return -1;
|
if (0 != create_command_buffers (init, data)) return -1;
|
||||||
@ -466,9 +465,8 @@ int draw_frame (Init& init, RenderData& data) {
|
|||||||
|
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||||
return recreate_swapchain (init, data);
|
return recreate_swapchain (init, data);
|
||||||
return 0;
|
|
||||||
} else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
|
} else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
|
||||||
std::cout << "failed to recreate swapchain. Error " << result << "\n";
|
std::cout << "failed to acquire swapchain image. Error " << result << "\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +513,6 @@ int draw_frame (Init& init, RenderData& data) {
|
|||||||
result = vkQueuePresentKHR (data.present_queue, &present_info);
|
result = vkQueuePresentKHR (data.present_queue, &present_info);
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
|
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
|
||||||
return recreate_swapchain (init, data);
|
return recreate_swapchain (init, data);
|
||||||
return 0;
|
|
||||||
} else if (result != VK_SUCCESS) {
|
} else if (result != VK_SUCCESS) {
|
||||||
std::cout << "failed to present swapchain image\n";
|
std::cout << "failed to present swapchain image\n";
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1292,9 +1292,11 @@ VkExtent2D find_extent (
|
|||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
void destroy_swapchain (Swapchain const& swapchain) {
|
void destroy_swapchain (Swapchain& swapchain) {
|
||||||
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE)
|
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE) {
|
||||||
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks);
|
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks);
|
||||||
|
swapchain.swapchain = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
SwapchainBuilder::SwapchainBuilder (Device const& device) {
|
||||||
|
@ -528,7 +528,7 @@ struct Swapchain {
|
|||||||
void destroy_image_views (std::vector<VkImageView> const& image_views);
|
void destroy_image_views (std::vector<VkImageView> const& image_views);
|
||||||
};
|
};
|
||||||
|
|
||||||
void destroy_swapchain (Swapchain const& swapchain);
|
void destroy_swapchain (Swapchain & swapchain);
|
||||||
|
|
||||||
class SwapchainBuilder {
|
class SwapchainBuilder {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user