diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 6ab7cfb06b..0f2491156f 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -986,6 +986,16 @@ void TextureCacheCommon::Clear(bool delete_them) { videos_.clear(); } +void TextureCacheCommon::DeleteTexture(TexCache::iterator it) { + ReleaseTexture(&it->second); + auto fbInfo = fbTexInfo_.find(it->first); + if (fbInfo != fbTexInfo_.end()) { + fbTexInfo_.erase(fbInfo); + } + cacheSizeEstimate_ -= EstimateTexMemoryUsage(&it->second); + cache.erase(it); +} + bool TextureCacheCommon::CheckFullHash(TexCacheEntry *const entry, bool &doDelete) { bool hashFail = false; int w = gstate.getTextureWidth(0); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 9eb8a9e360..60242b251f 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -164,6 +164,8 @@ struct TexCacheEntry { }; class FramebufferManagerCommon; +// Can't be unordered_map, we use lower_bound ... although for some reason that compiles on MSVC. +typedef std::map TexCache; class TextureCacheCommon { public: @@ -198,12 +200,10 @@ public: protected: virtual void Unbind() = 0; virtual void ReleaseTexture(TexCacheEntry *entry) = 0; + void DeleteTexture(TexCache::iterator it); bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); - // Can't be unordered_map, we use lower_bound ... although for some reason that compiles on MSVC. - typedef std::map TexCache; - // Separate to keep main texture cache size down. struct AttachedFramebufferInfo { u32 xOffset; @@ -279,6 +279,8 @@ protected: TexCacheEntry *nextTexture_; + u32 clutHash_ = 0; + // Raw is where we keep the original bytes. Converted is where we swap colors if necessary. u32 *clutBufRaw_; u32 *clutBufConverted_; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index ff7ad8fd9c..d2fee8f3ff 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -147,17 +147,6 @@ void TextureCacheD3D11::ReleaseTexture(TexCacheEntry *entry) { } } -void TextureCacheD3D11::DeleteTexture(TexCache::iterator it) { - ReleaseTexture(&it->second); - auto fbInfo = fbTexInfo_.find(it->first); - if (fbInfo != fbTexInfo_.end()) { - fbTexInfo_.erase(fbInfo); - } - - cacheSizeEstimate_ -= EstimateTexMemoryUsage(&it->second); - cache.erase(it); -} - void TextureCacheD3D11::ForgetLastTexture() { lastBoundTexture = INVALID_TEX; gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); @@ -323,10 +312,6 @@ void TextureCacheD3D11::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBa clutLastFormat_ = gstate.clutformat; } -inline u32 TextureCacheD3D11::GetCurrentClutHash() { - return clutHash_; -} - void TextureCacheD3D11::Unbind() { ID3D11ShaderResourceView *nullView = nullptr; context_->PSSetShaderResources(0, 1, &nullView); @@ -607,7 +592,7 @@ void TextureCacheD3D11::SetTexture(bool force) { // We update here because the clut format can be specified after the load. UpdateCurrentClut(gstate.getClutPaletteFormat(), gstate.getClutIndexStartPos(), gstate.isClutIndexSimple()); } - cluthash = GetCurrentClutHash() ^ gstate.clutformat; + cluthash = clutHash_ ^ gstate.clutformat; } else { cluthash = 0; } diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 2fe76de9b4..df63052820 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -73,12 +73,10 @@ protected: private: void Decimate(); // Run this once per frame to get rid of old textures. - void DeleteTexture(TexCache::iterator it); void UpdateSamplingParams(TexCacheEntry &entry, SamplerCacheKey &key); void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int maxLevel, bool replaceImages, int scaleFactor, u32 dstFmt); DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h); - u32 GetCurrentClutHash(); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); @@ -100,8 +98,6 @@ private: SamplerCacheD3D11 samplerCache_; - u32 clutHash_; - ID3D11ShaderResourceView *lastBoundTexture; int decimationCounter_; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index f18f369b33..d1deefb5d6 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -332,10 +332,6 @@ void TextureCacheDX9::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase clutLastFormat_ = gstate.clutformat; } -inline u32 TextureCacheDX9::GetCurrentClutHash() { - return clutHash_; -} - void TextureCacheDX9::Unbind() { pD3Ddevice->SetTexture(0, NULL); } @@ -618,7 +614,7 @@ void TextureCacheDX9::SetTexture(bool force) { // We update here because the clut format can be specified after the load. UpdateCurrentClut(gstate.getClutPaletteFormat(), gstate.getClutIndexStartPos(), gstate.isClutIndexSimple()); } - cluthash = GetCurrentClutHash() ^ gstate.clutformat; + cluthash = clutHash_ ^ gstate.clutformat; } else { cluthash = 0; } diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index d8ede25c4f..4edae8f3d5 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -71,7 +71,6 @@ private: void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int maxLevel, bool replaceImages, int scaleFactor, u32 dstFmt); D3DFORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h); - u32 GetCurrentClutHash(); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); @@ -85,8 +84,6 @@ private: TextureScalerDX9 scaler; - u32 clutHash_; - LPDIRECT3DVERTEXDECLARATION9 pFramebufferVertexDecl; LPDIRECT3DTEXTURE9 lastBoundTexture; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 7dc7450b08..97cc9282a7 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -101,17 +101,6 @@ void TextureCacheGLES::Clear(bool delete_them) { } } -void TextureCacheGLES::DeleteTexture(TexCache::iterator it) { - glDeleteTextures(1, &it->second.textureName); - auto fbInfo = fbTexInfo_.find(it->first); - if (fbInfo != fbTexInfo_.end()) { - fbTexInfo_.erase(fbInfo); - } - - cacheSizeEstimate_ -= EstimateTexMemoryUsage(&it->second); - cache.erase(it); -} - // Removes old textures. void TextureCacheGLES::Decimate() { if (--decimationCounter_ <= 0) { @@ -354,10 +343,6 @@ void TextureCacheGLES::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBas clutLastFormat_ = gstate.clutformat; } -inline u32 TextureCacheGLES::GetCurrentClutHash() { - return clutHash_; -} - // #define DEBUG_TEXTURES #ifdef DEBUG_TEXTURES @@ -703,7 +688,7 @@ void TextureCacheGLES::SetTexture(bool force) { // We update here because the clut format can be specified after the load. UpdateCurrentClut(gstate.getClutPaletteFormat(), gstate.getClutIndexStartPos(), gstate.isClutIndexSimple()); } - cluthash = GetCurrentClutHash() ^ gstate.clutformat; + cluthash = clutHash_ ^ gstate.clutformat; } else { cluthash = 0; } diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 7f54503d5c..06111ca3b8 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -82,13 +82,11 @@ protected: private: void Decimate(); // Run this once per frame to get rid of old textures. - void DeleteTexture(TexCache::iterator it); void UpdateSamplingParams(TexCacheEntry &entry, bool force); void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, bool replaceImages, int scaleFactor, GLenum dstFmt); GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; void *DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufw = 0); TexCacheEntry::Status CheckAlpha(const u32 *pixelData, GLenum dstFmt, int stride, int w, int h); - u32 GetCurrentClutHash(); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); @@ -99,8 +97,6 @@ private: TextureScalerGLES scaler; - u32 clutHash_; - u32 lastBoundTexture; float maxAnisotropyLevel; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index fa6b2e1b95..d992c479a9 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -397,10 +397,6 @@ void TextureCacheVulkan::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB clutLastFormat_ = gstate.clutformat; } -inline u32 TextureCacheVulkan::GetCurrentClutHash() { - return clutHash_; -} - void TextureCacheVulkan::Unbind() { } @@ -639,7 +635,7 @@ void TextureCacheVulkan::SetTexture() { // We update here because the clut format can be specified after the load. UpdateCurrentClut(gstate.getClutPaletteFormat(), gstate.getClutIndexStartPos(), gstate.isClutIndexSimple()); } - cluthash = GetCurrentClutHash() ^ gstate.clutformat; + cluthash = clutHash_ ^ gstate.clutformat; } else { cluthash = 0; } diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index 986b6c34ba..a85034618e 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -103,7 +103,6 @@ private: void LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt); VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h); - u32 GetCurrentClutHash(); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); void ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEntry *entry, VirtualFramebuffer *framebuffer, VkImageView &image, VkSampler &sampler); void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key); @@ -119,8 +118,6 @@ private: TextureScalerVulkan scaler; - u32 clutHash_; - CachedTextureVulkan *lastBoundTexture; int decimationCounter_;