diff --git a/src/GPU3D_Compute.cpp b/src/GPU3D_Compute.cpp index 9d5a2378..c22a66b9 100644 --- a/src/GPU3D_Compute.cpp +++ b/src/GPU3D_Compute.cpp @@ -21,6 +21,8 @@ #include #include +#include "Utils.h" + #include "OpenGLSupport.h" #include "GPU3D_Compute_shaders.h" @@ -302,7 +304,7 @@ void ComputeRenderer::Reset(GPU& gpu) void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinates) { - unsigned char TileScale; + u8 TileScale; CurGLCompositor.SetScaleFactor(scale); @@ -319,9 +321,12 @@ void ComputeRenderer::SetRenderSettings(int scale, bool highResolutionCoordinate //Starting at 4.5x we want to double TileSize every time scale doubles TileScale = 2 * ScaleFactor / 9; - TileScale &= ~(TileScale >> 1); + TileScale = GetMSBit(TileScale); TileScale <<= 1; TileScale += TileScale == 0; + + std::printf("Scale: %d\n", ScaleFactor); + std::printf("TileScale: %d\n", TileScale); TileSize = std::min(8 * TileScale, 32); CoarseTileCountY = TileSize < 32 ? 4 : 6; diff --git a/src/Utils.h b/src/Utils.h index 63be217b..e6444c51 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -38,6 +38,20 @@ std::pair, u32> PadToPowerOf2(const u8* data, u32 len) noe std::unique_ptr CopyToUnique(const u8* data, u32 len) noexcept; +template +T GetMSBit(T val) +{ + val |= (val >> 1); + val |= (val >> 2); + val |= (val >> 4); + + if constexpr(sizeof(val) > 1) val |= (val >> 8); + if constexpr(sizeof(val) > 2) val |= (val >> 16); + if constexpr(sizeof(val) > 4) val |= (val >> 32); + + return val - (val >> 1); +} + } #endif // MELONDS_UTILS_H