From f9717f66bbff255456c7546b02f6d8b7fd383b45 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Fri, 13 Oct 2023 10:28:12 -0600 Subject: [PATCH] Add PhysicalDevice::is_extension_present() Convenience function to check if a given extension would be enabled on the physical device. --- src/VkBootstrap.cpp | 5 +++++ src/VkBootstrap.h | 3 +++ tests/bootstrap_tests.cpp | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index 2566c59..774e2bb 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1369,6 +1369,11 @@ bool PhysicalDevice::has_separate_transfer_queue() const { } std::vector PhysicalDevice::get_queue_families() const { return queue_families; } std::vector PhysicalDevice::get_extensions() const { return extensions; } +bool PhysicalDevice::is_extension_present(const char* ext) const { + return std::find_if(std::begin(extensions), std::end(extensions), [ext](std::string const& ext_name) { + return ext_name == ext; + }) != std::end(extensions); +} PhysicalDevice::operator VkPhysicalDevice() const { return this->physical_device; } // ---- Queues ---- // diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 82553dd..f2eb2b9 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -495,6 +495,9 @@ struct PhysicalDevice { // Query the list of extensions which should be enabled std::vector get_extensions() const; + // Returns true if an extension should be enabled on the device + bool is_extension_present(const char* extension) const; + // 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 7531540..fb08dc6 100644 --- a/tests/bootstrap_tests.cpp +++ b/tests/bootstrap_tests.cpp @@ -113,6 +113,9 @@ TEST_CASE("Instance with surface", "[VkBootstrap.bootstrap]") { .set_minimum_version(1, 0) .select(); REQUIRE(phys_dev_ret.has_value()); + + REQUIRE(phys_dev_ret->is_extension_present(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME)); + REQUIRE(!phys_dev_ret->is_extension_present(VK_KHR_16BIT_STORAGE_EXTENSION_NAME)); } vkb::destroy_surface(instance, surface);