Files
XCEngine/tests/RHI/D3D12/unit/fixtures/D3D12TestFixture.cpp
ssdfasd f427699ac6 refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
  instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
  test discovery (math, core, containers, memory, threading, debug,
  components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
  from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
  build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00

77 lines
2.0 KiB
C++

#include "D3D12TestFixture.h"
#include <memory>
namespace XCEngine {
namespace RHI {
void D3D12TestFixture::SetUpTestSuite() {
}
void D3D12TestFixture::TearDownTestSuite() {
}
void D3D12TestFixture::SetUp() {
m_device = std::make_unique<D3D12Device>();
RHIDeviceDesc desc;
desc.enableDebugLayer = false;
desc.enableGPUValidation = false;
if (!m_device->Initialize(desc)) {
GTEST_SKIP() << "Failed to initialize D3D12Device";
return;
}
m_commandQueue = std::make_unique<D3D12CommandQueue>();
if (!m_commandQueue->Initialize(m_device->GetDevice(), CommandQueueType::Direct)) {
GTEST_SKIP() << "Failed to create command queue";
return;
}
m_commandAllocator = std::make_unique<D3D12CommandAllocator>();
if (!m_commandAllocator->Initialize(m_device->GetDevice(), CommandQueueType::Direct)) {
GTEST_SKIP() << "Failed to create command allocator";
return;
}
m_commandList = std::make_unique<D3D12CommandList>();
if (!m_commandList->Initialize(m_device->GetDevice(), CommandQueueType::Direct, m_commandAllocator->GetCommandAllocator())) {
GTEST_SKIP() << "Failed to create command list";
return;
}
}
void D3D12TestFixture::TearDown() {
if (m_commandQueue) {
WaitForGPU();
}
if (m_commandList) {
m_commandList->Shutdown();
m_commandList.reset();
}
if (m_commandAllocator) {
m_commandAllocator->Shutdown();
m_commandAllocator.reset();
}
if (m_commandQueue) {
m_commandQueue->Shutdown();
m_commandQueue.reset();
}
if (m_device) {
m_device->Shutdown();
m_device.reset();
}
}
void D3D12TestFixture::WaitForGPU() {
if (!m_commandQueue) return;
auto fence = std::make_unique<D3D12Fence>();
if (fence->Initialize(m_device->GetDevice(), 0)) {
m_commandQueue->Signal(fence.get(), 1);
fence->Wait(1);
}
}
} // namespace RHI
} // namespace XCEngine