From a1b6de5cdc4d42fe3632f46fda67ab48e689f89f Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 7 Feb 2025 12:43:38 +0100 Subject: [PATCH] [d3d11] Ignore Flush calls if we are waiting for a resolve --- src/d3d11/d3d11_context.cpp | 8 ++++++++ src/d3d11/d3d11_context_imm.cpp | 10 +++++++++- src/d3d11/d3d11_context_imm.h | 2 ++ src/d3d11/d3d11_device.cpp | 5 +++-- src/d3d11/d3d11_device.h | 6 ++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 90195f840..b0579d00b 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -923,6 +923,9 @@ namespace dxvk { ctx->resolveImage(cDstImage, cSrcImage, region, cFormat); }); + + if constexpr (!IsDeferred) + GetTypedContext()->m_ignoreNextExplicitFlush = false; } if (dstTextureInfo->HasSequenceNumber()) @@ -4895,6 +4898,7 @@ namespace dxvk { return; bool needsUpdate = false; + bool isMultisampled = false; if (likely(NumRTVs != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)) { // Native D3D11 does not change the render targets if @@ -4915,6 +4919,9 @@ namespace dxvk { if (NumUAVs == D3D11_KEEP_UNORDERED_ACCESS_VIEWS) ResolveOmUavHazards(rtv); } + + if (rtv && rtv->GetSampleCount() > 1u) + isMultisampled = true; } auto dsv = static_cast(pDepthStencilView); @@ -4966,6 +4973,7 @@ namespace dxvk { if constexpr (!IsDeferred) { // Doing this makes it less likely to flush during render passes + GetTypedContext()->m_ignoreNextExplicitFlush |= isMultisampled; GetTypedContext()->ConsiderFlush(GpuFlushType::ImplicitWeakHint); } } diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 90497b1e3..0aa0cb543 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -156,7 +156,13 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11ImmediateContext::Flush() { D3D10DeviceLock lock = LockContext(); - ExecuteFlush(GpuFlushType::ExplicitFlush, nullptr, true); + // Don't flush in tiler mode if we're waiting for a multisample resolve + bool needsFlush = !m_device->perfHints().preferRenderPassOps + || m_parent->Is11on12Device() + || m_parent->HasSharedResources(); + + if (needsFlush || !m_ignoreNextExplicitFlush) + ExecuteFlush(GpuFlushType::ExplicitFlush, nullptr, true); } @@ -873,6 +879,8 @@ namespace dxvk { if (cTracker && cTracker->needsAutoMarkers()) ctx->endLatencyTracking(cTracker); }); + + m_ignoreNextExplicitFlush = false; } diff --git a/src/d3d11/d3d11_context_imm.h b/src/d3d11/d3d11_context_imm.h index ca4fc5670..0b3b29277 100644 --- a/src/d3d11/d3d11_context_imm.h +++ b/src/d3d11/d3d11_context_imm.h @@ -136,6 +136,8 @@ namespace dxvk { Com m_stateObject; + bool m_ignoreNextExplicitFlush = false; + HRESULT MapBuffer( D3D11Buffer* pResource, D3D11_MAP MapType, diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 2ffc50e26..cbc39305a 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1893,8 +1893,8 @@ namespace dxvk { bool D3D11Device::Is11on12Device() const { return m_container->Is11on12Device(); } - - + + D3D_FEATURE_LEVEL D3D11Device::GetMaxFeatureLevel( const Rc& Instance, const Rc& Adapter) { @@ -2369,6 +2369,7 @@ namespace dxvk { try { const Com texture = new D3D11Texture2D(this, &d3d11Desc, nullptr, hResource); texture->QueryInterface(ReturnedInterface, ppResource); + m_hasSharedResources.store(true); return S_OK; } catch (const DxvkError& e) { diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index 48356f8b4..a0232719e 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -464,6 +464,10 @@ namespace dxvk { bool Is11on12Device() const; + bool HasSharedResources() const { + return m_hasSharedResources.load(); + } + static D3D_FEATURE_LEVEL GetMaxFeatureLevel( const Rc& Instance, const Rc& Adapter); @@ -512,6 +516,8 @@ namespace dxvk { D3D_FEATURE_LEVEL m_maxFeatureLevel; D3D11DeviceFeatures m_deviceFeatures; + std::atomic m_hasSharedResources = { false }; + HRESULT CreateShaderModule( D3D11CommonShader* pShaderModule, DxvkShaderKey ShaderKey,