From 03a7b275d254f6db7267ff894aeebb58e2e6e72f Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 21 Jul 2018 20:31:41 -0700 Subject: Added IFence interface --- DiligentCore | 2 +- README.md | 6 ++++++ .../IncludeTest/src/GraphicsEngine/FenceH_test.cpp | 24 +++++++++++++++++++++ .../src/GraphicsEngineD3D11/FenceD3D11H_test.cpp | 25 ++++++++++++++++++++++ .../src/GraphicsEngineD3D12/FenceD3D12H_test.cpp | 25 ++++++++++++++++++++++ .../src/GraphicsEngineOpenGL/FenceGLH_test .cpp | 25 ++++++++++++++++++++++ Tests/TestApp/include/TestApp.h | 2 ++ Tests/TestApp/src/TestApp.cpp | 13 +++++++++++ .../PluginSource/src/RenderAPI_D3D12.cpp | 5 +++++ .../src/DiligentGraphicsAdapterD3D12.cpp | 5 +++++ 10 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Tests/IncludeTest/src/GraphicsEngine/FenceH_test.cpp create mode 100644 Tests/IncludeTest/src/GraphicsEngineD3D11/FenceD3D11H_test.cpp create mode 100644 Tests/IncludeTest/src/GraphicsEngineD3D12/FenceD3D12H_test.cpp create mode 100644 Tests/IncludeTest/src/GraphicsEngineOpenGL/FenceGLH_test .cpp diff --git a/DiligentCore b/DiligentCore index 985d14e..47ddd8c 160000 --- a/DiligentCore +++ b/DiligentCore @@ -1 +1 @@ -Subproject commit 985d14e5ebef7006f25c58529923c582608ed721 +Subproject commit 47ddd8c9f1b89ba9706c79dce8cdf73149a00abf diff --git a/README.md b/README.md index f6d6f9a..473aa3a 100644 --- a/README.md +++ b/README.md @@ -420,6 +420,12 @@ and adds implementation using Diligent Engine API to allow comparing performance # Version History + +## Current Progress + +* Core + * Added `IFence` interface and `IDeviceContext::SignalFence()` method to enable CPU-GPU synchronization + ## v2.3 * Core: diff --git a/Tests/IncludeTest/src/GraphicsEngine/FenceH_test.cpp b/Tests/IncludeTest/src/GraphicsEngine/FenceH_test.cpp new file mode 100644 index 0000000..64f5cc5 --- /dev/null +++ b/Tests/IncludeTest/src/GraphicsEngine/FenceH_test.cpp @@ -0,0 +1,24 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "DiligentCore/Graphics/GraphicsEngine/interface/Fence.h" \ No newline at end of file diff --git a/Tests/IncludeTest/src/GraphicsEngineD3D11/FenceD3D11H_test.cpp b/Tests/IncludeTest/src/GraphicsEngineD3D11/FenceD3D11H_test.cpp new file mode 100644 index 0000000..db8fcce --- /dev/null +++ b/Tests/IncludeTest/src/GraphicsEngineD3D11/FenceD3D11H_test.cpp @@ -0,0 +1,25 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include +#include "DiligentCore/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h" diff --git a/Tests/IncludeTest/src/GraphicsEngineD3D12/FenceD3D12H_test.cpp b/Tests/IncludeTest/src/GraphicsEngineD3D12/FenceD3D12H_test.cpp new file mode 100644 index 0000000..8727a39 --- /dev/null +++ b/Tests/IncludeTest/src/GraphicsEngineD3D12/FenceD3D12H_test.cpp @@ -0,0 +1,25 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include +#include "DiligentCore/Graphics/GraphicsEngineD3D12/interface/FenceD3D12.h" diff --git a/Tests/IncludeTest/src/GraphicsEngineOpenGL/FenceGLH_test .cpp b/Tests/IncludeTest/src/GraphicsEngineOpenGL/FenceGLH_test .cpp new file mode 100644 index 0000000..f1e1e41 --- /dev/null +++ b/Tests/IncludeTest/src/GraphicsEngineOpenGL/FenceGLH_test .cpp @@ -0,0 +1,25 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +typedef unsigned int GLuint; +#include "DiligentCore/Graphics/GraphicsEngineOpenGL/interface/FenceGL.h" diff --git a/Tests/TestApp/include/TestApp.h b/Tests/TestApp/include/TestApp.h index 931007b..4c5ad53 100644 --- a/Tests/TestApp/include/TestApp.h +++ b/Tests/TestApp/include/TestApp.h @@ -87,6 +87,8 @@ protected: Diligent::RefCntAutoPtr m_pInstBuff, m_pInstBuff2, m_pUniformBuff, m_pUniformBuff2, m_pUniformBuff3, m_pUniformBuff4; Diligent::RefCntAutoPtr m_pTestTex; Diligent::RefCntAutoPtr m_pRenderScript; + Diligent::RefCntAutoPtr m_pFence; + Diligent::Uint64 m_NextFenceValue = 1; SmartPointerTest m_SmartPointerTest; double m_CurrTime = 0; diff --git a/Tests/TestApp/src/TestApp.cpp b/Tests/TestApp/src/TestApp.cpp index 8c5062a..d9e81df 100644 --- a/Tests/TestApp/src/TestApp.cpp +++ b/Tests/TestApp/src/TestApp.cpp @@ -495,6 +495,12 @@ void TestApp::InitializeRenderers() // This may cause D3D12 error m_pImmediateContext->Flush(); } + + { + FenceDesc fenceDesc; + fenceDesc.Name = "Test fence"; + m_pDevice->CreateFence(fenceDesc, &m_pFence); + } } void TestApp::ProcessCommandLine(const char *CmdLine) @@ -607,8 +613,15 @@ void TestApp::Render() m_TestGS.Draw(); m_TestTessellation.Draw(); + auto CompletedFenceValue = m_pFence->GetCompletedValue(); + VERIFY_EXPR(CompletedFenceValue < m_NextFenceValue); + m_pImmediateContext->SignalFence(m_pFence, m_NextFenceValue++); + m_pImmediateContext->Flush(); m_pImmediateContext->InvalidateState(); + + CompletedFenceValue = m_pFence->GetCompletedValue(); + VERIFY_EXPR(CompletedFenceValue < m_NextFenceValue); } void TestApp::Present() diff --git a/unityplugin/GhostCubePlugin/PluginSource/src/RenderAPI_D3D12.cpp b/unityplugin/GhostCubePlugin/PluginSource/src/RenderAPI_D3D12.cpp index 3850cf6..4f57a93 100644 --- a/unityplugin/GhostCubePlugin/PluginSource/src/RenderAPI_D3D12.cpp +++ b/unityplugin/GhostCubePlugin/PluginSource/src/RenderAPI_D3D12.cpp @@ -86,6 +86,11 @@ public: m_ResourcesToTransition.push_back(ResourceState); } + void SignalFence(ID3D12Fence* pFence, Uint64 Value) + { + UNSUPPORTED("Signalling fence via unity command graphics is not supported"); + } + private: IUnityGraphicsD3D12v2* const m_pUnityGraphicsD3D12; HANDLE m_WaitForGPUEventHandle = {}; diff --git a/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp b/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp index df5e6a9..5cae5fa 100644 --- a/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp +++ b/unityplugin/UnityEmulator/src/DiligentGraphicsAdapterD3D12.cpp @@ -67,6 +67,11 @@ public: m_GraphicsD3D12Impl.IdleGPU(); } + virtual void SignalFence(ID3D12Fence* pFence, Uint64 Value) + { + m_GraphicsD3D12Impl.GetCommandQueue()->Signal(pFence, Value); + } + private: UnityGraphicsD3D12Impl& m_GraphicsD3D12Impl; }; -- cgit v1.2.3