From e30ab9517985be9798247449cdae31d88ae6bfbc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 18:48:54 -0800 Subject: [PATCH] d3d9: Fix maxSeenV when not known. And just make the code reused between both. Fixes #8478. --- GPU/Common/TextureCacheCommon.cpp | 23 +++++++++++++++++++++++ GPU/Common/TextureCacheCommon.h | 1 + GPU/Directx9/TextureCacheDX9.cpp | 21 +-------------------- GPU/GLES/TextureCache.cpp | 21 +-------------------- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index b5d355b403..e9bf822f7a 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -119,6 +119,29 @@ void TextureCacheCommon::GetSamplingParams(int &minFilt, int &magFilt, bool &sCl } } +void TextureCacheCommon::UpdateMaxSeenV(bool throughMode) { + // If the texture is >= 512 pixels tall... + if (nextTexture_->dim >= 0x900) { + // Texture scale/offset and gen modes don't apply in through. + // So we can optimize how much of the texture we look at. + if (throughMode) { + if (nextTexture_->maxSeenV == 0 && gstate_c.vertBounds.maxV > 0) { + // Let's not hash less than 272, we might use more later and have to rehash. 272 is very common. + nextTexture_->maxSeenV = std::max((u16)272, gstate_c.vertBounds.maxV); + } else if (gstate_c.vertBounds.maxV > nextTexture_->maxSeenV) { + // The max height changed, so we're better off hashing the entire thing. + nextTexture_->maxSeenV = 512; + nextTexture_->status |= TexCacheEntry::STATUS_FREE_CHANGE; + } + } else { + // Otherwise, we need to reset to ensure we use the whole thing. + // Can't tell how much is used. + // TODO: We could tell for texcoord UV gen, and apply scale to max? + nextTexture_->maxSeenV = 512; + } + } +} + void TextureCacheCommon::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg) { // Must be in VRAM so | 0x04000000 it is. Also, ignore memory mirrors. // These checks are mainly to reduce scanning all textures. diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 542de147fc..caae0c6ecc 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -137,6 +137,7 @@ protected: void *RearrangeBuf(void *inBuf, u32 inRowBytes, u32 outRowBytes, int h, bool allowInPlace = true); void GetSamplingParams(int &minFilt, int &magFilt, bool &sClamp, bool &tClamp, float &lodBias, u8 maxLevel); + void UpdateMaxSeenV(bool throughMode); virtual bool AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, u32 texaddrOffset = 0) = 0; virtual void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer) = 0; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index dde7b8a48d..c8f2d67084 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -774,26 +774,7 @@ void TextureCacheDX9::ApplyTexture() { if (nextTexture_->framebuffer) { ApplyTextureFramebuffer(nextTexture_, nextTexture_->framebuffer); } else { - // If the texture is >= 512 pixels tall... - if (nextTexture_->dim >= 0x900) { - // Texture scale/offset and gen modes don't apply in through. - // So we can optimize how much of the texture we look at. - if (gstate.isModeThrough()) { - if (nextTexture_->maxSeenV == 0) { - // Let's not hash less than 272, we might use more later and have to rehash. 272 is very common. - nextTexture_->maxSeenV = std::max((u16)272, gstate_c.vertBounds.maxV); - } else if (gstate_c.vertBounds.maxV > nextTexture_->maxSeenV) { - // The max height changed higher, so we're better off hashing the entire thing. - nextTexture_->maxSeenV = 512; - nextTexture_->status |= TexCacheEntry::STATUS_FREE_CHANGE; - } - } else { - // Otherwise, we need to reset to ensure we use the whole thing. - // Can't tell how much is used. - // TODO: We could tell for texcoord UV gen, and apply scale to max? - nextTexture_->maxSeenV = 512; - } - } + UpdateMaxSeenV(gstate.isModeThrough()); LPDIRECT3DTEXTURE9 texture = DxTex(nextTexture_); pD3Ddevice->SetTexture(0, texture); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 000f7231e8..c799e02c85 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -848,26 +848,7 @@ void TextureCache::ApplyTexture() { if (nextTexture_->framebuffer) { ApplyTextureFramebuffer(nextTexture_, nextTexture_->framebuffer); } else { - // If the texture is >= 512 pixels tall... - if (nextTexture_->dim >= 0x900) { - // Texture scale/offset and gen modes don't apply in through. - // So we can optimize how much of the texture we look at. - if (gstate.isModeThrough()) { - if (nextTexture_->maxSeenV == 0 && gstate_c.vertBounds.maxV > 0) { - // Let's not hash less than 272, we might use more later and have to rehash. 272 is very common. - nextTexture_->maxSeenV = std::max((u16)272, gstate_c.vertBounds.maxV); - } else if (gstate_c.vertBounds.maxV > nextTexture_->maxSeenV) { - // The max height changed, so we're better off hashing the entire thing. - nextTexture_->maxSeenV = 512; - nextTexture_->status |= TexCacheEntry::STATUS_FREE_CHANGE; - } - } else { - // Otherwise, we need to reset to ensure we use the whole thing. - // Can't tell how much is used. - // TODO: We could tell for texcoord UV gen, and apply scale to max? - nextTexture_->maxSeenV = 512; - } - } + UpdateMaxSeenV(gstate.isModeThrough()); if (nextTexture_->textureName != lastBoundTexture) { glBindTexture(GL_TEXTURE_2D, nextTexture_->textureName);