summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-12-08 00:58:01 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-12-08 00:58:01 +0000
commit6099823697ea03300a5f4c4028d81978a1e558e7 (patch)
tree716f48794bb9e4c51cbfb73dea20a61b9a053468
parentReworked API Unit test to use run-time DLL loading to avoid apparent issue wi... (diff)
downloadDiligentCore-6099823697ea03300a5f4c4028d81978a1e558e7.tar.gz
DiligentCore-6099823697ea03300a5f4c4028d81978a1e558e7.zip
Added buffer creation test
-rw-r--r--UnitTests/DiligentCoreAPITest/CMakeLists.txt14
-rw-r--r--UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h42
-rw-r--r--UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h42
-rw-r--r--UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h42
-rw-r--r--UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h50
-rw-r--r--UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h43
-rw-r--r--UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp253
-rw-r--r--UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp126
-rw-r--r--UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp96
-rw-r--r--UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp158
-rw-r--r--UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp94
-rw-r--r--UnitTests/DiligentCoreAPITest/src/main.cpp16
12 files changed, 975 insertions, 1 deletions
diff --git a/UnitTests/DiligentCoreAPITest/CMakeLists.txt b/UnitTests/DiligentCoreAPITest/CMakeLists.txt
index ef3ac2ee..cbfe3fe8 100644
--- a/UnitTests/DiligentCoreAPITest/CMakeLists.txt
+++ b/UnitTests/DiligentCoreAPITest/CMakeLists.txt
@@ -23,8 +23,20 @@ PRIVATE
${ENGINE_LIBRARIES}
)
+if(GL_SUPPORTED OR GLES_SUPPORTED)
+ target_link_libraries(DiligentCoreAPITest PRIVATE Diligent-HLSL2GLSLConverterLib)
+endif()
+
+if(GL_SUPPORTED)
+ target_link_libraries(DiligentCoreAPITest PRIVATE glew-static)
+endif()
-target_include_directories(DiligentCoreAPITest PRIVATE include)
+
+target_include_directories(DiligentCoreAPITest
+PRIVATE
+ include
+ ../../ThirdParty/vulkan
+)
if(PLATFORM_WIN32)
diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h
new file mode 100644
index 00000000..2dad233b
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D11.h
@@ -0,0 +1,42 @@
+/* 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
new file mode 100644
index 00000000..96a47004
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResD3D12.h
@@ -0,0 +1,42 @@
+/* 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
new file mode 100644
index 00000000..decfc131
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResGL.h
@@ -0,0 +1,42 @@
+/* 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
new file mode 100644
index 00000000..5f9f23f8
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResTestBase.h
@@ -0,0 +1,50 @@
+/* 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 "RenderDevice.h"
+#include "Texture.h"
+#include "Buffer.h"
+#include "RefCntAutoPtr.h"
+
+namespace Diligent
+{
+
+class CreateObjFromNativeResTestBase
+{
+public:
+ CreateObjFromNativeResTestBase(IRenderDevice* pDevice) :
+ m_pDevice{pDevice}
+ {}
+
+ virtual ~CreateObjFromNativeResTestBase() {}
+
+ virtual void CreateTexture(ITexture* pTexture) = 0;
+ virtual void CreateBuffer(IBuffer* pBuffer) = 0;
+
+protected:
+ RefCntAutoPtr<IRenderDevice> m_pDevice;
+};
+
+} // namespace Diligent
diff --git a/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h
new file mode 100644
index 00000000..4db3bd8e
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/include/CreateObjFromNativeResVK.h
@@ -0,0 +1,43 @@
+/* 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/src/BufferCreationTest.cpp b/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp
new file mode 100644
index 00000000..1c5db70f
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/src/BufferCreationTest.cpp
@@ -0,0 +1,253 @@
+/* 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 D3D11_SUPPORTED
+# include "CreateObjFromNativeResD3D11.h"
+#endif
+
+#if D3D12_SUPPORTED
+# include "CreateObjFromNativeResD3D12.h"
+#endif
+
+#if GL_SUPPORTED || GLES_SUPPORTED
+# include "CreateObjFromNativeResGL.h"
+#endif
+
+#if VULKAN_SUPPORTED
+# include "CreateObjFromNativeResVK.h"
+#endif
+
+#include "TestingEnvironment.h"
+
+#include "gtest/gtest.h"
+
+using namespace Diligent;
+
+namespace
+{
+
+class BufferCreationTest : public ::testing::Test
+{
+protected:
+ static void SetUpTestSuite()
+ {
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ const auto DevCaps = pDevice->GetDeviceCaps();
+ switch (DevCaps.DevType)
+ {
+#if D3D11_SUPPORTED
+ case DeviceType::D3D11:
+ pCreateObjFromNativeRes.reset(new TestCreateObjFromNativeResD3D11(pDevice));
+ break;
+
+#endif
+
+#if D3D12_SUPPORTED
+ case DeviceType::D3D12:
+ pCreateObjFromNativeRes.reset(new TestCreateObjFromNativeResD3D12(pDevice));
+ break;
+#endif
+
+#if GL_SUPPORTED || GLES_SUPPORTED
+ case DeviceType::OpenGL:
+ case DeviceType::OpenGLES:
+ pCreateObjFromNativeRes.reset(new TestCreateObjFromNativeResGL(pDevice));
+ break;
+#endif
+
+#if VULKAN_SUPPORTED
+ case DeviceType::Vulkan:
+ pCreateObjFromNativeRes.reset(new TestCreateObjFromNativeResVK(pDevice));
+ break;
+#endif
+
+ default: UNEXPECTED("Unexpected device type");
+ }
+ }
+
+ static void TearDownTestSuite()
+ {
+ pCreateObjFromNativeRes.reset();
+ TestingEnvironment::GetInstance()->Reset();
+ }
+
+ static std::unique_ptr<CreateObjFromNativeResTestBase> pCreateObjFromNativeRes;
+};
+
+std::unique_ptr<CreateObjFromNativeResTestBase> BufferCreationTest::pCreateObjFromNativeRes;
+
+TEST_F(BufferCreationTest, CreateVertexBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Vertex buffer";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_VERTEX_BUFFER;
+
+ BufferData InitData;
+ InitData.DataSize = BuffDesc.uiSizeInBytes;
+ std::vector<Uint8> DummyData(InitData.DataSize);
+ InitData.pData = DummyData.data();
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, &InitData, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+TEST_F(BufferCreationTest, CreateIndexBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Index";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_VERTEX_BUFFER;
+
+ BufferData NullData;
+
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, &NullData, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+TEST_F(BufferCreationTest, CreateFormattedBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ const auto& DevCaps = pDevice->GetDeviceCaps();
+ if (!(DevCaps.bComputeShadersSupported && DevCaps.bIndirectRenderingSupported))
+ {
+ GTEST_SKIP();
+ }
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Formatted buffer";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE;
+ BuffDesc.Mode = BUFFER_MODE_FORMATTED;
+ BuffDesc.ElementByteStride = 16;
+
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, nullptr, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ BufferViewDesc ViewDesc;
+ ViewDesc.ViewType = BUFFER_VIEW_SHADER_RESOURCE;
+ ViewDesc.ByteOffset = 32;
+ ViewDesc.Format.NumComponents = 4;
+ ViewDesc.Format.ValueType = VT_FLOAT32;
+ ViewDesc.Format.IsNormalized = false;
+ RefCntAutoPtr<IBufferView> pBufferSRV;
+ pBuffer->CreateView(ViewDesc, &pBufferSRV);
+ EXPECT_NE(pBufferSRV, nullptr);
+
+ ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS;
+ RefCntAutoPtr<IBufferView> pBufferUAV;
+ pBuffer->CreateView(ViewDesc, &pBufferUAV);
+ EXPECT_NE(pBufferUAV, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+TEST_F(BufferCreationTest, CreateStructuedBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ const auto& DevCaps = pDevice->GetDeviceCaps();
+ if (!DevCaps.bComputeShadersSupported)
+ {
+ GTEST_SKIP();
+ }
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Structured buffer";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS;
+ BuffDesc.Mode = BUFFER_MODE_STRUCTURED;
+ BuffDesc.ElementByteStride = 16;
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, nullptr, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+TEST_F(BufferCreationTest, CreateUniformBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Uniform buffer";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_UNIFORM_BUFFER;
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, nullptr, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+TEST_F(BufferCreationTest, CreateRawBuffer)
+{
+ auto* pEnv = TestingEnvironment::GetInstance();
+ auto* pDevice = pEnv->GetDevice();
+
+ BufferDesc BuffDesc;
+ BuffDesc.Name = "Raw buffer";
+ BuffDesc.uiSizeInBytes = 256;
+ BuffDesc.BindFlags = BIND_VERTEX_BUFFER | BIND_INDEX_BUFFER | BIND_UNORDERED_ACCESS | BIND_SHADER_RESOURCE;
+ BuffDesc.Mode = BUFFER_MODE_RAW;
+ BuffDesc.ElementByteStride = 16;
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pDevice->CreateBuffer(BuffDesc, nullptr, &pBuffer);
+ ASSERT_NE(pBuffer, nullptr);
+
+ BufferViewDesc ViewDesc;
+ ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS;
+ ViewDesc.ByteOffset = 32;
+ ViewDesc.Format.NumComponents = 4;
+ ViewDesc.Format.ValueType = VT_FLOAT32;
+ RefCntAutoPtr<IBufferView> pBufferUAV;
+ pBuffer->CreateView(ViewDesc, &pBufferUAV);
+ ASSERT_NE(pBufferUAV, nullptr);
+
+ ViewDesc.ViewType = BUFFER_VIEW_SHADER_RESOURCE;
+ RefCntAutoPtr<IBufferView> pBufferSRV;
+ pBuffer->CreateView(ViewDesc, &pBufferSRV);
+ ASSERT_NE(pBufferSRV, nullptr);
+
+ pCreateObjFromNativeRes->CreateBuffer(pBuffer);
+}
+
+} // namespace
diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp
new file mode 100644
index 00000000..5b3a1782
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D11.cpp
@@ -0,0 +1,126 @@
+/* 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 <d3d11.h>
+#include "RenderDeviceD3D11.h"
+#include "TextureD3D11.h"
+#include "BufferD3D11.h"
+
+#include "gtest/gtest.h"
+
+namespace Diligent
+{
+
+void TestCreateObjFromNativeResD3D11::CreateTexture(ITexture* pTexture)
+{
+ RefCntAutoPtr<IRenderDeviceD3D11> pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11);
+ RefCntAutoPtr<ITextureD3D11> pTextureD3D11(pTexture, IID_TextureD3D11);
+ ASSERT_NE(pDeviceD3D11, nullptr);
+ ASSERT_NE(pTextureD3D11, nullptr);
+
+ const auto& SrcTexDesc = pTexture->GetDesc();
+ auto* pd3d11Texture = pTextureD3D11->GetD3D11Texture();
+ ASSERT_NE(pd3d11Texture, nullptr);
+
+ RefCntAutoPtr<ITexture> pTextureFromNativeD3D11Handle;
+ if (SrcTexDesc.Type == RESOURCE_DIM_TEX_1D ||
+ SrcTexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY)
+ {
+ pDeviceD3D11->CreateTextureFromD3DResource(static_cast<ID3D11Texture1D*>(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<ID3D11Texture2D*>(pd3d11Texture), RESOURCE_STATE_UNKNOWN, &pTextureFromNativeD3D11Handle);
+ }
+ else if (SrcTexDesc.Type == RESOURCE_DIM_TEX_3D)
+ {
+ pDeviceD3D11->CreateTextureFromD3DResource(static_cast<ID3D11Texture3D*>(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);
+ RefCntAutoPtr<ITextureD3D11> pTestTextureD3D11(pTextureFromNativeD3D11Handle, IID_TextureD3D11);
+ ASSERT_NE(pTestTextureD3D11, nullptr);
+ EXPECT_EQ(pTestTextureD3D11->GetD3D11Texture(), pd3d11Texture);
+ EXPECT_EQ(pTestTextureD3D11->GetNativeHandle(), pd3d11Texture);
+}
+
+void TestCreateObjFromNativeResD3D11::CreateBuffer(IBuffer* pBuffer)
+{
+ RefCntAutoPtr<IRenderDeviceD3D11> pDeviceD3D11(m_pDevice, IID_RenderDeviceD3D11);
+ RefCntAutoPtr<IBufferD3D11> 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<IBuffer> pBufferFromNativeD3D11Handle;
+ pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle);
+ ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr);
+
+ const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc();
+ EXPECT_EQ(TestBufferDesc, SrcBuffDesc);
+
+ RefCntAutoPtr<IBufferD3D11> 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<IBuffer> pBufferFromNativeD3D11Handle;
+ pDeviceD3D11->CreateBufferFromD3DResource(pd3d11Buffer, BuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D11Handle);
+ ASSERT_NE(pBufferFromNativeD3D11Handle, nullptr);
+
+ const auto& TestBufferDesc = pBufferFromNativeD3D11Handle->GetDesc();
+ EXPECT_EQ(TestBufferDesc, SrcBuffDesc);
+
+ RefCntAutoPtr<IBufferD3D11> 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
new file mode 100644
index 00000000..f5ffae02
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResD3D12.cpp
@@ -0,0 +1,96 @@
+/* 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 <d3d12.h>
+#include "RenderDeviceD3D12.h"
+#include "TextureD3D12.h"
+#include "BufferD3D12.h"
+
+#include "gtest/gtest.h"
+
+namespace Diligent
+{
+
+void TestCreateObjFromNativeResD3D12::CreateTexture(Diligent::ITexture* pTexture)
+{
+ RefCntAutoPtr<IRenderDeviceD3D12> pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12);
+ RefCntAutoPtr<ITextureD3D12> 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<ITexture> 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);
+
+ RefCntAutoPtr<ITextureD3D12> 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<IRenderDeviceD3D12> pDeviceD3D12(m_pDevice, IID_RenderDeviceD3D12);
+ RefCntAutoPtr<IBufferD3D12> 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<IBuffer> pBufferFromNativeD3D12Handle;
+ pDeviceD3D12->CreateBufferFromD3DResource(pD3D12Buffer, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeD3D12Handle);
+ ASSERT_NE(pBufferFromNativeD3D12Handle, nullptr);
+
+ const auto& TestBufferDesc = pBufferFromNativeD3D12Handle->GetDesc();
+ EXPECT_EQ(TestBufferDesc, SrcBuffDesc);
+
+ RefCntAutoPtr<IBufferD3D12> 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
new file mode 100644
index 00000000..48187a16
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResGL.cpp
@@ -0,0 +1,158 @@
+/* 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 <GLES3/gl3.h>
+# include <GLES3/gl3ext.h>
+
+#elif PLATFORM_IOS
+
+# include <OpenGLES/ES3/gl.h>
+
+#else
+# error Unsupported platform
+#endif
+
+#include "RenderDeviceGL.h"
+#include "TextureGL.h"
+#include "BufferGL.h"
+
+#include "CreateObjFromNativeResGL.h"
+
+#include "gtest/gtest.h"
+
+namespace Diligent
+{
+
+void TestCreateObjFromNativeResGL::CreateTexture(Diligent::ITexture* pTexture)
+{
+#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID
+ RefCntAutoPtr<IRenderDeviceGL> pDeviceGL(m_pDevice, IID_RenderDeviceGL);
+ RefCntAutoPtr<ITextureGL> 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<ITexture> 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);
+ RefCntAutoPtr<ITextureGL> pAttachedTextureGL(pAttachedTexture, IID_TextureGL);
+ ASSERT_NE(pAttachedTextureGL, nullptr);
+ EXPECT_EQ(pAttachedTextureGL->GetGLTextureHandle(), GLHandle);
+ EXPECT_EQ(pAttachedTextureGL->GetBindTarget(), pTextureGL->GetBindTarget());
+ EXPECT_EQ(reinterpret_cast<size_t>(pAttachedTextureGL->GetNativeHandle()), GLHandle);
+#endif
+}
+
+void TestCreateObjFromNativeResGL::CreateBuffer(Diligent::IBuffer* pBuffer)
+{
+#if PLATFORM_WIN32 || PLATFORM_LINUX || PLATFORM_ANDROID
+ RefCntAutoPtr<IRenderDeviceGL> pDeviceGL(m_pDevice, IID_RenderDeviceGL);
+ RefCntAutoPtr<IBufferGL> 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<IBuffer> pBufferFromNativeGLHandle;
+ pDeviceGL->CreateBufferFromGLHandle(GLBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeGLHandle);
+ ASSERT_NE(pBufferFromNativeGLHandle, nullptr);
+
+ const auto& TestBufferDesc = pBufferFromNativeGLHandle->GetDesc();
+ EXPECT_EQ(TestBufferDesc, SrcBuffDesc);
+
+ RefCntAutoPtr<IBufferGL> pTestBufferGL(pBufferFromNativeGLHandle, IID_BufferGL);
+ ASSERT_NE(pTestBufferGL, nullptr);
+ EXPECT_EQ(pTestBufferGL->GetGLBufferHandle(), GLBufferHandle);
+ EXPECT_EQ(reinterpret_cast<size_t>(pTestBufferGL->GetNativeHandle()), GLBufferHandle);
+#endif
+}
+
+} // namespace Diligent
diff --git a/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp
new file mode 100644
index 00000000..8807f9b7
--- /dev/null
+++ b/UnitTests/DiligentCoreAPITest/src/CreateObjFromNativeResVK.cpp
@@ -0,0 +1,94 @@
+/* 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 "CreateObjFromNativeResVK.h"
+
+#include "gtest/gtest.h"
+
+namespace Diligent
+{
+
+void TestCreateObjFromNativeResVK::CreateTexture(Diligent::ITexture* pTexture)
+{
+#if VULKAN_SUPPORTED
+ RefCntAutoPtr<IRenderDeviceVk> pDeviceVk(m_pDevice, IID_RenderDeviceVk);
+ RefCntAutoPtr<ITextureVk> 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<ITexture> pAttachedTexture;
+ pDeviceVk->CreateTextureFromVulkanImage(VkHandle, SrcTexDesc, RESOURCE_STATE_UNKNOWN, &pAttachedTexture);
+ ASSERT_NE(pAttachedTexture, nullptr);
+
+ const auto& TestTexDesc = pAttachedTexture->GetDesc();
+ EXPECT_EQ(TestTexDesc, SrcTexDesc);
+ RefCntAutoPtr<ITextureVk> pAttachedTextureVk(pAttachedTexture, IID_TextureVk);
+ ASSERT_NE(pAttachedTextureVk, nullptr);
+ EXPECT_EQ(pAttachedTextureVk->GetVkImage(), VkHandle);
+ EXPECT_EQ(reinterpret_cast<VkImage>(pAttachedTextureVk->GetNativeHandle()), VkHandle);
+#endif
+}
+
+void TestCreateObjFromNativeResVK::CreateBuffer(Diligent::IBuffer* pBuffer)
+{
+#if VULKAN_SUPPORTED
+ RefCntAutoPtr<IRenderDeviceVk> pDeviceVk(m_pDevice, IID_RenderDeviceVk);
+ RefCntAutoPtr<IBufferVk> 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<IBuffer> pBufferFromNativeVkHandle;
+ pDeviceVk->CreateBufferFromVulkanResource(VkBufferHandle, SrcBuffDesc, RESOURCE_STATE_UNKNOWN, &pBufferFromNativeVkHandle);
+ ASSERT_NE(pBufferFromNativeVkHandle, nullptr);
+
+ const auto& TestBufferDesc = pBufferFromNativeVkHandle->GetDesc();
+ EXPECT_EQ(TestBufferDesc, SrcBuffDesc);
+
+ RefCntAutoPtr<IBufferVk> pTestBufferVk(pBufferFromNativeVkHandle, IID_BufferVk);
+ ASSERT_NE(pTestBufferVk, nullptr);
+ EXPECT_EQ(pTestBufferVk->GetVkBuffer(), VkBufferHandle);
+ EXPECT_EQ(reinterpret_cast<VkBuffer>(pTestBufferVk->GetNativeHandle()), VkBufferHandle);
+#endif
+}
+
+} // namespace Diligent
diff --git a/UnitTests/DiligentCoreAPITest/src/main.cpp b/UnitTests/DiligentCoreAPITest/src/main.cpp
index 022badf6..d012300f 100644
--- a/UnitTests/DiligentCoreAPITest/src/main.cpp
+++ b/UnitTests/DiligentCoreAPITest/src/main.cpp
@@ -21,13 +21,23 @@
* of the possibility of such damages.
*/
+#include <iostream>
+
#include "gtest/gtest.h"
#include "TestingEnvironment.h"
+#if PLATFORM_WIN32
+# include <crtdbg.h>
+#endif
+
using namespace Diligent;
int main(int argc, char** argv)
{
+#if PLATFORM_WIN32
+ _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+#endif
+
::testing::InitGoogleTest(&argc, argv);
DeviceType deviceType = DeviceType::Undefined;
@@ -38,28 +48,34 @@ 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";
}
}