GPU/HW: Don't allow adaptive downsampling at non-pow2 scales

This commit is contained in:
Connor McLaughlin 2021-06-25 00:19:14 +10:00
parent 2fbfd53d51
commit defce709da
2 changed files with 28 additions and 3 deletions

View File

@ -36,4 +36,17 @@ constexpr bool IsPow2(T value)
{ {
return (value & (value - 1)) == 0; return (value & (value - 1)) == 0;
} }
template<typename T>
constexpr T PreviousPow2(T value)
{
if (value == static_cast<T>(0))
return 0;
value |= (value >> 1);
value |= (value >> 2);
value |= (value >> 4);
value |= (value >> 8);
value |= (value >> 16);
return value - (value >> 1);
}
} // namespace Common } // namespace Common

View File

@ -1,4 +1,5 @@
#include "gpu_hw.h" #include "gpu_hw.h"
#include "common/align.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/log.h" #include "common/log.h"
#include "common/state_wrapper.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 && 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)); const u32 new_scale = Common::PreviousPow2(scale);
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; return scale;