From 0aa67e5276a132c865c38dbc998e0d2567fe1c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 6 Sep 2023 15:38:47 +0200 Subject: [PATCH] Add some texture loading safety checks I hit a spurious, non-reproducible debug assert in Archer McLean's Mercury. Just want to rule out some bad code paths. --- GPU/Common/TextureCacheCommon.cpp | 1 + GPU/Vulkan/TextureCacheVulkan.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index c0ce65390d..d035825a59 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -2918,6 +2918,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt } if (plan.isVideo || plan.depth != 1 || plan.decodeToClut8) { + plan.levelsToLoad = 1; plan.maxPossibleLevels = 1; } else { plan.maxPossibleLevels = log2i(std::min(plan.createW, plan.createH)) + 1; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 3920f1aed3..fccab80ad1 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -442,6 +442,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { dstFmt = VULKAN_CLUT8_FORMAT; } + _dbg_assert_(plan.levelsToLoad <= plan.maxPossibleLevels); + // We don't generate mipmaps for 512x512 textures because they're almost exclusively used for menu backgrounds // and similar, which don't really need it. // Also, if using replacements, check that we really can generate mips for this format - that's not possible for compressed ones.