diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index e5043f41be..7f8c7a95a2 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,32 @@ constexpr std::array R16G16B16A16_UNORM{ } // namespace Alternatives +struct UnsupportedFormatKey { + VkFormat format; + VkFormatFeatureFlags usage; + FormatType type; + + bool operator==(const UnsupportedFormatKey&) const noexcept = default; +}; + +struct UnsupportedFormatKeyHash { + size_t operator()(const UnsupportedFormatKey& key) const noexcept { + size_t seed = std::hash{}(static_cast(key.format)); + seed ^= static_cast(key.usage) + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2); + seed ^= static_cast(key.type) + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2); + return seed; + } +}; + +bool ShouldLogUnsupportedFormat(VkFormat format, VkFormatFeatureFlags usage, FormatType type) { + static std::mutex mutex; + static std::unordered_set logged_keys; + const UnsupportedFormatKey key{format, usage, type}; + std::scoped_lock lock{mutex}; + const auto [it, inserted] = logged_keys.insert(key); + return inserted; +} + [[maybe_unused]] constexpr VkShaderStageFlags GraphicsStageMask = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | @@ -764,10 +791,12 @@ VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags const VkFormat* alternatives = GetFormatAlternatives(wanted_format); if (alternatives == nullptr) { - LOG_ERROR(Render_Vulkan, - "Format={} with usage={} and type={} has no defined alternatives and host " - "hardware does not support it", - wanted_format, wanted_usage, format_type); + if (ShouldLogUnsupportedFormat(wanted_format, wanted_usage, format_type)) { + LOG_ERROR(Render_Vulkan, + "Format={} with usage={} and type={} has no defined alternatives and host " + "hardware does not support it", + wanted_format, wanted_usage, format_type); + } return wanted_format; } @@ -810,10 +839,12 @@ VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags return selected; } - LOG_ERROR(Render_Vulkan, - "Format={} with usage={} and type={} is not supported by the host hardware and " - "doesn't support any of the alternatives", - wanted_format, wanted_usage, format_type); + if (ShouldLogUnsupportedFormat(wanted_format, wanted_usage, format_type)) { + LOG_ERROR(Render_Vulkan, + "Format={} with usage={} and type={} is not supported by the host hardware and " + "doesn't support any of the alternatives", + wanted_format, wanted_usage, format_type); + } return wanted_format; }