From 4e3c2581404fceb65b2f15096b267ae2f0db005d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 Aug 2022 13:58:14 +0200 Subject: [PATCH] Delete all the duplicate implementations of ApplyTextureFramebuffer --- GPU/Common/TextureCacheCommon.cpp | 95 +++++++++++++++++++++++++++++++ GPU/Common/TextureCacheCommon.h | 8 ++- GPU/D3D11/TextureCacheD3D11.cpp | 95 ------------------------------- GPU/D3D11/TextureCacheD3D11.h | 5 -- GPU/Directx9/TextureCacheDX9.cpp | 95 ------------------------------- GPU/Directx9/TextureCacheDX9.h | 5 -- GPU/GLES/TextureCacheGLES.cpp | 95 ------------------------------- GPU/GLES/TextureCacheGLES.h | 7 +-- GPU/Vulkan/TextureCacheVulkan.cpp | 95 ------------------------------- GPU/Vulkan/TextureCacheVulkan.h | 5 -- 10 files changed, 103 insertions(+), 402 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index aadb53637e..2a88e03dab 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1843,6 +1843,101 @@ void TextureCacheCommon::ApplyTexture() { gstate_c.SetTextureIs3D((entry->status & TexCacheEntry::STATUS_3D) != 0); } +void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { + DepalShader *depalShader = nullptr; + uint32_t clutMode = gstate.clutformat & 0xFFFFFF; + bool need_depalettize = IsClutFormat(texFormat); + + bool depth = channel == NOTIFY_FB_DEPTH; + bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; + if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { + useShaderDepal = false; + depth = false; // Can't support this + } + + if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { + if (useShaderDepal) { + const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); + + // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. + Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); + BindAsClutTexture(clutTexture); + + framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); + samplerKey.magFilt = false; + samplerKey.minFilt = false; + samplerKey.mipEnable = false; + ApplySamplingParams(samplerKey); + + // Since we started/ended render passes, might need these. + gstate_c.Dirty(DIRTY_DEPAL); + gstate_c.SetUseShaderDepal(true); + gstate_c.depalFramebufferFormat = framebuffer->drawnFormat; + const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); + const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; + CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors); + gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); + + draw_->InvalidateCachedState(); + InvalidateLastTexture(); + return; + } + + depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); + gstate_c.SetUseShaderDepal(false); + } + + if (depalShader) { + const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); + Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); + Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); + draw_->BindTexture(0, nullptr); + draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal"); + + draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight); + Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; + draw_->SetViewports(1, &vp); + + TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); + shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); + shaderApply.Use(); + + draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); + Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); + draw_->BindSamplerStates(0, 1, &nearest); + draw_->BindSamplerStates(1, 1, &nearest); + draw_->BindTexture(1, clutTexture); + + shaderApply.Shade(); + + framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); + + draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); + + const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); + const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; + + CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors); + gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); + + draw_->InvalidateCachedState(); + shaderManager_->DirtyLastShader(); + } else { + framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); + framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + + gstate_c.SetUseShaderDepal(false); + gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); + } + + SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); + ApplySamplingParams(samplerKey); + + // Since we started/ended render passes, might need these. + gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); +} + void TextureCacheCommon::Clear(bool delete_them) { depalShaderCache_->Clear(); diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 95a482805b..142f89ff70 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -50,6 +50,7 @@ enum FramebufferNotificationChannel { struct VirtualFramebuffer; class TextureReplacer; +class ShaderManagerCommon; namespace Draw { class DrawContext; @@ -288,6 +289,10 @@ public: // TODO: Return stuff directly instead of keeping state. TexCacheEntry *SetTexture(); + void SetShaderManager(ShaderManagerCommon *sm) { + shaderManager_ = sm; + } + void ApplyTexture(); bool SetOffsetTexture(u32 yOffset); void Invalidate(u32 addr, int size, GPUInvalidationType type); @@ -328,7 +333,7 @@ protected: void DeleteTexture(TexCache::iterator it); void Decimate(bool forcePressure = false); - virtual void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) = 0; + void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel); void HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete); virtual void BuildTexture(TexCacheEntry *const entry) = 0; @@ -405,6 +410,7 @@ protected: TextureScalerCommon scaler_; FramebufferManagerCommon *framebufferManager_; DepalShaderCache *depalShaderCache_; + ShaderManagerCommon *shaderManager_; bool clearCacheNextFrame_ = false; bool lowMemoryMode_ = false; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 760a1f5022..8479a3dcb1 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -264,101 +264,6 @@ void TextureCacheD3D11::BindAsClutTexture(Draw::Texture *tex) { context_->PSSetSamplers(3, 1, &stockD3D11.samplerPoint2DWrap); } -void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { - DepalShader *depalShader = nullptr; - uint32_t clutMode = gstate.clutformat & 0xFFFFFF; - bool need_depalettize = IsClutFormat(texFormat); - - bool depth = channel == NOTIFY_FB_DEPTH; - bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; - if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { - useShaderDepal = false; - depth = false; // Can't support this - } - - if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { - if (useShaderDepal) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - BindAsClutTexture(clutTexture); - - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - samplerKey.magFilt = false; - samplerKey.minFilt = false; - samplerKey.mipEnable = false; - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_DEPAL); - gstate_c.SetUseShaderDepal(true); - gstate_c.depalFramebufferFormat = framebuffer->drawnFormat; - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - InvalidateLastTexture(); - return; - } - - depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); - gstate_c.SetUseShaderDepal(false); - } - - if (depalShader) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); - draw_->BindTexture(0, nullptr); - draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal"); - - draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight); - Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; - draw_->SetViewports(1, &vp); - - TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); - shaderApply.Use(); - - draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); - Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); - draw_->BindSamplerStates(0, 1, &nearest); - draw_->BindSamplerStates(1, 1, &nearest); - draw_->BindTexture(1, clutTexture); - - shaderApply.Shade(); - - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - - draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); - - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - shaderManager_->DirtyLastShader(); - } else { - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - - gstate_c.SetUseShaderDepal(false); - gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); - } - - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - ApplySamplingParams(samplerKey); - - gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_RASTER_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_BLEND_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_TEXTURE_IMAGE | DIRTY_TEXTURE_PARAMS); - draw_->InvalidateCachedState(); -} - void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { BuildTexturePlan plan; if (!PrepareBuildTexture(plan, entry)) { diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index cda0860277..433f6e824e 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -49,9 +49,6 @@ public: void StartFrame() override; void SetFramebufferManager(FramebufferManagerD3D11 *fbManager); - void SetShaderManager(ShaderManagerD3D11 *sm) { - shaderManager_ = sm; - } void ForgetLastTexture() override; void InvalidateLastTexture() override; @@ -70,7 +67,6 @@ private: static CheckAlphaResult CheckAlpha(const u32 *pixelData, u32 dstFmt, int w); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; - void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; void BuildTexture(TexCacheEntry *const entry) override; ID3D11Device *device_; @@ -89,7 +85,6 @@ private: ID3D11Buffer *depalConstants_; FramebufferManagerD3D11 *framebufferManagerD3D11_; - ShaderManagerD3D11 *shaderManager_; }; DXGI_FORMAT GetClutDestFormatD3D11(GEPaletteFormat format); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 92a3b79c4f..e292d4f3c8 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -230,101 +230,6 @@ void TextureCacheDX9::BindAsClutTexture(Draw::Texture *tex) { device_->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE); } -void TextureCacheDX9::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { - DepalShader *depalShader = nullptr; - uint32_t clutMode = gstate.clutformat & 0xFFFFFF; - bool need_depalettize = IsClutFormat(texFormat); - - bool depth = channel == NOTIFY_FB_DEPTH; - bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; - if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { - useShaderDepal = false; - depth = false; // Can't support this - } - - if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { - if (useShaderDepal) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - BindAsClutTexture(clutTexture); - - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - samplerKey.magFilt = false; - samplerKey.minFilt = false; - samplerKey.mipEnable = false; - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_DEPAL); - gstate_c.SetUseShaderDepal(true); - gstate_c.depalFramebufferFormat = framebuffer->drawnFormat; - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - InvalidateLastTexture(); - return; - } - - depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); - gstate_c.SetUseShaderDepal(false); - } - - if (depalShader) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); - draw_->BindTexture(0, nullptr); - draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal"); - - draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight); - Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; - draw_->SetViewports(1, &vp); - - TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); - shaderApply.Use(); - - draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); - Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); - draw_->BindSamplerStates(0, 1, &nearest); - draw_->BindSamplerStates(1, 1, &nearest); - draw_->BindTexture(1, clutTexture); - - shaderApply.Shade(); - - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - - draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); - - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - shaderManager_->DirtyLastShader(); - } else { - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - - gstate_c.SetUseShaderDepal(false); - gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); - } - - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); -} - void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry) { BuildTexturePlan plan; if (!PrepareBuildTexture(plan, entry)) { diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 4ace0de969..bc4423b962 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -42,9 +42,6 @@ public: void SetDepalShaderCache(DepalShaderCache *dpCache) { depalShaderCache_ = dpCache; } - void SetShaderManager(ShaderManagerDX9 *sm) { - shaderManager_ = sm; - } void ForgetLastTexture() override { InvalidateLastTexture(); @@ -66,7 +63,6 @@ private: static CheckAlphaResult CheckAlpha(const u32 *pixelData, u32 dstFmt, int w); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; - void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; void BuildTexture(TexCacheEntry *const entry) override; LPDIRECT3DBASETEXTURE9 &DxTex(TexCacheEntry *entry) { @@ -82,7 +78,6 @@ private: float maxAnisotropyLevel; FramebufferManagerDX9 *framebufferManagerDX9_; - ShaderManagerDX9 *shaderManager_; }; D3DFORMAT getClutDestFormat(GEPaletteFormat format); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 5d9882095a..018d0c7a0e 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -239,101 +239,6 @@ void TextureCacheGLES::BindAsClutTexture(Draw::Texture *tex) { render_->SetTextureSampler(TEX_SLOT_CLUT, GL_REPEAT, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f); } -void TextureCacheGLES::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { - DepalShader *depalShader = nullptr; - uint32_t clutMode = gstate.clutformat & 0xFFFFFF; - bool need_depalettize = IsClutFormat(texFormat); - - bool depth = channel == NOTIFY_FB_DEPTH; - bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; - if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { - useShaderDepal = false; - depth = false; // Can't support this - } - - if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { - if (useShaderDepal) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - BindAsClutTexture(clutTexture); - - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - samplerKey.magFilt = false; - samplerKey.minFilt = false; - samplerKey.mipEnable = false; - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_DEPAL); - gstate_c.SetUseShaderDepal(true); - gstate_c.depalFramebufferFormat = framebuffer->drawnFormat; - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - InvalidateLastTexture(); - return; - } - - depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); - gstate_c.SetUseShaderDepal(false); - } - - if (depalShader) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); - draw_->BindTexture(0, nullptr); - draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal"); - - draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight); - Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; - draw_->SetViewports(1, &vp); - - TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); - shaderApply.Use(); - - draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); - Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); - draw_->BindSamplerStates(0, 1, &nearest); - draw_->BindSamplerStates(1, 1, &nearest); - draw_->BindTexture(1, clutTexture); - - shaderApply.Shade(); - - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - - draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); - - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - shaderManager_->DirtyLastShader(); - } else { - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - - gstate_c.SetUseShaderDepal(false); - gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); - } - - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); -} - void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) { BuildTexturePlan plan; if (!PrepareBuildTexture(plan, entry)) { diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index ecc4b4d6a2..90108d2639 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -44,9 +44,6 @@ public: void SetDepalShaderCache(DepalShaderCache *dpCache) { depalShaderCache_ = dpCache; } - void SetShaderManager(ShaderManagerGLES *sm) { - shaderManager_ = sm; - } void SetDrawEngine(DrawEngineGLES *td) { drawEngine_ = td; } @@ -75,8 +72,6 @@ private: Draw::DataFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; - void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; - void BuildTexture(TexCacheEntry *const entry) override; GLRenderManager *render_; @@ -84,7 +79,7 @@ private: GLRTexture *lastBoundTexture = nullptr; FramebufferManagerGLES *framebufferManagerGL_; - ShaderManagerGLES *shaderManager_; + ShaderManagerGLES *shaderManagerGL_; DrawEngineGLES *drawEngine_; enum { INVALID_TEX = -1 }; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 7680ad1c0b..54d9d1947d 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -415,101 +415,6 @@ void TextureCacheVulkan::BindAsClutTexture(Draw::Texture *tex) { drawEngine_->SetDepalTexture(clutTexture); } -void TextureCacheVulkan::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) { - DepalShader *depalShader = nullptr; - uint32_t clutMode = gstate.clutformat & 0xFFFFFF; - bool need_depalettize = IsClutFormat(texFormat); - - bool depth = channel == NOTIFY_FB_DEPTH; - bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300) || gstate_c.Supports(GPU_SUPPORTS_GLSL_330)) && !depth; - if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { - useShaderDepal = false; - depth = false; // Can't support this - } - - if (need_depalettize && !g_Config.bDisableSlowFramebufEffects) { - if (useShaderDepal) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - - // Very icky conflation here of native and thin3d rendering. This will need careful work per backend in BindAsClutTexture. - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - BindAsClutTexture(clutTexture); - - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - samplerKey.magFilt = false; - samplerKey.minFilt = false; - samplerKey.mipEnable = false; - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_DEPAL); - gstate_c.SetUseShaderDepal(true); - gstate_c.depalFramebufferFormat = framebuffer->drawnFormat; - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBuf_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - InvalidateLastTexture(); - return; - } - - depalShader = depalShaderCache_->GetDepalettizeShader(clutMode, depth ? GE_FORMAT_DEPTH16 : framebuffer->drawnFormat); - gstate_c.SetUseShaderDepal(false); - } - - if (depalShader) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); - Draw::Texture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBufRaw_); - Draw::Framebuffer *depalFBO = framebufferManager_->GetTempFBO(TempFBO::DEPAL, framebuffer->renderWidth, framebuffer->renderHeight); - draw_->BindTexture(0, nullptr); - draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE }, "Depal"); - - draw_->SetScissorRect(0, 0, (int)framebuffer->renderWidth, (int)framebuffer->renderHeight); - Draw::Viewport vp{ 0.0f, 0.0f, (float)framebuffer->renderWidth, (float)framebuffer->renderHeight, 0.0f, 1.0f }; - draw_->SetViewports(1, &vp); - - TextureShaderApplier shaderApply(draw_, depalShader, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight); - shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset); - shaderApply.Use(); - - draw_->BindFramebufferAsTexture(framebuffer->fbo, 0, depth ? Draw::FB_DEPTH_BIT : Draw::FB_COLOR_BIT, 0); - Draw::SamplerState *nearest = depalShaderCache_->GetSampler(); - draw_->BindSamplerStates(0, 1, &nearest); - draw_->BindSamplerStates(1, 1, &nearest); - draw_->BindTexture(1, clutTexture); - - shaderApply.Shade(); - - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - - draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0); - - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - CheckAlphaResult alphaStatus = CheckCLUTAlpha((const uint8_t *)clutBufRaw_, clutFormat, clutTotalColors); - gstate_c.SetTextureFullAlpha(alphaStatus == CHECKALPHA_FULL); - - draw_->InvalidateCachedState(); - shaderManagerVulkan_->DirtyLastShader(); - } else { - framebufferManager_->RebindFramebuffer("ApplyTextureFramebuffer"); - framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); - - gstate_c.SetUseShaderDepal(false); - gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); - } - - SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight); - ApplySamplingParams(samplerKey); - - // Since we started/ended render passes, might need these. - gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE); -} - static Draw::DataFormat FromVulkanFormat(VkFormat fmt) { switch (fmt) { case VULKAN_8888_FORMAT: default: return Draw::DataFormat::R8G8B8A8_UNORM; diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index d3c397d122..df63316895 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -67,9 +67,6 @@ public: void SetDepalShaderCache(DepalShaderCache *dpCache) { depalShaderCache_ = dpCache; } - void SetShaderManager(ShaderManagerVulkan *sm) { - shaderManagerVulkan_ = sm; - } void SetDrawEngine(DrawEngineVulkan *td) { drawEngine_ = td; } @@ -109,7 +106,6 @@ private: static CheckAlphaResult CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int w); void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; - void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; void BuildTexture(TexCacheEntry *const entry) override; void CompileScalingShader(); @@ -121,7 +117,6 @@ private: SamplerCache samplerCache_; - ShaderManagerVulkan *shaderManagerVulkan_; DrawEngineVulkan *drawEngine_; std::string textureShader_;