From 4a2984ad68ef6a08a3ba0700bd0cd5ae1b47f630 Mon Sep 17 00:00:00 2001 From: Nicholaus Clark Date: Wed, 16 Mar 2022 11:05:47 -0500 Subject: [PATCH] Added pNext chain support for swapchain::get_image_views --- src/VkBootstrap.cpp | 9 ++++++--- src/VkBootstrap.h | 4 +++- tests/bootstrap_tests.cpp | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index df297c8..01bba8f 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1849,16 +1849,19 @@ detail::Result> Swapchain::get_images() { return swapchain_images; } detail::Result> Swapchain::get_image_views() { - - auto swapchain_images_ret = get_images(); + return get_image_views(nullptr); +} +detail::Result> Swapchain::get_image_views(const void* pNext) { + const auto swapchain_images_ret = get_images(); if (!swapchain_images_ret) return swapchain_images_ret.error(); - auto swapchain_images = swapchain_images_ret.value(); + const auto swapchain_images = swapchain_images_ret.value(); std::vector views(swapchain_images.size()); for (size_t i = 0; i < swapchain_images.size(); i++) { VkImageViewCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + createInfo.pNext = pNext; createInfo.image = swapchain_images[i]; createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; createInfo.format = image_format; diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 61b116d..eaddb86 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -759,8 +759,10 @@ struct Swapchain { detail::Result> get_images(); // Returns a vector of VkImageView's to the VkImage's of the swapchain. - // VkImageViews must be destroyed. + // VkImageViews must be destroyed. The pNext chain must be a nullptr or a valid + // structure. detail::Result> get_image_views(); + detail::Result> get_image_views(const void* pNext); void destroy_image_views(std::vector const& image_views); // A conversion function which allows this Swapchain to be used diff --git a/tests/bootstrap_tests.cpp b/tests/bootstrap_tests.cpp index b964e61..3245c3d 100644 --- a/tests/bootstrap_tests.cpp +++ b/tests/bootstrap_tests.cpp @@ -290,6 +290,23 @@ TEST_CASE("Swapchain", "[VkBootstrap.bootstrap]") { REQUIRE(image_views.value().size() > 0); swapchain.destroy_image_views(image_views.value()); } + AND_THEN("Acquire swapchain images views with nullptr pNext chain") { + auto image_views = swapchain.get_image_views(nullptr); + REQUIRE(image_views.has_value()); + REQUIRE(image_views.value().size() > 0); + swapchain.destroy_image_views(image_views.value()); + } + AND_THEN("Acquire swapchain image views with valid pNext chain") { + VkImageViewUsageCreateInfo usage = { + VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO, + nullptr, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT + }; + auto image_views = swapchain.get_image_views(&usage); + REQUIRE(image_views.has_value()); + REQUIRE(image_views.value().size() > 0); + swapchain.destroy_image_views(image_views.value()); + } vkb::destroy_swapchain(swapchain_ret.value()); }