diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 7c3b0d3b92..e7a4b87012 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -328,7 +328,7 @@ SamplerCacheKey TextureCacheCommon::GetFramebufferSamplingParams(u16 bufferWidth // Kill any mipmapping settings. key.mipEnable = false; key.mipFilt = false; - key.aniso = 0.0; + key.aniso = 0.0f; key.maxLevel = 0.0f; key.lodBias = 0.0f; @@ -858,7 +858,7 @@ void TextureCacheCommon::HandleTextureChange(TexCacheEntry *const entry, const c if (doDelete) { ForgetLastTexture(); ReleaseTexture(entry, true); - entry->status &= ~TexCacheEntry::STATUS_IS_SCALED; + entry->status &= ~(TexCacheEntry::STATUS_IS_SCALED_OR_REPLACED | TexCacheEntry::STATUS_TO_REPLACE); } // Mark as hashing, if marked as reliable. @@ -1537,7 +1537,7 @@ ReplacedTexture *TextureCacheCommon::FindReplacement(TexCacheEntry *entry, int & if (replaced->State() == ReplacementState::ACTIVE) { replaced->GetSize(0, &w, &h); // Consider it already "scaled.". - entry->status |= TexCacheEntry::STATUS_IS_SCALED; + entry->status |= TexCacheEntry::STATUS_IS_SCALED_OR_REPLACED; } // Remove the flag, even if it was invalid. @@ -2073,6 +2073,8 @@ void TextureCacheCommon::ApplyTexture() { // This prevents temporary scaling perf hits on the first second of video. if (IsVideo(entry->addr)) { entry->status |= TexCacheEntry::STATUS_CHANGE_FREQUENT | TexCacheEntry::STATUS_VIDEO; + } else { + entry->status &= ~TexCacheEntry::STATUS_VIDEO; } if (nextNeedsRehash_) { @@ -2782,7 +2784,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt plan.scaleFactor = 1; } else { entry->status &= ~TexCacheEntry::STATUS_TO_SCALE; - entry->status |= TexCacheEntry::STATUS_IS_SCALED; + entry->status |= TexCacheEntry::STATUS_IS_SCALED_OR_REPLACED; texelsScaledThisFrame_ += plan.w * plan.h; } } @@ -2819,17 +2821,18 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt } if (canReplace) { + // This is the "trigger point" for replacement. plan.replaced = FindReplacement(entry, plan.w, plan.h, plan.depth); - plan.replaceValid = plan.replaced ? plan.replaced->State() == ReplacementState::ACTIVE : false; + plan.doReplace = plan.replaced ? plan.replaced->State() == ReplacementState::ACTIVE : false; } else { plan.replaced = nullptr; - plan.replaceValid = false; + plan.doReplace = false; } // NOTE! Last chance to change scale factor here! plan.saveTexture = false; - if (plan.replaceValid) { + if (plan.doReplace) { // We're replacing, so we won't scale. plan.scaleFactor = 1; // We're ignoring how many levels were specified - instead we just load all available from the replacer. @@ -2839,7 +2842,7 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt // But, we still need to create the texture at a larger size. plan.replaced->GetSize(0, &plan.createW, &plan.createH); } else { - if (replacer_.Enabled() && !plan.replaceValid && plan.depth == 1 && canReplace) { + if (replacer_.Enabled() && !plan.doReplace && plan.depth == 1 && canReplace) { ReplacedTextureDecodeInfo replacedInfo; // TODO: Do we handle the race where a replacement becomes valid AFTER this but before we save? replacedInfo.cachekey = entry->CacheKey(); @@ -2889,7 +2892,7 @@ void TextureCacheCommon::LoadTextureLevel(TexCacheEntry &entry, uint8_t *data, s PROFILE_THIS_SCOPE("decodetex"); - if (plan.replaceValid) { + if (plan.doReplace) { plan.replaced->GetSize(srcLevel, &w, &h); double replaceStart = time_now_d(); plan.replaced->CopyLevelTo(srcLevel, data, dataSize, stride); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index b70e1ea1a4..67e78c6f47 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -133,7 +133,7 @@ struct TexCacheEntry { STATUS_CHANGE_FREQUENT = 0x10, // Changes often (less than 6 frames in between.) STATUS_CLUT_RECHECK = 0x20, // Another texture with same addr had a hashfail. STATUS_TO_SCALE = 0x80, // Pending texture scaling in a later frame. - STATUS_IS_SCALED = 0x100, // Has been scaled (can't be replaceImages'd.) + STATUS_IS_SCALED_OR_REPLACED = 0x100, // Has been scaled already (ignored for replacement checks). STATUS_TO_REPLACE = 0x0200, // Pending texture replacement. // When hashing large textures, we optimize 512x512 down to 512x272 by default, since this // is commonly the only part accessed. If access is made above 272, we hash the entire @@ -287,14 +287,14 @@ struct BuildTexturePlan { // The replacement for the texture. ReplacedTexture *replaced; // Need to only check once since it can change during the load! - bool replaceValid; + bool doReplace; bool saveTexture; // TODO: Expand32 should probably also be decided in PrepareBuildTexture. bool decodeToClut8; void GetMipSize(int level, int *w, int *h) const { - if (replaceValid) { + if (doReplace) { replaced->GetSize(level, w, h); return; } diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index d26d48a5fa..aed4f29b07 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -261,7 +261,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { } DXGI_FORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); - if (plan.replaceValid) { + if (plan.doReplace) { dstFmt = ToDXGIFormat(plan.replaced->Format()); } else if (plan.scaleFactor > 1 || plan.saveTexture) { dstFmt = DXGI_FORMAT_B8G8R8A8_UNORM; @@ -298,7 +298,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { int stride = 0; int dataSize; - if (plan.replaceValid) { + if (plan.doReplace) { int blockSize = 0; if (Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), &blockSize)) { stride = ((mipWidth + 3) & ~3) * blockSize / 4; // Number of blocks * 4 * Size of a block / 4 @@ -404,7 +404,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { entry->status &= ~TexCacheEntry::STATUS_NO_MIPS; } - if (plan.replaceValid) { + if (plan.doReplace) { entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus())); if (!Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), nullptr)) { diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 3de9c870c1..ef823b3673 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -230,7 +230,7 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) { } D3DFORMAT dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); - if (plan.replaceValid) { + if (plan.doReplace) { dstFmt = ToD3D9Format(plan.replaced->Format()); } else if (plan.scaleFactor > 1 || plan.saveTexture) { dstFmt = D3DFMT_A8R8G8B8; @@ -316,7 +316,7 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) { entry->status |= TexCacheEntry::STATUS_3D; } - if (plan.replaceValid) { + if (plan.doReplace) { entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus())); if (!Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), nullptr)) { diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 9445d67421..437144e296 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -246,7 +246,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { int th = plan.createH; Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); - if (plan.replaceValid) { + if (plan.doReplace) { plan.replaced->GetSize(plan.baseLevelSrc, &tw, &th); dstFmt = plan.replaced->Format(); } else if (plan.scaleFactor > 1 || plan.saveTexture) { @@ -296,7 +296,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { bool bc = false; - if (plan.replaceValid) { + if (plan.doReplace) { int blockSize = 0; if (Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), &blockSize)) { stride = mipWidth * 4; @@ -357,7 +357,7 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { render_->FinalizeTexture(entry->textureName, 1, false); } - if (plan.replaceValid) { + if (plan.doReplace) { entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus())); } } diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index dcbb764a38..5fccb0cf37 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -435,7 +435,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { VkFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); if (plan.scaleFactor > 1) { - _dbg_assert_(!plan.replaceValid); + _dbg_assert_(!plan.doReplace); // Whether hardware or software scaling, this is the dest format. dstFmt = VULKAN_8888_FORMAT; } else if (plan.decodeToClut8) { @@ -445,7 +445,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { // 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. - if (g_Config.iTexFiltering == TEX_FILTER_AUTO_MAX_QUALITY && plan.w <= 256 && plan.h <= 256 && (!plan.replaceValid || plan.replaced->Format() == Draw::DataFormat::R8G8B8A8_UNORM)) { + if (g_Config.iTexFiltering == TEX_FILTER_AUTO_MAX_QUALITY && plan.w <= 256 && plan.h <= 256 && (!plan.doReplace || plan.replaced->Format() == Draw::DataFormat::R8G8B8A8_UNORM)) { // Boost the number of mipmaps. if (plan.maxPossibleLevels > plan.levelsToCreate) { // TODO: Should check against levelsToLoad, no? // We have to generate mips with a shader. This requires decoding to R8G8B8A8_UNORM format to avoid extra complications. @@ -458,7 +458,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { VkFormat actualFmt = plan.scaleFactor > 1 ? VULKAN_8888_FORMAT : dstFmt; bool bcFormat = false; int bcAlign = 0; - if (plan.replaceValid) { + if (plan.doReplace) { Draw::DataFormat fmt = plan.replaced->Format(); bcFormat = Draw::DataFormatIsBlockCompressed(fmt, &bcAlign); actualFmt = ToVulkanFormat(fmt); @@ -591,7 +591,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { }; bool dataScaled = true; - if (plan.replaceValid) { + if (plan.doReplace) { int rowLength = pixelStride; if (bcFormat) { // For block compressed formats, we just set the upload size to the data size.. @@ -601,7 +601,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { // Directly load the replaced image. data = pushBuffer->Allocate(uploadSize, pushAlignment, &texBuf, &bufferOffset); double replaceStart = time_now_d(); - if (!plan.replaced->CopyLevelTo(plan.baseLevelSrc + i, (uint8_t *)data, uploadSize, byteStride)) { // If plan.replaceValid, this shouldn't fail. + if (!plan.replaced->CopyLevelTo(plan.baseLevelSrc + i, (uint8_t *)data, uploadSize, byteStride)) { // If plan.doReplace, this shouldn't fail. WARN_LOG(G3D, "Failed to copy replaced texture level"); // TODO: Fill with some pattern? } @@ -681,7 +681,7 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { entry->status |= TexCacheEntry::STATUS_3D; } - if (plan.replaceValid) { + if (plan.doReplace) { entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus())); } }