2026-03-22 16:18:51 +08:00
|
|
|
#include "fixtures/RHITestFixture.h"
|
|
|
|
|
|
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_Create_Success) {
|
2026-03-22 16:18:51 +08:00
|
|
|
ASSERT_NE(GetDevice(), nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_Initialize_Shutdown) {
|
2026-03-22 16:18:51 +08:00
|
|
|
RHIDevice* device = RHIFactory::CreateRHIDevice(GetBackendType());
|
|
|
|
|
ASSERT_NE(device, nullptr);
|
|
|
|
|
|
|
|
|
|
RHIDeviceDesc desc = {};
|
|
|
|
|
desc.enableDebugLayer = true;
|
|
|
|
|
bool initResult = device->Initialize(desc);
|
|
|
|
|
ASSERT_TRUE(initResult);
|
|
|
|
|
|
|
|
|
|
device->Shutdown();
|
|
|
|
|
delete device;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_GetCapabilities_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
const auto& caps = GetDevice()->GetCapabilities();
|
|
|
|
|
|
|
|
|
|
EXPECT_GE(caps.maxTexture2DSize, 0u);
|
|
|
|
|
EXPECT_GE(caps.maxRenderTargets, 1u);
|
|
|
|
|
EXPECT_GE(caps.maxViewports, 1u);
|
|
|
|
|
EXPECT_GE(caps.maxVertexAttribs, 8u);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_GetDeviceInfo_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
const auto& info = GetDevice()->GetDeviceInfo();
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(info.vendor.empty());
|
|
|
|
|
EXPECT_FALSE(info.renderer.empty());
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateBuffer_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
BufferDesc desc = {};
|
|
|
|
|
desc.size = 1024;
|
|
|
|
|
desc.stride = sizeof(float);
|
|
|
|
|
desc.bufferType = static_cast<uint32_t>(BufferType::Vertex);
|
|
|
|
|
|
|
|
|
|
RHIBuffer* buffer = GetDevice()->CreateBuffer(desc);
|
|
|
|
|
ASSERT_NE(buffer, nullptr);
|
|
|
|
|
EXPECT_EQ(buffer->GetSize(), 1024u);
|
|
|
|
|
|
|
|
|
|
buffer->Shutdown();
|
|
|
|
|
delete buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateTexture_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
TextureDesc desc = {};
|
|
|
|
|
desc.width = 512;
|
|
|
|
|
desc.height = 512;
|
|
|
|
|
desc.mipLevels = 1;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
|
|
|
|
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
|
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
|
EXPECT_EQ(texture->GetWidth(), 512u);
|
|
|
|
|
EXPECT_EQ(texture->GetHeight(), 512u);
|
|
|
|
|
|
|
|
|
|
texture->Shutdown();
|
|
|
|
|
delete texture;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateFence_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
FenceDesc desc = {};
|
|
|
|
|
desc.initialValue = 0;
|
|
|
|
|
desc.flags = 0;
|
|
|
|
|
|
|
|
|
|
RHIFence* fence = GetDevice()->CreateFence(desc);
|
|
|
|
|
ASSERT_NE(fence, nullptr);
|
|
|
|
|
EXPECT_EQ(fence->GetCompletedValue(), 0u);
|
|
|
|
|
|
|
|
|
|
fence->Shutdown();
|
|
|
|
|
delete fence;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateCommandQueue_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
CommandQueueDesc desc = {};
|
|
|
|
|
desc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
|
|
|
|
|
|
RHICommandQueue* queue = GetDevice()->CreateCommandQueue(desc);
|
|
|
|
|
ASSERT_NE(queue, nullptr);
|
|
|
|
|
EXPECT_EQ(queue->GetType(), CommandQueueType::Direct);
|
|
|
|
|
|
|
|
|
|
queue->Shutdown();
|
|
|
|
|
delete queue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateCommandList_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
CommandListDesc desc = {};
|
|
|
|
|
desc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
|
|
|
|
|
|
|
|
RHICommandList* cmdList = GetDevice()->CreateCommandList(desc);
|
|
|
|
|
ASSERT_NE(cmdList, nullptr);
|
|
|
|
|
|
|
|
|
|
cmdList->Shutdown();
|
|
|
|
|
delete cmdList;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_CreateSampler_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SamplerDesc desc = {};
|
|
|
|
|
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
|
|
|
|
|
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
|
|
|
|
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
|
|
|
|
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
|
|
|
|
|
|
|
|
|
RHISampler* sampler = GetDevice()->CreateSampler(desc);
|
|
|
|
|
ASSERT_NE(sampler, nullptr);
|
|
|
|
|
|
|
|
|
|
sampler->Shutdown();
|
|
|
|
|
delete sampler;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, Device_GetNativeDevice_ReturnsValid) {
|
2026-03-22 16:18:51 +08:00
|
|
|
void* native = GetDevice()->GetNativeDevice();
|
|
|
|
|
ASSERT_NE(native, nullptr);
|
|
|
|
|
}
|