Browse Source

[vk] avoid calling vkENumerateInstanceFeatures multiple times in init code (#3147)

Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3147
Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
pull/3174/head
lizzie 6 days ago
committed by crueter
parent
commit
5130185d12
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 33
      src/video_core/vulkan_common/vulkan_instance.cpp

33
src/video_core/vulkan_common/vulkan_instance.cpp

@ -20,18 +20,12 @@
namespace Vulkan { namespace Vulkan {
namespace { namespace {
[[nodiscard]] bool AreExtensionsSupported(const vk::InstanceDispatch& dld,
std::span<const char* const> extensions) {
const std::optional properties = vk::EnumerateInstanceExtensionProperties(dld);
if (!properties) {
LOG_ERROR(Render_Vulkan, "Failed to query extension properties");
return false;
}
[[nodiscard]] bool AreExtensionsSupported(const vk::InstanceDispatch& dld, std::vector<VkExtensionProperties> const& properties, std::span<const char* const> extensions) {
for (const char* extension : extensions) { for (const char* extension : extensions) {
const auto it = std::ranges::find_if(*properties, [extension](const auto& prop) {
const auto it = std::ranges::find_if(properties, [extension](const auto& prop) {
return std::strcmp(extension, prop.extensionName) == 0; return std::strcmp(extension, prop.extensionName) == 0;
}); });
if (it == properties->end()) {
if (it == properties.end()) {
LOG_ERROR(Render_Vulkan, "Required instance extension {} is not available", extension); LOG_ERROR(Render_Vulkan, "Required instance extension {} is not available", extension);
return false; return false;
} }
@ -78,14 +72,16 @@ namespace {
if (window_type != Core::Frontend::WindowSystemType::Headless) { if (window_type != Core::Frontend::WindowSystemType::Headless) {
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
} }
if (auto const properties = vk::EnumerateInstanceExtensionProperties(dld); properties) {
#ifdef __APPLE__ #ifdef __APPLE__
if (AreExtensionsSupported(dld, std::array{VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME})) {
extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
if (AreExtensionsSupported(dld, *properties, std::array{VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME}))
extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
#endif #endif
if (enable_validation &&
AreExtensionsSupported(dld, std::array{VK_EXT_DEBUG_UTILS_EXTENSION_NAME})) {
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
if (enable_validation && AreExtensionsSupported(dld, *properties, std::array{VK_EXT_DEBUG_UTILS_EXTENSION_NAME}))
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
// VK_EXT_surface_maintenance1 is required for VK_EXT_swapchain_maintenance1
if (window_type != Core::Frontend::WindowSystemType::Headless && AreExtensionsSupported(dld, *properties, std::array{VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME}))
extensions.push_back(VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME);
} }
return extensions; return extensions;
} }
@ -133,11 +129,10 @@ vk::Instance CreateInstance(const Common::DynamicLibrary& library, vk::InstanceD
LOG_ERROR(Render_Vulkan, "Failed to load Vulkan function pointers"); LOG_ERROR(Render_Vulkan, "Failed to load Vulkan function pointers");
throw vk::Exception(VK_ERROR_INITIALIZATION_FAILED); throw vk::Exception(VK_ERROR_INITIALIZATION_FAILED);
} }
const std::vector<const char*> extensions =
RequiredExtensions(dld, window_type, enable_validation);
if (!AreExtensionsSupported(dld, extensions)) {
std::vector<const char*> const extensions = RequiredExtensions(dld, window_type, enable_validation);
auto const properties = vk::EnumerateInstanceExtensionProperties(dld);
if (!properties || !AreExtensionsSupported(dld, *properties, extensions))
throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT); throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
}
std::vector<const char*> layers = Layers(enable_validation); std::vector<const char*> layers = Layers(enable_validation);
RemoveUnavailableLayers(dld, layers); RemoveUnavailableLayers(dld, layers);

Loading…
Cancel
Save