From 8b64a2c70c0599922dbf075ee357f57acbd45041 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Oct 2013 19:55:01 -0700 Subject: [PATCH 1/4] Fix unlikely case in DrawPixels(). If linesize doesn't match, also use convBuf. --- GPU/GLES/Framebuffer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 63331c17fc..d178d5dccb 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -312,7 +312,9 @@ void FramebufferManager::DrawPixels(const u8 *framebuf, GEBufferFormat pixelForm } // TODO: We can just change the texture format and flip some bits around instead of this. + bool useConvBuf = false; if (pixelFormat != GE_FORMAT_8888 || linesize != 512) { + useConvBuf = true; if (!convBuf) { convBuf = new u8[512 * 272 * 4]; } @@ -385,7 +387,7 @@ void FramebufferManager::DrawPixels(const u8 *framebuf, GEBufferFormat pixelForm if (g_Config.iTexFiltering == LINEAR || (g_Config.iTexFiltering == LINEARFMV && g_iNumVideos)) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } - glTexSubImage2D(GL_TEXTURE_2D,0,0,0,512,272, GL_RGBA, GL_UNSIGNED_BYTE, pixelFormat == GE_FORMAT_8888 ? framebuf : convBuf); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 272, GL_RGBA, GL_UNSIGNED_BYTE, useConvBuf ? convBuf : framebuf); // This draws directly at the backbuffer so if there's a post shader, we need to apply it here. Should try to unify this path // with the regular path somehow, but this simple solution works for most of the post shaders (it always runs at output resolution so FXAA may look odd). From 42f7b42af42dc85e7805f829234cae5e677216e0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Oct 2013 20:32:02 -0700 Subject: [PATCH 2/4] Avoid getting stuck with a bad tex framebuffer. --- GPU/GLES/TextureCache.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 794e86cd3a..c7cf6fc273 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -135,7 +135,7 @@ void TextureCache::Invalidate(u32 addr, int size, GPUInvalidationType type) { // Start it over from 0 (unless it's safe.) iter->second.numFrames = type == GPU_INVALIDATE_SAFE ? 256 : 0; iter->second.framesUntilNextFullHash = 0; - } else { + } else if (!iter->second.framebuffer) { iter->second.invalidHint++; } } @@ -148,7 +148,9 @@ void TextureCache::InvalidateAll(GPUInvalidationType /*unused*/) { // Clear status -> STATUS_HASHING. iter->second.status &= ~TexCacheEntry::STATUS_MASK; } - iter->second.invalidHint++; + if (!iter->second.framebuffer) { + iter->second.invalidHint++; + } } } @@ -850,11 +852,16 @@ void TextureCache::SetTexture(bool force) { #endif // Check for FBO - slow! - if (entry->framebuffer && match) { - SetTextureFramebuffer(entry); - lastBoundTexture = -1; - entry->lastFrame = gpuStats.numFlips; - return; + if (entry->framebuffer) { + if (match) { + SetTextureFramebuffer(entry); + lastBoundTexture = -1; + entry->lastFrame = gpuStats.numFlips; + return; + } else { + // Make sure we re-evaluate framebuffers. + DetachFramebuffer(entry, texaddr, entry->framebuffer); + } } bool rehash = (entry->status & TexCacheEntry::STATUS_MASK) == TexCacheEntry::STATUS_UNRELIABLE; From 453be5530ef05e226784910587334cfa4bdef094 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 21 Oct 2013 08:09:08 -0700 Subject: [PATCH 3/4] Make sure we recheck a fb tex that didn't match. --- GPU/GLES/TextureCache.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index c7cf6fc273..cbfde4ccf7 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -861,6 +861,7 @@ void TextureCache::SetTexture(bool force) { } else { // Make sure we re-evaluate framebuffers. DetachFramebuffer(entry, texaddr, entry->framebuffer); + match = false; } } From 30bf067787e7220cce7f7030e63212ec7bc968b4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 26 Oct 2013 08:37:52 -0700 Subject: [PATCH 4/4] Generate a texture name even for fbo textures. Otherwise, when it stops being a render-to-texture, we won't have a texture name and we'll get confused. A texture name shouldn't be expensive to generate in this case anyway. --- GPU/GLES/TextureCache.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index cbfde4ccf7..81034c4961 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1008,6 +1008,11 @@ void TextureCache::SetTexture(bool force) { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Always generate a texture name, we might need it if the texture is replaced later. + if (!replaceImages) { + glGenTextures(1, &entry->texture); + } + // Before we go reading the texture from memory, let's check for render-to-texture. for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { auto framebuffer = fbCache_[i]; @@ -1032,10 +1037,6 @@ void TextureCache::SetTexture(bool force) { entry->lastFrame = gpuStats.numFlips; return; } - - if (!replaceImages) { - glGenTextures(1, &entry->texture); - } glBindTexture(GL_TEXTURE_2D, entry->texture); lastBoundTexture = entry->texture;