- Add CommandQueue unit tests for WaitForIdle and synchronization - Add SwapChain unit tests for Present and buffer operations - Add Texture unit tests for various texture types and mipmaps - Fix RHIIntegrationFixture with proper logging and debug output - Update minimal integration test with RHI abstraction layer - Add GT reference image for minimal test - Update TEST_SPEC.md documentation
203 lines
5.1 KiB
C++
203 lines
5.1 KiB
C++
#include "fixtures/RHITestFixture.h"
|
|
#include "XCEngine/RHI/RHISwapChain.h"
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Create) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBufferIndex) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
uint32_t index = swapChain->GetCurrentBackBufferIndex();
|
|
EXPECT_LT(index, 2u);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBuffer) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
RHITexture* backBuffer = swapChain->GetCurrentBackBuffer();
|
|
EXPECT_NE(backBuffer, nullptr);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Resize) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Resize(1024, 768);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Present_Basic) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Present(0, 0);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Present_WithSyncInterval) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Present(1, 0);
|
|
swapChain->Present(0, 0);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Present_Multiple) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
swapChain->Present(0, 0);
|
|
}
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_GetNativeHandle) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
void* handle = swapChain->GetNativeHandle();
|
|
EXPECT_NE(handle, nullptr);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_Resize_WithPresent) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Present(0, 0);
|
|
swapChain->Resize(1024, 768);
|
|
swapChain->Present(0, 0);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_TripleBuffering) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 3;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
uint32_t index0 = swapChain->GetCurrentBackBufferIndex();
|
|
EXPECT_LT(index0, 3u);
|
|
|
|
swapChain->Present(0, 0);
|
|
|
|
uint32_t index1 = swapChain->GetCurrentBackBufferIndex();
|
|
EXPECT_LT(index1, 3u);
|
|
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, SwapChain_DoubleShutdown) {
|
|
SwapChainDesc desc = {};
|
|
desc.windowHandle = GetWindowHandle();
|
|
desc.width = 800;
|
|
desc.height = 600;
|
|
desc.bufferCount = 2;
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
swapChain->Shutdown();
|
|
swapChain->Shutdown();
|
|
delete swapChain;
|
|
}
|