From d06553e2b4700aa026acd4445a598eadf10dfb35 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 8 Sep 2019 17:42:51 -0700 Subject: Added IDeviceContext::WaitForIdle() method (updated API version to 240028) --- .../include/DeviceContextD3D11Impl.h | 6 +++-- .../src/DeviceContextD3D11Impl.cpp | 26 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index 940529b4..86ca2fb2 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -103,8 +103,6 @@ public: virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; - virtual void Flush()override final; - virtual void UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, @@ -158,6 +156,10 @@ public: virtual void WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext)override final; + virtual void WaitForIdle()override final; + + virtual void Flush()override final; + virtual ID3D11DeviceContext* GetD3D11DeviceContext()override final { return m_pd3d11DeviceContext; } void CommitRenderTargets(); diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 72e26117..e3543bac 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -1747,20 +1747,28 @@ namespace Diligent #endif } - void DeviceContextD3D11Impl::SignalFence(IFence* pFence, Uint64 Value) + + static CComPtr CreateD3D11QueryEvent(ID3D11Device* pd3d11Device) { - VERIFY(!m_bIsDeferred, "Fence can only be signaled from immediate context"); - auto* pd3d11Device = m_pDevice.RawPtr()->GetD3D11Device(); D3D11_QUERY_DESC QueryDesc = {}; QueryDesc.Query = D3D11_QUERY_EVENT; // Determines whether or not the GPU is finished processing commands. // When the GPU is finished processing commands ID3D11DeviceContext::GetData will // return S_OK, and pData will point to a BOOL with a value of TRUE. When using this // type of query, ID3D11DeviceContext::Begin is disabled. QueryDesc.MiscFlags = 0; + CComPtr pd3d11Query; auto hr = pd3d11Device->CreateQuery(&QueryDesc, &pd3d11Query); DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to create D3D11 query"); VERIFY_EXPR(pd3d11Query); + return pd3d11Query; + } + + void DeviceContextD3D11Impl::SignalFence(IFence* pFence, Uint64 Value) + { + VERIFY(!m_bIsDeferred, "Fence can only be signaled from immediate context"); + auto* pd3d11Device = m_pDevice.RawPtr()->GetD3D11Device(); + CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); m_pd3d11DeviceContext->End(pd3d11Query); auto* pFenceD3D11Impl = ValidatedCast(pFence); pFenceD3D11Impl->AddPendingQuery(m_pd3d11DeviceContext, std::move(pd3d11Query), Value); @@ -1775,6 +1783,18 @@ namespace Diligent pFenceD3D11Impl->Wait(Value, FlushContext); } + void DeviceContextD3D11Impl::WaitForIdle() + { + VERIFY(!m_bIsDeferred, "Only immediate contexts can be idled"); + Flush(); + auto* pd3d11Device = m_pDevice.RawPtr()->GetD3D11Device(); + CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); + m_pd3d11DeviceContext->End(pd3d11Query); + BOOL Data; + while (m_pd3d11DeviceContext->GetData(pd3d11Query, &Data, sizeof(Data), 0) != S_OK) + std::this_thread::yield(); + } + void DeviceContextD3D11Impl::ClearStateCache() { TDeviceContextBase::ClearStateCache(); -- cgit v1.2.3