1. Add ALLOW_RENDER_TARGET flag for color textures in CreateTexture - This was the root cause of 5 failing RTV-related tests - Without this flag, creating RTV caused device removal 2. Add FromD3D12() reverse conversion for Format enum - GetFormat() was incorrectly casting DXGI_FORMAT to Format - DXGI_FORMAT_R8G8B8A8_UNORM=28 but Format::R8G8B8A8_UNorm=3 - Added FromD3D12() to properly convert back 3. Update RHITestFixture to pre-create CommandQueue and Fence - Prevents potential timing issues with GPU synchronization 4. Update RHITestFixture tests to pass correct format in ResourceViewDesc - Previously passed empty desc.format=0 which caused issues All 234 RHI unit tests now pass (117 D3D12 + 117 OpenGL)
104 lines
2.9 KiB
C++
104 lines
2.9 KiB
C++
#include "RHITestFixture.h"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <windows.h>
|
|
|
|
#include "XCEngine/RHI/D3D12/D3D12Device.h"
|
|
#include "XCEngine/RHI/D3D12/D3D12CommandQueue.h"
|
|
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
|
|
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
|
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
INSTANTIATE_TEST_SUITE_P(D3D12, RHITestFixture, ::testing::Values(RHIType::D3D12));
|
|
INSTANTIATE_TEST_SUITE_P(OpenGL, RHITestFixture, ::testing::Values(RHIType::OpenGL));
|
|
|
|
void RHITestFixture::SetUpTestSuite() {
|
|
}
|
|
|
|
void RHITestFixture::TearDownTestSuite() {
|
|
}
|
|
|
|
void RHITestFixture::SetUp() {
|
|
mDevice = RHIFactory::CreateRHIDevice(GetParam());
|
|
ASSERT_NE(mDevice, nullptr);
|
|
|
|
WNDCLASSEXW wc = {};
|
|
wc.cbSize = sizeof(WNDCLASSEXW);
|
|
wc.lpfnWndProc = DefWindowProcW;
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
|
wc.lpszClassName = L"RHIUnitTestClass";
|
|
RegisterClassExW(&wc);
|
|
|
|
mWindow = CreateWindowExW(0, L"RHIUnitTestClass", L"RHIUnitTest", WS_OVERLAPPEDWINDOW,
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
|
|
|
|
bool initResult = false;
|
|
if (GetParam() == RHIType::D3D12) {
|
|
RHIDeviceDesc desc = {};
|
|
desc.enableDebugLayer = false;
|
|
initResult = mDevice->Initialize(desc);
|
|
ASSERT_TRUE(initResult);
|
|
|
|
CommandQueueDesc queueDesc = {};
|
|
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
|
queueDesc.priority = 0;
|
|
queueDesc.nodeMask = 0;
|
|
queueDesc.flags = 0;
|
|
mCommandQueue = mDevice->CreateCommandQueue(queueDesc);
|
|
ASSERT_NE(mCommandQueue, nullptr);
|
|
|
|
FenceDesc fenceDesc = {};
|
|
fenceDesc.initialValue = 0;
|
|
fenceDesc.flags = 0;
|
|
mFence = mDevice->CreateFence(fenceDesc);
|
|
ASSERT_NE(mFence, nullptr);
|
|
mFenceValue = 0;
|
|
} else if (GetParam() == RHIType::OpenGL) {
|
|
auto* oglDevice = static_cast<OpenGLDevice*>(mDevice);
|
|
initResult = oglDevice->InitializeWithExistingWindow(mWindow);
|
|
ASSERT_TRUE(initResult);
|
|
}
|
|
}
|
|
|
|
void RHITestFixture::WaitForGPU() {
|
|
if (mDevice == nullptr || mCommandQueue == nullptr || mFence == nullptr) {
|
|
return;
|
|
}
|
|
|
|
if (GetParam() == RHIType::D3D12) {
|
|
mFenceValue++;
|
|
mCommandQueue->Signal(mFence, mFenceValue);
|
|
mFence->Wait(mFenceValue);
|
|
}
|
|
}
|
|
|
|
void RHITestFixture::TearDown() {
|
|
WaitForGPU();
|
|
|
|
if (mFence != nullptr) {
|
|
mFence->Shutdown();
|
|
delete mFence;
|
|
mFence = nullptr;
|
|
}
|
|
if (mCommandQueue != nullptr) {
|
|
mCommandQueue->Shutdown();
|
|
delete mCommandQueue;
|
|
mCommandQueue = nullptr;
|
|
}
|
|
if (mDevice != nullptr) {
|
|
mDevice->Shutdown();
|
|
delete mDevice;
|
|
mDevice = nullptr;
|
|
}
|
|
if (mWindow) {
|
|
DestroyWindow(mWindow);
|
|
mWindow = nullptr;
|
|
}
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|