Add Phase 1 D3D12 tests for Device and Fence
- Implement real D3D12 tests for Device (feature level, descriptor handle, shader model, resource binding tier, tiled resources) - Implement real D3D12 tests for Fence (create, signal, wait, event) - Move tests from tests/D3D12_engine/test/ to tests/RHI/D3D12/ - All 22 tests pass
This commit is contained in:
77
tests/RHI/D3D12/fixtures/D3D12TestFixture.cpp
Normal file
77
tests/RHI/D3D12/fixtures/D3D12TestFixture.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "D3D12TestFixture.h"
|
||||
|
||||
ComPtr<ID3D12Device> D3D12TestFixture::mDevice;
|
||||
|
||||
void D3D12TestFixture::SetUpTestSuite() {
|
||||
HRESULT hr = D3D12CreateDevice(
|
||||
nullptr,
|
||||
D3D_FEATURE_LEVEL_12_0,
|
||||
IID_PPV_ARGS(&mDevice)
|
||||
);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
GTEST_SKIP() << "Failed to create D3D12 device";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12TestFixture::TearDownTestSuite() {
|
||||
mDevice.Reset();
|
||||
}
|
||||
|
||||
void D3D12TestFixture::SetUp() {
|
||||
if (!mDevice) {
|
||||
GTEST_SKIP() << "D3D12 device not available";
|
||||
return;
|
||||
}
|
||||
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
|
||||
HRESULT hr = mDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue));
|
||||
if (FAILED(hr)) {
|
||||
GTEST_SKIP() << "Failed to create command queue";
|
||||
return;
|
||||
}
|
||||
|
||||
hr = mDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&mCommandAllocator));
|
||||
if (FAILED(hr)) {
|
||||
GTEST_SKIP() << "Failed to create command allocator";
|
||||
return;
|
||||
}
|
||||
|
||||
hr = mDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, mCommandAllocator.Get(), nullptr, IID_PPV_ARGS(&mCommandList));
|
||||
if (FAILED(hr)) {
|
||||
GTEST_SKIP() << "Failed to create command list";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12TestFixture::TearDown() {
|
||||
if (mCommandQueue) {
|
||||
WaitForGPU();
|
||||
}
|
||||
mCommandList.Reset();
|
||||
mCommandAllocator.Reset();
|
||||
mCommandQueue.Reset();
|
||||
}
|
||||
|
||||
void D3D12TestFixture::WaitForGPU() {
|
||||
if (!mCommandQueue || !mDevice) return;
|
||||
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
UINT64 fenceValue = 1;
|
||||
|
||||
HRESULT hr = mDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
if (SUCCEEDED(hr)) {
|
||||
mCommandQueue->Signal(fence.Get(), fenceValue);
|
||||
if (fence->GetCompletedValue() < fenceValue) {
|
||||
HANDLE eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
if (eventHandle) {
|
||||
fence->SetEventOnCompletion(fenceValue, eventHandle);
|
||||
WaitForSingleObject(eventHandle, INFINITE);
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user