diff options
| author | mitaclaw <140017135+mitaclaw@users.noreply.github.com> | 2024-09-21 14:50:23 -0700 |
|---|---|---|
| committer | mitaclaw <140017135+mitaclaw@users.noreply.github.com> | 2025-01-01 09:52:03 -0800 |
| commit | d92c68e1de481b509d92bbdd68f83c9a92f254aa (patch) | |
| tree | f0d502704016a0e79e5bafbb052a3e2e1b09b764 /Source/Core/VideoBackends | |
| parent | 110d32729ecbe5b19df9b2cc76de630334410589 (diff) | |
Simplify `std::find_if` with `Common::Contains`
Diffstat (limited to 'Source/Core/VideoBackends')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp | 14 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VulkanContext.cpp | 37 |
2 files changed, 17 insertions, 34 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp index bbe94944fb..f7260bdf0c 100644 --- a/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKSwapChain.cpp @@ -8,6 +8,7 @@ #include "Common/Assert.h" #include "Common/CommonFuncs.h" +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" @@ -243,31 +244,24 @@ bool SwapChain::SelectPresentMode() &mode_count, present_modes.data()); ASSERT(res == VK_SUCCESS); - // Checks if a particular mode is supported, if it is, returns that mode. - auto CheckForMode = [&present_modes](VkPresentModeKHR check_mode) { - auto it = std::find_if(present_modes.begin(), present_modes.end(), - [check_mode](VkPresentModeKHR mode) { return check_mode == mode; }); - return it != present_modes.end(); - }; - // If vsync is enabled, use VK_PRESENT_MODE_FIFO_KHR. // This check should not fail with conforming drivers, as the FIFO present mode is mandated by // the specification (VK_KHR_swapchain). In case it isn't though, fall through to any other mode. - if (m_vsync_enabled && CheckForMode(VK_PRESENT_MODE_FIFO_KHR)) + if (m_vsync_enabled && Common::Contains(present_modes, VK_PRESENT_MODE_FIFO_KHR)) { m_present_mode = VK_PRESENT_MODE_FIFO_KHR; return true; } // Prefer screen-tearing, if possible, for lowest latency. - if (CheckForMode(VK_PRESENT_MODE_IMMEDIATE_KHR)) + if (Common::Contains(present_modes, VK_PRESENT_MODE_IMMEDIATE_KHR)) { m_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; return true; } // Use optimized-vsync above vsync. - if (CheckForMode(VK_PRESENT_MODE_MAILBOX_KHR)) + if (Common::Contains(present_modes, VK_PRESENT_MODE_MAILBOX_KHR)) { m_present_mode = VK_PRESENT_MODE_MAILBOX_KHR; return true; diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index ed3b709529..3640752231 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -9,6 +9,7 @@ #include "Common/Assert.h" #include "Common/CommonFuncs.h" +#include "Common/Contains.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" @@ -170,15 +171,12 @@ bool VulkanContext::CheckValidationLayerAvailablility() res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data()); ASSERT(res == VK_SUCCESS); - bool supports_validation_layers = - std::find_if(layer_list.begin(), layer_list.end(), [](const auto& it) { - return strcmp(it.layerName, VALIDATION_LAYER_NAME) == 0; - }) != layer_list.end(); + bool supports_validation_layers = Common::Contains( + layer_list, std::string_view{VALIDATION_LAYER_NAME}, &VkLayerProperties::layerName); bool supports_debug_utils = - std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { - return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; - }) != extension_list.end(); + Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME}, + &VkExtensionProperties::extensionName); if (!supports_debug_utils && supports_validation_layers) { @@ -197,9 +195,8 @@ bool VulkanContext::CheckValidationLayerAvailablility() extension_list.data()); ASSERT(res == VK_SUCCESS); supports_debug_utils = - std::find_if(extension_list.begin(), extension_list.end(), [](const auto& it) { - return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0; - }) != extension_list.end(); + Common::Contains(extension_list, std::string_view{VK_EXT_DEBUG_UTILS_EXTENSION_NAME}, + &VkExtensionProperties::extensionName); } // Check for both VK_EXT_debug_utils and VK_LAYER_KHRONOS_validation @@ -330,16 +327,10 @@ bool VulkanContext::SelectInstanceExtensions(std::vector<const char*>* extension auto AddExtension = [&](const char* name, bool required) { bool extension_supported = - std::find_if(available_extension_list.begin(), available_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != available_extension_list.end(); - extension_supported = - extension_supported || - std::find_if(validation_layer_extension_list.begin(), validation_layer_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != validation_layer_extension_list.end(); + Common::Contains(available_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName) || + Common::Contains(validation_layer_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName); if (extension_supported) { @@ -648,10 +639,8 @@ bool VulkanContext::SelectDeviceExtensions(bool enable_surface) INFO_LOG_FMT(VIDEO, "Available extension: {}", extension_properties.extensionName); auto AddExtension = [&](const char* name, bool required) { - if (std::find_if(available_extension_list.begin(), available_extension_list.end(), - [&](const VkExtensionProperties& properties) { - return !strcmp(name, properties.extensionName); - }) != available_extension_list.end()) + if (Common::Contains(available_extension_list, std::string_view{name}, + &VkExtensionProperties::extensionName)) { INFO_LOG_FMT(VIDEO, "Enabling extension: {}", name); m_device_extensions.push_back(name); |
