From f168978d3e0f148a65982c18baca140138cac5b9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 21 May 2016 17:53:42 -0700 Subject: [PATCH] Properly set w/h on first use of a render-to-tex. We were getting the wrong w/h when it wasn't in the texture cache already. --- GPU/Directx9/TextureCacheDX9.cpp | 26 ++++++++++++++++---------- GPU/GLES/TextureCache.cpp | 26 ++++++++++++++++---------- GPU/Vulkan/TextureCacheVulkan.cpp | 26 ++++++++++++++++---------- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index ebcb2f6e46..b21f04d71f 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1145,8 +1145,22 @@ void TextureCacheDX9::SetTexture(bool force) { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1260,16 +1274,8 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry, bool replaceImage // TODO: If a framebuffer is attached here, might end up with a bad entry.texture. // Should just always create one here or something (like GLES.) - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index ff281bc2d6..dfd436e0f8 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1247,8 +1247,22 @@ void TextureCache::SetTexture(bool force) { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1364,16 +1378,8 @@ void TextureCache::BuildTexture(TexCacheEntry *const entry, bool replaceImages) entry->textureName = AllocTextureName(); } - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; } diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 7ad675778c..446290f917 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -1117,8 +1117,22 @@ void TextureCacheVulkan::SetTexture() { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1222,16 +1236,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry,VulkanPushBuffe // For the estimate, we assume cluts always point to 8888 for simplicity. cacheSizeEstimate_ += EstimateTexMemoryUsage(entry); - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; }