From d7044c2efd03c5fd0448aea3e37e5cc50e16818b Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Fri, 11 Oct 2024 21:30:55 +0200 Subject: [PATCH] [d3d9] Don't clear mipGenBit if texture is bound as attachment --- src/d3d9/d3d9_device.cpp | 22 ++++++++++++++-------- src/d3d9/d3d9_device.h | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 67b4d9bdfbd..ba1379d7608 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -6151,9 +6151,11 @@ namespace dxvk { // Guaranteed to not be nullptr... auto texInfo = GetCommonTexture(m_state.textures[texIdx]); - if (texInfo->NeedsMipGen()) { + if (likely(texInfo->NeedsMipGen())) { this->EmitGenerateMips(texInfo); - texInfo->SetNeedsMipGen(false); + if (likely(!IsTextureBoundAsAttachment(texInfo))) { + texInfo->SetNeedsMipGen(false); + } } } @@ -6178,14 +6180,18 @@ namespace dxvk { void D3D9DeviceEx::MarkTextureMipsUnDirty(D3D9CommonTexture* pResource) { - pResource->SetNeedsMipGen(false); + if (likely(!IsTextureBoundAsAttachment(pResource))) { + // We need to keep the texture marked as needing mipmap generation because we don't set that when rendering. + pResource->SetNeedsMipGen(false); - for (uint32_t i : bit::BitMask(m_activeTextures)) { - // Guaranteed to not be nullptr... - auto texInfo = GetCommonTexture(m_state.textures[i]); + for (uint32_t i : bit::BitMask(m_activeTextures)) { + // Guaranteed to not be nullptr... + auto texInfo = GetCommonTexture(m_state.textures[i]); - if (texInfo == pResource) - m_activeTexturesToGen &= ~(1 << i); + if (unlikely(texInfo == pResource)) { + m_activeTexturesToGen &= ~(1 << i); + } + } } } diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 5b1119291bd..8ee0265dbc9 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -1299,6 +1299,23 @@ namespace dxvk { m_mostRecentlyUsedSwapchain = m_implicitSwapchain.ptr(); } + bool IsTextureBoundAsAttachment(const D3D9CommonTexture* pTexture) const { + if (unlikely(pTexture->IsRenderTarget())) { + for (uint32_t i : bit::BitMask(m_boundRTs)) { + auto texInfo = m_state.renderTargets[i]->GetCommonTexture(); + if (unlikely(texInfo == pTexture)) { + return true; + } + } + } else if (unlikely(pTexture->IsDepthStencil() && m_state.depthStencil != nullptr)) { + auto texInfo = m_state.depthStencil->GetCommonTexture(); + if (unlikely(texInfo == pTexture)) { + return true; + } + } + return false; + } + Com m_parent; D3DDEVTYPE m_deviceType; HWND m_window;