Fix RHI swap chain queue binding and restore minimal GT checks
This commit is contained in:
@@ -21,6 +21,29 @@ namespace XCEngine {
|
||||
namespace RHI {
|
||||
namespace Integration {
|
||||
|
||||
namespace {
|
||||
|
||||
std::filesystem::path GetExecutableDirectory() {
|
||||
char exePath[MAX_PATH] = {};
|
||||
DWORD length = GetModuleFileNameA(nullptr, exePath, MAX_PATH);
|
||||
if (length == 0 || length >= MAX_PATH) {
|
||||
return std::filesystem::current_path();
|
||||
}
|
||||
|
||||
return std::filesystem::path(exePath).parent_path();
|
||||
}
|
||||
|
||||
std::filesystem::path ResolveRuntimePath(const char* path) {
|
||||
std::filesystem::path resolved(path);
|
||||
if (resolved.is_absolute()) {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
return GetExecutableDirectory() / resolved;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Log(const char* format, ...) {
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
@@ -71,19 +94,19 @@ void RHIIntegrationFixture::SetUp() {
|
||||
}
|
||||
ASSERT_TRUE(initResult);
|
||||
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
mCommandQueue = mDevice->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(mCommandQueue, nullptr);
|
||||
|
||||
SwapChainDesc swapDesc = {};
|
||||
swapDesc.windowHandle = mWindow;
|
||||
swapDesc.width = width;
|
||||
swapDesc.height = height;
|
||||
swapDesc.bufferCount = 2;
|
||||
mSwapChain = mDevice->CreateSwapChain(swapDesc);
|
||||
mSwapChain = mDevice->CreateSwapChain(swapDesc, mCommandQueue);
|
||||
ASSERT_NE(mSwapChain, nullptr);
|
||||
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
mCommandQueue = mDevice->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(mCommandQueue, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
mCommandList = mDevice->CreateCommandList(cmdDesc);
|
||||
@@ -112,11 +135,12 @@ void RHIIntegrationFixture::SetUp() {
|
||||
mRTVs.push_back(rtv);
|
||||
}
|
||||
|
||||
D3D12Texture depthStencil;
|
||||
depthStencil.InitializeDepthStencil(device, width, height);
|
||||
mDepthStencilTexture = new D3D12Texture();
|
||||
ASSERT_NE(mDepthStencilTexture, nullptr);
|
||||
ASSERT_TRUE(mDepthStencilTexture->InitializeDepthStencil(device, width, height));
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = D3D12ResourceView::CreateDepthStencilDesc(Format::D24_UNorm_S8_UInt, D3D12_DSV_DIMENSION_TEXTURE2D);
|
||||
auto* d3d12DSV = new D3D12ResourceView();
|
||||
d3d12DSV->InitializeAsDepthStencil(device, depthStencil.GetResource(), &dsvDesc, mDSVHeap, 0);
|
||||
d3d12DSV->InitializeAsDepthStencil(device, mDepthStencilTexture->GetResource(), &dsvDesc, mDSVHeap, 0);
|
||||
mDSV = d3d12DSV;
|
||||
}
|
||||
|
||||
@@ -178,6 +202,12 @@ void RHIIntegrationFixture::TearDown() {
|
||||
mDSV = nullptr;
|
||||
}
|
||||
|
||||
if (mDepthStencilTexture) {
|
||||
mDepthStencilTexture->Shutdown();
|
||||
delete mDepthStencilTexture;
|
||||
mDepthStencilTexture = nullptr;
|
||||
}
|
||||
|
||||
if (mRTVHeap) {
|
||||
mRTVHeap->Shutdown();
|
||||
delete mRTVHeap;
|
||||
@@ -255,8 +285,11 @@ bool RHIIntegrationFixture::TakeScreenshot(const char* filename) {
|
||||
(void*)mScreenshot, (void*)mDevice, (void*)mSwapChain);
|
||||
return false;
|
||||
}
|
||||
Log("[TEST] TakeScreenshot: capturing to %s", filename);
|
||||
bool result = mScreenshot->Capture(mDevice, mSwapChain, filename);
|
||||
|
||||
const std::filesystem::path outputPath = ResolveRuntimePath(filename);
|
||||
const std::string outputPathString = outputPath.string();
|
||||
Log("[TEST] TakeScreenshot: capturing to %s", outputPathString.c_str());
|
||||
bool result = mScreenshot->Capture(mDevice, mSwapChain, outputPathString.c_str());
|
||||
Log("[TEST] TakeScreenshot: result=%d", result);
|
||||
return result;
|
||||
}
|
||||
@@ -264,9 +297,10 @@ bool RHIIntegrationFixture::TakeScreenshot(const char* filename) {
|
||||
bool RHIIntegrationFixture::CompareWithGoldenTemplate(const char* outputPpm, const char* gtPpm, float threshold) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fs::path exeDir = fs::current_path();
|
||||
fs::path outputPath = exeDir / outputPpm;
|
||||
fs::path gtPath = exeDir / gtPpm;
|
||||
fs::path exeDir = GetExecutableDirectory();
|
||||
fs::path outputPath = ResolveRuntimePath(outputPpm);
|
||||
fs::path gtPath = ResolveRuntimePath(gtPpm);
|
||||
fs::path compareScriptPath = exeDir / "compare_ppm.py";
|
||||
|
||||
if (!fs::exists(outputPath)) {
|
||||
std::cerr << "Output file not found: " << outputPath << std::endl;
|
||||
@@ -278,7 +312,12 @@ bool RHIIntegrationFixture::CompareWithGoldenTemplate(const char* outputPpm, con
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cmd = "python compare_ppm.py \"" + outputPath.string() + "\" \"" + gtPath.string() + "\" " + std::to_string(static_cast<int>(threshold));
|
||||
if (!fs::exists(compareScriptPath)) {
|
||||
std::cerr << "Compare script not found: " << compareScriptPath << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string cmd = "python \"" + compareScriptPath.string() + "\" \"" + outputPath.string() + "\" \"" + gtPath.string() + "\" " + std::to_string(static_cast<int>(threshold));
|
||||
int result = system(cmd.c_str());
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ private:
|
||||
#if defined(XCENGINE_SUPPORT_D3D12)
|
||||
D3D12DescriptorHeap* mRTVHeap = nullptr;
|
||||
D3D12DescriptorHeap* mDSVHeap = nullptr;
|
||||
D3D12Texture* mDepthStencilTexture = nullptr;
|
||||
std::vector<RHIResourceView*> mRTVs;
|
||||
RHIResourceView* mDSV = nullptr;
|
||||
#endif
|
||||
@@ -73,4 +74,4 @@ private:
|
||||
|
||||
} // namespace Integration
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -46,14 +46,11 @@ add_custom_command(TARGET rhi_integration_minimal POST_BUILD
|
||||
$<TARGET_FILE_DIR:rhi_integration_minimal>/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_SOURCE_DIR}/tests/RHI/D3D12/integration/minimal/GT.ppm
|
||||
$<TARGET_FILE_DIR:rhi_integration_minimal>/GT_D3D12.ppm
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_SOURCE_DIR}/tests/RHI/OpenGL/integration/minimal/GT.ppm
|
||||
$<TARGET_FILE_DIR:rhi_integration_minimal>/GT_OpenGL.ppm
|
||||
$<TARGET_FILE_DIR:rhi_integration_minimal>/GT.ppm
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${ENGINE_ROOT_DIR}/third_party/renderdoc/renderdoc.dll
|
||||
$<TARGET_FILE_DIR:rhi_integration_minimal>/
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(rhi_integration_minimal)
|
||||
gtest_discover_tests(rhi_integration_minimal)
|
||||
|
||||
@@ -19,6 +19,14 @@ protected:
|
||||
void RenderFrame() override;
|
||||
};
|
||||
|
||||
const char* GetScreenshotFilename(RHIType type) {
|
||||
return type == RHIType::D3D12 ? "minimal_d3d12.ppm" : "minimal_opengl.ppm";
|
||||
}
|
||||
|
||||
int GetComparisonThreshold(RHIType type) {
|
||||
return type == RHIType::OpenGL ? 5 : 0;
|
||||
}
|
||||
|
||||
void MinimalTest::RenderFrame() {
|
||||
RHICommandList* cmdList = GetCommandList();
|
||||
RHICommandQueue* cmdQueue = GetCommandQueue();
|
||||
@@ -55,6 +63,8 @@ TEST_P(MinimalTest, RenderClear) {
|
||||
RHICommandQueue* cmdQueue = GetCommandQueue();
|
||||
RHISwapChain* swapChain = GetSwapChain();
|
||||
const int targetFrameCount = 30;
|
||||
const char* screenshotFilename = GetScreenshotFilename(GetBackendType());
|
||||
const int comparisonThreshold = GetComparisonThreshold(GetBackendType());
|
||||
|
||||
for (int frameCount = 0; frameCount <= targetFrameCount; ++frameCount) {
|
||||
if (frameCount > 0) {
|
||||
@@ -67,8 +77,10 @@ TEST_P(MinimalTest, RenderClear) {
|
||||
|
||||
if (frameCount >= targetFrameCount) {
|
||||
cmdQueue->WaitForIdle();
|
||||
Log("[TEST] MainLoop: frame %d reached, test complete", frameCount);
|
||||
// Screenshot temporarily disabled due to device state issue
|
||||
Log("[TEST] MainLoop: frame %d reached, capturing %s", frameCount, screenshotFilename);
|
||||
ASSERT_TRUE(TakeScreenshot(screenshotFilename));
|
||||
ASSERT_TRUE(CompareWithGoldenTemplate(screenshotFilename, "GT.ppm", static_cast<float>(comparisonThreshold)));
|
||||
Log("[TEST] MainLoop: frame %d compare passed", frameCount);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,25 +41,27 @@ void RHITestFixture::SetUp() {
|
||||
desc.enableDebugLayer = false;
|
||||
initResult = mDevice->Initialize(desc);
|
||||
ASSERT_TRUE(initResult);
|
||||
} else if (GetParam() == RHIType::OpenGL) {
|
||||
auto* oglDevice = static_cast<OpenGLDevice*>(mDevice);
|
||||
initResult = oglDevice->InitializeWithExistingWindow(mWindow);
|
||||
ASSERT_TRUE(initResult);
|
||||
}
|
||||
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
queueDesc.priority = 0;
|
||||
queueDesc.nodeMask = 0;
|
||||
queueDesc.flags = 0;
|
||||
mCommandQueue = mDevice->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(mCommandQueue, nullptr);
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
queueDesc.priority = 0;
|
||||
queueDesc.nodeMask = 0;
|
||||
queueDesc.flags = 0;
|
||||
mCommandQueue = mDevice->CreateCommandQueue(queueDesc);
|
||||
ASSERT_NE(mCommandQueue, nullptr);
|
||||
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
FenceDesc fenceDesc = {};
|
||||
fenceDesc.initialValue = 0;
|
||||
fenceDesc.flags = 0;
|
||||
mFence = mDevice->CreateFence(fenceDesc);
|
||||
ASSERT_NE(mFence, nullptr);
|
||||
mFenceValue = 0;
|
||||
} else if (GetParam() == RHIType::OpenGL) {
|
||||
auto* oglDevice = static_cast<OpenGLDevice*>(mDevice);
|
||||
initResult = oglDevice->InitializeWithExistingWindow(mWindow);
|
||||
ASSERT_TRUE(initResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ protected:
|
||||
void WaitForGPU();
|
||||
|
||||
RHIDevice* GetDevice() { return mDevice; }
|
||||
RHICommandQueue* GetCommandQueue() { return mCommandQueue; }
|
||||
RHIType GetBackendType() const { return GetParam(); }
|
||||
HWND GetWindowHandle() const { return mWindow; }
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ TEST_P(RHITestFixture, Screenshot_Capture_Basic) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
if (swapChain == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ TEST_P(RHITestFixture, Screenshot_Capture_WithPresent) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
if (swapChain == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -60,4 +60,4 @@ TEST_P(RHITestFixture, Screenshot_Capture_WithPresent) {
|
||||
|
||||
swapChain->Shutdown();
|
||||
delete swapChain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ TEST_P(RHITestFixture, SwapChain_Create) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Shutdown();
|
||||
@@ -26,7 +26,7 @@ TEST_P(RHITestFixture, SwapChain_GetCurrentBackBufferIndex) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
uint32_t index = swapChain->GetCurrentBackBufferIndex();
|
||||
@@ -44,7 +44,7 @@ TEST_P(RHITestFixture, SwapChain_GetCurrentBackBuffer) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
RHITexture* backBuffer = swapChain->GetCurrentBackBuffer();
|
||||
@@ -62,7 +62,7 @@ TEST_P(RHITestFixture, SwapChain_Resize) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Resize(1024, 768);
|
||||
@@ -79,7 +79,7 @@ TEST_P(RHITestFixture, SwapChain_Present_Basic) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
@@ -96,7 +96,7 @@ TEST_P(RHITestFixture, SwapChain_Present_WithSyncInterval) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(1, 0);
|
||||
@@ -114,7 +114,7 @@ TEST_P(RHITestFixture, SwapChain_Present_Multiple) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
@@ -133,7 +133,7 @@ TEST_P(RHITestFixture, SwapChain_GetNativeHandle) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
void* handle = swapChain->GetNativeHandle();
|
||||
@@ -151,7 +151,7 @@ TEST_P(RHITestFixture, SwapChain_Resize_WithPresent) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
@@ -170,7 +170,7 @@ TEST_P(RHITestFixture, SwapChain_TripleBuffering) {
|
||||
desc.bufferCount = 3;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
uint32_t index0 = swapChain->GetCurrentBackBufferIndex();
|
||||
@@ -193,7 +193,7 @@ TEST_P(RHITestFixture, SwapChain_DoubleShutdown) {
|
||||
desc.bufferCount = 2;
|
||||
desc.format = Format::R8G8B8A8_UNorm;
|
||||
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
||||
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc, GetCommandQueue());
|
||||
ASSERT_NE(swapChain, nullptr);
|
||||
|
||||
swapChain->Shutdown();
|
||||
|
||||
Reference in New Issue
Block a user