diff --git a/src/common/align.h b/src/common/align.h index ed893e32f..9708b0249 100644 --- a/src/common/align.h +++ b/src/common/align.h @@ -36,4 +36,17 @@ constexpr bool IsPow2(T value) { return (value & (value - 1)) == 0; } +template +constexpr T PreviousPow2(T value) +{ + if (value == static_cast(0)) + return 0; + + value |= (value >> 1); + value |= (value >> 2); + value |= (value >> 4); + value |= (value >> 8); + value |= (value >> 16); + return value - (value >> 1); +} } // namespace Common diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index c62d42c38..d66d2514e 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1,4 +1,5 @@ #include "gpu_hw.h" +#include "common/align.h" #include "common/assert.h" #include "common/log.h" #include "common/state_wrapper.h" @@ -221,10 +222,21 @@ u32 GPU_HW::CalculateResolutionScale() const } if (g_settings.gpu_downsample_mode == GPUDownsampleMode::Adaptive && m_supports_adaptive_downsampling && scale > 1 && - (scale % 2) != 0) + !Common::IsPow2(scale)) { - Log_InfoPrintf("Resolution scale %u not supported for adaptive smoothing, using %u", scale, (scale - 1)); - scale--; + const u32 new_scale = Common::PreviousPow2(scale); + Log_InfoPrintf("Resolution scale %ux not supported for adaptive smoothing, using %ux", scale, new_scale); + + if (g_settings.gpu_resolution_scale != 0) + { + g_host_interface->AddFormattedOSDMessage( + 10.0f, + g_host_interface->TranslateString("OSDMessage", + "Resolution scale %ux not supported for adaptive smoothing, using %ux."), + scale, new_scale); + } + + scale = new_scale; } return scale;