From 98981cc72486657bc1e91b2c1e86a0f14d63e23f Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Thu, 1 Dec 2011 02:40:58 +0100 Subject: [PATCH] Fixed EFB cache index computations in OpenGL renderer. The previous computation was very likely to go out of array bounds, which could result in crashes on EFB access. Also, the cache size was rounded down instead of up. This is a problem since EFB_HEIGHT (528) is not a multiple of EFB_CACHE_RECT_SIZE (64). --- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 792c14960e..6541188074 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -125,8 +125,8 @@ static std::thread scrshotThread; // EFB cache related const u32 EFB_CACHE_RECT_SIZE = 64; // Cache 64x64 blocks. -const u32 EFB_CACHE_WIDTH = EFB_WIDTH / EFB_CACHE_RECT_SIZE; -const u32 EFB_CACHE_HEIGHT = EFB_HEIGHT / EFB_CACHE_RECT_SIZE; +const u32 EFB_CACHE_WIDTH = (EFB_WIDTH + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; // round up +const u32 EFB_CACHE_HEIGHT = (EFB_HEIGHT + EFB_CACHE_RECT_SIZE - 1) / EFB_CACHE_RECT_SIZE; static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; static std::vector s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR @@ -698,7 +698,8 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) if (!g_ActiveConfig.bEFBAccessEnable) return 0; - u32 cacheRectIdx = ((x / EFB_CACHE_RECT_SIZE) << 16) | (y / EFB_CACHE_RECT_SIZE); + u32 cacheRectIdx = (y / EFB_CACHE_RECT_SIZE) * EFB_CACHE_WIDTH + + (x / EFB_CACHE_RECT_SIZE); // Get the rectangular target region containing the EFB pixel EFBRectangle efbPixelRc;