Files
XCEngine/tests/RHI/D3D12/unit/test_descriptor_heap.cpp
ssdfasd f427699ac6 refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
  instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
  test discovery (math, core, containers, memory, threading, debug,
  components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
  from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
  build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00

101 lines
3.8 KiB
C++

#include "fixtures/D3D12TestFixture.h"
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
using namespace XCEngine::RHI;
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_Initialize_RTV) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::RTV, 4);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetDescriptorCount(), 4u);
EXPECT_EQ(heap.GetType(), DescriptorHeapType::RTV);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetCPUDescriptorHandle) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::RTV, 4));
uint32_t descriptorSize = heap.GetDescriptorSize();
CPUDescriptorHandle handle0 = heap.GetCPUDescriptorHandle(0);
CPUDescriptorHandle handle1 = heap.GetCPUDescriptorHandle(1);
CPUDescriptorHandle handle2 = heap.GetCPUDescriptorHandle(2);
EXPECT_EQ(handle1.ptr - handle0.ptr, descriptorSize);
EXPECT_EQ(handle2.ptr - handle1.ptr, descriptorSize);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetGPUDescriptorHandle) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::CBV_SRV_UAV, 4, true));
uint32_t descriptorSize = heap.GetDescriptorSize();
GPUDescriptorHandle handle0 = heap.GetGPUDescriptorHandle(0);
GPUDescriptorHandle handle1 = heap.GetGPUDescriptorHandle(1);
EXPECT_EQ(handle1.ptr - handle0.ptr, descriptorSize);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetDescriptorSize) {
D3D12DescriptorHeap rtvHeap;
ASSERT_TRUE(rtvHeap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::RTV, 4));
EXPECT_GT(rtvHeap.GetDescriptorSize(), 0u);
D3D12DescriptorHeap cbvHeap;
ASSERT_TRUE(cbvHeap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::CBV_SRV_UAV, 4));
EXPECT_GT(cbvHeap.GetDescriptorSize(), 0u);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_Shutdown) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::RTV, 2));
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_CBV_SRV_UAV) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::CBV_SRV_UAV, 10, true);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetDescriptorCount(), 10u);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_Sampler) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::Sampler, 5, true);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetType(), DescriptorHeapType::Sampler);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_RTV) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::RTV, 4, false);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetType(), DescriptorHeapType::RTV);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_DSV) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice()->GetDevice(), DescriptorHeapType::DSV, 2, false);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetType(), DescriptorHeapType::DSV);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Get_HandleIncrementSize) {
UINT cbvSrvUavSize = GetDevice()->GetDescriptorHandleIncrementSize(DescriptorHeapType::CBV_SRV_UAV);
UINT samplerSize = GetDevice()->GetDescriptorHandleIncrementSize(DescriptorHeapType::Sampler);
UINT rtvSize = GetDevice()->GetDescriptorHandleIncrementSize(DescriptorHeapType::RTV);
UINT dsvSize = GetDevice()->GetDescriptorHandleIncrementSize(DescriptorHeapType::DSV);
EXPECT_GT(cbvSrvUavSize, 0);
EXPECT_GT(samplerSize, 0);
EXPECT_GT(rtvSize, 0);
EXPECT_GT(dsvSize, 0);
}