Files
XCEngine/tests/RHI/unit/test_command_queue.cpp
ssdfasd a9b9a6ebfc test: Add RHI integration tests and update unit tests
- 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
2026-03-25 20:50:49 +08:00

237 lines
6.4 KiB
C++

#include "fixtures/RHITestFixture.h"
#include "XCEngine/RHI/RHICommandQueue.h"
#include "XCEngine/RHI/RHICommandList.h"
#include "XCEngine/RHI/RHIFence.h"
using namespace XCEngine::RHI;
TEST_P(RHITestFixture, CommandQueue_ExecuteCommandLists) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
CommandListDesc cmdDesc = {};
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
ASSERT_NE(cmdList, nullptr);
cmdList->Reset();
void* cmdLists[] = { cmdList };
queue->ExecuteCommandLists(1, cmdLists);
cmdList->Close();
cmdList->Shutdown();
delete cmdList;
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_SignalWaitFence) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
FenceDesc fenceDesc = {};
fenceDesc.initialValue = 0;
RHIFence* fence = GetDevice()->CreateFence(fenceDesc);
ASSERT_NE(fence, nullptr);
queue->Signal(fence, 1);
fence->Wait(1);
EXPECT_EQ(fence->GetCompletedValue(), 1u);
fence->Shutdown();
delete fence;
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_GetCompletedValue) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
uint64_t completedValue = queue->GetCompletedValue();
EXPECT_GE(completedValue, 0u);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_WaitForIdle) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
queue->WaitForIdle();
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_GetType) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
EXPECT_EQ(queue->GetType(), CommandQueueType::Direct);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_GetTimestampFrequency) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
uint64_t frequency = queue->GetTimestampFrequency();
EXPECT_GT(frequency, 0u);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_WaitForPreviousFrame) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
queue->WaitForPreviousFrame();
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_GetCurrentFrame) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
uint64_t frame = queue->GetCurrentFrame();
EXPECT_GE(frame, 0ull);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_MultipleFrames) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
uint64_t initialFrame = queue->GetCurrentFrame();
for (int i = 0; i < 10; ++i) {
queue->WaitForPreviousFrame();
}
uint64_t laterFrame = queue->GetCurrentFrame();
EXPECT_GE(laterFrame, initialFrame);
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_ExecuteMultipleCommandLists) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
CommandListDesc cmdDesc = {};
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandList* cmdList1 = GetDevice()->CreateCommandList(cmdDesc);
RHICommandList* cmdList2 = GetDevice()->CreateCommandList(cmdDesc);
ASSERT_NE(cmdList1, nullptr);
ASSERT_NE(cmdList2, nullptr);
cmdList1->Reset();
cmdList2->Reset();
void* cmdLists[] = { cmdList1, cmdList2 };
queue->ExecuteCommandLists(2, cmdLists);
cmdList1->Close();
cmdList2->Close();
cmdList1->Shutdown();
cmdList2->Shutdown();
delete cmdList1;
delete cmdList2;
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_SignalMultipleFences) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
FenceDesc fenceDesc = {};
fenceDesc.initialValue = 0;
RHIFence* fence1 = GetDevice()->CreateFence(fenceDesc);
RHIFence* fence2 = GetDevice()->CreateFence(fenceDesc);
ASSERT_NE(fence1, nullptr);
ASSERT_NE(fence2, nullptr);
queue->Signal(fence1, 1);
queue->Signal(fence2, 2);
fence1->Wait(1);
fence2->Wait(2);
EXPECT_GE(fence1->GetCompletedValue(), 1u);
EXPECT_GE(fence2->GetCompletedValue(), 2u);
fence1->Shutdown();
fence2->Shutdown();
delete fence1;
delete fence2;
queue->Shutdown();
delete queue;
}
TEST_P(RHITestFixture, CommandQueue_GetNativeHandle) {
CommandQueueDesc queueDesc = {};
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(queueDesc);
ASSERT_NE(queue, nullptr);
void* handle = queue->GetNativeHandle();
EXPECT_NE(handle, nullptr);
queue->Shutdown();
delete queue;
}