diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 0f2491156f..9c00e8a44e 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -965,6 +965,58 @@ bool TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int level, const return true; } + +void TextureCacheCommon::ApplyTexture() { + TexCacheEntry *entry = nextTexture_; + if (entry == nullptr) { + return; + } + nextTexture_ = nullptr; + + UpdateMaxSeenV(entry, gstate.isModeThrough()); + + bool replaceImages = false; + if (nextNeedsRebuild_) { + if (nextNeedsRehash_) { + // Update the hash on the texture. + int w = gstate.getTextureWidth(0); + int h = gstate.getTextureHeight(0); + entry->fullhash = QuickTexHash(replacer, entry->addr, entry->bufw, w, h, GETextureFormat(entry->format), entry); + } + if (nextNeedsChange_) { + // This texture existed previously, let's handle the change. + replaceImages = HandleTextureChange(entry, nextChangeReason_, false, true); + } + // We actually build afterward (shared with rehash rebuild.) + } else if (nextNeedsRehash_) { + // Okay, this matched and didn't change - but let's check the hash. Maybe it will change. + bool doDelete = true; + if (!CheckFullHash(entry, doDelete)) { + replaceImages = HandleTextureChange(entry, "hash fail", true, doDelete); + nextNeedsRebuild_ = true; + } else if (nextTexture_ != nullptr) { + // Secondary cache picked a different texture, use it. + entry = nextTexture_; + nextTexture_ = nullptr; + UpdateMaxSeenV(entry, gstate.isModeThrough()); + } + } + + // Okay, now actually rebuild the texture if needed. + if (nextNeedsRebuild_) { + BuildTexture(entry, replaceImages); + } + + entry->lastFrame = gpuStats.numFlips; + if (entry->framebuffer) { + ApplyTextureFramebuffer(entry, entry->framebuffer); + } else { + BindTexture(entry); + gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; + gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN; + } +} + void TextureCacheCommon::Clear(bool delete_them) { ForgetLastTexture(); if (delete_them) { diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 2fe2e9cfda..ef26104f5e 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -175,6 +175,7 @@ public: void LoadClut(u32 clutAddr, u32 loadBytes); bool GetCurrentClutBuffer(GPUDebugBuffer &buffer); + void ApplyTexture(); bool SetOffsetTexture(u32 offset); void Invalidate(u32 addr, int size, GPUInvalidationType type); void InvalidateAll(GPUInvalidationType type); @@ -204,6 +205,10 @@ protected: virtual void ReleaseTexture(TexCacheEntry *entry) = 0; void DeleteTexture(TexCache::iterator it); + virtual void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) = 0; + virtual bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete) = 0; + virtual void BuildTexture(TexCacheEntry *const entry, bool replaceImages) = 0; + bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); // Separate to keep main texture cache size down. diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 1b280be4cf..47c5d6db8d 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -329,59 +329,6 @@ void TextureCacheD3D11::Unbind() { context_->PSSetShaderResources(0, 1, &nullView); } -void TextureCacheD3D11::ApplyTexture() { - TexCacheEntry *entry = nextTexture_; - if (entry == nullptr) { - // Unbind? - return; - } - nextTexture_ = nullptr; - - UpdateMaxSeenV(entry, gstate.isModeThrough()); - - bool replaceImages = false; - if (nextNeedsRebuild_) { - if (nextNeedsRehash_) { - // Update the hash on the texture. - int w = gstate.getTextureWidth(0); - int h = gstate.getTextureHeight(0); - entry->fullhash = QuickTexHash(replacer, entry->addr, entry->bufw, w, h, GETextureFormat(entry->format), entry); - } - if (nextNeedsChange_) { - // This texture existed previously, let's handle the change. - replaceImages = HandleTextureChange(entry, nextChangeReason_, false, true); - } - - // We actually build afterward (shared with rehash rebuild.) - } else if (nextNeedsRehash_) { - // Okay, this matched and didn't change - but let's check the hash. Maybe it will change. - bool doDelete = true; - if (!CheckFullHash(entry, doDelete)) { - replaceImages = HandleTextureChange(entry, "hash fail", true, doDelete); - nextNeedsRebuild_ = true; - } else if (nextTexture_ != nullptr) { - // Secondary cache picked a different texture, use it. - entry = nextTexture_; - nextTexture_ = nullptr; - UpdateMaxSeenV(entry, gstate.isModeThrough()); - } - } - - // Okay, now actually rebuild the texture if needed. - if (nextNeedsRebuild_) { - BuildTexture(entry, replaceImages); - } - - entry->lastFrame = gpuStats.numFlips; - if (entry->framebuffer) { - ApplyTextureFramebuffer(entry, entry->framebuffer); - } else { - BindTexture(entry); - gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; - gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN; - } -} - class TextureShaderApplierD3D11 { public: struct Pos { diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 824fafe657..55224e0f86 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -65,8 +65,6 @@ public: void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key); - void ApplyTexture(); - protected: void BindTexture(TexCacheEntry *entry) override; void Unbind() override; @@ -79,11 +77,12 @@ private: DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); - void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); - bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); - void BuildTexture(TexCacheEntry *const entry, bool replaceImages); + + void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override; + bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete) override; + void BuildTexture(TexCacheEntry *const entry, bool replaceImages) override; ID3D11Device *device_; ID3D11DeviceContext *context_; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index e145ae5708..96aebfb038 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -345,58 +345,6 @@ void TextureCacheDX9::Unbind() { pD3Ddevice->SetTexture(0, NULL); } -void TextureCacheDX9::ApplyTexture() { - TexCacheEntry *entry = nextTexture_; - if (entry == nullptr) { - return; - } - nextTexture_ = nullptr; - - UpdateMaxSeenV(entry, gstate.isModeThrough()); - - bool replaceImages = false; - if (nextNeedsRebuild_) { - if (nextNeedsRehash_) { - // Update the hash on the texture. - int w = gstate.getTextureWidth(0); - int h = gstate.getTextureHeight(0); - entry->fullhash = QuickTexHash(replacer, entry->addr, entry->bufw, w, h, GETextureFormat(entry->format), entry); - } - if (nextNeedsChange_) { - // This texture existed previously, let's handle the change. - replaceImages = HandleTextureChange(entry, nextChangeReason_, false, true); - } - - // We actually build afterward (shared with rehash rebuild.) - } else if (nextNeedsRehash_) { - // Okay, this matched and didn't change - but let's check the hash. Maybe it will change. - bool doDelete = true; - if (!CheckFullHash(entry, doDelete)) { - replaceImages = HandleTextureChange(entry, "hash fail", true, doDelete); - nextNeedsRebuild_ = true; - } else if (nextTexture_ != nullptr) { - // Secondary cache picked a different texture, use it. - entry = nextTexture_; - nextTexture_ = nullptr; - UpdateMaxSeenV(entry, gstate.isModeThrough()); - } - } - - // Okay, now actually rebuild the texture if needed. - if (nextNeedsRebuild_) { - BuildTexture(entry, replaceImages); - } - - entry->lastFrame = gpuStats.numFlips; - if (entry->framebuffer) { - ApplyTextureFramebuffer(entry, entry->framebuffer); - } else { - BindTexture(entry); - gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; - gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN; - } -} - class TextureShaderApplierDX9 { public: struct Pos { diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index dc3ef86183..54f51f8c4b 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -58,8 +58,6 @@ public: void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight); - void ApplyTexture(); - protected: void BindTexture(TexCacheEntry *entry) override; void Unbind() override; @@ -73,11 +71,11 @@ private: D3DFORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); - void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); - bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); - void BuildTexture(TexCacheEntry *const entry, bool replaceImages); + void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override; + bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete) override; + void BuildTexture(TexCacheEntry *const entry, bool replaceImages) override; LPDIRECT3DTEXTURE9 &DxTex(TexCacheEntry *entry) { return *(LPDIRECT3DTEXTURE9 *)&entry->texturePtr; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 6c3684b9a6..a8b8f6c9bd 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -397,57 +397,6 @@ void TextureCacheGLES::Unbind() { glBindTexture(GL_TEXTURE_2D, 0); } -void TextureCacheGLES::ApplyTexture() { - TexCacheEntry *entry = nextTexture_; - if (entry == nullptr) { - return; - } - nextTexture_ = nullptr; - - UpdateMaxSeenV(entry, gstate.isModeThrough()); - - bool replaceImages = false; - if (nextNeedsRebuild_) { - if (nextNeedsRehash_) { - // Update the hash on the texture. - int w = gstate.getTextureWidth(0); - int h = gstate.getTextureHeight(0); - entry->fullhash = QuickTexHash(replacer, entry->addr, entry->bufw, w, h, GETextureFormat(entry->format), entry); - } - if (nextNeedsChange_) { - // This texture existed previously, let's handle the change. - replaceImages = HandleTextureChange(entry, nextChangeReason_, false, true); - } - // We actually build afterward (shared with rehash rebuild.) - } else if (nextNeedsRehash_) { - // Okay, this matched and didn't change - but let's check the hash. Maybe it will change. - bool doDelete = true; - if (!CheckFullHash(entry, doDelete)) { - replaceImages = HandleTextureChange(entry, "hash fail", true, doDelete); - nextNeedsRebuild_ = true; - } else if (nextTexture_ != nullptr) { - // Secondary cache picked a different texture, use it. - entry = nextTexture_; - nextTexture_ = nullptr; - UpdateMaxSeenV(entry, gstate.isModeThrough()); - } - } - - // Okay, now actually rebuild the texture if needed. - if (nextNeedsRebuild_) { - BuildTexture(entry, replaceImages); - } - - entry->lastFrame = gpuStats.numFlips; - if (entry->framebuffer) { - ApplyTextureFramebuffer(entry, entry->framebuffer); - } else { - BindTexture(entry); - gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; - gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN; - } -} - class TextureShaderApplier { public: struct Pos { diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 4993322f98..98277a8475 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -74,8 +74,6 @@ public: void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight); - void ApplyTexture(); - protected: void BindTexture(TexCacheEntry *entry) override; void Unbind() override; @@ -89,10 +87,10 @@ private: 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); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); - void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); + void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override; - bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); - void BuildTexture(TexCacheEntry *const entry, bool replaceImages); + bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete) override; + void BuildTexture(TexCacheEntry *const entry, bool replaceImages) override; std::vector nameCache_; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 0de9df3e0c..589d361bb9 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -415,60 +415,6 @@ void TextureCacheVulkan::Unbind() { sampler_ = VK_NULL_HANDLE; } -void TextureCacheVulkan::ApplyTexture() { - TexCacheEntry *entry = nextTexture_; - if (entry == nullptr) { - // Unbind(); - return; - } - nextTexture_ = nullptr; - - UpdateMaxSeenV(entry, gstate.isModeThrough()); - - if (nextNeedsRebuild_) { - if (nextNeedsRehash_) { - // Update the hash on the texture. - int w = gstate.getTextureWidth(0); - int h = gstate.getTextureHeight(0); - entry->fullhash = QuickTexHash(replacer, entry->addr, entry->bufw, w, h, GETextureFormat(entry->format), entry); - } - if (nextNeedsChange_) { - // This texture existed previously, let's handle the change. - HandleTextureChange(entry, nextChangeReason_, false, true); - } - - // We actually build afterward (shared with rehash rebuild.) - } else if (nextNeedsRehash_) { - // Okay, this matched and didn't change - but let's check the hash. Maybe it will change. - bool doDelete = true; - if (!CheckFullHash(entry, doDelete)) { - HandleTextureChange(entry, "hash fail", true, doDelete); - nextNeedsRebuild_ = true; - } else if (nextTexture_ != nullptr) { - // Secondary cache picked a different texture, use it. - entry = nextTexture_; - nextTexture_ = nullptr; - UpdateMaxSeenV(entry, gstate.isModeThrough()); - } - } - - // Okay, now actually rebuild the texture if needed. - if (nextNeedsRebuild_) { - BuildTexture(entry); - } - - entry->lastFrame = gpuStats.numFlips; - if (entry->framebuffer) { - ApplyTextureFramebuffer(entry, entry->framebuffer); - } else { - BindTexture(entry); - gstate_c.textureFullAlpha = entry->GetAlphaStatus() == TexCacheEntry::STATUS_ALPHA_FULL; - gstate_c.textureSimpleAlpha = entry->GetAlphaStatus() != TexCacheEntry::STATUS_ALPHA_UNKNOWN; - - lastBoundTexture = entry->vkTex; - } -} - void TextureCacheVulkan::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) { DepalShaderVulkan *depal = nullptr; const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); @@ -906,7 +852,7 @@ bool TextureCacheVulkan::HandleTextureChange(TexCacheEntry *const entry, const c return false; } -void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { +void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry, bool replaceImages) { entry->status &= ~TexCacheEntry::STATUS_ALPHA_MASK; // For the estimate, we assume cluts always point to 8888 for simplicity. diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index 4014a04498..d11bf68353 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -90,7 +90,6 @@ public: gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } - void ApplyTexture(); void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) { imageView = imageView_; sampler = sampler_; @@ -109,12 +108,12 @@ private: VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; TexCacheEntry::Status CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple); - void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer); void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key); bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete); - bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); - void BuildTexture(TexCacheEntry *const entry); + void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override; + bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete) override; + void BuildTexture(TexCacheEntry *const entry, bool replaceImages) override; VulkanContext *vulkan_; VulkanDeviceAllocator *allocator_;