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
This commit is contained in:
2026-03-23 00:43:02 +08:00
parent 0f0ab8922a
commit f427699ac6
100 changed files with 1191 additions and 1136 deletions

View File

@@ -1,140 +1,93 @@
#include "fixtures/D3D12TestFixture.h"
#include "XCEngine/RHI/RHIEnums.h"
#include "XCEngine/RHI/RHITexture.h"
using namespace XCEngine::RHI;
TEST_F(D3D12TestFixture, Texture_Create_2D) {
const uint32_t width = 256;
const uint32_t height = 256;
const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
TextureDesc desc = {};
desc.width = 256;
desc.height = 256;
desc.depth = 1;
desc.mipLevels = 1;
desc.arraySize = 1;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.flags = 0;
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
RHITexture* texture = GetDevice()->CreateTexture(desc);
ASSERT_NE(texture, nullptr);
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
resourceDesc.Width = width;
resourceDesc.Height = height;
resourceDesc.DepthOrArraySize = 1;
resourceDesc.MipLevels = 1;
resourceDesc.Format = format;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.SampleDesc.Quality = 0;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
EXPECT_EQ(texture->GetWidth(), 256);
EXPECT_EQ(texture->GetHeight(), 256);
EXPECT_EQ(texture->GetFormat(), Format::R8G8B8A8_UNorm);
ComPtr<ID3D12Resource> texture;
HRESULT hr = GetDevice()->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&resourceDesc,
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(&texture)
);
ASSERT_HRESULT_SUCCEEDED(hr);
ASSERT_NE(texture.Get(), nullptr);
D3D12_RESOURCE_DESC desc = texture->GetDesc();
EXPECT_EQ(desc.Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE2D);
EXPECT_EQ(desc.Width, width);
EXPECT_EQ(desc.Height, height);
EXPECT_EQ(desc.Format, format);
texture->Shutdown();
delete texture;
}
TEST_F(D3D12TestFixture, Texture_Create_3D) {
const uint32_t width = 64;
const uint32_t height = 64;
const uint32_t depth = 64;
TextureDesc desc = {};
desc.width = 64;
desc.height = 64;
desc.depth = 64;
desc.mipLevels = 1;
desc.arraySize = 1;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture3D);
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.flags = 0;
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
RHITexture* texture = GetDevice()->CreateTexture(desc);
ASSERT_NE(texture, nullptr);
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D;
resourceDesc.Width = width;
resourceDesc.Height = height;
resourceDesc.DepthOrArraySize = depth;
resourceDesc.MipLevels = 1;
resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
EXPECT_EQ(texture->GetDepth(), 64);
ComPtr<ID3D12Resource> texture;
HRESULT hr = GetDevice()->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&resourceDesc,
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(&texture)
);
ASSERT_HRESULT_SUCCEEDED(hr);
ASSERT_NE(texture.Get(), nullptr);
D3D12_RESOURCE_DESC desc = texture->GetDesc();
EXPECT_EQ(desc.Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D);
EXPECT_EQ(desc.DepthOrArraySize, depth);
texture->Shutdown();
delete texture;
}
TEST_F(D3D12TestFixture, Texture_Create_MultipleMips) {
const uint32_t width = 512;
const uint32_t height = 512;
const uint32_t mipLevels = 5;
TextureDesc desc = {};
desc.width = 512;
desc.height = 512;
desc.depth = 1;
desc.mipLevels = 5;
desc.arraySize = 1;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.flags = 0;
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
RHITexture* texture = GetDevice()->CreateTexture(desc);
ASSERT_NE(texture, nullptr);
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
resourceDesc.Width = width;
resourceDesc.Height = height;
resourceDesc.DepthOrArraySize = 1;
resourceDesc.MipLevels = mipLevels;
resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
EXPECT_EQ(texture->GetMipLevels(), 5);
ComPtr<ID3D12Resource> texture;
HRESULT hr = GetDevice()->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&resourceDesc,
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(&texture)
);
ASSERT_HRESULT_SUCCEEDED(hr);
D3D12_RESOURCE_DESC desc = texture->GetDesc();
EXPECT_EQ(desc.MipLevels, mipLevels);
texture->Shutdown();
delete texture;
}
TEST_F(D3D12TestFixture, Texture_Create_Array) {
const uint32_t width = 128;
const uint32_t height = 128;
const uint32_t arraySize = 4;
TextureDesc desc = {};
desc.width = 128;
desc.height = 128;
desc.depth = 1;
desc.mipLevels = 1;
desc.arraySize = 4;
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.textureType = static_cast<uint32_t>(TextureType::Texture2DArray);
desc.sampleCount = 1;
desc.sampleQuality = 0;
desc.flags = 0;
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
RHITexture* texture = GetDevice()->CreateTexture(desc);
ASSERT_NE(texture, nullptr);
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
resourceDesc.Width = width;
resourceDesc.Height = height;
resourceDesc.DepthOrArraySize = arraySize;
resourceDesc.MipLevels = 1;
resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
resourceDesc.SampleDesc.Count = 1;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
ComPtr<ID3D12Resource> texture;
HRESULT hr = GetDevice()->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&resourceDesc,
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(&texture)
);
ASSERT_HRESULT_SUCCEEDED(hr);
D3D12_RESOURCE_DESC desc = texture->GetDesc();
EXPECT_EQ(desc.DepthOrArraySize, arraySize);
}
texture->Shutdown();
delete texture;
}