From 9fee253d09ea1f1d38c4492f4b89028d83a6d8d9 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 27 Jun 2018 18:34:17 +0200 Subject: [PATCH] [d3d11] Add more implicit flush points All these methods will implicitly spill the active render pass and are typically not called very often, so we can try to keep the GPU busy. --- src/d3d11/d3d11_context.h | 16 ++-- src/d3d11/d3d11_context_imm.cpp | 144 ++++++++++++++++++++++++++++---- src/d3d11/d3d11_context_imm.h | 61 ++++++++++++++ 3 files changed, 198 insertions(+), 23 deletions(-) diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 576a152a..a3cfa68d 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -62,7 +62,7 @@ namespace dxvk { UINT DstZ, ID3D11Resource* pSrcResource, UINT SrcSubresource, - const D3D11_BOX* pSrcBox) final; + const D3D11_BOX* pSrcBox); void STDMETHODCALLTYPE CopySubresourceRegion1( ID3D11Resource* pDstResource, @@ -73,11 +73,11 @@ namespace dxvk { ID3D11Resource* pSrcResource, UINT SrcSubresource, const D3D11_BOX* pSrcBox, - UINT CopyFlags) final; + UINT CopyFlags); void STDMETHODCALLTYPE CopyResource( ID3D11Resource* pDstResource, - ID3D11Resource* pSrcResource) final; + ID3D11Resource* pSrcResource); void STDMETHODCALLTYPE CopyStructureCount( ID3D11Buffer* pDstBuffer, @@ -109,7 +109,7 @@ namespace dxvk { UINT NumRects) final; void STDMETHODCALLTYPE GenerateMips( - ID3D11ShaderResourceView* pShaderResourceView) final; + ID3D11ShaderResourceView* pShaderResourceView); void STDMETHODCALLTYPE UpdateSubresource( ID3D11Resource* pDstResource, @@ -117,7 +117,7 @@ namespace dxvk { const D3D11_BOX* pDstBox, const void* pSrcData, UINT SrcRowPitch, - UINT SrcDepthPitch) final; + UINT SrcDepthPitch); void STDMETHODCALLTYPE UpdateSubresource1( ID3D11Resource* pDstResource, @@ -126,7 +126,7 @@ namespace dxvk { const void* pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch, - UINT CopyFlags) final; + UINT CopyFlags); void STDMETHODCALLTYPE SetResourceMinLOD( ID3D11Resource* pResource, @@ -140,7 +140,7 @@ namespace dxvk { UINT DstSubresource, ID3D11Resource* pSrcResource, UINT SrcSubresource, - DXGI_FORMAT Format) final; + DXGI_FORMAT Format); void STDMETHODCALLTYPE DrawAuto() final; @@ -566,7 +566,7 @@ namespace dxvk { UINT UAVStartSlot, UINT NumUAVs, ID3D11UnorderedAccessView* const* ppUnorderedAccessViews, - const UINT* pUAVInitialCounts) final; + const UINT* pUAVInitialCounts); void STDMETHODCALLTYPE OMSetBlendState( ID3D11BlendState* pBlendState, diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index fc7b9777..b283737a 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -191,6 +191,135 @@ namespace dxvk { } + void STDMETHODCALLTYPE D3D11ImmediateContext::CopySubresourceRegion( + ID3D11Resource* pDstResource, + UINT DstSubresource, + UINT DstX, + UINT DstY, + UINT DstZ, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + const D3D11_BOX* pSrcBox) { + FlushImplicit(); + + D3D11DeviceContext::CopySubresourceRegion( + pDstResource, DstSubresource, DstX, DstY, DstZ, + pSrcResource, SrcSubresource, pSrcBox); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::CopySubresourceRegion1( + ID3D11Resource* pDstResource, + UINT DstSubresource, + UINT DstX, + UINT DstY, + UINT DstZ, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + const D3D11_BOX* pSrcBox, + UINT CopyFlags) { + FlushImplicit(); + + D3D11DeviceContext::CopySubresourceRegion1( + pDstResource, DstSubresource, DstX, DstY, DstZ, + pSrcResource, SrcSubresource, pSrcBox, CopyFlags); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::CopyResource( + ID3D11Resource* pDstResource, + ID3D11Resource* pSrcResource) { + FlushImplicit(); + + D3D11DeviceContext::CopyResource( + pDstResource, pSrcResource); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::GenerateMips( + ID3D11ShaderResourceView* pShaderResourceView) { + FlushImplicit(); + + D3D11DeviceContext::GenerateMips( + pShaderResourceView); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::UpdateSubresource( + ID3D11Resource* pDstResource, + UINT DstSubresource, + const D3D11_BOX* pDstBox, + const void* pSrcData, + UINT SrcRowPitch, + UINT SrcDepthPitch) { + FlushImplicit(); + + D3D11DeviceContext::UpdateSubresource( + pDstResource, DstSubresource, pDstBox, + pSrcData, SrcRowPitch, SrcDepthPitch); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::UpdateSubresource1( + ID3D11Resource* pDstResource, + UINT DstSubresource, + const D3D11_BOX* pDstBox, + const void* pSrcData, + UINT SrcRowPitch, + UINT SrcDepthPitch, + UINT CopyFlags) { + FlushImplicit(); + + D3D11DeviceContext::UpdateSubresource1( + pDstResource, DstSubresource, pDstBox, + pSrcData, SrcRowPitch, SrcDepthPitch, + CopyFlags); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::ResolveSubresource( + ID3D11Resource* pDstResource, + UINT DstSubresource, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + DXGI_FORMAT Format) { + FlushImplicit(); + + D3D11DeviceContext::ResolveSubresource( + pDstResource, DstSubresource, + pSrcResource, SrcSubresource, + Format); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::OMSetRenderTargets( + UINT NumViews, + ID3D11RenderTargetView* const* ppRenderTargetViews, + ID3D11DepthStencilView* pDepthStencilView) { + FlushImplicit(); + + D3D11DeviceContext::OMSetRenderTargets( + NumViews, ppRenderTargetViews, pDepthStencilView); + } + + + void STDMETHODCALLTYPE D3D11ImmediateContext::OMSetRenderTargetsAndUnorderedAccessViews( + UINT NumRTVs, + ID3D11RenderTargetView* const* ppRenderTargetViews, + ID3D11DepthStencilView* pDepthStencilView, + UINT UAVStartSlot, + UINT NumUAVs, + ID3D11UnorderedAccessView* const* ppUnorderedAccessViews, + const UINT* pUAVInitialCounts) { + FlushImplicit(); + + D3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews( + NumRTVs, ppRenderTargetViews, pDepthStencilView, + UAVStartSlot, NumUAVs, ppUnorderedAccessViews, + pUAVInitialCounts); + } + + HRESULT D3D11ImmediateContext::MapBuffer( D3D11Buffer* pResource, D3D11_MAP MapType, @@ -234,21 +363,6 @@ namespace dxvk { } - void STDMETHODCALLTYPE D3D11ImmediateContext::OMSetRenderTargets( - UINT NumViews, - ID3D11RenderTargetView* const* ppRenderTargetViews, - ID3D11DepthStencilView* pDepthStencilView) { - // Optimization: If the number of draw and dispatch calls issued - // prior to the previous context flush is above a certain threshold, - // submit the current command buffer in order to keep the GPU busy. - // This also helps keep the command buffers at a reasonable size. - FlushImplicit(); - - D3D11DeviceContext::OMSetRenderTargets( - NumViews, ppRenderTargetViews, pDepthStencilView); - } - - HRESULT D3D11ImmediateContext::MapImage( D3D11CommonTexture* pResource, UINT Subresource, diff --git a/src/d3d11/d3d11_context_imm.h b/src/d3d11/d3d11_context_imm.h index ed41a682..013de381 100644 --- a/src/d3d11/d3d11_context_imm.h +++ b/src/d3d11/d3d11_context_imm.h @@ -54,11 +54,72 @@ namespace dxvk { ID3D11Resource* pResource, UINT Subresource) final; + void STDMETHODCALLTYPE CopySubresourceRegion( + ID3D11Resource* pDstResource, + UINT DstSubresource, + UINT DstX, + UINT DstY, + UINT DstZ, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + const D3D11_BOX* pSrcBox) final; + + void STDMETHODCALLTYPE CopySubresourceRegion1( + ID3D11Resource* pDstResource, + UINT DstSubresource, + UINT DstX, + UINT DstY, + UINT DstZ, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + const D3D11_BOX* pSrcBox, + UINT CopyFlags) final; + + void STDMETHODCALLTYPE CopyResource( + ID3D11Resource* pDstResource, + ID3D11Resource* pSrcResource) final; + + void STDMETHODCALLTYPE GenerateMips( + ID3D11ShaderResourceView* pShaderResourceView) final; + + void STDMETHODCALLTYPE UpdateSubresource( + ID3D11Resource* pDstResource, + UINT DstSubresource, + const D3D11_BOX* pDstBox, + const void* pSrcData, + UINT SrcRowPitch, + UINT SrcDepthPitch) final; + + void STDMETHODCALLTYPE UpdateSubresource1( + ID3D11Resource* pDstResource, + UINT DstSubresource, + const D3D11_BOX* pDstBox, + const void* pSrcData, + UINT SrcRowPitch, + UINT SrcDepthPitch, + UINT CopyFlags) final; + + void STDMETHODCALLTYPE ResolveSubresource( + ID3D11Resource* pDstResource, + UINT DstSubresource, + ID3D11Resource* pSrcResource, + UINT SrcSubresource, + DXGI_FORMAT Format) final; + void STDMETHODCALLTYPE OMSetRenderTargets( UINT NumViews, ID3D11RenderTargetView* const* ppRenderTargetViews, ID3D11DepthStencilView* pDepthStencilView) final; + void STDMETHODCALLTYPE OMSetRenderTargetsAndUnorderedAccessViews( + UINT NumRTVs, + ID3D11RenderTargetView* const* ppRenderTargetViews, + ID3D11DepthStencilView* pDepthStencilView, + UINT UAVStartSlot, + UINT NumUAVs, + ID3D11UnorderedAccessView* const* ppUnorderedAccessViews, + const UINT* pUAVInitialCounts) final; + void SynchronizeCsThread(); private: