diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 804cd04..5bf56bb 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1399,6 +1399,17 @@ bool PhysicalDevice::enable_extension_if_present(const char* extension) { } return false; } +bool PhysicalDevice::enable_extensions_if_present(const std::vector& extensions) { + for (const auto extension : extensions) { + auto it = std::find_if(std::begin(available_extensions), + std::end(available_extensions), + [extension](std::string const& ext_name) { return ext_name == extension; }); + if (it == std::end(available_extensions)) return false; + } + for (const auto extension : extensions) + extensions_to_enable.push_back(extension); + return true; +} PhysicalDevice::operator VkPhysicalDevice() const { return this->physical_device; } diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index a491a6c..c77033b 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -509,6 +509,10 @@ struct PhysicalDevice { // Returns true the extension is present. bool enable_extension_if_present(const char* extension); + // If all the given extensions are present, make all the extensions be enabled on the device. + // Returns true if all the extensions are present. + bool enable_extensions_if_present(const std::vector& extensions); + // A conversion function which allows this PhysicalDevice to be used // in places where VkPhysicalDevice would have been used. operator VkPhysicalDevice() const; diff --git a/tests/bootstrap_tests.cpp b/tests/bootstrap_tests.cpp index b252cf6..21affd6 100644 --- a/tests/bootstrap_tests.cpp +++ b/tests/bootstrap_tests.cpp @@ -121,6 +121,14 @@ TEST_CASE("Instance with surface", "[VkBootstrap.bootstrap]") { REQUIRE(phys_dev_ret->enable_extension_if_present(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME)); REQUIRE(!phys_dev_ret->enable_extension_if_present(VK_KHR_16BIT_STORAGE_EXTENSION_NAME)); + const std::vector extension_set_1 = { VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, + VK_EXT_ROBUSTNESS_2_EXTENSION_NAME }; + const std::vector extension_set_2 = { VK_KHR_16BIT_STORAGE_EXTENSION_NAME, + VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME }; + + REQUIRE(phys_dev_ret->enable_extensions_if_present(extension_set_1)); + REQUIRE(!phys_dev_ret->enable_extensions_if_present(extension_set_2)); + auto device_ret = vkb::DeviceBuilder(phys_dev_ret.value()).build(); REQUIRE(device_ret.has_value()); vkb::destroy_device(device_ret.value());