Skip to content

Commit

Permalink
igl | vulkan | Add VulkanSwapchain tests
Browse files Browse the repository at this point in the history
Reviewed By: EricGriffith, corporateshark

Differential Revision: D64074684

fbshipit-source-id: 71d9152a52b2aa95e98f038c6e3c0ed1ca75ede9
  • Loading branch information
Jason Zink authored and facebook-github-bot committed Oct 11, 2024
1 parent cbf8d73 commit 4f2a644
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/igl/tests/util/device/vulkan/TestDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HWDeviceDesc> devices =
Expand Down
76 changes: 76 additions & 0 deletions src/igl/tests/vulkan/VulkanSwapchainTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
#include <gtest/gtest.h>
#include <igl/vulkan/Common.h>
#include <igl/vulkan/Device.h>
#include <igl/vulkan/HWDevice.h>
#include <igl/vulkan/VulkanContext.h>
#include <igl/vulkan/VulkanSwapchain.h>
#include <memory>

#include <igl/tests/util/device/TestDevice.h>

#ifdef __ANDROID__
#include <vulkan/vulkan_android.h>
#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<igl::vulkan::Device&>(*device_);
context_ = &device.getVulkanContext();
ASSERT_TRUE(context_ != nullptr);
}

protected:
std::shared_ptr<IDevice> device_;
vulkan::VulkanContext* context_ = nullptr;
};

TEST_F(VulkanSwapchainTest, CreateVulkanSwapchain) {
auto swapchain = std::make_unique<igl::vulkan::VulkanSwapchain>(*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

0 comments on commit 4f2a644

Please sign in to comment.