From d18164bd4d09740da2a902c1cfd062bcdd0165a0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 30 Dec 2015 16:54:25 -0800 Subject: [PATCH] d3d9: Clean up some scaling handling. --- GPU/Directx9/TextureCacheDX9.cpp | 39 +++++++++++++++++++++++++------- GPU/GLES/TextureCache.cpp | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 4a0268280b..eb94db1a53 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -55,6 +55,8 @@ namespace DX9 { // Changes more frequent than this will be considered "frequent" and prevent texture scaling. #define TEXCACHE_FRAME_CHANGE_FREQUENT 6 +// Note: only used when hash backoff is disabled. +#define TEXCACHE_FRAME_CHANGE_FREQUENT_REGAIN_TRUST 33 #define TEXCACHE_MAX_TEXELS_SCALED (256*256) // Per frame @@ -246,6 +248,13 @@ void TextureCacheDX9::Invalidate(u32 addr, int size, GPUInvalidationType type) { gpuStats.numTextureInvalidations++; // Start it over from 0 (unless it's safe.) iter->second.numFrames = type == GPU_INVALIDATE_SAFE ? 256 : 0; + if (type == GPU_INVALIDATE_SAFE) { + u32 diff = gpuStats.numFlips - iter->second.lastFrame; + // We still need to mark if the texture is frequently changing, even if it's safely changing. + if (diff < TEXCACHE_FRAME_CHANGE_FREQUENT) { + iter->second.status |= TexCacheEntry::STATUS_CHANGE_FREQUENT; + } + } iter->second.framesUntilNextFullHash = 0; } else if (!iter->second.framebuffer) { iter->second.invalidHint++; @@ -1251,12 +1260,16 @@ void TextureCacheDX9::SetTexture(bool force) { fullhash = QuickTexHash(texaddr, bufw, w, h, format, entry); if (fullhash != entry->fullhash) { hashFail = true; - } else if (entry->GetHashStatus() != TexCacheEntry::STATUS_HASHING && entry->numFrames > TexCacheEntry::FRAMES_REGAIN_TRUST) { - // Reset to STATUS_HASHING. + } else { if (g_Config.bTextureBackoffCache) { - entry->SetHashStatus(TexCacheEntry::STATUS_HASHING); + if (entry->GetHashStatus() != TexCacheEntry::STATUS_HASHING && entry->numFrames > TexCacheEntry::FRAMES_REGAIN_TRUST) { + // Reset to STATUS_HASHING. + entry->SetHashStatus(TexCacheEntry::STATUS_HASHING); + entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT; + } + } else if (entry->numFrames > TEXCACHE_FRAME_CHANGE_FREQUENT_REGAIN_TRUST) { + entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT; } - entry->status &= ~TexCacheEntry::STATUS_CHANGE_FREQUENT; } } @@ -1458,15 +1471,25 @@ void TextureCacheDX9::SetTexture(bool force) { scaleFactor = g_Config.iTexScalingLevel; } + // Rachet down scale factor in low-memory mode. + if (lowMemoryMode_) { + // Keep it even, though, just in case of npot troubles. + scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); + } + // Don't scale the PPGe texture. if (entry->addr > 0x05000000 && entry->addr < 0x08800000) scaleFactor = 1; + if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0) { + // Remember for later that we /wanted/ to scale this texture. + entry->status |= TexCacheEntry::STATUS_TO_SCALE; + scaleFactor = 1; + } - if (scaleFactor != 1 && (entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0) { + if (scaleFactor != 1) { if (texelsScaledThisFrame_ >= TEXCACHE_MAX_TEXELS_SCALED) { entry->status |= TexCacheEntry::STATUS_TO_SCALE; scaleFactor = 1; - // INFO_LOG(G3D, "Skipped scaling for now.."); } else { entry->status &= ~TexCacheEntry::STATUS_TO_SCALE; texelsScaledThisFrame_ += w * h; @@ -1489,7 +1512,7 @@ void TextureCacheDX9::SetTexture(bool force) { } // Mipmapping is only enabled when texture scaling is disabled. - if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) { + if (maxLevel > 0 && scaleFactor == 1) { for (u32 i = 1; i <= maxLevel; i++) { LoadTextureLevel(*entry, i, maxLevel, replaceImages, scaleFactor, dstFmt); } @@ -1840,7 +1863,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, int level, int maxL pool = D3DPOOL_DEFAULT; usage = D3DUSAGE_DYNAMIC; // TODO: Switch to using a staging texture? } - int levels = g_Config.iTexScalingLevel == 1 ? maxLevel + 1 : 1; + int levels = scaleFactor == 1 ? maxLevel + 1 : 1; HRESULT hr = pD3Ddevice->CreateTexture(w, h, levels, usage, (D3DFORMAT)D3DFMT(dstFmt), pool, &texture, NULL); if (FAILED(hr)) { INFO_LOG(G3D, "Failed to create D3D texture"); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index c0652928df..799244d2a4 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1619,7 +1619,7 @@ void TextureCache::SetTexture(bool force) { LoadTextureLevel(*entry, 0, replaceImages, scaleFactor, dstFmt); // Mipmapping only enable when texture scaling disable - if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) { + if (maxLevel > 0 && scaleFactor == 1) { if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { if (badMipSizes) { // WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format);