Files
XCEngine/tests/RHI/unit/test_command_queue.cpp
ssdfasd 8d4447915d feat: add RHI abstraction layer unit tests
- Add RHITestFixture with RHI_BACKEND env var support for backend selection
- Add unit tests for: Device, Buffer, Texture, SwapChain, CommandList, CommandQueue, Shader, Fence, Sampler
- Tests can run against D3D12 or OpenGL backends via RHI_BACKEND env var
- Add integration folder placeholder for future integration tests
2026-03-22 16:18:51 +08:00

110 lines
3.0 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_F(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();
cmdList->Close();
void* cmdLists[] = { cmdList };
queue->ExecuteCommandLists(1, cmdLists);
cmdList->Shutdown();
delete cmdList;
queue->Shutdown();
delete queue;
}
TEST_F(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_F(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_F(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_F(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_F(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;
}