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:
@@ -38,7 +38,7 @@ add_subdirectory(memory)
|
||||
add_subdirectory(threading)
|
||||
add_subdirectory(debug)
|
||||
add_subdirectory(D3D12)
|
||||
add_subdirectory(D3D12_engine/test)
|
||||
add_subdirectory(RHI/D3D12)
|
||||
|
||||
# ============================================================
|
||||
# Test Summary
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "fixtures/D3D12TestFixture.h"
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CreateDevice_Success) {
|
||||
ASSERT_NE(GetDevice(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_GetCommandQueue_Success) {
|
||||
ASSERT_NE(GetCommandQueue(), nullptr);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "fixtures/D3D12TestFixture.h"
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_CreateFence_Success) {
|
||||
ASSERT_NE(GetDevice(), nullptr);
|
||||
}
|
||||
62
tests/RHI/D3D12/test_device.cpp
Normal file
62
tests/RHI/D3D12/test_device.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "fixtures/D3D12TestFixture.h"
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_4.h>
|
||||
#include <windows.h>
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CreateDevice_Success) {
|
||||
ASSERT_NE(GetDevice(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_GetCommandQueue_Success) {
|
||||
ASSERT_NE(GetCommandQueue(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CheckFeatureLevel) {
|
||||
static const D3D_FEATURE_LEVEL requestedLevels[] = { D3D_FEATURE_LEVEL_12_0 };
|
||||
D3D12_FEATURE_DATA_FEATURE_LEVELS featureLevels = {};
|
||||
featureLevels.NumFeatureLevels = 1;
|
||||
featureLevels.pFeatureLevelsRequested = requestedLevels;
|
||||
|
||||
HRESULT hr = GetDevice()->CheckFeatureSupport(D3D12_FEATURE_FEATURE_LEVELS, &featureLevels, sizeof(featureLevels));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
EXPECT_EQ(featureLevels.MaxSupportedFeatureLevel, D3D_FEATURE_LEVEL_12_0);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_GetDescriptorHandleIncrementSize) {
|
||||
UINT cbvSrvUavSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
EXPECT_GT(cbvSrvUavSize, 0);
|
||||
|
||||
UINT samplerSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
EXPECT_GT(samplerSize, 0);
|
||||
|
||||
UINT rtvSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
EXPECT_GT(rtvSize, 0);
|
||||
|
||||
UINT dsvSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
|
||||
EXPECT_GT(dsvSize, 0);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CheckShaderModelSupport) {
|
||||
D3D12_FEATURE_DATA_SHADER_MODEL shaderModel = {};
|
||||
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_0;
|
||||
|
||||
HRESULT hr = GetDevice()->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
EXPECT_GE(shaderModel.HighestShaderModel, D3D_SHADER_MODEL_6_0);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CheckResourceBindingTier) {
|
||||
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
|
||||
|
||||
HRESULT hr = GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
EXPECT_GE(options.ResourceBindingTier, D3D12_RESOURCE_BINDING_TIER_1);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Device_CheckTiledResourcesTier) {
|
||||
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
|
||||
|
||||
HRESULT hr = GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
EXPECT_GE(options.TiledResourcesTier, D3D12_TILED_RESOURCES_TIER_NOT_SUPPORTED);
|
||||
}
|
||||
97
tests/RHI/D3D12/test_fence.cpp
Normal file
97
tests/RHI/D3D12/test_fence.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "fixtures/D3D12TestFixture.h"
|
||||
#include <Windows.h>
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_CreateFence_Success) {
|
||||
ASSERT_NE(GetDevice(), nullptr);
|
||||
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HRESULT hr = GetDevice()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
ASSERT_NE(fence.Get(), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_GetCompletedValue_Initial) {
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HRESULT hr = GetDevice()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
EXPECT_EQ(fence->GetCompletedValue(), 0);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_SignalAndWait) {
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HRESULT hr = GetDevice()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
const UINT64 fenceValue = 100;
|
||||
hr = GetCommandQueue()->Signal(fence.Get(), fenceValue);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
HANDLE eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT_NE(eventHandle, nullptr);
|
||||
|
||||
hr = fence->SetEventOnCompletion(fenceValue, eventHandle);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
DWORD waitResult = WaitForSingleObject(eventHandle, 1000);
|
||||
EXPECT_EQ(waitResult, WAIT_OBJECT_0);
|
||||
|
||||
EXPECT_EQ(fence->GetCompletedValue(), fenceValue);
|
||||
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_SetEventOnCompletion) {
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HRESULT hr = GetDevice()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
const UINT64 fenceValue = 200;
|
||||
hr = GetCommandQueue()->Signal(fence.Get(), fenceValue);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
HANDLE eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT_NE(eventHandle, nullptr);
|
||||
|
||||
hr = fence->SetEventOnCompletion(fenceValue, eventHandle);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
DWORD waitResult = WaitForSingleObject(eventHandle, 1000);
|
||||
EXPECT_EQ(waitResult, WAIT_OBJECT_0);
|
||||
|
||||
EXPECT_EQ(fence->GetCompletedValue(), fenceValue);
|
||||
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
|
||||
TEST_F(D3D12TestFixture, Fence_MultipleSignals) {
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HRESULT hr = GetDevice()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
const UINT64 value1 = 1;
|
||||
const UINT64 value2 = 2;
|
||||
const UINT64 value3 = 3;
|
||||
|
||||
hr = GetCommandQueue()->Signal(fence.Get(), value1);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
hr = GetCommandQueue()->Signal(fence.Get(), value2);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
hr = GetCommandQueue()->Signal(fence.Get(), value3);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
HANDLE eventHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT_NE(eventHandle, nullptr);
|
||||
|
||||
hr = fence->SetEventOnCompletion(value3, eventHandle);
|
||||
ASSERT_HRESULT_SUCCEEDED(hr);
|
||||
|
||||
DWORD waitResult = WaitForSingleObject(eventHandle, 1000);
|
||||
EXPECT_EQ(waitResult, WAIT_OBJECT_0);
|
||||
|
||||
EXPECT_EQ(fence->GetCompletedValue(), value3);
|
||||
|
||||
CloseHandle(eventHandle);
|
||||
}
|
||||
Reference in New Issue
Block a user