Skip to content

Commit

Permalink
Added an overlod to supports_given_extensions, also listing which ext…
Browse files Browse the repository at this point in the history
…ensions are missing if some are missing
  • Loading branch information
johannesugb committed Oct 9, 2023
1 parent 5fe5ed5 commit 018017b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
17 changes: 13 additions & 4 deletions auto_vk_toolkit/include/context_vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,20 @@ namespace avk
#endif

/** Checks whether the given physical device supports given extensions.
* @return True if the physical device supports all the extensions, false otherwise.
*/
bool supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector<const char*>& aExtensionsInQuestion) const;
* @param aPhysicalDevice The physical device whose extensions shall be compared with the extensions in question
* @param aExtensionsInQuestion The extensions in question, which we want to know of if the physical device supports them
* @return True if the physical device supports all the extensions, false otherwise.
*/
bool supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector<const char*>& aExtensionsInQuestion) const;

/** Checks whether the given physical device supports given extensions.
* @param aPhysicalDeviceExtensionsAvailable List of physical device extensions that are available
* @param aExtensionsInQuestion The extensions in question, which we want to know of if they are contained in the list of available extensions
* @return True if the physical device supports all the extensions, false otherwise.
*/
bool supports_given_extensions(const std::vector<vk::ExtensionProperties>& aPhysicalDeviceExtensionsAvailable, const std::vector<const char*>& aExtensionsInQuestion) const;

/** Pick the physical device which looks to be the most promising one */
/** Pick the physical device which looks to be the most promising one */
void pick_physical_device();

/** Gets the right resolution for the given window, considering the window's size and surface capabilities */
Expand Down
39 changes: 32 additions & 7 deletions auto_vk_toolkit/src/context_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,19 +967,25 @@ namespace avk
bool context_vulkan::supports_given_extensions(const vk::PhysicalDevice& aPhysicalDevice, const std::vector<const char*>& aExtensionsInQuestion) const
{
// Search for each extension requested!
auto deviceExtensions = aPhysicalDevice.enumerateDeviceExtensionProperties();
return supports_given_extensions(deviceExtensions, aExtensionsInQuestion);
}

bool context_vulkan::supports_given_extensions(const std::vector<vk::ExtensionProperties>& aPhysicalDeviceExtensionsAvailable, const std::vector<const char*>& aExtensionsInQuestion) const
{
for (const auto& extensionName : aExtensionsInQuestion) {
auto deviceExtensions = aPhysicalDevice.enumerateDeviceExtensionProperties();
// See if we can find the current requested extension in the array of all device extensions
auto result = std::ranges::find_if(deviceExtensions,
// See if we can find the current requested extension in the array of all device extensions:
auto result = std::ranges::find_if(aPhysicalDeviceExtensionsAvailable,
[extensionName](const vk::ExtensionProperties& devext) {
return strcmp(extensionName, devext.extensionName) == 0;
});
if (result == std::end(deviceExtensions)) {
if (result == std::end(aPhysicalDeviceExtensionsAvailable)) {
// could not find the device extension
return false;
}
}
return true; // All extensions supported

}

void context_vulkan::pick_physical_device()
Expand Down Expand Up @@ -1040,15 +1046,34 @@ namespace avk
}
}

// Check if extensions are required
if (!supports_given_extensions(physicalDevice, sRequiredDeviceExtensions)) {
// Check if Auto-Vk-Toolkit-required extensions are supported
auto deviceExtensions = physicalDevice.enumerateDeviceExtensionProperties();
if (!supports_given_extensions(deviceExtensions, sRequiredDeviceExtensions)) {
LOG_WARNING(fmt::format("Depreciating physical device \"{}\" because it does not support all extensions required by Auto-Vk-Toolkit.", properties.deviceName));
for (const auto& extensionName : sRequiredDeviceExtensions) {
auto extensionInfo = std::string(" - ") + extensionName + " ...";
while (extensionInfo.length() < 60) {
extensionInfo += ".";
}
auto result = std::ranges::find_if(deviceExtensions, [extensionName](const vk::ExtensionProperties& devext) { return strcmp(extensionName, devext.extensionName) == 0; });
extensionInfo += result != deviceExtensions.end() ? " supported" : " NOT supported";
LOG_WARNING(extensionInfo);
}
score = 0;
}

// Check if extensions are required
// Check if user-requested extensions are supported
if (!supports_given_extensions(physicalDevice, mSettings.mRequiredDeviceExtensions.mExtensions)) {
LOG_WARNING(fmt::format("Depreciating physical device \"{}\" because it does not support all extensions required by the application.", properties.deviceName));
for (const auto& extensionName : mSettings.mRequiredDeviceExtensions.mExtensions) {
auto extensionInfo = std::string(" - ") + extensionName + " ...";
while (extensionInfo.length() < 60) {
extensionInfo += ".";
}
auto result = std::ranges::find_if(deviceExtensions, [extensionName](const vk::ExtensionProperties& devext) { return strcmp(extensionName, devext.extensionName) == 0; });
extensionInfo += result != deviceExtensions.end() ? " supported" : " NOT supported";
LOG_WARNING(extensionInfo);
}
score = 0;
}

Expand Down

0 comments on commit 018017b

Please sign in to comment.