From 688e44bc8b07a81b4b39a86485dc6e3dcc7fff27 Mon Sep 17 00:00:00 2001 From: Marshall Mohror Date: Sat, 22 Feb 2020 15:37:42 -0600 Subject: [PATCH] videocore/renderer_opengl/gl_rasterizer_cache: Move bits per pixel table out of function (#5101) * videocore/renderer_opengl/gl_rasterizer_cache: Move bits per pixel table out of function GCC and MSVC copy the table at runtime with the old implementation, which is wasteful and prevents inlining. Unfortunately, static constexpr variables are not legal in constexpr functions, so the table has to be external. Also replaced non-standard assert with DEBUG_ASSERT_MSG. * fix case of table name in assert * set table to private --- .../renderer_opengl/gl_rasterizer_cache.h | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index cd601ef29a..0073ef1d2a 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -101,6 +101,29 @@ enum class ScaleMatch { }; struct SurfaceParams { +private: + static constexpr std::array BPP_TABLE = { + 32, // RGBA8 + 24, // RGB8 + 16, // RGB5A1 + 16, // RGB565 + 16, // RGBA4 + 16, // IA8 + 16, // RG8 + 8, // I8 + 8, // A8 + 8, // IA4 + 4, // I4 + 4, // A4 + 4, // ETC1 + 8, // ETC1A4 + 16, // D16 + 0, + 24, // D24 + 32, // D24S8 + }; + +public: enum class PixelFormat { // First 5 formats are shared between textures and color buffers RGBA8 = 0, @@ -139,30 +162,11 @@ struct SurfaceParams { }; static constexpr unsigned int GetFormatBpp(PixelFormat format) { - constexpr std::array bpp_table = { - 32, // RGBA8 - 24, // RGB8 - 16, // RGB5A1 - 16, // RGB565 - 16, // RGBA4 - 16, // IA8 - 16, // RG8 - 8, // I8 - 8, // A8 - 8, // IA4 - 4, // I4 - 4, // A4 - 4, // ETC1 - 8, // ETC1A4 - 16, // D16 - 0, - 24, // D24 - 32, // D24S8 - }; - - assert(static_cast(format) < bpp_table.size()); - return bpp_table[static_cast(format)]; + const auto format_idx = static_cast(format); + DEBUG_ASSERT_MSG(format_idx < BPP_TABLE.size(), "Invalid pixel format {}", format_idx); + return BPP_TABLE[format_idx]; } + unsigned int GetFormatBpp() const { return GetFormatBpp(pixel_format); }