From e24e652b0d929d62ef2f2f5083acf074034580b4 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 19 Feb 2017 23:50:04 +0100 Subject: [PATCH] Prepare to unify SetTexture --- GPU/Common/TextureCacheCommon.h | 1 + GPU/D3D11/TextureCacheD3D11.cpp | 4 ++++ GPU/D3D11/TextureCacheD3D11.h | 1 + GPU/Directx9/TextureCacheDX9.cpp | 8 ++++++-- GPU/Directx9/TextureCacheDX9.h | 1 + GPU/GLES/TextureCacheGLES.cpp | 9 +++------ GPU/GLES/TextureCacheGLES.h | 7 ++++++- GPU/Vulkan/TextureCacheVulkan.h | 3 +++ 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 197ccd02d1..67452014a1 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -184,6 +184,7 @@ public: void ClearNextFrame(); virtual void ForgetLastTexture() = 0; + virtual void InvalidateLastTexture() = 0; virtual void Clear(bool delete_them); // FramebufferManager keeps TextureCache updated about what regions of memory are being rendered to. diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 801703b41f..da6c523c37 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -139,6 +139,10 @@ void TextureCacheD3D11::ForgetLastTexture() { context_->PSSetShaderResources(0, 1, &nullTex); } +void TextureCacheD3D11::InvalidateLastTexture() { + lastBoundTexture = INVALID_TEX; +} + DXGI_FORMAT getClutDestFormatD3D11(GEPaletteFormat format) { switch (format) { case GE_CMODE_16BIT_ABGR4444: diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 472610aa10..6f086ee90d 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -62,6 +62,7 @@ public: bool DecodeTexture(u8 *output, const GPUgstate &state); void ForgetLastTexture() override; + void InvalidateLastTexture() override; void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index ac66ea2b99..86a3eecfe8 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -107,6 +107,10 @@ void TextureCacheDX9::ForgetLastTexture() { gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } +void TextureCacheDX9::InvalidateLastTexture() { + lastBoundTexture = INVALID_TEX; +} + D3DFORMAT getClutDestFormat(GEPaletteFormat format) { switch (format) { case GE_CMODE_16BIT_ABGR4444: @@ -467,13 +471,13 @@ void TextureCacheDX9::SetTexture(bool force) { #ifdef DEBUG_TEXTURES if (SetDebugTexture()) { // A different texture was bound, let's rebind next time. - lastBoundTexture = INVALID_TEX; + InvalidateLastTexture(); return; } #endif if (force) { - lastBoundTexture = INVALID_TEX; + InvalidateLastTexture(); } u8 level = 0; diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 2eb96b8dc7..7d0cf5b345 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -55,6 +55,7 @@ public: bool DecodeTexture(u8 *output, const GPUgstate &state); void ForgetLastTexture() override; + void InvalidateLastTexture() override; void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 08867fe599..cb81c8271a 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -47,8 +47,6 @@ #define GL_UNPACK_ROW_LENGTH 0x0CF2 #endif -#define INVALID_TEX -1 - #define TEXCACHE_NAME_CACHE_SIZE 16 TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw) @@ -541,13 +539,13 @@ void TextureCacheGLES::SetTexture(bool force) { #ifdef DEBUG_TEXTURES if (SetDebugTexture()) { // A different texture was bound, let's rebind next time. - lastBoundTexture = INVALID_TEX; + InvalidateLastTexture(); return; } #endif if (force) { - lastBoundTexture = INVALID_TEX; + InvalidateLastTexture(); } u8 level = 0; @@ -557,7 +555,6 @@ void TextureCacheGLES::SetTexture(bool force) { if (!Memory::IsValidAddress(texaddr)) { // Bind a null texture and return. Unbind(); - glBindTexture(GL_TEXTURE_2D, 0); lastBoundTexture = INVALID_TEX; return; } @@ -768,7 +765,7 @@ bool TextureCacheGLES::HandleTextureChange(TexCacheEntry *const entry, const cha if (entry->textureName == lastBoundTexture) { lastBoundTexture = INVALID_TEX; } - glDeleteTextures(1, &entry->textureName); + ReleaseTexture(entry); entry->status &= ~TexCacheEntry::STATUS_IS_SCALED; } } diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 0d3fa241a6..9da5020017 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -63,9 +63,12 @@ public: } void ForgetLastTexture() override { - lastBoundTexture = -1; + lastBoundTexture = INVALID_TEX; gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } + void InvalidateLastTexture() override { + lastBoundTexture = INVALID_TEX; + } u32 AllocTextureName(); @@ -102,6 +105,8 @@ private: DepalShaderCacheGLES *depalShaderCache_; ShaderManagerGLES *shaderManager_; DrawEngineGLES *drawEngine_; + + enum { INVALID_TEX = -1 }; }; GLenum getClutDestFormat(GEPaletteFormat format); diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index fe103e36f8..3041677b9f 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -89,6 +89,9 @@ public: lastBoundTexture = nullptr; gstate_c.Dirty(DIRTY_TEXTURE_PARAMS); } + void InvalidateLastTexture() override { + lastBoundTexture = nullptr; + } void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) { imageView = imageView_;