diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 5a312ce05b9a..d3b6a57cf063 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -244,16 +244,6 @@ IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(VSShader *vshader } } -VertexDecoder *DrawEngineDX9::GetVertexDecoder(u32 vtype) { - auto iter = decoderMap_.find(vtype); - if (iter != decoderMap_.end()) - return iter->second; - VertexDecoder *dec = new VertexDecoder(); - dec->SetVertexType(vtype, decOptions_, decJitCache_); - decoderMap_[vtype] = dec; - return dec; -} - void DrawEngineDX9::SetupVertexDecoder(u32 vertType) { SetupVertexDecoderInternal(vertType); } diff --git a/GPU/Directx9/DrawEngineDX9.h b/GPU/Directx9/DrawEngineDX9.h index f98202f09588..8f54c6287774 100644 --- a/GPU/Directx9/DrawEngineDX9.h +++ b/GPU/Directx9/DrawEngineDX9.h @@ -201,8 +201,6 @@ class DrawEngineDX9 : public DrawEngineCommon { ReliableHashType ComputeHash(); // Reads deferred vertex data. void MarkUnreliable(VertexArrayInfoDX9 *vai); - VertexDecoder *GetVertexDecoder(u32 vtype); - // Defer all vertex decoding to a Flush, so that we can hash and cache the // generated buffers without having to redecode them every time. struct DeferredDrawCall { diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 5c0ba999fbc9..b21f04d71f31 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -649,28 +649,9 @@ 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(); const u64 cachekey = entry->CacheKey(); const auto &fbInfo = fbTexInfo_[cachekey]; - LPDIRECT3DPIXELSHADER9 pshader = nullptr; - if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - pshader = depalShaderCache_->GetDepalettizePixelShader(clutFormat, framebuffer->drawnFormat); - } - if (pshader) { - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - 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 { - entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - - gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; - gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; - } - // Keep the framebuffer alive. framebuffer->last_frame_used = gpuStats.numFlips; @@ -694,6 +675,10 @@ void TextureCacheDX9::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebu pD3Ddevice->SetTexture(0, NULL); gstate_c.needShaderTexClamp = false; } + + nextNeedsRehash_ = false; + nextNeedsChange_ = false; + nextNeedsRebuild_ = false; } void TextureCacheDX9::ApplyTexture() { @@ -911,8 +896,20 @@ void TextureCacheDX9::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFrame shaderApply.Shade(); fbo_bind_color_as_texture(depalFBO, 0); + + const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); + const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; + + 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 { + entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; + framebufferManager_->BindFramebufferColor(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + + gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; + gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; } framebufferManager_->RebindFramebuffer(); @@ -1148,8 +1145,22 @@ void TextureCacheDX9::SetTexture(bool force) { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1263,16 +1274,8 @@ void TextureCacheDX9::BuildTexture(TexCacheEntry *const entry, bool replaceImage // TODO: If a framebuffer is attached here, might end up with a bad entry.texture. // Should just always create one here or something (like GLES.) - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; } diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index f13b061dc01c..0663d2d013db 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -847,13 +847,6 @@ void DrawEngineGLES::DoFlush() { prim = indexGen.Prim(); } - if (gstate_c.Supports(GPU_SUPPORTS_VAO) && vbo == 0) { - vbo = BindBuffer(decoded, dec_->GetDecVtxFmt().stride * indexGen.MaxIndex()); - if (useElements) { - ebo = BindElementBuffer(decIndex, sizeof(short) * indexGen.VertexCount()); - } - } - VERBOSE_LOG(G3D, "Flush prim %i! %i verts in one go", prim, vertexCount); bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE; if (gstate.isModeThrough()) { @@ -863,6 +856,14 @@ void DrawEngineGLES::DoFlush() { } ApplyDrawStateLate(); + + if (gstate_c.Supports(GPU_SUPPORTS_VAO) && vbo == 0) { + vbo = BindBuffer(decoded, dec_->GetDecVtxFmt().stride * indexGen.MaxIndex()); + if (useElements) { + ebo = BindElementBuffer(decIndex, sizeof(short) * indexGen.VertexCount()); + } + } + LinkedShader *program = shaderManager_->ApplyFragmentShader(vsid, vshader, lastVType_, prim); SetupDecFmtForDraw(program, dec_->GetDecVtxFmt(), vbo ? 0 : decoded); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 1f09773f5e5c..8dad33f70df4 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -882,7 +882,7 @@ void FramebufferManager::BindFramebufferColor(int stage, u32 fbRawAddress, Virtu } if (stage != GL_TEXTURE0) { - glActiveTexture(stage); + glActiveTexture(GL_TEXTURE0); } } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index e97e3997757e..dfd436e0f82e 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -719,28 +719,9 @@ 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(); const u64 cachekey = entry->CacheKey(); const auto &fbInfo = fbTexInfo_[cachekey]; - DepalShader *depal = nullptr; - if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - depal = depalShaderCache_->GetDepalettizeShader(clutFormat, framebuffer->drawnFormat); - } - if (depal) { - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - 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 { - entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - - gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; - gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; - } - // Keep the framebuffer alive. framebuffer->last_frame_used = gpuStats.numFlips; @@ -763,6 +744,10 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe glBindTexture(GL_TEXTURE_2D, 0); gstate_c.needShaderTexClamp = false; } + + nextNeedsRehash_ = false; + nextNeedsChange_ = false; + nextNeedsRebuild_ = false; } void TextureCache::ApplyTexture() { @@ -985,8 +970,20 @@ void TextureCache::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuf shaderApply.Shade(); fbo_bind_color_as_texture(depalFBO, 0); + + const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); + const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; + + 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 { + entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; + framebufferManager_->BindFramebufferColor(GL_TEXTURE0, gstate.getFrameBufRawAddress(), framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); + + gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; + gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; } framebufferManager_->RebindFramebuffer(); @@ -1250,8 +1247,22 @@ void TextureCache::SetTexture(bool force) { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1367,16 +1378,8 @@ void TextureCache::BuildTexture(TexCacheEntry *const entry, bool replaceImages) entry->textureName = AllocTextureName(); } - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; } diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 95638f624787..e0351015777d 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -268,16 +268,6 @@ void DrawEngineVulkan::EndFrame() { curFrame_++; } -VertexDecoder *DrawEngineVulkan::GetVertexDecoder(u32 vtype) { - auto iter = decoderMap_.find(vtype); - if (iter != decoderMap_.end()) - return iter->second; - VertexDecoder *dec = new VertexDecoder(); - dec->SetVertexType(vtype, decOptions_, decJitCache_); - decoderMap_[vtype] = dec; - return dec; -} - void DrawEngineVulkan::SetupVertexDecoder(u32 vertType) { SetupVertexDecoderInternal(vertType); } diff --git a/GPU/Vulkan/DrawEngineVulkan.h b/GPU/Vulkan/DrawEngineVulkan.h index dbaf6f68b7bd..280555aed8af 100644 --- a/GPU/Vulkan/DrawEngineVulkan.h +++ b/GPU/Vulkan/DrawEngineVulkan.h @@ -168,8 +168,6 @@ class DrawEngineVulkan : public DrawEngineCommon { VkDescriptorSet GetDescriptorSet(VkImageView imageView, VkSampler sampler, VkBuffer base, VkBuffer light, VkBuffer bone); - VertexDecoder *GetVertexDecoder(u32 vtype); - VulkanContext *vulkan_; // We use a single descriptor set layout for all PSP draws. diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index d3bb0bc15928..446290f917ec 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -659,28 +659,9 @@ void TextureCacheVulkan::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFram framebuffer->usageFlags |= FB_USAGE_TEXTURE; bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; if (useBufferedRendering) { - const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); const u64 cachekey = entry->CacheKey(); const auto &fbInfo = fbTexInfo_[cachekey]; - DepalShaderVulkan *depal = nullptr; - if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - // depal = depalShaderCache_->GetDepalettizeShader(clutFormat, framebuffer->drawnFormat); - } - if (depal) { - const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); - const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; - - TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormatVulkan(clutFormat), clutTotalColors, clutTotalColors, 1); - gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL; - gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE; - } else { - entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; - - gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; - gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; - } - // Keep the framebuffer alive. framebuffer->last_frame_used = gpuStats.numFlips; @@ -702,6 +683,10 @@ void TextureCacheVulkan::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFram } gstate_c.needShaderTexClamp = false; } + + nextNeedsRehash_ = false; + nextNeedsChange_ = false; + nextNeedsRebuild_ = false; } void TextureCacheVulkan::ApplyTexture(VulkanPushBuffer *uploadBuffer, VkImageView &imageView, VkSampler &sampler) { @@ -847,6 +832,18 @@ void TextureCacheVulkan::ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEn //depalFBO->EndPass(cmd); //depalFBO->TransitionToTexture(cmd); //imageView = depalFBO->GetColorImageView(); + + const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); + const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor; + + TexCacheEntry::Status alphaStatus = CheckAlpha(clutBuf_, getClutDestFormatVulkan(clutFormat), clutTotalColors, clutTotalColors, 1); + gstate_c.textureFullAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL; + gstate_c.textureSimpleAlpha = alphaStatus == TexCacheEntry::STATUS_ALPHA_SIMPLE; + } else { + entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE; + + gstate_c.textureFullAlpha = gstate.getTextureFormat() == GE_TFMT_5650; + gstate_c.textureSimpleAlpha = gstate_c.textureFullAlpha; } /* @@ -1120,8 +1117,22 @@ void TextureCacheVulkan::SetTexture() { gstate_c.curTextureWidth = w; gstate_c.curTextureHeight = h; + // Before we go reading the texture from memory, let's check for render-to-texture. + // We must do this early so we have the right w/h. + entry->framebuffer = 0; + for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { + auto framebuffer = fbCache_[i]; + AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); + } + + // If we ended up with a framebuffer, attach it - no texture decoding needed. + if (entry->framebuffer) { + SetTextureFramebuffer(entry, entry->framebuffer); + } + nextTexture_ = entry; - nextNeedsRehash_ = true; + nextNeedsRehash_ = entry->framebuffer == nullptr; + // We still need to rebuild, to allocate a texture. But we'll bail early. nextNeedsRebuild_= true; } @@ -1225,16 +1236,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry,VulkanPushBuffe // For the estimate, we assume cluts always point to 8888 for simplicity. cacheSizeEstimate_ += EstimateTexMemoryUsage(entry); - // Before we go reading the texture from memory, let's check for render-to-texture. - entry->framebuffer = 0; - for (size_t i = 0, n = fbCache_.size(); i < n; ++i) { - auto framebuffer = fbCache_[i]; - AttachFramebuffer(entry, framebuffer->fb_address, framebuffer); - } - - // If we ended up with a framebuffer, attach it - no texture decoding needed. if (entry->framebuffer) { - SetTextureFramebuffer(entry, entry->framebuffer); + // Nothing else to do here. return; }