Files
XCEngine/tests/RHI/integration/minimal/main.cpp

94 lines
2.8 KiB
C++
Raw Normal View History

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <gtest/gtest.h>
#include "../fixtures/RHIIntegrationFixture.h"
#include "XCEngine/Debug/Logger.h"
#include "XCEngine/Debug/ConsoleLogSink.h"
using namespace XCEngine::RHI;
using namespace XCEngine::RHI::Integration;
using namespace XCEngine::Debug;
namespace {
class MinimalTest : public RHIIntegrationFixture {
protected:
void RenderFrame() override;
};
void MinimalTest::RenderFrame() {
RHICommandList* cmdList = GetCommandList();
RHICommandQueue* cmdQueue = GetCommandQueue();
Log("[TEST] RenderFrame: calling Reset");
cmdList->Reset();
Log("[TEST] RenderFrame: calling SetRenderTargetForClear");
SetRenderTargetForClear();
Viewport viewport = { 0.0f, 0.0f, 1280.0f, 720.0f, 0.0f, 1.0f };
Rect scissorRect = { 0, 0, 1280, 720 };
cmdList->SetViewport(viewport);
cmdList->SetScissorRect(scissorRect);
float clearColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
Log("[TEST] RenderFrame: calling Clear");
cmdList->Clear(clearColor[0], clearColor[1], clearColor[2], clearColor[3], 1);
Log("[TEST] RenderFrame: calling EndRender");
EndRender();
Log("[TEST] RenderFrame: calling Close");
cmdList->Close();
Log("[TEST] RenderFrame: calling ExecuteCommandLists");
void* cmdLists[] = { cmdList };
cmdQueue->ExecuteCommandLists(1, cmdLists);
Log("[TEST] RenderFrame: done");
}
TEST_P(MinimalTest, RenderClear) {
RHICommandQueue* cmdQueue = GetCommandQueue();
RHISwapChain* swapChain = GetSwapChain();
const int targetFrameCount = 30;
for (int frameCount = 0; frameCount <= targetFrameCount; ++frameCount) {
if (frameCount > 0) {
cmdQueue->WaitForPreviousFrame();
}
Log("[TEST] MainLoop: frame %d", frameCount);
BeginRender();
RenderFrame();
if (frameCount >= targetFrameCount) {
cmdQueue->WaitForIdle();
Log("[TEST] MainLoop: frame %d reached, test complete", frameCount);
// Screenshot temporarily disabled due to device state issue
break;
}
Log("[TEST] MainLoop: calling Present, index before=%d", swapChain->GetCurrentBackBufferIndex());
swapChain->Present(0, 0);
Log("[TEST] MainLoop: Present done, index after=%d", swapChain->GetCurrentBackBufferIndex());
}
}
} // namespace
INSTANTIATE_TEST_SUITE_P(D3D12, MinimalTest, ::testing::Values(RHIType::D3D12));
INSTANTIATE_TEST_SUITE_P(OpenGL, MinimalTest, ::testing::Values(RHIType::OpenGL));
GTEST_API_ int main(int argc, char** argv) {
Logger::Get().Initialize();
Logger::Get().AddSink(std::make_unique<ConsoleLogSink>());
Logger::Get().SetMinimumLevel(LogLevel::Debug);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}