Fix GPU state issue - make device non-static per test

- Each test now creates its own D3D12 device, command queue, allocator, and command list
- Properly cleanup in TearDown to avoid GPU state issues
- All 29 tests now pass
This commit is contained in:
2026-03-17 03:54:50 +08:00
parent 0049f8334d
commit 11ea2a4fc5
2 changed files with 9 additions and 15 deletions

View File

@@ -1,8 +1,12 @@
#include "D3D12TestFixture.h" #include "D3D12TestFixture.h"
ComPtr<ID3D12Device> D3D12TestFixture::mDevice;
void D3D12TestFixture::SetUpTestSuite() { void D3D12TestFixture::SetUpTestSuite() {
}
void D3D12TestFixture::TearDownTestSuite() {
}
void D3D12TestFixture::SetUp() {
HRESULT hr = D3D12CreateDevice( HRESULT hr = D3D12CreateDevice(
nullptr, nullptr,
D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_12_0,
@@ -13,22 +17,11 @@ void D3D12TestFixture::SetUpTestSuite() {
GTEST_SKIP() << "Failed to create D3D12 device"; GTEST_SKIP() << "Failed to create D3D12 device";
return; return;
} }
}
void D3D12TestFixture::TearDownTestSuite() {
mDevice.Reset();
}
void D3D12TestFixture::SetUp() {
if (!mDevice) {
GTEST_SKIP() << "D3D12 device not available";
return;
}
D3D12_COMMAND_QUEUE_DESC queueDesc = {}; D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
HRESULT hr = mDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)); hr = mDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue));
if (FAILED(hr)) { if (FAILED(hr)) {
GTEST_SKIP() << "Failed to create command queue"; GTEST_SKIP() << "Failed to create command queue";
return; return;
@@ -54,6 +47,7 @@ void D3D12TestFixture::TearDown() {
mCommandList.Reset(); mCommandList.Reset();
mCommandAllocator.Reset(); mCommandAllocator.Reset();
mCommandQueue.Reset(); mCommandQueue.Reset();
mDevice.Reset();
} }
void D3D12TestFixture::WaitForGPU() { void D3D12TestFixture::WaitForGPU() {

View File

@@ -29,7 +29,7 @@ protected:
void WaitForGPU(); void WaitForGPU();
private: private:
static ComPtr<ID3D12Device> mDevice; ComPtr<ID3D12Device> mDevice;
ComPtr<ID3D12CommandQueue> mCommandQueue; ComPtr<ID3D12CommandQueue> mCommandQueue;
ComPtr<ID3D12CommandAllocator> mCommandAllocator; ComPtr<ID3D12CommandAllocator> mCommandAllocator;
ComPtr<ID3D12GraphicsCommandList> mCommandList; ComPtr<ID3D12GraphicsCommandList> mCommandList;