From 32eb882bc6205f5b488e86bf40076d6fd2fd4e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 1 Nov 2020 23:19:25 +0100 Subject: [PATCH] Clarify some logic, improve framebuffer names --- GPU/Common/FramebufferManagerCommon.cpp | 9 ++++++--- GPU/Common/FramebufferManagerCommon.h | 2 +- GPU/Common/TextureCacheCommon.cpp | 14 +++++++++++--- GPU/Common/TextureCacheCommon.h | 1 + GPU/D3D11/TextureCacheD3D11.cpp | 1 + GPU/GLES/TextureCacheGLES.cpp | 13 +++++++------ Windows/GEDebugger/GEDebugger.cpp | 2 +- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index cb656a35ef..502742c6a4 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -265,10 +265,13 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame if (v->fb_address == params.fb_address) { vfb = v; // Update fb stride in case it changed - if (vfb->fb_stride != params.fb_stride || vfb->format != params.fmt) { - vfbFormatChanged = true; + if (vfb->fb_stride != params.fb_stride) { vfb->fb_stride = params.fb_stride; + vfbFormatChanged = true; + } + if (vfb->format != params.fmt) { vfb->format = params.fmt; + vfbFormatChanged = true; } if (vfb->z_address == 0 && vfb->z_stride == 0 && params.z_stride != 0) { @@ -1087,7 +1090,7 @@ void FramebufferManagerCommon::ResizeFramebufFBO(VirtualFramebuffer *vfb, int w, shaderManager_->DirtyLastShader(); char tag[256]; - snprintf(tag, sizeof(tag), "%08x_%08x_%dx%d", vfb->fb_address, vfb->z_address, w, h); + snprintf(tag, sizeof(tag), "%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, w, h, GeBufferFormatToString((GEBufferFormat)vfb->colorDepth)); vfb->fbo = draw_->CreateFramebuffer({ vfb->renderWidth, vfb->renderHeight, 1, 1, true, (Draw::FBColorDepth)vfb->colorDepth, tag }); if (old.fbo) { INFO_LOG(FRAMEBUF, "Resizing FBO for %08x : %dx%dx%s", vfb->fb_address, w, h, GeBufferFormatToString(vfb->format)); diff --git a/GPU/Common/FramebufferManagerCommon.h b/GPU/Common/FramebufferManagerCommon.h index 44cd2f6b5f..ab92f4df23 100644 --- a/GPU/Common/FramebufferManagerCommon.h +++ b/GPU/Common/FramebufferManagerCommon.h @@ -55,7 +55,7 @@ struct VirtualFramebuffer { int fb_stride; int z_stride; - GEBufferFormat format; // virtual, right now they are all RGBA8888 + GEBufferFormat format; // virtual, in reality they are all RGBA8888 for better quality but we can reinterpret that as necessary // width/height: The detected size of the current framebuffer, in original PSP pixels. u16 width; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 1c5c63cdce..fb84f0f6ec 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -471,11 +471,16 @@ TexCacheEntry *TextureCacheCommon::SetTexture() { // No texture found, or changed (depending on entry). // Check for framebuffers. - TextureDefinition def{}; + TextureDefinition def; def.addr = texaddr; def.dim = dim; def.format = format; def.bufw = bufw; + def.swizzled = gstate.isTextureSwizzled(); + + if (texaddr == 0x40cc000) { + texaddr = texaddr; + } std::vector candidates = GetFramebufferCandidates(def, 0); if (candidates.size() > 0) { @@ -851,9 +856,11 @@ FramebufferMatchInfo TextureCacheCommon::MatchFramebuffer( // NOTE: This check is okay because the first texture formats are the same as the buffer formats. if (entry.format != (GETextureFormat)framebuffer->format) { WARN_LOG_ONCE(diffFormat1, G3D, "Texturing from framebuffer with different formats %s != %s", GeTextureFormatToString(entry.format), GeBufferFormatToString(framebuffer->format)); - return FramebufferMatchInfo{ FramebufferMatch::NO_MATCH }; - } else { return FramebufferMatchInfo{ FramebufferMatch::VALID }; + } else { + // TODO: Here we should either change the format of the framebuffer, reinterpreting it, + // or read from it while reinterpreting it. Not sure which is generally best. + return FramebufferMatchInfo{ FramebufferMatch::NO_MATCH }; } } else { // Apply to buffered mode only. @@ -1007,6 +1014,7 @@ bool TextureCacheCommon::SetOffsetTexture(u32 yOffset) { def.format = fmt; def.bufw = GetTextureBufw(0, texaddr, fmt); def.dim = gstate.getTextureDimension(0); + def.swizzled = gstate.isTextureSwizzled(); std::vector candidates = GetFramebufferCandidates(def, texaddrOffset); if (candidates.size() > 0) { diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 1b0300724b..7acfe3042c 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -98,6 +98,7 @@ struct TextureDefinition { GETextureFormat format; u32 dim; u32 bufw; + bool swizzled; }; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index a989cf353f..4c3b92cdd7 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -496,6 +496,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { // Don't scale the PPGe texture. if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) scaleFactor = 1; + if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && scaleFactor != 1) { // Remember for later that we /wanted/ to scale this texture. entry->status |= TexCacheEntry::STATUS_TO_SCALE; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 7a62854e6f..07adb059d8 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -492,9 +492,6 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { } } - // If GLES3 is available, we can preallocate the storage, which makes texture loading more efficient. - Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); - int scaleFactor = standardScaleFactor_; // Rachet down scale factor in low-memory mode. @@ -535,7 +532,10 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { texelsScaledThisFrame_ += w * h; } } - + + // If GLES3 is available, we can preallocate the storage, which makes texture loading more efficient. + Draw::DataFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat()); + // GLES2 doesn't have support for a "Max lod" which is critical as PSP games often // don't specify mips all the way down. As a result, we either need to manually generate // the bottom few levels or rely on OpenGL's autogen mipmaps instead, which might not @@ -546,10 +546,11 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { // NOTE: Since the level is not part of the cache key, we assume it never changes. u8 level = std::max(0, gstate.getTexLevelOffset16() / 16); LoadTextureLevel(*entry, replaced, level, scaleFactor, dstFmt); - } else + } else { LoadTextureLevel(*entry, replaced, 0, scaleFactor, dstFmt); + } - // Mipmapping only enable when texture scaling disable + // Mipmapping is only enabled when texture scaling is disabled. int texMaxLevel = 0; bool genMips = false; if (maxLevel > 0 && scaleFactor == 1) { diff --git a/Windows/GEDebugger/GEDebugger.cpp b/Windows/GEDebugger/GEDebugger.cpp index 61ca7784a2..affeb1c6d4 100644 --- a/Windows/GEDebugger/GEDebugger.cpp +++ b/Windows/GEDebugger/GEDebugger.cpp @@ -285,7 +285,7 @@ void CGEDebugger::DescribePrimaryPreview(const GPUgstate &state, wchar_t desc[25 switch (PrimaryDisplayType(fbTabs->CurrentTabIndex())) { case PRIMARY_FRAMEBUF: - _snwprintf(desc, 256, L"Color: 0x%08x (%dx%d) fmt %i", state.getFrameBufRawAddress(), primaryBuffer_->GetStride(), primaryBuffer_->GetHeight(), state.FrameBufFormat()); + _snwprintf(desc, 256, L"Color: 0x%08x (%dx%d) fmt %s", state.getFrameBufRawAddress(), primaryBuffer_->GetStride(), primaryBuffer_->GetHeight(), GeBufferFormatToString(state.FrameBufFormat())); break; case PRIMARY_DEPTHBUF: