From 4f2a6448f23ffd50e8dcfc10ae2861eca12b1dfb Mon Sep 17 00:00:00 2001 From: Jason Zink Date: Fri, 11 Oct 2024 05:48:03 -0700 Subject: [PATCH] igl | vulkan | Add VulkanSwapchain tests Reviewed By: EricGriffith, corporateshark Differential Revision: D64074684 fbshipit-source-id: 71d9152a52b2aa95e98f038c6e3c0ed1ca75ede9 --- .../tests/util/device/vulkan/TestDevice.cpp | 4 + src/igl/tests/vulkan/VulkanSwapchainTest.cpp | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/igl/tests/vulkan/VulkanSwapchainTest.cpp diff --git a/src/igl/tests/util/device/vulkan/TestDevice.cpp b/src/igl/tests/util/device/vulkan/TestDevice.cpp index 805ceb5304..2024b3d1f3 100644 --- a/src/igl/tests/util/device/vulkan/TestDevice.cpp +++ b/src/igl/tests/util/device/vulkan/TestDevice.cpp @@ -56,6 +56,10 @@ std::shared_ptr<::igl::IDevice> createTestDevice(bool enableValidation) { config.swapChainColorSpace = igl::ColorSpace::SRGB_NONLINEAR; config.enableExtraLogs = enableValidation; +#if IGL_PLATFORM_WIN || IGL_PLATFORM_ANDROID || IGL_PLATFORM_LINUX + config.headless = true; +#endif + auto ctx = igl::vulkan::HWDevice::createContext(config, nullptr); std::vector devices = diff --git a/src/igl/tests/vulkan/VulkanSwapchainTest.cpp b/src/igl/tests/vulkan/VulkanSwapchainTest.cpp new file mode 100644 index 0000000000..1d22b259b2 --- /dev/null +++ b/src/igl/tests/vulkan/VulkanSwapchainTest.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef __ANDROID__ +#include +#endif + +#if IGL_PLATFORM_WIN || IGL_PLATFORM_ANDROID || IGL_PLATFORM_LINUX + +namespace igl::tests { + +namespace { +constexpr uint32_t kWidth = 1024; +constexpr uint32_t kHeight = 1024; +} // namespace + +// +// VulkanSwapchainTest +// +// Unit tests for igl::vulkan::VulkanSwapchain +// +class VulkanSwapchainTest : public ::testing::Test { + public: + // Set up common resources. + void SetUp() override { + // Turn off debug break so unit tests can run + igl::setDebugBreakEnabled(false); + + device_ = igl::tests::util::device::createTestDevice(igl::BackendType::Vulkan); + ASSERT_TRUE(device_ != nullptr); + auto& device = static_cast(*device_); + context_ = &device.getVulkanContext(); + ASSERT_TRUE(context_ != nullptr); + } + + protected: + std::shared_ptr device_; + vulkan::VulkanContext* context_ = nullptr; +}; + +TEST_F(VulkanSwapchainTest, CreateVulkanSwapchain) { + auto swapchain = std::make_unique(*context_, kWidth, kHeight); + ASSERT_NE(swapchain, nullptr); + + ASSERT_EQ(swapchain->getWidth(), kWidth); + ASSERT_EQ(swapchain->getHeight(), kHeight); + + const VkExtent2D extent = swapchain->getExtent(); + ASSERT_EQ(extent.width, kWidth); + ASSERT_EQ(extent.height, kHeight); + + ASSERT_NE(swapchain->getFormatColor(), VK_FORMAT_UNDEFINED); + + ASSERT_GT(swapchain->getNumSwapchainImages(), 0); + + ASSERT_EQ(swapchain->getCurrentImageIndex(), 0); +} + +} // namespace igl::tests + +#endif // IGL_PLATFORM_WIN || IGL_PLATFORM_ANDROID || IGL_PLATFORM_LINUX