Fix RHI D3D12 RTV creation and GetFormat bug
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)
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#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 {
|
||||
@@ -37,57 +40,54 @@ void RHITestFixture::SetUp() {
|
||||
RHIDeviceDesc desc = {};
|
||||
desc.enableDebugLayer = false;
|
||||
initResult = mDevice->Initialize(desc);
|
||||
} else if (GetParam() == RHIType::OpenGL) {
|
||||
auto* oglDevice = static_cast<OpenGLDevice*>(mDevice);
|
||||
initResult = oglDevice->InitializeWithExistingWindow(mWindow);
|
||||
}
|
||||
ASSERT_TRUE(initResult);
|
||||
}
|
||||
ASSERT_TRUE(initResult);
|
||||
|
||||
void RHITestFixture::WaitForGPU() {
|
||||
if (mDevice == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetParam() == RHIType::D3D12) {
|
||||
auto* device = static_cast<D3D12Device*>(mDevice);
|
||||
|
||||
CommandQueueDesc queueDesc = {};
|
||||
queueDesc.queueType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
queueDesc.priority = 0;
|
||||
queueDesc.nodeMask = 0;
|
||||
queueDesc.flags = 0;
|
||||
auto* commandQueue = device->CreateCommandQueue(queueDesc);
|
||||
if (commandQueue) {
|
||||
FenceDesc fenceDesc = {};
|
||||
fenceDesc.initialValue = 0;
|
||||
fenceDesc.flags = 0;
|
||||
auto* fence = mDevice->CreateFence(fenceDesc);
|
||||
if (fence) {
|
||||
commandQueue->Signal(fence, 1);
|
||||
fence->Wait(1);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (fence->GetCompletedValue() >= 1) {
|
||||
break;
|
||||
}
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
fence->Shutdown();
|
||||
delete fence;
|
||||
}
|
||||
commandQueue->Shutdown();
|
||||
delete commandQueue;
|
||||
}
|
||||
|
||||
Sleep(100);
|
||||
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;
|
||||
|
||||
@@ -37,6 +37,9 @@ protected:
|
||||
private:
|
||||
RHIDevice* mDevice = nullptr;
|
||||
HWND mWindow = nullptr;
|
||||
RHICommandQueue* mCommandQueue = nullptr;
|
||||
RHIFence* mFence = nullptr;
|
||||
uint64_t mFenceValue = 0;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
Reference in New Issue
Block a user