diff --git a/GPU/Directx9/DepalettizeShaderDX9.cpp b/GPU/Directx9/DepalettizeShaderDX9.cpp index 8cfc8cb7de..a85f6282db 100644 --- a/GPU/Directx9/DepalettizeShaderDX9.cpp +++ b/GPU/Directx9/DepalettizeShaderDX9.cpp @@ -20,7 +20,6 @@ #include "base/logging.h" #include "Common/Log.h" #include "Core/Reporting.h" -#include "GPU/GPUState.h" #include "GPU/Directx9/TextureCacheDX9.h" #include "GPU/Directx9/DepalettizeShaderDX9.h" #include "GPU/Common/DepalettizeShaderCommon.h" @@ -64,13 +63,12 @@ DepalShaderCacheDX9::~DepalShaderCacheDX9() { } } -u32 DepalShaderCacheDX9::GenerateShaderID(GEBufferFormat pixelFormat) { - return (gstate.clutformat & 0xFFFFFF) | (pixelFormat << 24); +u32 DepalShaderCacheDX9::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) { + return (clutFormat & 0xFFFFFF) | (pixelFormat << 24); } -LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(const u32 clutID, u32 *rawClut) { - GEPaletteFormat palFormat = gstate.getClutPaletteFormat(); - const u32 realClutID = clutID ^ palFormat; +LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) { + const u32 realClutID = clutID ^ clutFormat; auto oldtex = texCache_.find(realClutID); if (oldtex != texCache_.end()) { @@ -78,8 +76,8 @@ LPDIRECT3DTEXTURE9 DepalShaderCacheDX9::GetClutTexture(const u32 clutID, u32 *ra return oldtex->second->texture; } - D3DFORMAT dstFmt = DX9::getClutDestFormat(palFormat); - int texturePixels = palFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; + D3DFORMAT dstFmt = DX9::getClutDestFormat(clutFormat); + int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; DepalTextureDX9 *tex = new DepalTextureDX9(); @@ -144,8 +142,8 @@ void DepalShaderCacheDX9::Decimate() { } } -LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(GEBufferFormat pixelFormat) { - u32 id = GenerateShaderID(pixelFormat); +LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) { + u32 id = GenerateShaderID(clutFormat, pixelFormat); auto shader = cache_.find(id); if (shader != cache_.end()) { diff --git a/GPU/Directx9/DepalettizeShaderDX9.h b/GPU/Directx9/DepalettizeShaderDX9.h index 55a4ae7911..7cdcb9413f 100644 --- a/GPU/Directx9/DepalettizeShaderDX9.h +++ b/GPU/Directx9/DepalettizeShaderDX9.h @@ -42,14 +42,14 @@ public: ~DepalShaderCacheDX9(); // This also uploads the palette and binds the correct texture. - LPDIRECT3DPIXELSHADER9 GetDepalettizePixelShader(GEBufferFormat pixelFormat); + LPDIRECT3DPIXELSHADER9 GetDepalettizePixelShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat); LPDIRECT3DVERTEXSHADER9 GetDepalettizeVertexShader() { return vertexShader_; } - LPDIRECT3DTEXTURE9 GetClutTexture(const u32 clutHash, u32 *rawClut); + LPDIRECT3DTEXTURE9 GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut); void Clear(); void Decimate(); private: - u32 GenerateShaderID(GEBufferFormat pixelFormat); + u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat); LPDIRECT3DVERTEXSHADER9 vertexShader_; std::map cache_; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 0d3e2f1b6f..5c74e097a2 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -911,13 +911,15 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu framebuffer->usageFlags |= FB_USAGE_TEXTURE; bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; if (useBufferedRendering) { + const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); + LPDIRECT3DPIXELSHADER9 pshader = nullptr; if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - pshader = depalShaderCache_->GetDepalettizePixelShader(framebuffer->drawnFormat); + pshader = depalShaderCache_->GetDepalettizePixelShader(clutFormat, framebuffer->drawnFormat); } if (pshader) { - LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBuf_); + LPDIRECT3DTEXTURE9 clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_); FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888); fbo_bind_as_render_target(depalFBO); @@ -974,11 +976,10 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu dxstate.Restore(); dxstate.viewport.restore(); - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(gstate.getClutPaletteFormat()), clutTotalColors, clutTotalColors, 1); + TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(clutFormat), clutTotalColors, clutTotalColors, 1); gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL; gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE; } else { diff --git a/GPU/GLES/DepalettizeShader.cpp b/GPU/GLES/DepalettizeShader.cpp index 111a7a06bf..1a2859aa2c 100644 --- a/GPU/GLES/DepalettizeShader.cpp +++ b/GPU/GLES/DepalettizeShader.cpp @@ -21,7 +21,6 @@ #include "Common/Log.h" #include "Core/Reporting.h" #include "DepalettizeShader.h" -#include "GPU/GPUState.h" #include "GPU/GLES/TextureCache.h" #include "GPU/Common/DepalettizeShaderCommon.h" @@ -121,13 +120,12 @@ bool DepalShaderCache::CreateVertexShader() { return !vertexShaderFailed_; } -u32 DepalShaderCache::GenerateShaderID(GEBufferFormat pixelFormat) { +u32 DepalShaderCache::GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) { return (gstate.clutformat & 0xFFFFFF) | (pixelFormat << 24); } -GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) { - GEPaletteFormat palFormat = gstate.getClutPaletteFormat(); - const u32 realClutID = clutID ^ palFormat; +GLuint DepalShaderCache::GetClutTexture(GEPaletteFormat clutFormat, const u32 clutID, u32 *rawClut) { + const u32 realClutID = clutID ^ clutFormat; auto oldtex = texCache_.find(realClutID); if (oldtex != texCache_.end()) { @@ -135,8 +133,8 @@ GLuint DepalShaderCache::GetClutTexture(const u32 clutID, u32 *rawClut) { return oldtex->second->texture; } - GLuint dstFmt = getClutDestFormat(palFormat); - int texturePixels = palFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; + GLuint dstFmt = getClutDestFormat(clutFormat); + int texturePixels = clutFormat == GE_CMODE_32BIT_ABGR8888 ? 256 : 512; bool useBGRA = UseBGRA8888() && dstFmt == GL_UNSIGNED_BYTE; @@ -194,8 +192,8 @@ void DepalShaderCache::Decimate() { } } -DepalShader *DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) { - u32 id = GenerateShaderID(pixelFormat); +DepalShader *DepalShaderCache::GetDepalettizeShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat) { + u32 id = GenerateShaderID(clutFormat, pixelFormat); auto shader = cache_.find(id); if (shader != cache_.end()) { diff --git a/GPU/GLES/DepalettizeShader.h b/GPU/GLES/DepalettizeShader.h index 60a80fdf59..82479b8cff 100644 --- a/GPU/GLES/DepalettizeShader.h +++ b/GPU/GLES/DepalettizeShader.h @@ -42,13 +42,13 @@ public: ~DepalShaderCache(); // This also uploads the palette and binds the correct texture. - DepalShader *GetDepalettizeShader(GEBufferFormat pixelFormat); - GLuint GetClutTexture(const u32 clutHash, u32 *rawClut); + DepalShader *GetDepalettizeShader(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat); + GLuint GetClutTexture(GEPaletteFormat clutFormat, const u32 clutHash, u32 *rawClut); void Clear(); void Decimate(); private: - u32 GenerateShaderID(GEBufferFormat pixelFormat); + u32 GenerateShaderID(GEPaletteFormat clutFormat, GEBufferFormat pixelFormat); bool CreateVertexShader(); bool useGL3_; diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 6c32f3eb34..7d4bb76130 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -980,12 +980,13 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe framebuffer->usageFlags |= FB_USAGE_TEXTURE; bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; if (useBufferedRendering) { + const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); DepalShader *depal = nullptr; if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - depal = depalShaderCache_->GetDepalettizeShader(framebuffer->drawnFormat); + depal = depalShaderCache_->GetDepalettizeShader(clutFormat, framebuffer->drawnFormat); } if (depal) { - GLuint clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBuf_); + GLuint clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_); FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888); fbo_bind_as_render_target(depalFBO); static const float pos[12] = { @@ -1040,11 +1041,10 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe glstate.Restore(); framebufferManager_->RebindFramebuffer(); - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(gstate.getClutPaletteFormat()), clutTotalColors, clutTotalColors, 1); + TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormat(clutFormat), clutTotalColors, clutTotalColors, 1); gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL; gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE; } else {