From c9655a6749434bb463d615754cbb910c7183c49e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 5 May 2019 10:15:10 -0700 Subject: Added safe check that same PSO is being bound --- Graphics/GraphicsEngine/include/DeviceObjectBase.h | 7 +++++++ Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp | 3 +++ Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp | 5 ++++- Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 3 +++ Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 9 ++++++--- 5 files changed, 23 insertions(+), 4 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index 7d83d025..8f301d6a 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -146,6 +146,13 @@ public: return m_UniqueID.GetID(); } + static bool IsSameObject(DeviceObjectBase* pObj1, DeviceObjectBase* pObj2) + { + UniqueIdentifier Id1 = (pObj1 != nullptr) ? pObj1->GetUniqueID() : 0; + UniqueIdentifier Id2 = (pObj2 != nullptr) ? pObj2->GetUniqueID() : 0; + return Id1 == Id2; + } + RenderDeviceImplType* GetDevice()const{return m_pDevice;} protected: diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index ea121585..dc6c3281 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -59,6 +59,9 @@ namespace Diligent void DeviceContextD3D11Impl::SetPipelineState(IPipelineState* pPipelineState) { auto* pPipelineStateD3D11 = ValidatedCast(pPipelineState); + if (PipelineStateD3D11Impl::IsSameObject(m_pPipelineState, pPipelineStateD3D11)) + return; + TDeviceContextBase::SetPipelineState( pPipelineStateD3D11, 0 /*Dummy*/ ); auto& Desc = pPipelineStateD3D11->GetDesc(); if (Desc.IsComputePipeline) diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index e4c04ba4..3c1a4ca6 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -165,13 +165,16 @@ namespace Diligent void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState) { + auto* pPipelineStateD3D12 = ValidatedCast(pPipelineState); + if (PipelineStateD3D12Impl::IsSameObject(m_pPipelineState, pPipelineStateD3D12)) + return; + // Never flush deferred context! if (!m_bIsDeferred && m_State.NumCommands >= m_NumCommandsToFlush) { Flush(true); } - auto* pPipelineStateD3D12 = ValidatedCast(pPipelineState); const auto &PSODesc = pPipelineStateD3D12->GetDesc(); bool CommitStates = false; diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index ef960062..f6fde626 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -66,6 +66,9 @@ namespace Diligent void DeviceContextGLImpl::SetPipelineState(IPipelineState* pPipelineState) { auto* pPipelineStateGLImpl = ValidatedCast(pPipelineState); + if (PipelineStateGLImpl::IsSameObject(m_pPipelineState, pPipelineStateGLImpl)) + return; + TDeviceContextBase::SetPipelineState(pPipelineStateGLImpl, 0 /*Dummy*/); const auto& Desc = pPipelineStateGLImpl->GetDesc(); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 865d4177..583feb6f 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -207,16 +207,19 @@ namespace Diligent } - void DeviceContextVkImpl::SetPipelineState(IPipelineState *pPipelineState) + void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) { + auto* pPipelineStateVk = ValidatedCast(pPipelineState); + if (PipelineStateVkImpl::IsSameObject(m_pPipelineState, pPipelineStateVk)) + return; + // Never flush deferred context! if (!m_bIsDeferred && m_State.NumCommands >= m_NumCommandsToFlush) { Flush(); } - auto* pPipelineStateVk = ValidatedCast(pPipelineState); - const auto& PSODesc = pPipelineStateVk->GetDesc(); + const auto& PSODesc = pPipelineStateVk->GetDesc(); bool CommitStates = false; bool CommitScissor = false; -- cgit v1.2.3