From c859aaae84642ded91fe046ef91404431c84f48b Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 10 Aug 2012 12:36:19 +0200 Subject: [optimization] TextureCacheBase: Slightly loosen the requirements for reusing mipmapped textures --- Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/Src/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index a5c390df3d..65407f2a0e 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -363,8 +363,10 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, } // 2. b) For normal textures, all texture parameters need to match + // NOTE: maxlevel is specified via render states, so it doesn't need to match exactly + // TODO: D3D9 doesn't support min_lod, so we should check for this here if (address == entry->addr && tex_hash == entry->hash && full_format == entry->format && - entry->num_mipmaps == maxlevel && entry->native_width == nativeW && entry->native_height == nativeH) + entry->num_mipmaps > maxlevel && entry->native_width == nativeW && entry->native_height == nativeH) { goto return_entry; } @@ -374,7 +376,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, // // TODO: Don't we need to force texture decoding to RGBA8 for dynamic EFB copies? // TODO: Actually, it should be enough if the internal texture format matches... - if ((entry->type == TCET_NORMAL && width == entry->native_width && height == entry->native_height && full_format == entry->format && entry->num_mipmaps == maxlevel) + if ((entry->type == TCET_NORMAL && width == entry->native_width && height == entry->native_height && full_format == entry->format && entry->num_mipmaps > maxlevel) || (entry->type == TCET_EC_DYNAMIC && entry->native_width == width && entry->native_height == height)) { // reuse the texture @@ -421,9 +423,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, // Sometimes, we can get around recreating a texture if only the number of mip levels changes // e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states // Thus, we don't update this member for every Load, but just whenever the texture gets recreated - // - // TODO: Won't we end up recreating textures all the time because maxlevel doesn't necessarily equal texLevels? - entry->num_mipmaps = maxlevel; // TODO: Does this actually work? We can't really adjust mipmap settings per-stage... + // TODO: D3D9 doesn't support min_lod. We should add a workaround for that here! + entry->num_mipmaps = maxlevel + 1; // TODO: Does this actually work? We can't really adjust mipmap settings per-stage... entry->type = TCET_NORMAL; GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true); -- cgit v1.2.3 From ee3d6d66d77dd40cc69e0cf219833d0c0a3a5be3 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 10 Aug 2012 13:09:16 +0200 Subject: [cleanup] [bugfix] TextureCacheBase: Cleanup and simplify mipmapping logic. Possibly fixes a bug or two. --- Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'Source/Core/VideoCommon/Src/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index 65407f2a0e..21e4a9d989 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -211,6 +211,9 @@ void TextureCache::ClearRenderTargets() bool TextureCache::CheckForCustomTextureLODs(u64 tex_hash, int texformat, unsigned int levels) { + if (levels == 1) + return false; + // Just checking if the necessary files exist, if they can't be loaded or have incorrect dimensions LODs will be black char texBasePathTemp[MAX_PATH]; char texPathTemp[MAX_PATH]; @@ -293,7 +296,7 @@ void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level) TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, u32 address, unsigned int width, unsigned int height, int texformat, - unsigned int tlutaddr, int tlutfmt, bool UseNativeMips, unsigned int maxlevel, bool from_tmem) + unsigned int tlutaddr, int tlutfmt, bool use_mipmaps, unsigned int maxlevel, bool from_tmem) { if (0 == address) return NULL; @@ -363,8 +366,6 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, } // 2. b) For normal textures, all texture parameters need to match - // NOTE: maxlevel is specified via render states, so it doesn't need to match exactly - // TODO: D3D9 doesn't support min_lod, so we should check for this here if (address == entry->addr && tex_hash == entry->hash && full_format == entry->format && entry->num_mipmaps > maxlevel && entry->native_width == nativeW && entry->native_height == nativeH) { @@ -406,15 +407,12 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, pcfmt = TexDecoder_Decode(temp, src_data, expandedWidth, expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures); - // TODO: Cleanup. Plus, we still autogenerate mipmaps in certain cases (we shouldn't do that) - bool isPow2; unsigned int texLevels; - isPow2 = !((width & (width - 1)) || (height & (height - 1))); - texLevels = (isPow2 && maxlevel) ? GetPow2(std::max(width, height)) : !isPow2; - texLevels = maxlevel ? std::min(texLevels, maxlevel + 1) : texLevels; + bool use_native_mips; + texLevels = use_mipmaps ? (maxlevel + 1) : 1; using_custom_lods = using_custom_texture && CheckForCustomTextureLODs(tex_hash, texformat, texLevels); - UseNativeMips = UseNativeMips && !using_custom_lods && (width == nativeW && height == nativeH); // Only load native mips if their dimensions fit to our virtual texture dimensions - texLevels = (UseNativeMips || using_custom_lods) ? texLevels : !isPow2; + use_native_mips = use_mipmaps && !using_custom_lods && (width == nativeW && height == nativeH); // Only load native mips if their dimensions fit to our virtual texture dimensions + texLevels = (use_native_mips || using_custom_lods) ? texLevels : 1; // create the entry/texture if (NULL == entry) { @@ -424,7 +422,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, // e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states // Thus, we don't update this member for every Load, but just whenever the texture gets recreated // TODO: D3D9 doesn't support min_lod. We should add a workaround for that here! - entry->num_mipmaps = maxlevel + 1; // TODO: Does this actually work? We can't really adjust mipmap settings per-stage... + entry->num_mipmaps = maxlevel + 1; entry->type = TCET_NORMAL; GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true); @@ -443,7 +441,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, DumpTexture(entry, 0); // load mips - TODO: Loading mipmaps from tmem is untested! - if (texLevels > 1 && pcfmt != PC_TEX_FMT_NONE && UseNativeMips) + if (texLevels > 1 && pcfmt != PC_TEX_FMT_NONE && use_native_mips) { const unsigned int bsdepth = TexDecoder_GetTexelSizeInNibbles(texformat); -- cgit v1.2.3 From 069d949a572ea2543e86819487c0ba34e5564af8 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 10 Aug 2012 13:13:51 +0200 Subject: [cleanup] TextureCache: Kill the autogen_mipmap parameter --- Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoCommon/Src/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index 21e4a9d989..dc80d98639 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -435,7 +435,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, else entry->type = TCET_NORMAL; // load texture - entry->Load(width, height, expandedWidth, 0, (texLevels == 0)); + entry->Load(width, height, expandedWidth, 0); if (g_ActiveConfig.bDumpTextures && !using_custom_texture) DumpTexture(entry, 0); @@ -470,7 +470,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, expandedHeight = (currentHeight + bsh) & (~bsh); TexDecoder_Decode(temp, *ptr, expandedWidth, expandedHeight, texformat, tlutaddr, tlutfmt, g_ActiveConfig.backend_info.bUseRGBATextures); - entry->Load(currentWidth, currentHeight, expandedWidth, level, false); + entry->Load(currentWidth, currentHeight, expandedWidth, level); if (g_ActiveConfig.bDumpTextures) DumpTexture(entry, level); @@ -493,7 +493,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int stage, unsigned int currentHeight = (mipHeight > 0) ? mipHeight : 1; LoadCustomTexture(tex_hash, texformat, level, currentWidth, currentHeight); - entry->Load(currentWidth, currentHeight, currentWidth, level, false); + entry->Load(currentWidth, currentHeight, currentWidth, level); mipWidth >>= 1; mipHeight >>= 1; -- cgit v1.2.3