fix: RHI抽象层单元测试修复

- 实现 D3D12Device::CreateCommandQueue/CreateCommandList/CreateSwapChain
- 修复 Buffer::Map 对 DEFAULT heap 的问题 (Vertex/Index 使用 UPLOAD heap)
- 修复 Fence::IsSignaled() 初始值问题
- 修复 Sampler::GetNativeHandle() 返回值
- 修复 RHICapabilities 和 RHIDeviceInfo 初始化
- 修复 Shader 测试 (空 ShaderCompileDesc 预期)
- 修复 RHITestFixture 创建窗口句柄
- 重命名 opengl_engine_tests -> rhi_opengl_tests
- 添加 tests/RHI/unit/ 到构建系统

测试结果: 22 passed -> 59 passed
This commit is contained in:
2026-03-23 18:53:29 +08:00
parent 66df465661
commit 6935a91a1f
10 changed files with 174 additions and 113 deletions

View File

@@ -1,6 +1,7 @@
#include "RHITestFixture.h"
#include <cstdlib>
#include <iostream>
#include <windows.h>
namespace XCEngine {
namespace RHI {
@@ -14,22 +15,23 @@ void RHITestFixture::TearDownTestSuite() {
}
void RHITestFixture::SetUp() {
const char* backend = std::getenv("RHI_BACKEND");
if (backend != nullptr) {
std::string backendStr(backend);
if (backendStr == "OpenGL" || backendStr == "opengl") {
mBackendType = RHIType::OpenGL;
} else if (backendStr == "D3D12" || backendStr == "d3d12") {
mBackendType = RHIType::D3D12;
}
}
mDevice = RHIFactory::CreateRHIDevice(mBackendType);
ASSERT_NE(mDevice, nullptr);
WNDCLASSEXW wc = {};
wc.cbSize = sizeof(WNDCLASSEXW);
wc.lpfnWndProc = DefWindowProcW;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpszClassName = L"RHIUnitTestClass";
RegisterClassExW(&wc);
HWND hwnd = CreateWindowExW(0, L"RHIUnitTestClass", L"RHIUnitTest", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
RHIDeviceDesc desc = {};
desc.enableDebugLayer = true;
desc.appName = L"RHIUnitTest";
desc.windowHandle = hwnd;
bool initResult = mDevice->Initialize(desc);
ASSERT_TRUE(initResult);