From 05d9bfb4dd6d94d4ef80f582305aa383da295483 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 15 Dec 2019 21:31:46 -0800 Subject: Added testing framework for rendering commands. Added initial draw command test in D3D11 and D3D12 --- UnitTests/DiligentCoreAPITest/CMakeLists.txt | 24 ++ .../include/CreateObjFromNativeResD3D11.h | 42 ---- .../include/CreateObjFromNativeResD3D12.h | 42 ---- .../include/CreateObjFromNativeResGL.h | 42 ---- .../include/CreateObjFromNativeResTestBase.h | 5 + .../include/CreateObjFromNativeResVK.h | 43 ---- .../include/D3D11/CreateObjFromNativeResD3D11.h | 47 ++++ .../include/D3D11/TestingEnvironmentD3D11.h | 115 +++++++++ .../include/D3D11/TestingSwapChainD3D11.h | 81 +++++++ .../include/D3D12/CreateObjFromNativeResD3D12.h | 47 ++++ .../D3D12/D3D12DebugLayerSetNameBugWorkaround.h | 5 + .../include/D3D12/TestingEnvironmentD3D12.h | 79 +++++++ .../include/D3D12/TestingSwapChainD3D12.h | 87 +++++++ .../include/GL/CreateObjFromNativeResGL.h | 47 ++++ .../include/GL/TestingEnvironmentGL.h | 46 ++++ .../include/GL/TestingSwapChainGL.h | 48 ++++ .../DiligentCoreAPITest/include/PSOTestBase.h | 5 + .../include/TestingEnvironment.h | 13 +- .../include/TestingSwapChainBase.h | 213 +++++++++++++++++ .../include/Vulkan/CreateObjFromNativeResVK.h | 47 ++++ .../include/Vulkan/TestingEnvironmentVk.h | 46 ++++ .../include/Vulkan/TestingSwapChainVk.h | 48 ++++ .../DiligentCoreAPITest/src/BlendStateTest.cpp | 1 + .../DiligentCoreAPITest/src/BrokenShaderTest.cpp | 1 + .../DiligentCoreAPITest/src/BufferCreationTest.cpp | 9 +- .../src/CreateObjFromNativeResD3D11.cpp | 131 ----------- .../src/CreateObjFromNativeResD3D12.cpp | 99 -------- .../src/CreateObjFromNativeResGL.cpp | 162 ------------- .../src/CreateObjFromNativeResVK.cpp | 98 -------- .../src/D3D11/CreateObjFromNativeResD3D11.cpp | 136 +++++++++++ .../src/D3D11/DrawCommandRefenceD3D11.cpp | 119 ++++++++++ .../src/D3D11/TestingEnvironmentD3D11.cpp | 233 +++++++++++++++++++ .../src/D3D11/TestingSwapChainD3D11.cpp | 134 +++++++++++ .../src/D3D12/CreateObjFromNativeResD3D12.cpp | 104 +++++++++ .../D3D12/D3D12DebugLayerSetNameBugWorkaround.cpp | 7 +- .../src/D3D12/DrawCommandRefenceD3D12.cpp | 178 ++++++++++++++ .../src/D3D12/TestingEnvironmentD3D12.cpp | 84 +++++++ .../src/D3D12/TestingSwapChainD3D12.cpp | 257 +++++++++++++++++++++ .../src/DepthStencilStateTest.cpp | 1 + .../DiligentCoreAPITest/src/DrawCommandTest.cpp | 254 ++++++++++++++++++++ .../src/GL/CreateObjFromNativeResGL.cpp | 167 +++++++++++++ .../src/GL/DrawCommandRefenceGL.cpp | 44 ++++ .../src/GL/TestingEnvironmentGL.cpp | 44 ++++ .../src/GL/TestingSwapChainGL.cpp | 61 +++++ .../DiligentCoreAPITest/src/GenerateMipsTest.cpp | 1 + .../src/HLSL2GLSLConverterTest.cpp | 1 + .../src/MTResourceCreationTest.cpp | 1 + .../src/PSOCompatibilityTest.cpp | 1 + UnitTests/DiligentCoreAPITest/src/PSOTestBase.cpp | 5 + .../src/RasterizerStateTest.cpp | 1 + .../src/SamplerCreationTest.cpp | 1 + .../src/SeparateTextureSamplerTest.cpp | 1 + .../src/ShaderResourceArrayTest.cpp | 1 + .../src/ShaderResourceLayoutTest.cpp | 1 + .../src/ShaderVariableAccessTest.cpp | 1 + .../DiligentCoreAPITest/src/TestingEnvironment.cpp | 16 +- .../src/TestingSwapChainBase.cpp | 184 +++++++++++++++ .../src/TextureCreationTest.cpp | 10 +- .../src/Vulkan/CreateObjFromNativeResVK.cpp | 103 +++++++++ .../src/Vulkan/DrawCommandRefenceVk.cpp | 46 ++++ .../src/Vulkan/TestingEnvironmentVk.cpp | 44 ++++ .../src/Vulkan/TestingSwapChainVk.cpp | 61 +++++ .../src/Win32/TestingEnvironmentWin32.cpp | 5 + UnitTests/DiligentCoreAPITest/src/main.cpp | 84 ++++++- 64 files changed, 3382 insertions(+), 682 deletions(-) delete mode 100644 UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h delete mode 100644 UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h delete mode 100644 UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h delete mode 100644 UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D11/CreateObjFromNativeResD3D11.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D11/TestingEnvironmentD3D11.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D11/TestingSwapChainD3D11.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D12/CreateObjFromNativeResD3D12.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D12/TestingEnvironmentD3D12.h create mode 100644 UnitTests/DiligentCoreAPITest/include/D3D12/TestingSwapChainD3D12.h create mode 100644 UnitTests/DiligentCoreAPITest/include/GL/CreateObjFromNativeResGL.h create mode 100644 UnitTests/DiligentCoreAPITest/include/GL/TestingEnvironmentGL.h create mode 100644 UnitTests/DiligentCoreAPITest/include/GL/TestingSwapChainGL.h create mode 100644 UnitTests/DiligentCoreAPITest/include/TestingSwapChainBase.h create mode 100644 UnitTests/DiligentCoreAPITest/include/Vulkan/CreateObjFromNativeResVK.h create mode 100644 UnitTests/DiligentCoreAPITest/include/Vulkan/TestingEnvironmentVk.h create mode 100644 UnitTests/DiligentCoreAPITest/include/Vulkan/TestingSwapChainVk.h delete mode 100644 UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp delete mode 100644 UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp delete mode 100644 UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp delete mode 100644 UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D11/CreateObjFromNativeResD3D11.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D11/DrawCommandRefenceD3D11.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D11/TestingEnvironmentD3D11.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D11/TestingSwapChainD3D11.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D12/CreateObjFromNativeResD3D12.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D12/DrawCommandRefenceD3D12.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D12/TestingEnvironmentD3D12.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/D3D12/TestingSwapChainD3D12.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/DrawCommandTest.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/GL/CreateObjFromNativeResGL.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/GL/DrawCommandRefenceGL.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/GL/TestingEnvironmentGL.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/GL/TestingSwapChainGL.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/TestingSwapChainBase.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/Vulkan/CreateObjFromNativeResVK.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/Vulkan/DrawCommandRefenceVk.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/Vulkan/TestingEnvironmentVk.cpp create mode 100644 UnitTests/DiligentCoreAPITest/src/Vulkan/TestingSwapChainVk.cpp (limited to 'UnitTests') diff --git a/UnitTests/DiligentCoreAPITest/CMakeLists.txt b/UnitTests/DiligentCoreAPITest/CMakeLists.txt index 7e96699f..aa786314 100644 --- a/UnitTests/DiligentCoreAPITest/CMakeLists.txt +++ b/UnitTests/DiligentCoreAPITest/CMakeLists.txt @@ -38,6 +38,13 @@ if(PLATFORM_WIN32) list(APPEND SOURCE ${SOURCE_WIN32}) endif() +if(D3D11_SUPPORTED) + file(GLOB D3D11_SOURCE LIST_DIRECTORIES false src/D3D11/*) + file(GLOB D3D11_INCLUDE LIST_DIRECTORIES false include/D3D11/*) + list(APPEND INCLUDE ${D3D11_INCLUDE}) + list(APPEND SOURCE ${D3D11_SOURCE}) +endif() + if(D3D12_SUPPORTED) file(GLOB D3D12_SOURCE LIST_DIRECTORIES false src/D3D12/*) file(GLOB D3D12_INCLUDE LIST_DIRECTORIES false include/D3D12/*) @@ -45,6 +52,19 @@ if(D3D12_SUPPORTED) list(APPEND SOURCE ${D3D12_SOURCE}) endif() +if(VULKAN_SUPPORTED) + file(GLOB VK_SOURCE LIST_DIRECTORIES false src/Vulkan/*) + file(GLOB VK_INCLUDE LIST_DIRECTORIES false include/Vulkan/*) + list(APPEND INCLUDE ${VK_INCLUDE}) + list(APPEND SOURCE ${VK_SOURCE}) +endif() + +if(GL_SUPPORTED OR GLES_SUPPORTED) + file(GLOB GL_SOURCE LIST_DIRECTORIES false src/GL/*) + file(GLOB GL_INCLUDE LIST_DIRECTORIES false include/GL/*) + list(APPEND INCLUDE ${GL_INCLUDE}) + list(APPEND SOURCE ${GL_SOURCE}) +endif() add_executable(DiligentCoreAPITest ${SOURCE} ${INCLUDE} ${SHADERS}) set_common_target_properties(DiligentCoreAPITest) @@ -62,6 +82,10 @@ PRIVATE ${ENGINE_LIBRARIES} ) +if(D3D11_SUPPORTED OR D3D12_SUPPORTED) + target_link_libraries(DiligentCoreAPITest PRIVATE d3dcompiler.lib) +endif() + if(GL_SUPPORTED OR GLES_SUPPORTED) target_link_libraries(DiligentCoreAPITest PRIVATE Diligent-HLSL2GLSLConverterLib) endif() diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h deleted file mode 100644 index 2dad233b..00000000 --- a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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. - */ - -#pragma once - -#include "CreateObjFromNativeResTestBase.h" - -namespace Diligent -{ - -class TestCreateObjFromNativeResD3D11 : public CreateObjFromNativeResTestBase -{ -public: - TestCreateObjFromNativeResD3D11(IRenderDevice* pDevice) : - CreateObjFromNativeResTestBase(pDevice) - {} - - virtual void CreateTexture(ITexture* pTexture) override final; - virtual void CreateBuffer(IBuffer* pBuffer) override final; -}; - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h deleted file mode 100644 index 96a47004..00000000 --- a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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. - */ - -#pragma once - -#include "CreateObjFromNativeResTestBase.h" - -namespace Diligent -{ - -class TestCreateObjFromNativeResD3D12 : public CreateObjFromNativeResTestBase -{ -public: - TestCreateObjFromNativeResD3D12(IRenderDevice* pDevice) : - CreateObjFromNativeResTestBase(pDevice) - {} - - virtual void CreateTexture(ITexture* pTexture) override final; - virtual void CreateBuffer(IBuffer* pBuffer) override final; -}; - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h deleted file mode 100644 index decfc131..00000000 --- a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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. - */ - -#pragma once - -#include "CreateObjFromNativeResTestBase.h" - -namespace Diligent -{ - -class TestCreateObjFromNativeResGL : public CreateObjFromNativeResTestBase -{ -public: - TestCreateObjFromNativeResGL(IRenderDevice* pDevice) : - CreateObjFromNativeResTestBase(pDevice) - {} - - virtual void CreateTexture(ITexture* pTexture) override final; - virtual void CreateBuffer(IBuffer* pBuffer) override final; -}; - -} // namespace Diligent \ No newline at end of file diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h index 5f9f23f8..4e6bfc25 100644 --- a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h +++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h @@ -31,6 +31,9 @@ namespace Diligent { +namespace Testing +{ + class CreateObjFromNativeResTestBase { public: @@ -47,4 +50,6 @@ protected: RefCntAutoPtr m_pDevice; }; +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h deleted file mode 100644 index 4db3bd8e..00000000 --- a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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. - */ - -#pragma once - -#include "CreateObjFromNativeResTestBase.h" - -namespace Diligent -{ - - -class TestCreateObjFromNativeResVK : public CreateObjFromNativeResTestBase -{ -public: - TestCreateObjFromNativeResVK(IRenderDevice* pDevice) : - CreateObjFromNativeResTestBase(pDevice) - {} - - virtual void CreateTexture(ITexture* pTexture) override final; - virtual void CreateBuffer(IBuffer* pBuffer) override final; -}; - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D11/CreateObjFromNativeResD3D11.h b/UnitTests/DiligentCoreAPITest/include/D3D11/CreateObjFromNativeResD3D11.h new file mode 100644 index 00000000..579ed6aa --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D11/CreateObjFromNativeResD3D11.h @@ -0,0 +1,47 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "CreateObjFromNativeResTestBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestCreateObjFromNativeResD3D11 : public CreateObjFromNativeResTestBase +{ +public: + TestCreateObjFromNativeResD3D11(IRenderDevice* pDevice) : + CreateObjFromNativeResTestBase(pDevice) + {} + + virtual void CreateTexture(ITexture* pTexture) override final; + virtual void CreateBuffer(IBuffer* pBuffer) override final; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D11/TestingEnvironmentD3D11.h b/UnitTests/DiligentCoreAPITest/include/D3D11/TestingEnvironmentD3D11.h new file mode 100644 index 00000000..7d5b883c --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D11/TestingEnvironmentD3D11.h @@ -0,0 +1,115 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "TestingEnvironment.h" + +#ifndef NOMINMAX +# define NOMINMAX +#endif + +#include +#include + +namespace Diligent +{ + +namespace Testing +{ + +HRESULT CompileD3DShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile, + ID3DBlob** ppBlobOut); + +class TestingEnvironmentD3D11 final : public TestingEnvironment +{ +public: + TestingEnvironmentD3D11(DeviceType deviceType, ADAPTER_TYPE AdapterType); + + ID3D11Device* GetD3D11Device() + { + return m_pd3d11Device; + } + + ID3D11DeviceContext* GetD3D11Context() + { + return m_pd3d11Context; + } + + ID3D11RasterizerState* GetNoCullRS() + { + return m_pd3d11NoCullRS; + } + + ID3D11DepthStencilState* GetDisableDepthDSS() + { + return m_pd3d11DisableDepthDSS; + } + + ID3D11BlendState* GetDefaultBS() + { + return m_pd3d11DefaultBS; + } + + CComPtr CreateVertexShader(const char* Source, + LPCSTR strFunctionName = "main", + const D3D_SHADER_MACRO* pDefines = nullptr, + LPCSTR profile = "vs_5_0"); + + CComPtr CreatePixelShader(const char* Source, + LPCSTR strFunctionName = "main", + const D3D_SHADER_MACRO* pDefines = nullptr, + LPCSTR profile = "ps_5_0"); + + CComPtr CreateGeometryShader(const char* Source, + LPCSTR strFunctionName = "main", + const D3D_SHADER_MACRO* pDefines = nullptr, + LPCSTR profile = "gs_5_0"); + + CComPtr CreateDomainShader(const char* Source, + LPCSTR strFunctionName = "main", + const D3D_SHADER_MACRO* pDefines = nullptr, + LPCSTR profile = "ds_5_0"); + + CComPtr CreateHullShader(const char* Source, + LPCSTR strFunctionName = "main", + const D3D_SHADER_MACRO* pDefines = nullptr, + LPCSTR profile = "gs_5_0"); + + static TestingEnvironmentD3D11* GetInstance() { return ValidatedCast(TestingEnvironment::GetInstance()); } + +private: + CComPtr m_pd3d11Device; + CComPtr m_pd3d11Context; + + CComPtr m_pd3d11NoCullRS; + CComPtr m_pd3d11DisableDepthDSS; + CComPtr m_pd3d11DefaultBS; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D11/TestingSwapChainD3D11.h b/UnitTests/DiligentCoreAPITest/include/D3D11/TestingSwapChainD3D11.h new file mode 100644 index 00000000..33815257 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D11/TestingSwapChainD3D11.h @@ -0,0 +1,81 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "TestingSwapChainBase.h" + +#ifndef NOMINMAX +# define NOMINMAX +#endif + +#include +#include + +namespace Diligent +{ + +namespace Testing +{ + +class TestingSwapChainD3D11 final : public TestingSwapChainBase +{ +public: + using TBase = TestingSwapChainBase; + TestingSwapChainD3D11(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc); + + virtual void TakeSnapshot() override final; + + ID3D11Texture2D* GetD3D11RenderTarget() + { + return m_pd3d11RenderTarget; + } + + ID3D11Texture2D* GetD3D11DepthBuffer() + { + return m_pd3d11DepthBuffer; + } + + ID3D11RenderTargetView* GetD3D11RTV() + { + return m_pd3d11RTV; + } + + ID3D11DepthStencilView* GetD3D11DSV() + { + return m_pd3d11DSV; + } + +private: + CComPtr m_pd3d11Context; + CComPtr m_pd3d11RenderTarget; + CComPtr m_pd3d11DepthBuffer; + CComPtr m_pd3d11RTV; + CComPtr m_pd3d11DSV; + CComPtr m_pd3d11StagingTex; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D12/CreateObjFromNativeResD3D12.h b/UnitTests/DiligentCoreAPITest/include/D3D12/CreateObjFromNativeResD3D12.h new file mode 100644 index 00000000..b00c9676 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D12/CreateObjFromNativeResD3D12.h @@ -0,0 +1,47 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "CreateObjFromNativeResTestBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestCreateObjFromNativeResD3D12 : public CreateObjFromNativeResTestBase +{ +public: + TestCreateObjFromNativeResD3D12(IRenderDevice* pDevice) : + CreateObjFromNativeResTestBase(pDevice) + {} + + virtual void CreateTexture(ITexture* pTexture) override final; + virtual void CreateBuffer(IBuffer* pBuffer) override final; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D12/D3D12DebugLayerSetNameBugWorkaround.h b/UnitTests/DiligentCoreAPITest/include/D3D12/D3D12DebugLayerSetNameBugWorkaround.h index 9243cdf7..a2d06acb 100644 --- a/UnitTests/DiligentCoreAPITest/include/D3D12/D3D12DebugLayerSetNameBugWorkaround.h +++ b/UnitTests/DiligentCoreAPITest/include/D3D12/D3D12DebugLayerSetNameBugWorkaround.h @@ -28,6 +28,9 @@ namespace Diligent { +namespace Testing +{ + // There is a bug in D3D12 debug layer as of build version 10.0.18362: SetName() method // is not protected by a mutex internally. This, in combination with the fact that root signatures are // de-duplicated by D3D12 runtime, causes the following problem: @@ -49,4 +52,6 @@ private: std::unique_ptr m_RootSignature; }; +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D12/TestingEnvironmentD3D12.h b/UnitTests/DiligentCoreAPITest/include/D3D12/TestingEnvironmentD3D12.h new file mode 100644 index 00000000..1d042e12 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D12/TestingEnvironmentD3D12.h @@ -0,0 +1,79 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "TestingEnvironment.h" + +#ifndef NOMINMAX +# define NOMINMAX +#endif + +#include +#include +#include + +namespace Diligent +{ + +namespace Testing +{ + +// Implemented in TestingEnvironmentD3D11.cpp +HRESULT CompileD3DShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile, + ID3DBlob** ppBlobOut); + +class TestingEnvironmentD3D12 final : public TestingEnvironment +{ +public: + TestingEnvironmentD3D12(DeviceType deviceType, ADAPTER_TYPE AdapterType); + ~TestingEnvironmentD3D12(); + + static TestingEnvironmentD3D12* GetInstance() { return ValidatedCast(TestingEnvironment::GetInstance()); } + + ID3D12Device* GetD3D12Device() + { + return m_pd3d12Device; + } + + // The allocator is currently never reset, which is not an issue in this testing system. + CComPtr CreateGraphicsCommandList(); + + void IdleCommandQueue(ID3D12CommandQueue* pd3d12Queue); + +private: + CComPtr m_pd3d12Device; + CComPtr m_pd3d12CmdAllocator; + CComPtr m_pd3d12Fence; + + UINT64 m_NextFenceValue = 1; + + HANDLE m_WaitForGPUEventHandle = {}; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/D3D12/TestingSwapChainD3D12.h b/UnitTests/DiligentCoreAPITest/include/D3D12/TestingSwapChainD3D12.h new file mode 100644 index 00000000..3eb1549e --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/D3D12/TestingSwapChainD3D12.h @@ -0,0 +1,87 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "TestingSwapChainBase.h" + +#ifndef NOMINMAX +# define NOMINMAX +#endif + +#include +#include + +namespace Diligent +{ + +namespace Testing +{ + +class TestingSwapChainD3D12 : public TestingSwapChainBase +{ +public: + using TBase = TestingSwapChainBase; + TestingSwapChainD3D12(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc); + + virtual void TakeSnapshot() override final; + + void TransitionRenderTarget(ID3D12GraphicsCommandList* pCmdList, + D3D12_RESOURCE_STATES RTVState); + + void TransitionBuffers(ID3D12GraphicsCommandList* pCmdList, + D3D12_RESOURCE_STATES RTVState, + D3D12_RESOURCE_STATES DSVState); + + D3D12_CPU_DESCRIPTOR_HANDLE GetRTVDescriptorHandle() + { + return m_RTVDescriptorHandle; + } + + D3D12_CPU_DESCRIPTOR_HANDLE GetDSVDescriptorHandle() + { + return m_DSVDescriptorHandle; + } + +private: + CComPtr m_pd3d12RenderTaget; + CComPtr m_pd3d12DepthBuffer; + CComPtr m_pd3d12StagingBuffer; + + CComPtr m_pd3d12RTVDescriptorHeap; + CComPtr m_pd3d12DSVDescriptorHeap; + + D3D12_RESOURCE_STATES m_RenderTargetState = D3D12_RESOURCE_STATE_RENDER_TARGET; + D3D12_RESOURCE_STATES m_DepthBufferState = D3D12_RESOURCE_STATE_DEPTH_WRITE; + + D3D12_CPU_DESCRIPTOR_HANDLE m_RTVDescriptorHandle = {}; + D3D12_CPU_DESCRIPTOR_HANDLE m_DSVDescriptorHandle = {}; + + D3D12_PLACED_SUBRESOURCE_FOOTPRINT m_StagingBufferFootprint = {}; + UINT64 m_StagingBufferSize = 0; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/GL/CreateObjFromNativeResGL.h b/UnitTests/DiligentCoreAPITest/include/GL/CreateObjFromNativeResGL.h new file mode 100644 index 00000000..2584e426 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/GL/CreateObjFromNativeResGL.h @@ -0,0 +1,47 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "CreateObjFromNativeResTestBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestCreateObjFromNativeResGL : public CreateObjFromNativeResTestBase +{ +public: + TestCreateObjFromNativeResGL(IRenderDevice* pDevice) : + CreateObjFromNativeResTestBase(pDevice) + {} + + virtual void CreateTexture(ITexture* pTexture) override final; + virtual void CreateBuffer(IBuffer* pBuffer) override final; +}; + +} // namespace Testing + +} // namespace Diligent \ No newline at end of file diff --git a/UnitTests/DiligentCoreAPITest/include/GL/TestingEnvironmentGL.h b/UnitTests/DiligentCoreAPITest/include/GL/TestingEnvironmentGL.h new file mode 100644 index 00000000..b8d7d9e6 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/GL/TestingEnvironmentGL.h @@ -0,0 +1,46 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "TestingEnvironment.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestingEnvironmentGL final : public TestingEnvironment +{ +public: + TestingEnvironmentGL(DeviceType deviceType, ADAPTER_TYPE AdapterType); + + static TestingEnvironmentGL* GetInstance() { return ValidatedCast(TestingEnvironment::GetInstance()); } + +private: +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/GL/TestingSwapChainGL.h b/UnitTests/DiligentCoreAPITest/include/GL/TestingSwapChainGL.h new file mode 100644 index 00000000..3a5058e8 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/GL/TestingSwapChainGL.h @@ -0,0 +1,48 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "TestingSwapChainBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestingSwapChainGL : public TestingSwapChainBase +{ +public: + using TBase = TestingSwapChainBase; + TestingSwapChainGL(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc); + + virtual void TakeSnapshot() override final; + +private: +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/PSOTestBase.h b/UnitTests/DiligentCoreAPITest/include/PSOTestBase.h index afd75881..a66a5cf6 100644 --- a/UnitTests/DiligentCoreAPITest/include/PSOTestBase.h +++ b/UnitTests/DiligentCoreAPITest/include/PSOTestBase.h @@ -29,6 +29,9 @@ namespace Diligent { +namespace Testing +{ + class PSOTestBase { protected: @@ -54,4 +57,6 @@ private: static Resources sm_Resources; }; +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/TestingEnvironment.h b/UnitTests/DiligentCoreAPITest/include/TestingEnvironment.h index bb3d1025..f2440987 100644 --- a/UnitTests/DiligentCoreAPITest/include/TestingEnvironment.h +++ b/UnitTests/DiligentCoreAPITest/include/TestingEnvironment.h @@ -21,6 +21,8 @@ * of the possibility of such damages. */ +#pragma once + #include #include "RenderDevice.h" @@ -34,7 +36,10 @@ namespace Diligent { -class TestingEnvironment final : public ::testing::Environment +namespace Testing +{ + +class TestingEnvironment : public ::testing::Environment { public: struct NativeWindow @@ -82,6 +87,7 @@ public: IRenderDevice* GetDevice() { return m_pDevice; } IDeviceContext* GetDeviceContext() { return m_pDeviceContext; } + ISwapChain* GetSwapChain() { return m_pSwapChain; } static TestingEnvironment* GetInstance() { return m_pTheEnvironment; } @@ -89,8 +95,7 @@ public: static void SetErrorAllowance(int NumErrorsToAllow, const char* InfoMessage = nullptr); - -private: +protected: NativeWindow CreateNativeWindow(); static void MessageCallback(DebugMessageSeverity Severity, @@ -110,4 +115,6 @@ private: static std::atomic_int m_NumAllowedErrors; }; +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/TestingSwapChainBase.h b/UnitTests/DiligentCoreAPITest/include/TestingSwapChainBase.h new file mode 100644 index 00000000..3191f6c8 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/TestingSwapChainBase.h @@ -0,0 +1,213 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "ObjectBase.h" +#include "RefCntAutoPtr.h" +#include "RenderDevice.h" +#include "DeviceContext.h" +#include "SwapChain.h" +#include "Texture.h" +#include "TextureView.h" +#include "TestingEnvironment.h" + +namespace Diligent +{ + +namespace Testing +{ + +void CompareTestImages(const Uint8* pReferencePixels, + Uint32 RefPixelsStride, + const Uint8* pPixels, + Uint32 PixelsStride, + Uint32 Width, + Uint32 Height, + TEXTURE_FORMAT Format); + +// {41BF4655-9B33-4E6C-9300-0CB45FBFE104} +static constexpr INTERFACE_ID IID_TestingSwapChain = + {0x41bf4655, 0x9b33, 0x4e6c, {0x93, 0x0, 0xc, 0xb4, 0x5f, 0xbf, 0xe1, 0x4}}; + +class ITestingSwapChain : public IObject +{ +public: + virtual void TakeSnapshot() = 0; +}; + +template +class SwapChainCombinedBaseInterface : public ITestingSwapChain, public SwapChainInterface +{}; + +template +class TestingSwapChainBase : public RefCountedObject> +{ +public: + using TObjectBase = RefCountedObject>; + + TestingSwapChainBase(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc) : + TObjectBase{pRefCounters}, + m_pDevice{pDevice}, + m_pContext{pContext}, + m_SwapChainDesc{SCDesc} + { + VERIFY_EXPR(m_SwapChainDesc.ColorBufferFormat != TEX_FORMAT_UNKNOWN); + VERIFY_EXPR(m_SwapChainDesc.Width != 0); + VERIFY_EXPR(m_SwapChainDesc.Height != 0); + + { + TextureDesc RenderTargetDesc; + RenderTargetDesc.Name = "Testing color buffer"; + RenderTargetDesc.Type = RESOURCE_DIM_TEX_2D; + RenderTargetDesc.Width = m_SwapChainDesc.Width; + RenderTargetDesc.Height = m_SwapChainDesc.Height; + RenderTargetDesc.Format = m_SwapChainDesc.ColorBufferFormat; + RenderTargetDesc.SampleCount = 1; + RenderTargetDesc.Usage = USAGE_DEFAULT; + RenderTargetDesc.BindFlags = BIND_RENDER_TARGET; + m_pDevice->CreateTexture(RenderTargetDesc, nullptr, static_cast(&m_pRenderTarget)); + VERIFY_EXPR(m_pRenderTarget != nullptr); + m_pRTV = m_pRenderTarget->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET); + VERIFY_EXPR(m_pRTV != nullptr); + + RenderTargetDesc.Usage = USAGE_STAGING; + RenderTargetDesc.CPUAccessFlags = CPU_ACCESS_READ; + RenderTargetDesc.BindFlags = BIND_NONE; + m_pDevice->CreateTexture(RenderTargetDesc, nullptr, static_cast(&m_pStagingTexture)); + } + + if (m_SwapChainDesc.DepthBufferFormat != TEX_FORMAT_UNKNOWN) + { + TextureDesc DepthBufferDesc; + DepthBufferDesc.Name = "Testing depth buffer"; + DepthBufferDesc.Type = RESOURCE_DIM_TEX_2D; + DepthBufferDesc.Width = m_SwapChainDesc.Width; + DepthBufferDesc.Height = m_SwapChainDesc.Height; + DepthBufferDesc.Format = m_SwapChainDesc.DepthBufferFormat; + DepthBufferDesc.SampleCount = 1; + DepthBufferDesc.Usage = USAGE_DEFAULT; + DepthBufferDesc.BindFlags = BIND_DEPTH_STENCIL; + + DepthBufferDesc.ClearValue.Format = DepthBufferDesc.Format; + DepthBufferDesc.ClearValue.DepthStencil.Depth = m_SwapChainDesc.DefaultDepthValue; + DepthBufferDesc.ClearValue.DepthStencil.Stencil = m_SwapChainDesc.DefaultStencilValue; + + m_pDevice->CreateTexture(DepthBufferDesc, nullptr, &m_pDepthBuffer); + VERIFY_EXPR(m_pDepthBuffer != nullptr); + m_pDSV = m_pDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); + VERIFY_EXPR(m_pDSV != nullptr); + } + } + + void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) + { + if (ppInterface == nullptr) + return; + + if (IID == IID_SwapChain || IID == IID_Unknown) + { + *ppInterface = static_cast(this); + (*ppInterface)->AddRef(); + } + if (IID == IID_TestingSwapChain) + { + *ppInterface = static_cast(this); + (*ppInterface)->AddRef(); + } + } + + virtual void Present(Uint32 SyncInterval = 1) override + { + CopyTextureAttribs CopyInfo // + { + m_pRenderTarget, + RESOURCE_STATE_TRANSITION_MODE_TRANSITION, + m_pStagingTexture, + RESOURCE_STATE_TRANSITION_MODE_TRANSITION // + }; + m_pContext->CopyTexture(CopyInfo); + m_pContext->WaitForIdle(); + MappedTextureSubresource MapData; + m_pContext->MapTextureSubresource(m_pStagingTexture, 0, 0, MAP_READ, MAP_FLAG_DO_NOT_SYNCHRONIZE, nullptr, MapData); + CompareTestImages(m_ReferenceData.data(), m_ReferenceDataPitch, reinterpret_cast(MapData.pData), MapData.Stride, + m_SwapChainDesc.Width, m_SwapChainDesc.Height, m_SwapChainDesc.ColorBufferFormat); + + m_pContext->UnmapTextureSubresource(m_pStagingTexture, 0, 0); + } + + virtual void Resize(Uint32 NewWidth, Uint32 NewHeight) override final + { + UNEXPECTED("Resizing testing swap chains is not supported"); + } + + virtual void SetFullscreenMode(const DisplayModeAttribs& DisplayMode) override final + { + UNEXPECTED("Testing swap chain can't go into full screen mode"); + } + + virtual void SetWindowedMode() override final + { + UNEXPECTED("Testing swap chain can't switch between windowed and full screen modes"); + } + + virtual ITextureView* GetCurrentBackBufferRTV() override final + { + return m_pRTV; + } + + virtual ITextureView* GetDepthBufferDSV() override final + { + return m_pDSV; + } + + virtual const SwapChainDesc& GetDesc() const override final + { + return m_SwapChainDesc; + } + +protected: + const SwapChainDesc m_SwapChainDesc; + RefCntAutoPtr m_pDevice; + RefCntAutoPtr m_pContext; + RefCntAutoPtr m_pRenderTarget; + RefCntAutoPtr m_pDepthBuffer; + RefCntAutoPtr m_pRTV; + RefCntAutoPtr m_pDSV; + RefCntAutoPtr m_pStagingTexture; + + std::vector m_ReferenceData; + Uint32 m_ReferenceDataPitch = 0; +}; + +void CreateTestingSwapChain(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain); + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/Vulkan/CreateObjFromNativeResVK.h b/UnitTests/DiligentCoreAPITest/include/Vulkan/CreateObjFromNativeResVK.h new file mode 100644 index 00000000..f3b36403 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/Vulkan/CreateObjFromNativeResVK.h @@ -0,0 +1,47 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "CreateObjFromNativeResTestBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestCreateObjFromNativeResVK : public CreateObjFromNativeResTestBase +{ +public: + TestCreateObjFromNativeResVK(IRenderDevice* pDevice) : + CreateObjFromNativeResTestBase(pDevice) + {} + + virtual void CreateTexture(ITexture* pTexture) override final; + virtual void CreateBuffer(IBuffer* pBuffer) override final; +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingEnvironmentVk.h b/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingEnvironmentVk.h new file mode 100644 index 00000000..14334a83 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingEnvironmentVk.h @@ -0,0 +1,46 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#pragma once + +#include "TestingEnvironment.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestingEnvironmentVk final : public TestingEnvironment +{ +public: + TestingEnvironmentVk(DeviceType deviceType, ADAPTER_TYPE AdapterType); + + static TestingEnvironmentVk* GetInstance() { return ValidatedCast(TestingEnvironment::GetInstance()); } + +private: +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingSwapChainVk.h b/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingSwapChainVk.h new file mode 100644 index 00000000..e4261e69 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/include/Vulkan/TestingSwapChainVk.h @@ -0,0 +1,48 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "TestingSwapChainBase.h" + +namespace Diligent +{ + +namespace Testing +{ + +class TestingSwapChainVk : public TestingSwapChainBase +{ +public: + using TBase = TestingSwapChainBase; + TestingSwapChainVk(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc); + + virtual void TakeSnapshot() override final; + +private: +}; + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/BlendStateTest.cpp b/UnitTests/DiligentCoreAPITest/src/BlendStateTest.cpp index b033b136..7a33f10f 100644 --- a/UnitTests/DiligentCoreAPITest/src/BlendStateTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/BlendStateTest.cpp @@ -29,6 +29,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/BrokenShaderTest.cpp b/UnitTests/DiligentCoreAPITest/src/BrokenShaderTest.cpp index bacaaf45..d6eed1cd 100644 --- a/UnitTests/DiligentCoreAPITest/src/BrokenShaderTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/BrokenShaderTest.cpp @@ -26,6 +26,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp b/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp index 03ca4710..3af7125c 100644 --- a/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp @@ -22,19 +22,19 @@ */ #if D3D11_SUPPORTED -# include "CreateObjFromNativeResD3D11.h" +# include "D3D11/CreateObjFromNativeResD3D11.h" #endif #if D3D12_SUPPORTED -# include "CreateObjFromNativeResD3D12.h" +# include "D3D12/CreateObjFromNativeResD3D12.h" #endif #if GL_SUPPORTED || GLES_SUPPORTED -# include "CreateObjFromNativeResGL.h" +# include "GL/CreateObjFromNativeResGL.h" #endif #if VULKAN_SUPPORTED -# include "CreateObjFromNativeResVK.h" +# include "Vulkan/CreateObjFromNativeResVK.h" #endif #include "GraphicsAccessories.h" @@ -44,6 +44,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp deleted file mode 100644 index 407c4939..00000000 --- a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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 "CreateObjFromNativeResD3D11.h" - -#include -#include "RenderDeviceD3D11.h" -#include "TextureD3D11.h" -#include "BufferD3D11.h" -#include "GraphicsAccessories.h" - -#include "gtest/gtest.h" - -namespace Diligent -{ - -void TestCreateObjFromNativeResD3D11::CreateTexture(ITexture* pTexture) -{ - RefCntAutoPtr pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11); - RefCntAutoPtr pTextureD3D11(pTexture, IID_TextureD3D11); - ASSERT_NE(pDeviceD3D11, nullptr); - ASSERT_NE(pTextureD3D11, nullptr); - - auto* pd3d11Texture = pTextureD3D11->GetD3D11Texture(); - ASSERT_NE(pd3d11Texture, nullptr); - - const auto& SrcTexDesc = pTexture->GetDesc(); - - RefCntAutoPtr pTextureFromNativeD3D11Handle; - if (SrcTexDesc.Type == RESOURCE_DIM_TEX_1D || - SrcTexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY) - { - pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); - } - else if (SrcTexDesc.Type == RESOURCE_DIM_TEX_2D || - SrcTexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY || - SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || - SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - { - pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); - } - else if (SrcTexDesc.Type == RESOURCE_DIM_TEX_3D) - { - pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); - } - else - { - ADD_FAILURE(); - } - - ASSERT_NE(pTextureFromNativeD3D11Handle, nullptr); - - auto TestTexDesc = pTextureFromNativeD3D11Handle->GetDesc(); - if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - { - EXPECT_EQ(TestTexDesc.Type, RESOURCE_DIM_TEX_2D_ARRAY); - TestTexDesc.Type = SrcTexDesc.Type; - } - EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) - << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); - - RefCntAutoPtr pTestTextureD3D11(pTextureFromNativeD3D11Handle, IID_TextureD3D11); - ASSERT_NE(pTestTextureD3D11, nullptr); - EXPECT_EQ(pTestTextureD3D11->GetD3D11Texture(), pd3d11Texture); - EXPECT_EQ(pTestTextureD3D11->GetNativeHandle(), pd3d11Texture); -} - -void TestCreateObjFromNativeResD3D11::CreateBuffer(IBuffer* pBuffer) -{ - RefCntAutoPtr pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11); - RefCntAutoPtr pBufferD3D11(pBuffer, IID_BufferD3D11); - ASSERT_NE(pDeviceD3D11, nullptr); - ASSERT_NE(pBufferD3D11, nullptr); - - auto* pd3d11Buffer = pBufferD3D11->GetD3D11Buffer(); - ASSERT_NE(pd3d11Buffer, nullptr); - - const auto& SrcBuffDesc = pBuffer->GetDesc(); - { - RefCntAutoPtr pBufferFromNativeD3D11Handle; - pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle); - ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr); - - const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc(); - EXPECT_EQ(TestBufferDesc, SrcBuffDesc); - - RefCntAutoPtr pTestBufferD3D11(pBufferFromNativeD3D11Handle, IID_BufferD3D11); - EXPECT_EQ(pTestBufferD3D11->GetD3D11Buffer(), pd3d11Buffer); - EXPECT_EQ(pTestBufferD3D11->GetNativeHandle(), pd3d11Buffer); - } - - { - BufferDesc BuffDesc; - BuffDesc.Name = "Test buffer from D3D11 buffer"; - BuffDesc.ElementByteStride = SrcBuffDesc.ElementByteStride; - RefCntAutoPtr pBufferFromNativeD3D11Handle; - pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, BuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle); - ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr); - - const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc(); - EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) - << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); - - RefCntAutoPtr pTestBufferD3D11(pBufferFromNativeD3D11Handle, IID_BufferD3D11); - ASSERT_NE(pTestBufferD3D11, nullptr); - EXPECT_EQ(pTestBufferD3D11->GetD3D11Buffer(), pd3d11Buffer); - EXPECT_EQ(pTestBufferD3D11->GetNativeHandle(), pd3d11Buffer); - } -} - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp deleted file mode 100644 index f1d1de3d..00000000 --- a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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 "CreateObjFromNativeResD3D12.h" -#include -#include "RenderDeviceD3D12.h" -#include "TextureD3D12.h" -#include "BufferD3D12.h" -#include "GraphicsAccessories.h" - -#include "gtest/gtest.h" - -namespace Diligent -{ - -void TestCreateObjFromNativeResD3D12::CreateTexture(Diligent::ITexture* pTexture) -{ - RefCntAutoPtr pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12); - RefCntAutoPtr pTextureD3D12(pTexture, IID_TextureD3D12); - ASSERT_NE(pDeviceD3D12, nullptr); - ASSERT_NE(pTextureD3D12, nullptr); - - const auto& SrcTexDesc = pTexture->GetDesc(); - auto* pD3D12Texture = pTextureD3D12->GetD3D12Texture(); - ASSERT_NE(pD3D12Texture, nullptr); - - RefCntAutoPtr pTextureFromNativeD3D12Handle; - pDeviceD3D12->CreateTextureFromD3DResource(pD3D12Texture, RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D12Handle); - ASSERT_NE(pTextureFromNativeD3D12Handle, nullptr); - - auto TestTexDesc = pTextureFromNativeD3D12Handle->GetDesc(); - if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - { - EXPECT_EQ(TestTexDesc.Type, RESOURCE_DIM_TEX_2D_ARRAY); - TestTexDesc.Type = SrcTexDesc.Type; - } - EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) - << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); - - RefCntAutoPtr pTestTextureD3D12(pTextureFromNativeD3D12Handle, IID_TextureD3D12); - ASSERT_NE(pTestTextureD3D12, nullptr); - EXPECT_EQ(pTestTextureD3D12->GetD3D12Texture(), pD3D12Texture); - EXPECT_EQ(pTestTextureD3D12->GetNativeHandle(), pD3D12Texture); -} - -void TestCreateObjFromNativeResD3D12::CreateBuffer(Diligent::IBuffer* pBuffer) -{ - RefCntAutoPtr pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12); - RefCntAutoPtr pBufferD3D12(pBuffer, IID_BufferD3D12); - ASSERT_NE(pDeviceD3D12, nullptr); - ASSERT_NE(pBufferD3D12, nullptr); - - - Uint64 DataStartByteOffset; - auto* pD3D12Buffer = pBufferD3D12->GetD3D12Buffer(DataStartByteOffset, nullptr); - ASSERT_NE(pD3D12Buffer, nullptr); - EXPECT_EQ(DataStartByteOffset, 0); - - const auto& SrcBuffDesc = pBuffer->GetDesc(); - { - RefCntAutoPtr pBufferFromNativeD3D12Handle; - pDeviceD3D12->CreateBufferFromD3DResource(pD3D12Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D12Handle); - ASSERT_NE(pBufferFromNativeD3D12Handle, nullptr); - - const auto& TestBufferDesc = pBufferFromNativeD3D12Handle->GetDesc(); - EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) - << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); - - RefCntAutoPtr pTestBufferD3D12(pBufferFromNativeD3D12Handle, IID_BufferD3D12); - ASSERT_NE(pTestBufferD3D12, nullptr); - - Uint64 TestBuffDataStartByteOffset; - EXPECT_EQ(pTestBufferD3D12->GetD3D12Buffer(TestBuffDataStartByteOffset, nullptr), pD3D12Buffer); - EXPECT_EQ(TestBuffDataStartByteOffset, 0); - EXPECT_EQ(pTestBufferD3D12->GetNativeHandle(), pD3D12Buffer); - } -} - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp deleted file mode 100644 index 973a54cd..00000000 --- a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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. - */ - -#if PLATFORM_WIN32 - -# ifndef GLEW_STATIC -# define GLEW_STATIC // Must be defined to use static version of glew -# endif -# include "GL/glew.h" -#elif PLATFORM_LINUX - -# ifndef GLEW_STATIC -# define GLEW_STATIC // Must be defined to use static version of glew -# endif -# ifndef GLEW_NO_GLU -# define GLEW_NO_GLU -# endif - -# include "GL/glew.h" - -// Undefine beautiful defines from GL/glx.h -> X11/Xlib.h -# ifdef Bool -# undef Bool -# endif -# ifdef True -# undef True -# endif -# ifdef False -# undef False -# endif -# ifdef Status -# undef Status -# endif -# ifdef Success -# undef Success -# endif - -#elif PLATFORM_MACOS - -# ifndef GLEW_STATIC -# define GLEW_STATIC // Must be defined to use static version of glew -# endif -# ifndef GLEW_NO_GLU -# define GLEW_NO_GLU -# endif - -# include "GL/glew.h" - -#elif PLATFORM_ANDROID - -# include -# include - -#elif PLATFORM_IOS - -# include - -#else -# error Unsupported platform -#endif - -#include "RenderDeviceGL.h" -#include "TextureGL.h" -#include "BufferGL.h" -#include "GraphicsAccessories.h" - -#include "CreateObjFromNativeResGL.h" - -#include "gtest/gtest.h" - -namespace Diligent -{ - -void TestCreateObjFromNativeResGL::CreateTexture(Diligent::ITexture* pTexture) -{ -#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID - RefCntAutoPtr pDeviceGL(m_pDevice, IID_RenderDeviceGL); - RefCntAutoPtr pTextureGL(pTexture, IID_TextureGL); - ASSERT_NE(pDeviceGL, nullptr); - ASSERT_NE(pTextureGL, nullptr); - - const auto& SrcTexDesc = pTexture->GetDesc(); - if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - return; - - auto GLHandle = pTextureGL->GetGLTextureHandle(); - ASSERT_NE(GLHandle, (GLuint)0); - - auto TmpTexDesc = SrcTexDesc; - - TmpTexDesc.Width = 0; - TmpTexDesc.Height = 0; - TmpTexDesc.MipLevels = 0; - TmpTexDesc.Format = TEX_FORMAT_UNKNOWN; - - RefCntAutoPtr pAttachedTexture; - pDeviceGL->CreateTextureFromGLHandle(GLHandle, TmpTexDesc, RESOURCE_STATE_UNKNOWN, &pAttachedTexture); - ASSERT_NE(pAttachedTexture, nullptr); - - auto TestTexDesc = pAttachedTexture->GetDesc(); - if (m_pDevice->GetTextureFormatInfo(SrcTexDesc.Format).IsTypeless) - TestTexDesc.Format = SrcTexDesc.Format; - - EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) - << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); - - RefCntAutoPtr pAttachedTextureGL(pAttachedTexture, IID_TextureGL); - ASSERT_NE(pAttachedTextureGL, nullptr); - EXPECT_EQ(pAttachedTextureGL->GetGLTextureHandle(), GLHandle); - EXPECT_EQ(pAttachedTextureGL->GetBindTarget(), pTextureGL->GetBindTarget()); - EXPECT_EQ(reinterpret_cast(pAttachedTextureGL->GetNativeHandle()), GLHandle); -#endif -} - -void TestCreateObjFromNativeResGL::CreateBuffer(Diligent::IBuffer* pBuffer) -{ -#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID - RefCntAutoPtr pDeviceGL(m_pDevice, IID_RenderDeviceGL); - RefCntAutoPtr pBufferGL(pBuffer, IID_BufferGL); - ASSERT_NE(pDeviceGL, nullptr); - ASSERT_NE(pBufferGL, nullptr); - - const auto& SrcBuffDesc = pBuffer->GetDesc(); - auto GLBufferHandle = pBufferGL->GetGLBufferHandle(); - ASSERT_NE(GLBufferHandle, (GLuint)0); - - RefCntAutoPtr pBufferFromNativeGLHandle; - pDeviceGL->CreateBufferFromGLHandle(GLBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeGLHandle); - ASSERT_NE(pBufferFromNativeGLHandle, nullptr); - - const auto& TestBufferDesc = pBufferFromNativeGLHandle->GetDesc(); - EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) - << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); - - RefCntAutoPtr pTestBufferGL(pBufferFromNativeGLHandle, IID_BufferGL); - ASSERT_NE(pTestBufferGL, nullptr); - EXPECT_EQ(pTestBufferGL->GetGLBufferHandle(), GLBufferHandle); - EXPECT_EQ(reinterpret_cast(pTestBufferGL->GetNativeHandle()), GLBufferHandle); -#endif -} - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp deleted file mode 100644 index 11fe0b7a..00000000 --- a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * 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 neVkigence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly neVkigent 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. - */ - -#if VULKAN_SUPPORTED -# include "vulkan.h" -#endif - -#include "RenderDeviceVk.h" -#include "TextureVk.h" -#include "BufferVk.h" -#include "GraphicsAccessories.h" - -#include "CreateObjFromNativeResVK.h" - -#include "gtest/gtest.h" - -namespace Diligent -{ - -void TestCreateObjFromNativeResVK::CreateTexture(Diligent::ITexture* pTexture) -{ -#if VULKAN_SUPPORTED - RefCntAutoPtr pDeviceVk(m_pDevice, IID_RenderDeviceVk); - RefCntAutoPtr pTextureVk(pTexture, IID_TextureVk); - ASSERT_NE(pDeviceVk, nullptr); - ASSERT_NE(pTextureVk, nullptr); - - const auto& SrcTexDesc = pTexture->GetDesc(); - if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) - return; - - auto VkHandle = pTextureVk->GetVkImage(); - ASSERT_NE(VkHandle, (VkImage)VK_NULL_HANDLE); - - RefCntAutoPtr pAttachedTexture; - pDeviceVk->CreateTextureFromVulkanImage(VkHandle, SrcTexDesc, RESOURCE_STATE_UNKNOWN, &pAttachedTexture); - ASSERT_NE(pAttachedTexture, nullptr); - - const auto& TestTexDesc = pAttachedTexture->GetDesc(); - EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) - << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); - - RefCntAutoPtr pAttachedTextureVk(pAttachedTexture, IID_TextureVk); - ASSERT_NE(pAttachedTextureVk, nullptr); - EXPECT_EQ(pAttachedTextureVk->GetVkImage(), VkHandle); - EXPECT_EQ(reinterpret_cast(pAttachedTextureVk->GetNativeHandle()), VkHandle); -#endif -} - -void TestCreateObjFromNativeResVK::CreateBuffer(Diligent::IBuffer* pBuffer) -{ -#if VULKAN_SUPPORTED - RefCntAutoPtr pDeviceVk(m_pDevice, IID_RenderDeviceVk); - RefCntAutoPtr pBufferVk(pBuffer, IID_BufferVk); - ASSERT_NE(pDeviceVk, nullptr); - ASSERT_NE(pBufferVk, nullptr); - - auto VkBufferHandle = pBufferVk->GetVkBuffer(); - ASSERT_NE(VkBufferHandle, (VkBuffer)VK_NULL_HANDLE); - - const auto& SrcBuffDesc = pBuffer->GetDesc(); - - RefCntAutoPtr pBufferFromNativeVkHandle; - pDeviceVk->CreateBufferFromVulkanResource(VkBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeVkHandle); - ASSERT_NE(pBufferFromNativeVkHandle, nullptr); - - const auto& TestBufferDesc = pBufferFromNativeVkHandle->GetDesc(); - EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) - << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); - - RefCntAutoPtr pTestBufferVk(pBufferFromNativeVkHandle, IID_BufferVk); - ASSERT_NE(pTestBufferVk, nullptr); - EXPECT_EQ(pTestBufferVk->GetVkBuffer(), VkBufferHandle); - EXPECT_EQ(reinterpret_cast(pTestBufferVk->GetNativeHandle()), VkBufferHandle); -#endif -} - -} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D11/CreateObjFromNativeResD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/D3D11/CreateObjFromNativeResD3D11.cpp new file mode 100644 index 00000000..08b9b6fd --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D11/CreateObjFromNativeResD3D11.cpp @@ -0,0 +1,136 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D11/CreateObjFromNativeResD3D11.h" + +#include +#include "RenderDeviceD3D11.h" +#include "TextureD3D11.h" +#include "BufferD3D11.h" +#include "GraphicsAccessories.h" + +#include "gtest/gtest.h" + +namespace Diligent +{ + +namespace Testing +{ + +void TestCreateObjFromNativeResD3D11::CreateTexture(ITexture* pTexture) +{ + RefCntAutoPtr pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11); + RefCntAutoPtr pTextureD3D11(pTexture, IID_TextureD3D11); + ASSERT_NE(pDeviceD3D11, nullptr); + ASSERT_NE(pTextureD3D11, nullptr); + + auto* pd3d11Texture = pTextureD3D11->GetD3D11Texture(); + ASSERT_NE(pd3d11Texture, nullptr); + + const auto& SrcTexDesc = pTexture->GetDesc(); + + RefCntAutoPtr pTextureFromNativeD3D11Handle; + if (SrcTexDesc.Type == RESOURCE_DIM_TEX_1D || + SrcTexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY) + { + pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); + } + else if (SrcTexDesc.Type == RESOURCE_DIM_TEX_2D || + SrcTexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY || + SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || + SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + { + pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); + } + else if (SrcTexDesc.Type == RESOURCE_DIM_TEX_3D) + { + pDeviceD3D11->CreateTextureFromD3DResource(static_cast(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle); + } + else + { + ADD_FAILURE(); + } + + ASSERT_NE(pTextureFromNativeD3D11Handle, nullptr); + + auto TestTexDesc = pTextureFromNativeD3D11Handle->GetDesc(); + if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + { + EXPECT_EQ(TestTexDesc.Type, RESOURCE_DIM_TEX_2D_ARRAY); + TestTexDesc.Type = SrcTexDesc.Type; + } + EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) + << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); + + RefCntAutoPtr pTestTextureD3D11(pTextureFromNativeD3D11Handle, IID_TextureD3D11); + ASSERT_NE(pTestTextureD3D11, nullptr); + EXPECT_EQ(pTestTextureD3D11->GetD3D11Texture(), pd3d11Texture); + EXPECT_EQ(pTestTextureD3D11->GetNativeHandle(), pd3d11Texture); +} + +void TestCreateObjFromNativeResD3D11::CreateBuffer(IBuffer* pBuffer) +{ + RefCntAutoPtr pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11); + RefCntAutoPtr pBufferD3D11(pBuffer, IID_BufferD3D11); + ASSERT_NE(pDeviceD3D11, nullptr); + ASSERT_NE(pBufferD3D11, nullptr); + + auto* pd3d11Buffer = pBufferD3D11->GetD3D11Buffer(); + ASSERT_NE(pd3d11Buffer, nullptr); + + const auto& SrcBuffDesc = pBuffer->GetDesc(); + { + RefCntAutoPtr pBufferFromNativeD3D11Handle; + pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle); + ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr); + + const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc(); + EXPECT_EQ(TestBufferDesc, SrcBuffDesc); + + RefCntAutoPtr pTestBufferD3D11(pBufferFromNativeD3D11Handle, IID_BufferD3D11); + EXPECT_EQ(pTestBufferD3D11->GetD3D11Buffer(), pd3d11Buffer); + EXPECT_EQ(pTestBufferD3D11->GetNativeHandle(), pd3d11Buffer); + } + + { + BufferDesc BuffDesc; + BuffDesc.Name = "Test buffer from D3D11 buffer"; + BuffDesc.ElementByteStride = SrcBuffDesc.ElementByteStride; + RefCntAutoPtr pBufferFromNativeD3D11Handle; + pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, BuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle); + ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr); + + const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc(); + EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) + << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); + + RefCntAutoPtr pTestBufferD3D11(pBufferFromNativeD3D11Handle, IID_BufferD3D11); + ASSERT_NE(pTestBufferD3D11, nullptr); + EXPECT_EQ(pTestBufferD3D11->GetD3D11Buffer(), pd3d11Buffer); + EXPECT_EQ(pTestBufferD3D11->GetNativeHandle(), pd3d11Buffer); + } +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D11/DrawCommandRefenceD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/D3D11/DrawCommandRefenceD3D11.cpp new file mode 100644 index 00000000..7ed16a68 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D11/DrawCommandRefenceD3D11.cpp @@ -0,0 +1,119 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D11/TestingEnvironmentD3D11.h" +#include "D3D11/TestingSwapChainD3D11.h" + +namespace Diligent +{ + +namespace Testing +{ + +static const char* VSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +void main(in uint VertId : SV_VertexID, + out PSInput PSIn) +{ + float4 Pos[3]; + Pos[0] = float4(-0.5, -0.5, 0.0, 1.0); + Pos[1] = float4( 0.0, +0.5, 0.0, 1.0); + Pos[2] = float4(+0.5, -0.5, 0.0, 1.0); + + float3 Col[3]; + Col[0] = float3(1.0, 0.0, 0.0); // red + Col[1] = float3(0.0, 1.0, 0.0); // green + Col[2] = float3(0.0, 0.0, 1.0); // blue + + PSIn.Pos = Pos[VertId]; + PSIn.Color = Col[VertId]; +} +)"; + +static const char* PSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +struct PSOutput +{ + float4 Color : SV_TARGET; +}; + +void main(in PSInput PSIn, + out PSOutput PSOut) +{ + PSOut.Color = float4(PSIn.Color.rgb, 1.0); +} +)"; + +void RenderDrawCommandRefenceTriangleD3D11(ISwapChain* pSwapChain) +{ + auto* pEnvD3D11 = TestingEnvironmentD3D11::GetInstance(); + auto* pd3d11Context = pEnvD3D11->GetD3D11Context(); + auto* pTestingSwapChainD3D11 = ValidatedCast(pSwapChain); + + pd3d11Context->ClearState(); + + auto pVS = pEnvD3D11->CreateVertexShader(VSSource); + ASSERT_NE(pVS, nullptr); + + auto pPS = pEnvD3D11->CreatePixelShader(PSSource); + ASSERT_NE(pPS, nullptr); + + pd3d11Context->VSSetShader(pVS, nullptr, 0); + pd3d11Context->PSSetShader(pPS, nullptr, 0); + pd3d11Context->RSSetState(pEnvD3D11->GetNoCullRS()); + pd3d11Context->OMSetBlendState(pEnvD3D11->GetDefaultBS(), nullptr, 0xFFFFFFFF); + pd3d11Context->OMSetDepthStencilState(pEnvD3D11->GetDisableDepthDSS(), 0); + pd3d11Context->IASetInputLayout(nullptr); + + ID3D11RenderTargetView* pd3d11RTVs[] = {pTestingSwapChainD3D11->GetD3D11RTV()}; + pd3d11Context->OMSetRenderTargets(1, pd3d11RTVs, nullptr); + float ClearColor[] = {0, 0, 0, 0}; + pd3d11Context->ClearRenderTargetView(pd3d11RTVs[0], ClearColor); + + D3D11_VIEWPORT d3dVP = {}; + + const auto& SCDesc = pTestingSwapChainD3D11->GetDesc(); + d3dVP.Width = static_cast(SCDesc.Width); + d3dVP.Height = static_cast(SCDesc.Height); + d3dVP.MaxDepth = 1; + pd3d11Context->RSSetViewports(1, &d3dVP); + + pd3d11Context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + pd3d11Context->Draw(3, 0); + + pd3d11Context->ClearState(); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D11/TestingEnvironmentD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/D3D11/TestingEnvironmentD3D11.cpp new file mode 100644 index 00000000..2abfbdbc --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D11/TestingEnvironmentD3D11.cpp @@ -0,0 +1,233 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D11/TestingEnvironmentD3D11.h" + +#include "RenderDeviceD3D11.h" +#include "DeviceContextD3D11.h" + +#include + +namespace Diligent +{ + +namespace Testing +{ + +TestingEnvironmentD3D11::TestingEnvironmentD3D11(DeviceType deviceType, ADAPTER_TYPE AdapterType) : + TestingEnvironment{deviceType, AdapterType} +{ + RefCntAutoPtr pRenderDeviceD3D11{m_pDevice, IID_RenderDeviceD3D11}; + RefCntAutoPtr pContextD3D11{m_pDeviceContext, IID_DeviceContextD3D11}; + + m_pd3d11Device = pRenderDeviceD3D11->GetD3D11Device(); + m_pd3d11Context = pContextD3D11->GetD3D11DeviceContext(); + + { + D3D11_RASTERIZER_DESC RSDesc = {}; + + RSDesc.CullMode = D3D11_CULL_NONE; + RSDesc.FillMode = D3D11_FILL_SOLID; + auto hr = m_pd3d11Device->CreateRasterizerState(&RSDesc, &m_pd3d11NoCullRS); + VERIFY_EXPR(SUCCEEDED(hr)); + } + + { + D3D11_DEPTH_STENCIL_DESC DSDesc = {}; + + DSDesc.DepthEnable = False; + auto hr = m_pd3d11Device->CreateDepthStencilState(&DSDesc, &m_pd3d11DisableDepthDSS); + VERIFY_EXPR(SUCCEEDED(hr)); + } + + { + D3D11_BLEND_DESC BSDesc = {}; + + BSDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + + auto hr = m_pd3d11Device->CreateBlendState(&BSDesc, &m_pd3d11DefaultBS); + VERIFY_EXPR(SUCCEEDED(hr)); + } +} + +HRESULT CompileD3DShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile, + ID3DBlob** ppBlobOut) +{ + DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS; +#if defined(DEBUG) || defined(_DEBUG) + // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders. + // Setting this flag improves the shader debugging experience, but still allows + // the shaders to be optimized and to run exactly the way they will run in + // the release configuration of this program. + dwShaderFlags |= D3DCOMPILE_DEBUG; +#else + // Warning: do not use this flag as it causes shader compiler to fail the compilation and + // report strange errors: + // dwShaderFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL3; +#endif + + CComPtr pCompilerOutput; + + auto SourceLen = strlen(Source); + + auto hr = D3DCompile(Source, SourceLen, NULL, pDefines, nullptr, strFunctionName, profile, dwShaderFlags, 0, ppBlobOut, &pCompilerOutput); + + const char* CompilerMsg = pCompilerOutput ? reinterpret_cast(pCompilerOutput->GetBufferPointer()) : nullptr; + if (FAILED(hr)) + { + LOG_ERROR_AND_THROW("Failed to compile D3D shader :\n", (CompilerMsg != nullptr ? CompilerMsg : "")); + } + else if (CompilerMsg != nullptr) + { + LOG_INFO_MESSAGE("Shader compiler output:\n", CompilerMsg); + } + + return hr; +} + +CComPtr TestingEnvironmentD3D11::CreateVertexShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile) +{ + CComPtr pByteCode; + CComPtr pVS; + + auto hr = CompileD3DShader(Source, strFunctionName, pDefines, profile, &pByteCode); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to compile vertex shader"; + return pVS; + } + + hr = m_pd3d11Device->CreateVertexShader(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), NULL, &pVS); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to create vertex shader"; + } + return pVS; +} + +CComPtr TestingEnvironmentD3D11::CreatePixelShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile) +{ + CComPtr pByteCode; + CComPtr pPS; + + auto hr = CompileD3DShader(Source, strFunctionName, pDefines, profile, &pByteCode); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to compile pixel shader"; + return pPS; + } + + hr = m_pd3d11Device->CreatePixelShader(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), NULL, &pPS); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to create pixel shader"; + } + return pPS; +} + +CComPtr TestingEnvironmentD3D11::CreateGeometryShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile) +{ + CComPtr pByteCode; + CComPtr pGS; + + auto hr = CompileD3DShader(Source, strFunctionName, pDefines, profile, &pByteCode); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to compile geometry shader"; + return pGS; + } + + hr = m_pd3d11Device->CreateGeometryShader(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), NULL, &pGS); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to create geometry shader"; + } + return pGS; +} + +CComPtr TestingEnvironmentD3D11::CreateDomainShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile) +{ + CComPtr pByteCode; + CComPtr pDS; + + auto hr = CompileD3DShader(Source, strFunctionName, pDefines, profile, &pByteCode); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to compile domain shader"; + return pDS; + } + + hr = m_pd3d11Device->CreateDomainShader(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), NULL, &pDS); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to create domain shader"; + } + return pDS; +} + +CComPtr TestingEnvironmentD3D11::CreateHullShader(const char* Source, + LPCSTR strFunctionName, + const D3D_SHADER_MACRO* pDefines, + LPCSTR profile) +{ + CComPtr pByteCode; + CComPtr pDS; + + auto hr = CompileD3DShader(Source, strFunctionName, pDefines, profile, &pByteCode); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to compile hull shader"; + return pDS; + } + + hr = m_pd3d11Device->CreateHullShader(pByteCode->GetBufferPointer(), pByteCode->GetBufferSize(), NULL, &pDS); + if (FAILED(hr)) + { + ADD_FAILURE() << "Failed to create hull shader"; + } + return pDS; +} + +TestingEnvironment* CreateTestingEnvironmentD3D11(DeviceType deviceType, ADAPTER_TYPE AdapterType) +{ + return new TestingEnvironmentD3D11{deviceType, AdapterType}; +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D11/TestingSwapChainD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/D3D11/TestingSwapChainD3D11.cpp new file mode 100644 index 00000000..675dd134 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D11/TestingSwapChainD3D11.cpp @@ -0,0 +1,134 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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/D3D11/TestingSwapChainD3D11.h" +#include "../include/DXGITypeConversions.h" + +#include "RenderDeviceD3D11.h" +#include "DeviceContextD3D11.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingSwapChainD3D11::TestingSwapChainD3D11(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc) : + TBase // + { + pRefCounters, + pDevice, + pContext, + SCDesc // + } +{ + RefCntAutoPtr pRenderDeviceD3D11{pDevice, IID_RenderDeviceD3D11}; + RefCntAutoPtr pContextD3D11{pContext, IID_DeviceContextD3D11}; + + auto* pd3d11Device = pRenderDeviceD3D11->GetD3D11Device(); + m_pd3d11Context = pContextD3D11->GetD3D11DeviceContext(); + + D3D11_TEXTURE2D_DESC TexDesc = {}; + + TexDesc.Width = SCDesc.Width; + TexDesc.Height = SCDesc.Height; + TexDesc.MipLevels = 1; + TexDesc.ArraySize = 1; + TexDesc.Format = TexFormatToDXGI_Format(SCDesc.ColorBufferFormat); + TexDesc.SampleDesc.Count = 1; + TexDesc.SampleDesc.Quality = 0; + TexDesc.Usage = D3D11_USAGE_DEFAULT; + TexDesc.BindFlags = BIND_RENDER_TARGET; + TexDesc.CPUAccessFlags = 0; + TexDesc.MiscFlags = 0; + + auto hr = pd3d11Device->CreateTexture2D(&TexDesc, nullptr, &m_pd3d11RenderTarget); + VERIFY(SUCCEEDED(hr), "Failed to create D3D11 render target"); + + hr = pd3d11Device->CreateRenderTargetView(m_pd3d11RenderTarget, nullptr, &m_pd3d11RTV); + VERIFY(SUCCEEDED(hr), "Failed to create D3D11 render target view"); + + TexDesc.BindFlags = 0; + TexDesc.Usage = D3D11_USAGE_STAGING; + TexDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + + hr = pd3d11Device->CreateTexture2D(&TexDesc, nullptr, &m_pd3d11StagingTex); + VERIFY(SUCCEEDED(hr), "Failed to create staging D3D11 texture"); + + if (SCDesc.DepthBufferFormat != TEX_FORMAT_UNKNOWN) + { + TexDesc.Usage = D3D11_USAGE_DEFAULT; + TexDesc.Format = TexFormatToDXGI_Format(SCDesc.DepthBufferFormat); + TexDesc.BindFlags = BIND_DEPTH_STENCIL; + TexDesc.CPUAccessFlags = 0; + + hr = pd3d11Device->CreateTexture2D(&TexDesc, nullptr, &m_pd3d11DepthBuffer); + VERIFY(SUCCEEDED(hr), "Failed to create D3D11 depth buffer"); + + hr = pd3d11Device->CreateDepthStencilView(m_pd3d11DepthBuffer, nullptr, &m_pd3d11DSV); + VERIFY(SUCCEEDED(hr), "Failed to create D3D11 depth-stencil view"); + } +} + +void TestingSwapChainD3D11::TakeSnapshot() +{ + m_pd3d11Context->CopyResource(m_pd3d11StagingTex, m_pd3d11RenderTarget); + D3D11_MAPPED_SUBRESOURCE MappedData; + + auto hr = m_pd3d11Context->Map(m_pd3d11StagingTex, 0, D3D11_MAP_READ, 0, &MappedData); + if (SUCCEEDED(hr)) + { + m_ReferenceDataPitch = MappedData.RowPitch; + m_ReferenceData.resize(m_ReferenceDataPitch * m_SwapChainDesc.Height); + for (Uint32 row = 0; row < m_SwapChainDesc.Height; ++row) + { + memcpy(&m_ReferenceData[row * m_ReferenceDataPitch], + reinterpret_cast(MappedData.pData) + row * m_ReferenceDataPitch, + m_ReferenceDataPitch); + } + } + else + { + ADD_FAILURE() << "Failed to map stagin texture"; + return; + } + + m_pd3d11Context->Unmap(m_pd3d11StagingTex, 0); + m_pd3d11Context->ClearState(); +} + +void CreateTestingSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain) +{ + TestingSwapChainD3D11* pTestingSC(MakeNewRCObj()(pDevice, pContext, SCDesc)); + pTestingSC->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D12/CreateObjFromNativeResD3D12.cpp b/UnitTests/DiligentCoreAPITest/src/D3D12/CreateObjFromNativeResD3D12.cpp new file mode 100644 index 00000000..d76e084d --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D12/CreateObjFromNativeResD3D12.cpp @@ -0,0 +1,104 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D12/CreateObjFromNativeResD3D12.h" +#include +#include "RenderDeviceD3D12.h" +#include "TextureD3D12.h" +#include "BufferD3D12.h" +#include "GraphicsAccessories.h" + +#include "gtest/gtest.h" + +namespace Diligent +{ + +namespace Testing +{ + +void TestCreateObjFromNativeResD3D12::CreateTexture(Diligent::ITexture* pTexture) +{ + RefCntAutoPtr pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12); + RefCntAutoPtr pTextureD3D12(pTexture, IID_TextureD3D12); + ASSERT_NE(pDeviceD3D12, nullptr); + ASSERT_NE(pTextureD3D12, nullptr); + + const auto& SrcTexDesc = pTexture->GetDesc(); + auto* pD3D12Texture = pTextureD3D12->GetD3D12Texture(); + ASSERT_NE(pD3D12Texture, nullptr); + + RefCntAutoPtr pTextureFromNativeD3D12Handle; + pDeviceD3D12->CreateTextureFromD3DResource(pD3D12Texture, RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D12Handle); + ASSERT_NE(pTextureFromNativeD3D12Handle, nullptr); + + auto TestTexDesc = pTextureFromNativeD3D12Handle->GetDesc(); + if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE || SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + { + EXPECT_EQ(TestTexDesc.Type, RESOURCE_DIM_TEX_2D_ARRAY); + TestTexDesc.Type = SrcTexDesc.Type; + } + EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) + << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); + + RefCntAutoPtr pTestTextureD3D12(pTextureFromNativeD3D12Handle, IID_TextureD3D12); + ASSERT_NE(pTestTextureD3D12, nullptr); + EXPECT_EQ(pTestTextureD3D12->GetD3D12Texture(), pD3D12Texture); + EXPECT_EQ(pTestTextureD3D12->GetNativeHandle(), pD3D12Texture); +} + +void TestCreateObjFromNativeResD3D12::CreateBuffer(Diligent::IBuffer* pBuffer) +{ + RefCntAutoPtr pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12); + RefCntAutoPtr pBufferD3D12(pBuffer, IID_BufferD3D12); + ASSERT_NE(pDeviceD3D12, nullptr); + ASSERT_NE(pBufferD3D12, nullptr); + + + Uint64 DataStartByteOffset; + auto* pD3D12Buffer = pBufferD3D12->GetD3D12Buffer(DataStartByteOffset, nullptr); + ASSERT_NE(pD3D12Buffer, nullptr); + EXPECT_EQ(DataStartByteOffset, 0); + + const auto& SrcBuffDesc = pBuffer->GetDesc(); + { + RefCntAutoPtr pBufferFromNativeD3D12Handle; + pDeviceD3D12->CreateBufferFromD3DResource(pD3D12Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D12Handle); + ASSERT_NE(pBufferFromNativeD3D12Handle, nullptr); + + const auto& TestBufferDesc = pBufferFromNativeD3D12Handle->GetDesc(); + EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) + << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); + + RefCntAutoPtr pTestBufferD3D12(pBufferFromNativeD3D12Handle, IID_BufferD3D12); + ASSERT_NE(pTestBufferD3D12, nullptr); + + Uint64 TestBuffDataStartByteOffset; + EXPECT_EQ(pTestBufferD3D12->GetD3D12Buffer(TestBuffDataStartByteOffset, nullptr), pD3D12Buffer); + EXPECT_EQ(TestBuffDataStartByteOffset, 0); + EXPECT_EQ(pTestBufferD3D12->GetNativeHandle(), pD3D12Buffer); + } +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D12/D3D12DebugLayerSetNameBugWorkaround.cpp b/UnitTests/DiligentCoreAPITest/src/D3D12/D3D12DebugLayerSetNameBugWorkaround.cpp index b0ef512f..e186dbfd 100644 --- a/UnitTests/DiligentCoreAPITest/src/D3D12/D3D12DebugLayerSetNameBugWorkaround.cpp +++ b/UnitTests/DiligentCoreAPITest/src/D3D12/D3D12DebugLayerSetNameBugWorkaround.cpp @@ -21,7 +21,7 @@ * of the possibility of such damages. */ -#include "../include/D3D12/D3D12DebugLayerSetNameBugWorkaround.h" +#include "D3D12/D3D12DebugLayerSetNameBugWorkaround.h" #include "RefCntAutoPtr.h" @@ -37,6 +37,9 @@ namespace Diligent { +namespace Testing +{ + struct D3D12DebugLayerSetNameBugWorkaround::RootSignatureWrapper { CComPtr pRootSignature; @@ -68,4 +71,6 @@ D3D12DebugLayerSetNameBugWorkaround::~D3D12DebugLayerSetNameBugWorkaround() { } +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D12/DrawCommandRefenceD3D12.cpp b/UnitTests/DiligentCoreAPITest/src/D3D12/DrawCommandRefenceD3D12.cpp new file mode 100644 index 00000000..ae7ff0fe --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D12/DrawCommandRefenceD3D12.cpp @@ -0,0 +1,178 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D12/TestingEnvironmentD3D12.h" +#include "D3D12/TestingSwapChainD3D12.h" +#include "../include/DXGITypeConversions.h" +#include "../include/d3dx12_win.h" + +#include "RenderDeviceD3D12.h" +#include "DeviceContextD3D12.h" + +namespace Diligent +{ + +namespace Testing +{ + +static const char* VSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +void main(in uint VertId : SV_VertexID, + out PSInput PSIn) +{ + float4 Pos[3]; + Pos[0] = float4(-0.5, -0.5, 0.5, 1.0); + Pos[1] = float4( 0.0, +0.5, 0.5, 1.0); + Pos[2] = float4(+0.5, -0.5, 0.5, 1.0); + + float3 Col[3]; + Col[0] = float3(1.0, 0.0, 0.0); // red + Col[1] = float3(0.0, 1.0, 0.0); // green + Col[2] = float3(0.0, 0.0, 1.0); // blue + + PSIn.Pos = Pos[VertId]; + PSIn.Color = Col[VertId]; +} +)"; + +static const char* PSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +struct PSOutput +{ + float4 Color : SV_TARGET; +}; + +void main(in PSInput PSIn, + out PSOutput PSOut) +{ + PSOut.Color = float4(PSIn.Color.rgb, 1.0); +} +)"; + +void RenderDrawCommandRefenceTriangleD3D12(ISwapChain* pSwapChain) +{ + auto* pEnv = TestingEnvironmentD3D12::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + auto* pd3d12Device = pEnv->GetD3D12Device(); + auto* pTestingSwapChainD3D12 = ValidatedCast(pSwapChain); + + const auto& SCDesc = pSwapChain->GetDesc(); + + CComPtr pVSByteCode, pPSByteCode; + + auto hr = CompileD3DShader(VSSource, "main", nullptr, "vs_5_0", &pVSByteCode); + ASSERT_HRESULT_SUCCEEDED(hr) << "Failed to compile vertex shader"; + + hr = CompileD3DShader(PSSource, "main", nullptr, "ps_5_0", &pPSByteCode); + ASSERT_HRESULT_SUCCEEDED(hr) << "Failed to compile pixel shader"; + + + D3D12_ROOT_SIGNATURE_DESC RootSignatureDesc = {}; + + RootSignatureDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; + + CComPtr signature; + CComPtr pd3d12RootSignature; + D3D12SerializeRootSignature(&RootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, nullptr); + pd3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), __uuidof(pd3d12RootSignature), reinterpret_cast(static_cast(&pd3d12RootSignature))); + + D3D12_GRAPHICS_PIPELINE_STATE_DESC PSODesc = {}; + + PSODesc.pRootSignature = pd3d12RootSignature; + PSODesc.VS.pShaderBytecode = pVSByteCode->GetBufferPointer(); + PSODesc.VS.BytecodeLength = pVSByteCode->GetBufferSize(); + PSODesc.PS.pShaderBytecode = pPSByteCode->GetBufferPointer(); + PSODesc.PS.BytecodeLength = pPSByteCode->GetBufferSize(); + + PSODesc.BlendState = CD3DX12_BLEND_DESC{D3D12_DEFAULT}; + PSODesc.RasterizerState = CD3DX12_RASTERIZER_DESC{D3D12_DEFAULT}; + PSODesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC{D3D12_DEFAULT}; + + PSODesc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; + PSODesc.DepthStencilState.DepthEnable = FALSE; + PSODesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; + + PSODesc.SampleMask = 0xFFFFFFFF; + + PSODesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; + PSODesc.NumRenderTargets = 1; + PSODesc.RTVFormats[0] = TexFormatToDXGI_Format(SCDesc.ColorBufferFormat); + PSODesc.SampleDesc.Count = 1; + PSODesc.SampleDesc.Quality = 0; + PSODesc.NodeMask = 0; + PSODesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; + + CComPtr pd3d12PSO; + hr = pd3d12Device->CreateGraphicsPipelineState(&PSODesc, __uuidof(pd3d12PSO), reinterpret_cast(static_cast(&pd3d12PSO))); + ASSERT_HRESULT_SUCCEEDED(hr) << "Failed to create pipeline state"; + + auto pCmdList = pEnv->CreateGraphicsCommandList(); + pTestingSwapChainD3D12->TransitionRenderTarget(pCmdList, D3D12_RESOURCE_STATE_RENDER_TARGET); + + D3D12_VIEWPORT d3d12VP = {}; + d3d12VP.Width = static_cast(SCDesc.Width); + d3d12VP.Height = static_cast(SCDesc.Height); + d3d12VP.MaxDepth = 1; + pCmdList->RSSetViewports(1, &d3d12VP); + D3D12_RECT Rect = {0, 0, static_cast(SCDesc.Width), static_cast(SCDesc.Height)}; + pCmdList->RSSetScissorRects(1, &Rect); + + auto RTVDesriptorHandle = pTestingSwapChainD3D12->GetRTVDescriptorHandle(); + + pCmdList->OMSetRenderTargets(1, &RTVDesriptorHandle, FALSE, nullptr); + + float ClearColor[] = {0, 0, 0, 0}; + pCmdList->ClearRenderTargetView(RTVDesriptorHandle, ClearColor, 0, nullptr); + + pCmdList->SetPipelineState(pd3d12PSO); + pCmdList->SetGraphicsRootSignature(pd3d12RootSignature); + pCmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + pCmdList->DrawInstanced(3, 1, 0, 0); + + pCmdList->Close(); + ID3D12CommandList* pCmdLits[] = {pCmdList}; + + RefCntAutoPtr pContextD3D12{pContext, IID_DeviceContextD3D12}; + + auto* pQeueD3D12 = pContextD3D12->LockCommandQueue(); + auto* pd3d12Queue = pQeueD3D12->GetD3D12CommandQueue(); + + pd3d12Queue->ExecuteCommandLists(_countof(pCmdLits), pCmdLits); + pEnv->IdleCommandQueue(pd3d12Queue); + + pContextD3D12->UnlockCommandQueue(); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D12/TestingEnvironmentD3D12.cpp b/UnitTests/DiligentCoreAPITest/src/D3D12/TestingEnvironmentD3D12.cpp new file mode 100644 index 00000000..0b221539 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D12/TestingEnvironmentD3D12.cpp @@ -0,0 +1,84 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D12/TestingEnvironmentD3D12.h" +#include "RenderDeviceD3D12.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingEnvironmentD3D12::TestingEnvironmentD3D12(DeviceType deviceType, ADAPTER_TYPE AdapterType) : + TestingEnvironment{deviceType, AdapterType}, + m_WaitForGPUEventHandle{CreateEvent(nullptr, false, false, nullptr)} +{ + RefCntAutoPtr pRenderDeviceD3D12{m_pDevice, IID_RenderDeviceD3D12}; + m_pd3d12Device = pRenderDeviceD3D12->GetD3D12Device(); + auto hr = + m_pd3d12Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(m_pd3d12CmdAllocator), + reinterpret_cast(static_cast(&m_pd3d12CmdAllocator))); + VERIFY_EXPR(SUCCEEDED(hr)); + + hr = m_pd3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(m_pd3d12Fence), + reinterpret_cast(static_cast(&m_pd3d12Fence))); + VERIFY_EXPR(SUCCEEDED(hr)); +} + +TestingEnvironmentD3D12::~TestingEnvironmentD3D12() +{ + CloseHandle(m_WaitForGPUEventHandle); +} + +CComPtr TestingEnvironmentD3D12::CreateGraphicsCommandList() +{ + CComPtr pd3d12CmdList; + m_pd3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_pd3d12CmdAllocator, nullptr, __uuidof(pd3d12CmdList), + reinterpret_cast(static_cast(&pd3d12CmdList))); + return pd3d12CmdList; +} + +void TestingEnvironmentD3D12::IdleCommandQueue(ID3D12CommandQueue* pd3d12Queue) +{ + Uint64 LastSignaledFenceValue = m_NextFenceValue; + ++m_NextFenceValue; + + pd3d12Queue->Signal(m_pd3d12Fence, LastSignaledFenceValue); + + if (m_pd3d12Fence->GetCompletedValue() < LastSignaledFenceValue) + { + m_pd3d12Fence->SetEventOnCompletion(LastSignaledFenceValue, m_WaitForGPUEventHandle); + WaitForSingleObject(m_WaitForGPUEventHandle, INFINITE); + VERIFY(m_pd3d12Fence->GetCompletedValue() == LastSignaledFenceValue, "Unexpected signaled fence value"); + } +} + +TestingEnvironment* CreateTestingEnvironmentD3D12(DeviceType deviceType, ADAPTER_TYPE AdapterType) +{ + return new TestingEnvironmentD3D12{deviceType, AdapterType}; +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/D3D12/TestingSwapChainD3D12.cpp b/UnitTests/DiligentCoreAPITest/src/D3D12/TestingSwapChainD3D12.cpp new file mode 100644 index 00000000..e893a1c0 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/D3D12/TestingSwapChainD3D12.cpp @@ -0,0 +1,257 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "D3D12/TestingEnvironmentD3D12.h" +#include "D3D12/TestingSwapChainD3D12.h" +#include "../include/DXGITypeConversions.h" + +#include "RenderDeviceD3D12.h" +#include "DeviceContextD3D12.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingSwapChainD3D12::TestingSwapChainD3D12(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc) : + TBase // + { + pRefCounters, + pDevice, + pContext, + SCDesc // + } +{ + RefCntAutoPtr pRenderDeviceD3D12{pDevice, IID_RenderDeviceD3D12}; + + auto* pd3d12Device = pRenderDeviceD3D12->GetD3D12Device(); + + D3D12_HEAP_PROPERTIES HeapProps = {}; + HeapProps.Type = D3D12_HEAP_TYPE_DEFAULT; + HeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; + HeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; + HeapProps.CreationNodeMask = 1; + HeapProps.VisibleNodeMask = 1; + + D3D12_RESOURCE_DESC TexDesc = {}; + TexDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + TexDesc.Alignment = 0; + TexDesc.Width = m_SwapChainDesc.Width; + TexDesc.Height = m_SwapChainDesc.Height; + TexDesc.DepthOrArraySize = 1; + TexDesc.MipLevels = 1; + TexDesc.Format = TexFormatToDXGI_Format(SCDesc.ColorBufferFormat); + TexDesc.SampleDesc.Count = 1; + TexDesc.SampleDesc.Quality = 0; + TexDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; + TexDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + + D3D12_CLEAR_VALUE ClearColorValue = {}; + ClearColorValue.Format = TexDesc.Format; + auto hr = + pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE, &TexDesc, m_RenderTargetState, &ClearColorValue, + __uuidof(m_pd3d12RenderTaget), + reinterpret_cast(static_cast(&m_pd3d12RenderTaget))); + VERIFY(SUCCEEDED(hr), "Failed to create D3D12 render target"); + + { + pd3d12Device->GetCopyableFootprints(&TexDesc, 0, 1, 0, &m_StagingBufferFootprint, nullptr, nullptr, &m_StagingBufferSize); + + D3D12_HEAP_PROPERTIES DownloadHeapProps; + DownloadHeapProps.Type = D3D12_HEAP_TYPE_READBACK; + DownloadHeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; + DownloadHeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; + DownloadHeapProps.CreationNodeMask = 1; + DownloadHeapProps.VisibleNodeMask = 1; + + D3D12_RESOURCE_DESC BufferDesc; + BufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + BufferDesc.Alignment = 0; + BufferDesc.Width = m_StagingBufferSize; + BufferDesc.Height = 1; + BufferDesc.DepthOrArraySize = 1; + BufferDesc.MipLevels = 1; + BufferDesc.Format = DXGI_FORMAT_UNKNOWN; + BufferDesc.SampleDesc.Count = 1; + BufferDesc.SampleDesc.Quality = 0; + BufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + BufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE; + + hr = pd3d12Device->CreateCommittedResource(&DownloadHeapProps, D3D12_HEAP_FLAG_NONE, + &BufferDesc, D3D12_RESOURCE_STATE_COPY_DEST, + nullptr, __uuidof(m_pd3d12StagingBuffer), + reinterpret_cast(static_cast(&m_pd3d12StagingBuffer))); + if (FAILED(hr)) + LOG_ERROR_AND_THROW("Failed to create committed staging buffer in an upload heap"); + } + + if (SCDesc.DepthBufferFormat != TEX_FORMAT_UNKNOWN) + { + TexDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + TexDesc.Format = TexFormatToDXGI_Format(SCDesc.DepthBufferFormat); + + D3D12_CLEAR_VALUE ClearDepthValue = {}; + ClearDepthValue.Format = TexDesc.Format; + ClearDepthValue.DepthStencil.Depth = 1; + hr = + pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE, &TexDesc, m_DepthBufferState, &ClearDepthValue, + __uuidof(m_pd3d12DepthBuffer), + reinterpret_cast(static_cast(&m_pd3d12DepthBuffer))); + VERIFY(SUCCEEDED(hr), "Failed to create D3D12 depth buffer"); + } + + D3D12_DESCRIPTOR_HEAP_DESC DescriptorHeapDesc = {}; + DescriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; + DescriptorHeapDesc.NumDescriptors = 1; + DescriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; + DescriptorHeapDesc.NodeMask = 0; + hr = + pd3d12Device->CreateDescriptorHeap(&DescriptorHeapDesc, + __uuidof(m_pd3d12RTVDescriptorHeap), + reinterpret_cast(static_cast(&m_pd3d12RTVDescriptorHeap))); + VERIFY(SUCCEEDED(hr), "Failed to create D3D12 RTV descriptor heap"); + m_RTVDescriptorHandle = m_pd3d12RTVDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); + pd3d12Device->CreateRenderTargetView(m_pd3d12RenderTaget, nullptr, m_RTVDescriptorHandle); + + DescriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV; + hr = + pd3d12Device->CreateDescriptorHeap(&DescriptorHeapDesc, + __uuidof(m_pd3d12DSVDescriptorHeap), + reinterpret_cast(static_cast(&m_pd3d12DSVDescriptorHeap))); + VERIFY(SUCCEEDED(hr), "Failed to create D3D12 DSV descriptor heap"); + m_DSVDescriptorHandle = m_pd3d12DSVDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); + pd3d12Device->CreateDepthStencilView(m_pd3d12DepthBuffer, nullptr, m_DSVDescriptorHandle); +} + +void TestingSwapChainD3D12::TransitionBuffers(ID3D12GraphicsCommandList* pCmdList, + D3D12_RESOURCE_STATES RTVState, + D3D12_RESOURCE_STATES DSVState) +{ + std::vector Barriers; + if (m_RenderTargetState != RTVState) + { + D3D12_RESOURCE_BARRIER Barrier = {}; + Barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + Barrier.Transition.pResource = m_pd3d12RenderTaget; + Barrier.Transition.StateBefore = m_RenderTargetState; + Barrier.Transition.StateAfter = RTVState; + Barrier.Transition.Subresource = 0; + + m_RenderTargetState = RTVState; + + Barriers.emplace_back(Barrier); + } + + if (m_DepthBufferState != DSVState) + { + D3D12_RESOURCE_BARRIER Barrier = {}; + Barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + Barrier.Transition.pResource = m_pd3d12DepthBuffer; + Barrier.Transition.StateBefore = m_DepthBufferState; + Barrier.Transition.StateAfter = DSVState; + Barrier.Transition.Subresource = 0; + + m_DepthBufferState = DSVState; + + Barriers.emplace_back(Barrier); + } + + if (!Barriers.empty()) + { + pCmdList->ResourceBarrier(static_cast(Barriers.size()), Barriers.data()); + } +} + +void TestingSwapChainD3D12::TransitionRenderTarget(ID3D12GraphicsCommandList* pCmdList, + D3D12_RESOURCE_STATES RTVState) +{ + TransitionBuffers(pCmdList, RTVState, m_DepthBufferState); +} + +void TestingSwapChainD3D12::TakeSnapshot() +{ + auto* pEnv = TestingEnvironmentD3D12::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + auto pCmdList = pEnv->CreateGraphicsCommandList(); + + TransitionRenderTarget(pCmdList, D3D12_RESOURCE_STATE_COPY_SOURCE); + + D3D12_TEXTURE_COPY_LOCATION SrcLocation = {}; + + SrcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + SrcLocation.pResource = m_pd3d12RenderTaget; + SrcLocation.SubresourceIndex = 0; + + D3D12_TEXTURE_COPY_LOCATION DstLocation = {}; + + DstLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + DstLocation.pResource = m_pd3d12StagingBuffer; + DstLocation.PlacedFootprint = m_StagingBufferFootprint; + + pCmdList->CopyTextureRegion(&DstLocation, 0, 0, 0, &SrcLocation, nullptr); + + pCmdList->Close(); + ID3D12CommandList* pCmdLits[] = {pCmdList}; + + RefCntAutoPtr pContextD3D12{pContext, IID_DeviceContextD3D12}; + + auto* pQeueD3D12 = pContextD3D12->LockCommandQueue(); + auto* pd3d12Queue = pQeueD3D12->GetD3D12CommandQueue(); + + pd3d12Queue->ExecuteCommandLists(1, pCmdLits); + pEnv->IdleCommandQueue(pd3d12Queue); + + D3D12_RANGE InvalidateRange = {0, m_StagingBufferSize}; + void* pStagingDataPtr = nullptr; + m_pd3d12StagingBuffer->Map(0, &InvalidateRange, &pStagingDataPtr); + m_ReferenceDataPitch = m_SwapChainDesc.Width * 4; + m_ReferenceData.resize(m_SwapChainDesc.Height * m_ReferenceDataPitch); + for (Uint32 row = 0; row < m_SwapChainDesc.Height; ++row) + { + memcpy(&m_ReferenceData[row * m_ReferenceDataPitch], + reinterpret_cast(pStagingDataPtr) + m_StagingBufferFootprint.Footprint.RowPitch * row, + m_ReferenceDataPitch); + } + m_pd3d12StagingBuffer->Unmap(0, nullptr); + + pContextD3D12->UnlockCommandQueue(); +} + +void CreateTestingSwapChainD3D12(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain) +{ + TestingSwapChainD3D12* pTestingSC(MakeNewRCObj()(pDevice, pContext, SCDesc)); + pTestingSC->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/DepthStencilStateTest.cpp b/UnitTests/DiligentCoreAPITest/src/DepthStencilStateTest.cpp index ff8c20cf..421c9872 100644 --- a/UnitTests/DiligentCoreAPITest/src/DepthStencilStateTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/DepthStencilStateTest.cpp @@ -28,6 +28,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/DrawCommandTest.cpp b/UnitTests/DiligentCoreAPITest/src/DrawCommandTest.cpp new file mode 100644 index 00000000..e00dd0b5 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/DrawCommandTest.cpp @@ -0,0 +1,254 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "TestingEnvironment.h" +#include "TestingSwapChainBase.h" + +#include "gtest/gtest.h" + +namespace Diligent +{ + +namespace Testing +{ + +#if D3D11_SUPPORTED +void RenderDrawCommandRefenceTriangleD3D11(ISwapChain* pSwapChain); +#endif + +#if D3D12_SUPPORTED +void RenderDrawCommandRefenceTriangleD3D12(ISwapChain* pSwapChain); +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED +void RenderDrawCommandRefenceTriangleGL(ISwapChain* pSwapChain); +#endif + +#if VULKAN_SUPPORTED +void RenderDrawCommandRefenceTriangleVk(ISwapChain* pSwapChain); +#endif + +#if METAL_SUPPORTED + +#endif + +} // namespace Testing + +} // namespace Diligent + +using namespace Diligent; +using namespace Diligent::Testing; + +namespace +{ + +const char* ProceduralVSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +void main(in uint VertId : SV_VertexID, + out PSInput PSIn) +{ + float4 Pos[3]; + Pos[0] = float4(-0.5, -0.5, 0.0, 1.0); + Pos[1] = float4( 0.0, +0.5, 0.0, 1.0); + Pos[2] = float4(+0.5, -0.5, 0.0, 1.0); + + float3 Col[3]; + Col[0] = float3(1.0, 0.0, 0.0); // red + Col[1] = float3(0.0, 1.0, 0.0); // green + Col[2] = float3(0.0, 0.0, 1.0); // blue + + PSIn.Pos = Pos[VertId]; + PSIn.Color = Col[VertId]; +} +)"; + +const char* PSSource = R"( +struct PSInput +{ + float4 Pos : SV_POSITION; + float3 Color : COLOR; +}; + +struct PSOutput +{ + float4 Color : SV_TARGET; +}; + +void main(in PSInput PSIn, + out PSOutput PSOut) +{ + PSOut.Color = float4(PSIn.Color.rgb, 1.0); +} +)"; + +class DrawCommandTest : public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pDevice = pEnv->GetDevice(); + auto* pSwapChain = pEnv->GetSwapChain(); + auto* pConext = pEnv->GetDeviceContext(); + + RefCntAutoPtr pTestingSwapChain(pSwapChain, IID_TestingSwapChain); + if (pTestingSwapChain) + { + pConext->Flush(); + pConext->InvalidateState(); + + auto deviceType = pDevice->GetDeviceCaps().DevType; + switch (deviceType) + { +#if D3D11_SUPPORTED + case DeviceType::D3D11: + RenderDrawCommandRefenceTriangleD3D11(pSwapChain); + break; +#endif + +#if D3D12_SUPPORTED + case DeviceType::D3D12: + RenderDrawCommandRefenceTriangleD3D12(pSwapChain); + break; +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED + case DeviceType::OpenGL: + case DeviceType::OpenGLES: + RenderDrawCommandRefenceTriangleGL(pSwapChain); + break; + +#endif + +#if VULKAN_SUPPORTED + case DeviceType::Vulkan: + RenderDrawCommandRefenceTriangleVk(pSwapChain); + break; + +#endif + + default: + LOG_ERROR_AND_THROW("Unsupported device type"); + } + + pTestingSwapChain->TakeSnapshot(); + } + TestingEnvironment::ScopedReleaseResources EnvironmentAutoReset; + + PipelineStateDesc PSODesc; + PSODesc.Name = "Procedural triangle PSO"; + + PSODesc.IsComputePipeline = false; + PSODesc.GraphicsPipeline.NumRenderTargets = 1; + PSODesc.GraphicsPipeline.RTVFormats[0] = pSwapChain->GetDesc().ColorBufferFormat; + PSODesc.GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; + PSODesc.GraphicsPipeline.RasterizerDesc.CullMode = CULL_MODE_NONE; + PSODesc.GraphicsPipeline.DepthStencilDesc.DepthEnable = False; + + ShaderCreateInfo ShaderCI; + ShaderCI.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL; + ShaderCI.UseCombinedTextureSamplers = true; + + RefCntAutoPtr pProceduralVS; + { + ShaderCI.Desc.ShaderType = SHADER_TYPE_VERTEX; + ShaderCI.EntryPoint = "main"; + ShaderCI.Desc.Name = "Draw command test procedural vertex shader"; + ShaderCI.Source = ProceduralVSSource; + pDevice->CreateShader(ShaderCI, &pProceduralVS); + ASSERT_NE(pProceduralVS, nullptr); + } + + RefCntAutoPtr pPS; + { + ShaderCI.Desc.ShaderType = SHADER_TYPE_PIXEL; + ShaderCI.EntryPoint = "main"; + ShaderCI.Desc.Name = "Draw command test pixel shader"; + ShaderCI.Source = PSSource; + pDevice->CreateShader(ShaderCI, &pPS); + ASSERT_NE(pPS, nullptr); + } + + PSODesc.GraphicsPipeline.pVS = pProceduralVS; + PSODesc.GraphicsPipeline.pPS = pPS; + pDevice->CreatePipelineState(PSODesc, &sm_pDrawProceduralPSO); + ASSERT_NE(sm_pDrawProceduralPSO, nullptr); + } + + static void TearDownTestSuite() + { + sm_pDrawProceduralPSO.Release(); + + auto* pEnv = TestingEnvironment::GetInstance(); + pEnv->Reset(); + } + + static void SetRenderTargets() + { + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + auto* pSwapChain = pEnv->GetSwapChain(); + + ITextureView* pRTVs[] = {pSwapChain->GetCurrentBackBufferRTV()}; + pContext->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + + const float ClearColor[] = {0.f, 0.f, 0.f, 0.0f}; + pContext->ClearRenderTarget(pRTVs[0], ClearColor, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + } + + static void DrawTriangle(IPipelineState* pPSO) + { + auto* pEnv = TestingEnvironment::GetInstance(); + auto* pContext = pEnv->GetDeviceContext(); + auto* pSwapChain = pEnv->GetSwapChain(); + + pContext->SetPipelineState(pPSO); + // Commit shader resources. we don't really have any resources, this call also sets the shaders in OpenGL backend. + pContext->CommitShaderResources(nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + + DrawAttribs drawAttrs; + drawAttrs.NumVertices = 3; + pContext->Draw(drawAttrs); + + pSwapChain->Present(); + } + + static RefCntAutoPtr sm_pDrawProceduralPSO; +}; + +RefCntAutoPtr DrawCommandTest::sm_pDrawProceduralPSO; + +TEST_F(DrawCommandTest, DrawProcedural) +{ + TestingEnvironment::ScopedReset EnvironmentAutoReset; + + SetRenderTargets(); + DrawTriangle(sm_pDrawProceduralPSO); +} + +} // namespace diff --git a/UnitTests/DiligentCoreAPITest/src/GL/CreateObjFromNativeResGL.cpp b/UnitTests/DiligentCoreAPITest/src/GL/CreateObjFromNativeResGL.cpp new file mode 100644 index 00000000..ad265eaf --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/GL/CreateObjFromNativeResGL.cpp @@ -0,0 +1,167 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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. + */ + +#if PLATFORM_WIN32 + +# ifndef GLEW_STATIC +# define GLEW_STATIC // Must be defined to use static version of glew +# endif +# include "GL/glew.h" +#elif PLATFORM_LINUX + +# ifndef GLEW_STATIC +# define GLEW_STATIC // Must be defined to use static version of glew +# endif +# ifndef GLEW_NO_GLU +# define GLEW_NO_GLU +# endif + +# include "GL/glew.h" + +// Undefine beautiful defines from GL/glx.h -> X11/Xlib.h +# ifdef Bool +# undef Bool +# endif +# ifdef True +# undef True +# endif +# ifdef False +# undef False +# endif +# ifdef Status +# undef Status +# endif +# ifdef Success +# undef Success +# endif + +#elif PLATFORM_MACOS + +# ifndef GLEW_STATIC +# define GLEW_STATIC // Must be defined to use static version of glew +# endif +# ifndef GLEW_NO_GLU +# define GLEW_NO_GLU +# endif + +# include "GL/glew.h" + +#elif PLATFORM_ANDROID + +# include +# include + +#elif PLATFORM_IOS + +# include + +#else +# error Unsupported platform +#endif + +#include "RenderDeviceGL.h" +#include "TextureGL.h" +#include "BufferGL.h" +#include "GraphicsAccessories.h" + +#include "GL/CreateObjFromNativeResGL.h" + +#include "gtest/gtest.h" + +namespace Diligent +{ + +namespace Testing +{ + +void TestCreateObjFromNativeResGL::CreateTexture(Diligent::ITexture* pTexture) +{ +#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID + RefCntAutoPtr pDeviceGL(m_pDevice, IID_RenderDeviceGL); + RefCntAutoPtr pTextureGL(pTexture, IID_TextureGL); + ASSERT_NE(pDeviceGL, nullptr); + ASSERT_NE(pTextureGL, nullptr); + + const auto& SrcTexDesc = pTexture->GetDesc(); + if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + return; + + auto GLHandle = pTextureGL->GetGLTextureHandle(); + ASSERT_NE(GLHandle, (GLuint)0); + + auto TmpTexDesc = SrcTexDesc; + + TmpTexDesc.Width = 0; + TmpTexDesc.Height = 0; + TmpTexDesc.MipLevels = 0; + TmpTexDesc.Format = TEX_FORMAT_UNKNOWN; + + RefCntAutoPtr pAttachedTexture; + pDeviceGL->CreateTextureFromGLHandle(GLHandle, TmpTexDesc, RESOURCE_STATE_UNKNOWN, &pAttachedTexture); + ASSERT_NE(pAttachedTexture, nullptr); + + auto TestTexDesc = pAttachedTexture->GetDesc(); + if (m_pDevice->GetTextureFormatInfo(SrcTexDesc.Format).IsTypeless) + TestTexDesc.Format = SrcTexDesc.Format; + + EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) + << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); + + RefCntAutoPtr pAttachedTextureGL(pAttachedTexture, IID_TextureGL); + ASSERT_NE(pAttachedTextureGL, nullptr); + EXPECT_EQ(pAttachedTextureGL->GetGLTextureHandle(), GLHandle); + EXPECT_EQ(pAttachedTextureGL->GetBindTarget(), pTextureGL->GetBindTarget()); + EXPECT_EQ(reinterpret_cast(pAttachedTextureGL->GetNativeHandle()), GLHandle); +#endif +} + +void TestCreateObjFromNativeResGL::CreateBuffer(Diligent::IBuffer* pBuffer) +{ +#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID + RefCntAutoPtr pDeviceGL(m_pDevice, IID_RenderDeviceGL); + RefCntAutoPtr pBufferGL(pBuffer, IID_BufferGL); + ASSERT_NE(pDeviceGL, nullptr); + ASSERT_NE(pBufferGL, nullptr); + + const auto& SrcBuffDesc = pBuffer->GetDesc(); + auto GLBufferHandle = pBufferGL->GetGLBufferHandle(); + ASSERT_NE(GLBufferHandle, (GLuint)0); + + RefCntAutoPtr pBufferFromNativeGLHandle; + pDeviceGL->CreateBufferFromGLHandle(GLBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeGLHandle); + ASSERT_NE(pBufferFromNativeGLHandle, nullptr); + + const auto& TestBufferDesc = pBufferFromNativeGLHandle->GetDesc(); + EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) + << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); + + RefCntAutoPtr pTestBufferGL(pBufferFromNativeGLHandle, IID_BufferGL); + ASSERT_NE(pTestBufferGL, nullptr); + EXPECT_EQ(pTestBufferGL->GetGLBufferHandle(), GLBufferHandle); + EXPECT_EQ(reinterpret_cast(pTestBufferGL->GetNativeHandle()), GLBufferHandle); +#endif +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/GL/DrawCommandRefenceGL.cpp b/UnitTests/DiligentCoreAPITest/src/GL/DrawCommandRefenceGL.cpp new file mode 100644 index 00000000..5a02a310 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/GL/DrawCommandRefenceGL.cpp @@ -0,0 +1,44 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "GL/TestingEnvironmentGL.h" + +namespace Diligent +{ + +namespace Testing +{ + +static const char* VSSource = R"( +)"; + +static const char* PSSource = R"( +)"; + +void RenderDrawCommandRefenceTriangleGL(ISwapChain* pSwapChain) +{ +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/GL/TestingEnvironmentGL.cpp b/UnitTests/DiligentCoreAPITest/src/GL/TestingEnvironmentGL.cpp new file mode 100644 index 00000000..d0707184 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/GL/TestingEnvironmentGL.cpp @@ -0,0 +1,44 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "GL/TestingEnvironmentGL.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingEnvironmentGL::TestingEnvironmentGL(DeviceType deviceType, ADAPTER_TYPE AdapterType) : + TestingEnvironment{deviceType, AdapterType} +{ +} + +TestingEnvironment* CreateTestingEnvironmentGL(DeviceType deviceType, ADAPTER_TYPE AdapterType) +{ + return new TestingEnvironmentGL{deviceType, AdapterType}; +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/GL/TestingSwapChainGL.cpp b/UnitTests/DiligentCoreAPITest/src/GL/TestingSwapChainGL.cpp new file mode 100644 index 00000000..b5e36936 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/GL/TestingSwapChainGL.cpp @@ -0,0 +1,61 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "GL/TestingSwapChainGL.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingSwapChainGL::TestingSwapChainGL(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc) : + TBase // + { + pRefCounters, + pDevice, + pContext, + SCDesc // + } +{ +} + +void TestingSwapChainGL::TakeSnapshot() +{ +} + +void CreateTestingSwapChainGL(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain) +{ + TestingSwapChainGL* pTestingSC(MakeNewRCObj()(pDevice, pContext, SCDesc)); + pTestingSC->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/GenerateMipsTest.cpp b/UnitTests/DiligentCoreAPITest/src/GenerateMipsTest.cpp index 1bcab569..5e3acc50 100644 --- a/UnitTests/DiligentCoreAPITest/src/GenerateMipsTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/GenerateMipsTest.cpp @@ -26,6 +26,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/HLSL2GLSLConverterTest.cpp b/UnitTests/DiligentCoreAPITest/src/HLSL2GLSLConverterTest.cpp index ee78313f..50358d06 100644 --- a/UnitTests/DiligentCoreAPITest/src/HLSL2GLSLConverterTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/HLSL2GLSLConverterTest.cpp @@ -27,6 +27,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/MTResourceCreationTest.cpp b/UnitTests/DiligentCoreAPITest/src/MTResourceCreationTest.cpp index 7e105fdc..1a7e4e5f 100644 --- a/UnitTests/DiligentCoreAPITest/src/MTResourceCreationTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/MTResourceCreationTest.cpp @@ -34,6 +34,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/PSOCompatibilityTest.cpp b/UnitTests/DiligentCoreAPITest/src/PSOCompatibilityTest.cpp index 6ec93b28..8e8f261d 100644 --- a/UnitTests/DiligentCoreAPITest/src/PSOCompatibilityTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/PSOCompatibilityTest.cpp @@ -26,6 +26,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/PSOTestBase.cpp b/UnitTests/DiligentCoreAPITest/src/PSOTestBase.cpp index 91840c80..5b0bc8d0 100644 --- a/UnitTests/DiligentCoreAPITest/src/PSOTestBase.cpp +++ b/UnitTests/DiligentCoreAPITest/src/PSOTestBase.cpp @@ -27,6 +27,9 @@ namespace Diligent { +namespace Testing +{ + PSOTestBase::Resources PSOTestBase::sm_Resources; static const char g_ShaderSource[] = R"( @@ -91,4 +94,6 @@ RefCntAutoPtr PSOTestBase::CreateTestPSO(const PipelineStateDesc return pPSO; } +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/RasterizerStateTest.cpp b/UnitTests/DiligentCoreAPITest/src/RasterizerStateTest.cpp index dd064074..aea21319 100644 --- a/UnitTests/DiligentCoreAPITest/src/RasterizerStateTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/RasterizerStateTest.cpp @@ -28,6 +28,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/SamplerCreationTest.cpp b/UnitTests/DiligentCoreAPITest/src/SamplerCreationTest.cpp index dbe643ae..59450ef1 100644 --- a/UnitTests/DiligentCoreAPITest/src/SamplerCreationTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/SamplerCreationTest.cpp @@ -31,6 +31,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/SeparateTextureSamplerTest.cpp b/UnitTests/DiligentCoreAPITest/src/SeparateTextureSamplerTest.cpp index c8750706..c842cf02 100644 --- a/UnitTests/DiligentCoreAPITest/src/SeparateTextureSamplerTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/SeparateTextureSamplerTest.cpp @@ -26,6 +26,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/ShaderResourceArrayTest.cpp b/UnitTests/DiligentCoreAPITest/src/ShaderResourceArrayTest.cpp index 1e373448..515ecbbc 100644 --- a/UnitTests/DiligentCoreAPITest/src/ShaderResourceArrayTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/ShaderResourceArrayTest.cpp @@ -26,6 +26,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp b/UnitTests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp index f92be608..76a6b71f 100644 --- a/UnitTests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/ShaderResourceLayoutTest.cpp @@ -32,6 +32,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace Diligent { diff --git a/UnitTests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp b/UnitTests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp index 56e97c53..052d8371 100644 --- a/UnitTests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/ShaderVariableAccessTest.cpp @@ -29,6 +29,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace Diligent { diff --git a/UnitTests/DiligentCoreAPITest/src/TestingEnvironment.cpp b/UnitTests/DiligentCoreAPITest/src/TestingEnvironment.cpp index bb078469..a51dbd1a 100644 --- a/UnitTests/DiligentCoreAPITest/src/TestingEnvironment.cpp +++ b/UnitTests/DiligentCoreAPITest/src/TestingEnvironment.cpp @@ -23,6 +23,7 @@ #include "TestingEnvironment.h" #include "PlatformDebug.h" +#include "TestingSwapChainBase.h" #if D3D11_SUPPORTED # include "EngineFactoryD3D11.h" @@ -47,6 +48,9 @@ namespace Diligent { +namespace Testing +{ + TestingEnvironment* TestingEnvironment::m_pTheEnvironment = nullptr; std::atomic_int TestingEnvironment::m_NumAllowedErrors; @@ -227,7 +231,7 @@ TestingEnvironment::TestingEnvironment(DeviceType deviceType, ADAPTER_TYPE Adapt } } CreateInfo.EnableDebugLayer = true; - //CreateInfo.EnableGPUBasedValidation = true; + //CreateInfo.EnableGPUBasedValidation = true; CreateInfo.CPUDescriptorHeapAllocationSize[0] = 64; // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV CreateInfo.CPUDescriptorHeapAllocationSize[1] = 32; // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER CreateInfo.CPUDescriptorHeapAllocationSize[2] = 16; // D3D12_DESCRIPTOR_HEAP_TYPE_RTV @@ -341,8 +345,14 @@ TestingEnvironment::TestingEnvironment(DeviceType deviceType, ADAPTER_TYPE Adapt LOG_ERROR_AND_THROW("Unknown device type"); break; } - m_pDeviceContext.Attach(ppContexts[0]); + + SCDesc.Width = 512; + SCDesc.Height = 512; + SCDesc.ColorBufferFormat = TEX_FORMAT_RGBA8_UNORM; + SCDesc.DepthBufferFormat = TEX_FORMAT_D32_FLOAT; + + CreateTestingSwapChain(m_pDevice, m_pDeviceContext, SCDesc, &m_pSwapChain); } TestingEnvironment::~TestingEnvironment() @@ -399,4 +409,6 @@ RefCntAutoPtr TestingEnvironment::CreateTexture(const char* Name, TEXT return pTexture; } +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/TestingSwapChainBase.cpp b/UnitTests/DiligentCoreAPITest/src/TestingSwapChainBase.cpp new file mode 100644 index 00000000..7721b6a0 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/TestingSwapChainBase.cpp @@ -0,0 +1,184 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 +#include + +#include "TestingSwapChainBase.h" +#include "GraphicsAccessories.h" + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "../../../ThirdParty/stb/stb_image_write.h" + +namespace Diligent +{ + +namespace Testing +{ + +#if D3D11_SUPPORTED +void CreateTestingSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain); +#endif + +#if D3D12_SUPPORTED +void CreateTestingSwapChainD3D12(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain); +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED +void CreateTestingSwapChainGL(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain); +#endif + +#if VULKAN_SUPPORTED +void CreateTestingSwapChainVk(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain); +#endif + +#if METAL_SUPPORTED + +#endif + +void CreateTestingSwapChain(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain) +{ + auto deviceType = pDevice->GetDeviceCaps().DevType; + switch (deviceType) + { +#if D3D11_SUPPORTED + case DeviceType::D3D11: + CreateTestingSwapChainD3D11(pDevice, pContext, SCDesc, ppSwapChain); + break; +#endif + +#if D3D12_SUPPORTED + case DeviceType::D3D12: + CreateTestingSwapChainD3D12(pDevice, pContext, SCDesc, ppSwapChain); + break; +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED + case DeviceType::OpenGL: + case DeviceType::OpenGLES: + CreateTestingSwapChainGL(pDevice, pContext, SCDesc, ppSwapChain); + break; + +#endif + +#if VULKAN_SUPPORTED + case DeviceType::Vulkan: + CreateTestingSwapChainVk(pDevice, pContext, SCDesc, ppSwapChain); + break; + +#endif + + default: + UNSUPPORTED("Unsupported device type"); + } +} + +void CompareTestImages(const Uint8* pReferencePixels, + Uint32 RefPixelsStride, + const Uint8* pPixels, + Uint32 PixelsStride, + Uint32 Width, + Uint32 Height, + TEXTURE_FORMAT Format) +{ + VERIFY_EXPR(pReferencePixels != nullptr); + VERIFY_EXPR(pPixels != nullptr); + VERIFY_EXPR(Width != 0); + VERIFY_EXPR(Height != 0); + VERIFY_EXPR(PixelsStride != 0); + VERIFY_EXPR(RefPixelsStride != 0); + VERIFY(Format == TEX_FORMAT_RGBA8_UNORM, GetTextureFormatAttribs(Format).Name, " is not supported"); + + bool bIsIdentical = true; + + std::vector Delta(Width * Height * 4); + for (Uint32 row = 0; row < Height; ++row) + { + if (memcmp(pReferencePixels + row * RefPixelsStride, + pPixels + row * PixelsStride, + Width * 4) != 0) + { + bIsIdentical = false; + } + } + + if (bIsIdentical) + { + } + else + { + auto ReportImageStride = (Width * 2) * 3; + + std::vector ReportImage(ReportImageStride * (Height * 2)); + for (Uint32 row = 0; row < Height; ++row) + { + for (Uint32 col = 0; col < Width; ++col) + { + for (Uint32 c = 0; c < 3; ++c) + { + auto RefVal = pReferencePixels[row * RefPixelsStride + col * 4 + c]; + auto Val = pPixels[row * PixelsStride + col * 4 + c]; + auto diff = static_cast(std::min(std::abs(int{RefVal} - int{Val}), 255)); + + // clang-format off + ReportImage[row * ReportImageStride + col * 3 + c] = RefVal; + ReportImage[row * ReportImageStride + (Width + col) * 3 + c] = Val; + ReportImage[(row + Height) * ReportImageStride + col * 3 + c] = diff; + ReportImage[(row + Height) * ReportImageStride + (Width + col) * 3 + c] = static_cast(std::min(diff*16, 255)); + // clang-format on + } + } + } + const auto* const TestInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + + std::string FileName = TestInfo->test_suite_name(); + FileName += '.'; + FileName += TestInfo->name(); + FileName += "_FAIL_.png"; + if (stbi_write_png(FileName.c_str(), Width * 2, Height * 2, 3, ReportImage.data(), (Width * 2) * 3) == 0) + { + LOG_ERROR_MESSAGE("Failed to write ", FileName); + } + ADD_FAILURE() << "Captured image is not identical to the reference image"; + } +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/TextureCreationTest.cpp b/UnitTests/DiligentCoreAPITest/src/TextureCreationTest.cpp index 90146e53..7fe667a4 100644 --- a/UnitTests/DiligentCoreAPITest/src/TextureCreationTest.cpp +++ b/UnitTests/DiligentCoreAPITest/src/TextureCreationTest.cpp @@ -25,22 +25,21 @@ #include "RenderDevice.h" #include "GraphicsAccessories.h" -//#include "GraphicsUtilities.h" #if D3D11_SUPPORTED -# include "CreateObjFromNativeResD3D11.h" +# include "D3D11/CreateObjFromNativeResD3D11.h" #endif #if D3D12_SUPPORTED -# include "CreateObjFromNativeResD3D12.h" +# include "D3D12/CreateObjFromNativeResD3D12.h" #endif #if GL_SUPPORTED || GLES_SUPPORTED -# include "CreateObjFromNativeResGL.h" +# include "GL/CreateObjFromNativeResGL.h" #endif #if VULKAN_SUPPORTED -# include "CreateObjFromNativeResVK.h" +# include "Vulkan/CreateObjFromNativeResVK.h" #endif #include "TestingEnvironment.h" @@ -48,6 +47,7 @@ #include "gtest/gtest.h" using namespace Diligent; +using namespace Diligent::Testing; namespace { diff --git a/UnitTests/DiligentCoreAPITest/src/Vulkan/CreateObjFromNativeResVK.cpp b/UnitTests/DiligentCoreAPITest/src/Vulkan/CreateObjFromNativeResVK.cpp new file mode 100644 index 00000000..a003b8c9 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/Vulkan/CreateObjFromNativeResVK.cpp @@ -0,0 +1,103 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 neVkigence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly neVkigent 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. + */ + +#if VULKAN_SUPPORTED +# include "vulkan.h" +#endif + +#include "RenderDeviceVk.h" +#include "TextureVk.h" +#include "BufferVk.h" +#include "GraphicsAccessories.h" + +#include "Vulkan/CreateObjFromNativeResVK.h" + +#include "gtest/gtest.h" + +namespace Diligent +{ + +namespace Testing +{ + +void TestCreateObjFromNativeResVK::CreateTexture(Diligent::ITexture* pTexture) +{ +#if VULKAN_SUPPORTED + RefCntAutoPtr pDeviceVk(m_pDevice, IID_RenderDeviceVk); + RefCntAutoPtr pTextureVk(pTexture, IID_TextureVk); + ASSERT_NE(pDeviceVk, nullptr); + ASSERT_NE(pTextureVk, nullptr); + + const auto& SrcTexDesc = pTexture->GetDesc(); + if (SrcTexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + return; + + auto VkHandle = pTextureVk->GetVkImage(); + ASSERT_NE(VkHandle, (VkImage)VK_NULL_HANDLE); + + RefCntAutoPtr pAttachedTexture; + pDeviceVk->CreateTextureFromVulkanImage(VkHandle, SrcTexDesc, RESOURCE_STATE_UNKNOWN, &pAttachedTexture); + ASSERT_NE(pAttachedTexture, nullptr); + + const auto& TestTexDesc = pAttachedTexture->GetDesc(); + EXPECT_EQ(TestTexDesc, SrcTexDesc) << "Src tex desc: " << GetObjectDescString(SrcTexDesc) + << "\nTest tex desc: " << GetObjectDescString(TestTexDesc); + + RefCntAutoPtr pAttachedTextureVk(pAttachedTexture, IID_TextureVk); + ASSERT_NE(pAttachedTextureVk, nullptr); + EXPECT_EQ(pAttachedTextureVk->GetVkImage(), VkHandle); + EXPECT_EQ(reinterpret_cast(pAttachedTextureVk->GetNativeHandle()), VkHandle); +#endif +} + +void TestCreateObjFromNativeResVK::CreateBuffer(Diligent::IBuffer* pBuffer) +{ +#if VULKAN_SUPPORTED + RefCntAutoPtr pDeviceVk(m_pDevice, IID_RenderDeviceVk); + RefCntAutoPtr pBufferVk(pBuffer, IID_BufferVk); + ASSERT_NE(pDeviceVk, nullptr); + ASSERT_NE(pBufferVk, nullptr); + + auto VkBufferHandle = pBufferVk->GetVkBuffer(); + ASSERT_NE(VkBufferHandle, (VkBuffer)VK_NULL_HANDLE); + + const auto& SrcBuffDesc = pBuffer->GetDesc(); + + RefCntAutoPtr pBufferFromNativeVkHandle; + pDeviceVk->CreateBufferFromVulkanResource(VkBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeVkHandle); + ASSERT_NE(pBufferFromNativeVkHandle, nullptr); + + const auto& TestBufferDesc = pBufferFromNativeVkHandle->GetDesc(); + EXPECT_EQ(TestBufferDesc, SrcBuffDesc) << "Src buff desc: " << GetObjectDescString(SrcBuffDesc) + << "\nTest buff desc: " << GetObjectDescString(TestBufferDesc); + + RefCntAutoPtr pTestBufferVk(pBufferFromNativeVkHandle, IID_BufferVk); + ASSERT_NE(pTestBufferVk, nullptr); + EXPECT_EQ(pTestBufferVk->GetVkBuffer(), VkBufferHandle); + EXPECT_EQ(reinterpret_cast(pTestBufferVk->GetNativeHandle()), VkBufferHandle); +#endif +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/Vulkan/DrawCommandRefenceVk.cpp b/UnitTests/DiligentCoreAPITest/src/Vulkan/DrawCommandRefenceVk.cpp new file mode 100644 index 00000000..fb580307 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/Vulkan/DrawCommandRefenceVk.cpp @@ -0,0 +1,46 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "Vulkan/TestingEnvironmentVk.h" + +namespace Diligent +{ + +namespace Testing +{ + +static const char* VSSource = R"( + +)"; + +static const char* PSSource = R"( + +)"; + +void RenderDrawCommandRefenceTriangleVk(ISwapChain* pSwapChain) +{ +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingEnvironmentVk.cpp b/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingEnvironmentVk.cpp new file mode 100644 index 00000000..efb7ca30 --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingEnvironmentVk.cpp @@ -0,0 +1,44 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "Vulkan/TestingEnvironmentVk.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingEnvironmentVk::TestingEnvironmentVk(DeviceType deviceType, ADAPTER_TYPE AdapterType) : + TestingEnvironment{deviceType, AdapterType} +{ +} + +TestingEnvironment* CreateTestingEnvironmentVk(DeviceType deviceType, ADAPTER_TYPE AdapterType) +{ + return new TestingEnvironmentVk{deviceType, AdapterType}; +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingSwapChainVk.cpp b/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingSwapChainVk.cpp new file mode 100644 index 00000000..7c8b42af --- /dev/null +++ b/UnitTests/DiligentCoreAPITest/src/Vulkan/TestingSwapChainVk.cpp @@ -0,0 +1,61 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * 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 "Vulkan/TestingSwapChainVk.h" + +namespace Diligent +{ + +namespace Testing +{ + +TestingSwapChainVk::TestingSwapChainVk(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc) : + TBase // + { + pRefCounters, + pDevice, + pContext, + SCDesc // + } +{ +} + +void TestingSwapChainVk::TakeSnapshot() +{ +} + +void CreateTestingSwapChainVk(IRenderDevice* pDevice, + IDeviceContext* pContext, + const SwapChainDesc& SCDesc, + ISwapChain** ppSwapChain) +{ + TestingSwapChainVk* pTestingSC(MakeNewRCObj()(pDevice, pContext, SCDesc)); + pTestingSC->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); +} + +} // namespace Testing + +} // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/Win32/TestingEnvironmentWin32.cpp b/UnitTests/DiligentCoreAPITest/src/Win32/TestingEnvironmentWin32.cpp index 474163be..bc241ffc 100644 --- a/UnitTests/DiligentCoreAPITest/src/Win32/TestingEnvironmentWin32.cpp +++ b/UnitTests/DiligentCoreAPITest/src/Win32/TestingEnvironmentWin32.cpp @@ -31,6 +31,9 @@ namespace Diligent { +namespace Testing +{ + TestingEnvironment::NativeWindow TestingEnvironment::CreateNativeWindow() { #ifdef UNICODE @@ -61,4 +64,6 @@ TestingEnvironment::NativeWindow TestingEnvironment::CreateNativeWindow() return NativeWnd; } +} // namespace Testing + } // namespace Diligent diff --git a/UnitTests/DiligentCoreAPITest/src/main.cpp b/UnitTests/DiligentCoreAPITest/src/main.cpp index d012300f..b0f35b4d 100644 --- a/UnitTests/DiligentCoreAPITest/src/main.cpp +++ b/UnitTests/DiligentCoreAPITest/src/main.cpp @@ -30,7 +30,40 @@ # include #endif + +namespace Diligent +{ + +namespace Testing +{ + +#if D3D11_SUPPORTED +TestingEnvironment* CreateTestingEnvironmentD3D11(DeviceType deviceType, ADAPTER_TYPE AdapterType); +#endif + +#if D3D12_SUPPORTED +TestingEnvironment* CreateTestingEnvironmentD3D12(DeviceType deviceType, ADAPTER_TYPE AdapterType); +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED +TestingEnvironment* CreateTestingEnvironmentGL(DeviceType deviceType, ADAPTER_TYPE AdapterType); +#endif + +#if VULKAN_SUPPORTED +TestingEnvironment* CreateTestingEnvironmentVk(DeviceType deviceType, ADAPTER_TYPE AdapterType); +#endif + +#if METAL_SUPPORTED + +#endif + +} // namespace Testing + +} // namespace Diligent + + using namespace Diligent; +using namespace Diligent::Testing; int main(int argc, char** argv) { @@ -48,34 +81,28 @@ int main(int argc, char** argv) if (strcmp(arg, "--mode=d3d11") == 0) { deviceType = DeviceType::D3D11; - std::cout << "\n\n\n================== Testing Diligent Core API in Direct3D11 mode ==================\n\n"; } else if (strcmp(arg, "--mode=d3d11_sw") == 0) { deviceType = DeviceType::D3D11; AdapterType = ADAPTER_TYPE_SOFTWARE; - std::cout << "\n\n\n================ Testing Diligent Core API in Direct3D11-SW mode =================\n\n"; } else if (strcmp(arg, "--mode=d3d12") == 0) { deviceType = DeviceType::D3D12; - std::cout << "\n\n\n================== Testing Diligent Core API in Direct3D12 mode ==================\n\n"; } else if (strcmp(arg, "--mode=d3d12_sw") == 0) { deviceType = DeviceType::D3D12; AdapterType = ADAPTER_TYPE_SOFTWARE; - std::cout << "\n\n\n================ Testing Diligent Core API in Direct3D12-SW mode =================\n\n"; } else if (strcmp(arg, "--mode=vk") == 0) { deviceType = DeviceType::Vulkan; - std::cout << "\n\n\n==================== Testing Diligent Core API in Vulkan mode ====================\n\n"; } else if (strcmp(arg, "--mode=gl") == 0) { deviceType = DeviceType::OpenGL; - std::cout << "\n\n\n==================== Testing Diligent Core API in OpenGL mode ====================\n\n"; } } @@ -85,10 +112,51 @@ int main(int argc, char** argv) return -1; } - Diligent::TestingEnvironment* pEnv = nullptr; + Diligent::Testing::TestingEnvironment* pEnv = nullptr; try { - pEnv = new Diligent::TestingEnvironment{deviceType, AdapterType}; + switch (deviceType) + { +#if D3D11_SUPPORTED + case DeviceType::D3D11: + pEnv = CreateTestingEnvironmentD3D11(deviceType, AdapterType); + if (AdapterType == ADAPTER_TYPE_SOFTWARE) + std::cout << "\n\n\n================ Testing Diligent Core API in Direct3D11-SW mode =================\n\n"; + else + std::cout << "\n\n\n================== Testing Diligent Core API in Direct3D11 mode ==================\n\n"; + break; +#endif + +#if D3D12_SUPPORTED + case DeviceType::D3D12: + pEnv = CreateTestingEnvironmentD3D12(deviceType, AdapterType); + if (AdapterType == ADAPTER_TYPE_SOFTWARE) + std::cout << "\n\n\n================ Testing Diligent Core API in Direct3D12-SW mode =================\n\n"; + else + std::cout << "\n\n\n================== Testing Diligent Core API in Direct3D12 mode ==================\n\n"; + break; +#endif + +#if GL_SUPPORTED || GLES_SUPPORTED + case DeviceType::OpenGL: + case DeviceType::OpenGLES: + pEnv = CreateTestingEnvironmentGL(deviceType, AdapterType); + std::cout << "\n\n\n==================== Testing Diligent Core API in OpenGL mode ====================\n\n"; + break; + +#endif + +#if VULKAN_SUPPORTED + case DeviceType::Vulkan: + pEnv = CreateTestingEnvironmentVk(deviceType, AdapterType); + std::cout << "\n\n\n==================== Testing Diligent Core API in Vulkan mode ====================\n\n"; + break; + +#endif + + default: + LOG_ERROR_AND_THROW("Unsupported device type"); + } } catch (...) { -- cgit v1.2.3