From 0528646ea34dd97b1768e80a875d582d3db066fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 16 Jul 2026 19:07:46 +0200 Subject: [PATCH] Invert the relationship between the two functions --- GPU/Common/TextureCacheCommon.cpp | 14 ++++++-------- GPU/Common/TextureCacheCommon.h | 3 ++- GPU/D3D11/TextureCacheD3D11.cpp | 14 +++++++------- GPU/GLES/TextureCacheGLES.cpp | 8 ++++---- GPU/Vulkan/TextureCacheVulkan.cpp | 7 +++---- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 0be511869e..47ca3fdd49 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -508,7 +508,7 @@ void TextureCacheCommon::UpdateMaxSeenV(TexCacheEntry *entry, bool throughMode) } } -TexCacheEntry *TextureCacheCommon::SetTexture() { +TextureApplyResult TextureCacheCommon::ApplyTexture(bool doBind) { u8 level = 0; if (IsFakeMipmapChange()) { level = std::max(0, gstate.getTexLevelOffset16() / 16); @@ -522,7 +522,7 @@ TexCacheEntry *TextureCacheCommon::SetTexture() { gstate_c.SetTextureIsArray(false); gstate_c.SetTextureIsFramebuffer(false); gstate_c.SetShaderDepal(ShaderDepalMode::OFF); - return nullptr; + return ApplyTextureFinish(doBind); } const u16 dim = gstate.getTextureDimension(level); @@ -688,7 +688,7 @@ TexCacheEntry *TextureCacheCommon::SetTexture() { nextNeedsRebuild_ = false; failedTexture_ = false; VERBOSE_LOG(Log::G3D, "Texture at %08x found in cache, applying", texaddr); - return entry; //Done! + return ApplyTextureFinish(doBind); //Done! } else { // Wasn't a match, we will rebuild. nextChangeReason_ = reason; @@ -717,7 +717,7 @@ TexCacheEntry *TextureCacheCommon::SetTexture() { nextNeedsRebuild_ = false; SetTextureFramebuffer(bestCandidate); // sets curTexture3D - return nullptr; + return ApplyTextureFinish(doBind); } // Didn't match a framebuffer, keep going. @@ -791,12 +791,10 @@ TexCacheEntry *TextureCacheCommon::SetTexture() { nextFramebufferTexture_ = nullptr; nextNeedsRehash_ = true; nextNeedsRebuild_ = true; - return entry; + return ApplyTextureFinish(doBind); } -TextureApplyResult TextureCacheCommon::ApplyTexture(bool doBind) { - SetTexture(); - +TextureApplyResult TextureCacheCommon::ApplyTextureFinish(bool doBind) { TextureApplyResult result; TexCacheEntry *entry = nextTexture_; if (!entry) { diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 598ef41b68..6b0120d93b 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -329,6 +329,7 @@ struct TextureApplyResult { // At most one of these will be set. TexCacheEntry *texCacheEntry = nullptr; VirtualFramebuffer *framebuffer = nullptr; + bool otherTexture = false; }; class TextureCacheCommon { @@ -405,7 +406,7 @@ protected: // This updates nextTexture_ / nextFramebufferTexture_, which is then used by ApplyTexture. // TODO: Return stuff directly instead of keeping state. - TexCacheEntry *SetTexture(); + TextureApplyResult ApplyTextureFinish(bool doBind); virtual void BindTexture(TexCacheEntry *entry) = 0; virtual void Unbind() = 0; virtual void ReleaseTexture(TexCacheEntry *entry, bool delete_them) = 0; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index cd16a793ed..abc32eddf2 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -444,21 +444,21 @@ DXGI_FORMAT TextureCacheD3D11::GetDestFormat(GETextureFormat format, GEPaletteFo } bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) { - SetTexture(); - if (!nextTexture_) { - return GetCurrentFramebufferTextureDebug(buffer, isFramebuffer); - } - // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. TextureApplyResult textureResult = ApplyTexture(true); - TexCacheEntry *entry = textureResult.texCacheEntry; + if (textureResult.framebuffer) { + return GetCurrentFramebufferTextureDebug(buffer, isFramebuffer); + } + const TexCacheEntry *entry = textureResult.texCacheEntry; if (!entry) { return false; } ID3D11Texture2D *texture = (ID3D11Texture2D *)entry->texturePtr; - if (!texture) + if (!texture) { + // Hm. return false; + } D3D11_TEXTURE2D_DESC desc; texture->GetDesc(&desc); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index b37d930ec7..a6a16dfa94 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -361,15 +361,15 @@ Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPalet bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) { ForgetLastTexture(); - SetTexture(); - if (!nextTexture_) { - return GetCurrentFramebufferTextureDebug(buffer, isFramebuffer); - } // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. // We might need a render pass to set the sampling params, unfortunately. Otherwise BuildTexture may crash. framebufferManagerGL_->RebindFramebuffer("RebindFramebuffer - GetCurrentTextureDebug"); TextureApplyResult textureResult = ApplyTexture(false); + if (textureResult.framebuffer) { + return GetCurrentFramebufferTextureDebug(buffer, isFramebuffer); + } + TexCacheEntry *entry = textureResult.texCacheEntry; if (!entry) { return false; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 5822d2b824..6998358f01 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -1002,13 +1002,12 @@ void TextureCacheVulkan::BoundFramebufferTexture() { } bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) { - SetTexture(); - if (!nextTexture_) { + // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. + TextureApplyResult textureResult = ApplyTexture(true); + if (textureResult.framebuffer) { return GetCurrentFramebufferTextureDebug(buffer, isFramebuffer); } - // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. - TextureApplyResult textureResult = ApplyTexture(true); TexCacheEntry *entry = textureResult.texCacheEntry; if (!entry || !entry->vkTex) { return false;