implemented enable_extensions_if_present and tests

This commit is contained in:
Diamond-D0gs 2024-01-18 16:19:24 -05:00 committed by Charles Giessen
parent 382259e32b
commit 0af4cb5055
3 changed files with 23 additions and 0 deletions

View File

@ -1399,6 +1399,17 @@ bool PhysicalDevice::enable_extension_if_present(const char* extension) {
} }
return false; return false;
} }
bool PhysicalDevice::enable_extensions_if_present(const std::vector<const char*>& 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; } PhysicalDevice::operator VkPhysicalDevice() const { return this->physical_device; }

View File

@ -509,6 +509,10 @@ struct PhysicalDevice {
// Returns true the extension is present. // Returns true the extension is present.
bool enable_extension_if_present(const char* extension); 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<const char*>& extensions);
// A conversion function which allows this PhysicalDevice to be used // A conversion function which allows this PhysicalDevice to be used
// in places where VkPhysicalDevice would have been used. // in places where VkPhysicalDevice would have been used.
operator VkPhysicalDevice() const; operator VkPhysicalDevice() const;

View File

@ -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_EXT_ROBUSTNESS_2_EXTENSION_NAME));
REQUIRE(!phys_dev_ret->enable_extension_if_present(VK_KHR_16BIT_STORAGE_EXTENSION_NAME)); REQUIRE(!phys_dev_ret->enable_extension_if_present(VK_KHR_16BIT_STORAGE_EXTENSION_NAME));
const std::vector<const char*> extension_set_1 = { VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
VK_EXT_ROBUSTNESS_2_EXTENSION_NAME };
const std::vector<const char*> 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(); auto device_ret = vkb::DeviceBuilder(phys_dev_ret.value()).build();
REQUIRE(device_ret.has_value()); REQUIRE(device_ret.has_value());
vkb::destroy_device(device_ret.value()); vkb::destroy_device(device_ret.value());