From 60a2d5c1f6fe094fe5aaf49513b8c6a8a7ae4775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 27 Jun 2023 23:02:31 +0300 Subject: [PATCH] Use static initialization to get the correct masking function --- src/openrct2/drawing/Drawing.cpp | 22 +++++++++++++--------- src/openrct2/drawing/Drawing.h | 3 +-- src/openrct2/platform/Platform.Common.cpp | 2 -- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index dbdbe752a8..5b46494e2c 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -709,30 +709,34 @@ ImageCatalogue ImageId::GetCatalogue() const return ImageCatalogue::UNKNOWN; } -void (*MaskFn)( - int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, - int32_t maskWrap, int32_t colourWrap, int32_t dstWrap) - = nullptr; - -void MaskInit() +static auto GetMaskFunction() { if (AVX2Available()) { LOG_VERBOSE("registering AVX2 mask function"); - MaskFn = MaskAvx2; + return MaskAvx2; } else if (SSE41Available()) { LOG_VERBOSE("registering SSE4.1 mask function"); - MaskFn = MaskSse4_1; + return MaskSse4_1; } else { LOG_VERBOSE("registering scalar mask function"); - MaskFn = MaskScalar; + return MaskScalar; } } +static const auto MaskFunc = GetMaskFunction(); + +void MaskFn( + int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, + int32_t maskWrap, int32_t colourWrap, int32_t dstWrap) +{ + MaskFunc(width, height, maskSrc, colourSrc, dst, maskWrap, colourWrap, dstWrap); +} + void GfxFilterPixel(DrawPixelInfo& dpi, const ScreenCoordsXY& coords, FilterPaletteID palette) { GfxFilterRect(dpi, { coords, coords }, palette); diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 690b6c3e30..35da0cfd23 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -597,9 +597,8 @@ void MaskSse4_1( void MaskAvx2( int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap); -void MaskInit(); -extern void (*MaskFn)( +void MaskFn( int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst, int32_t maskWrap, int32_t colourWrap, int32_t dstWrap); diff --git a/src/openrct2/platform/Platform.Common.cpp b/src/openrct2/platform/Platform.Common.cpp index 83b4e13fa9..fbbfd2afb0 100644 --- a/src/openrct2/platform/Platform.Common.cpp +++ b/src/openrct2/platform/Platform.Common.cpp @@ -47,8 +47,6 @@ namespace Platform #ifdef __ANDROID__ Platform::AndroidInitClassLoader(); #endif // __ANDROID__ - - MaskInit(); } }