- Add CommandQueue unit tests for WaitForIdle and synchronization - Add SwapChain unit tests for Present and buffer operations - Add Texture unit tests for various texture types and mipmaps - Fix RHIIntegrationFixture with proper logging and debug output - Update minimal integration test with RHI abstraction layer - Add GT reference image for minimal test - Update TEST_SPEC.md documentation
336 lines
9.8 KiB
C++
336 lines
9.8 KiB
C++
#include "fixtures/RHITestFixture.h"
|
|
#include "XCEngine/RHI/RHITexture.h"
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_Texture2D) {
|
|
TextureDesc desc = {};
|
|
desc.width = 512;
|
|
desc.height = 512;
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
EXPECT_EQ(texture->GetWidth(), 512u);
|
|
EXPECT_EQ(texture->GetHeight(), 512u);
|
|
EXPECT_EQ(texture->GetDepth(), 1u);
|
|
EXPECT_EQ(texture->GetMipLevels(), 1u);
|
|
EXPECT_EQ(texture->GetFormat(), Format::R8G8B8A8_UNorm);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture2D);
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_Texture3D) {
|
|
TextureDesc desc = {};
|
|
desc.width = 64;
|
|
desc.height = 64;
|
|
desc.depth = 64;
|
|
desc.mipLevels = 1;
|
|
desc.format = static_cast<uint32_t>(Format::R16_Float);
|
|
desc.textureType = static_cast<uint32_t>(TextureType::Texture3D);
|
|
desc.sampleCount = 1;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
EXPECT_EQ(texture->GetWidth(), 64u);
|
|
EXPECT_EQ(texture->GetHeight(), 64u);
|
|
EXPECT_EQ(texture->GetDepth(), 64u);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture3D);
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_StateManagement) {
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::Common);
|
|
texture->SetState(ResourceStates::RenderTarget);
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::RenderTarget);
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Naming) {
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
texture->SetName("TestTexture");
|
|
EXPECT_EQ(texture->GetName(), "TestTexture");
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_GetNativeHandle) {
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
ASSERT_NE(texture, nullptr);
|
|
|
|
EXPECT_NE(texture->GetNativeHandle(), nullptr);
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_Texture1D) {
|
|
TextureDesc desc = {};
|
|
desc.width = 512;
|
|
desc.height = 1;
|
|
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::Texture1D);
|
|
desc.sampleCount = 1;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetWidth(), 512u);
|
|
EXPECT_EQ(texture->GetHeight(), 1u);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture1D);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_Texture2DArray) {
|
|
TextureDesc desc = {};
|
|
desc.width = 256;
|
|
desc.height = 256;
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetWidth(), 256u);
|
|
EXPECT_EQ(texture->GetHeight(), 256u);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::Texture2DArray);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_TextureCube) {
|
|
TextureDesc desc = {};
|
|
desc.width = 256;
|
|
desc.height = 256;
|
|
desc.depth = 1;
|
|
desc.mipLevels = 1;
|
|
desc.arraySize = 6;
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
desc.textureType = static_cast<uint32_t>(TextureType::TextureCube);
|
|
desc.sampleCount = 1;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetWidth(), 256u);
|
|
EXPECT_EQ(texture->GetHeight(), 256u);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::TextureCube);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_TextureCubeArray) {
|
|
TextureDesc desc = {};
|
|
desc.width = 256;
|
|
desc.height = 256;
|
|
desc.depth = 1;
|
|
desc.mipLevels = 1;
|
|
desc.arraySize = 12;
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
desc.textureType = static_cast<uint32_t>(TextureType::TextureCubeArray);
|
|
desc.sampleCount = 1;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetWidth(), 256u);
|
|
EXPECT_EQ(texture->GetHeight(), 256u);
|
|
EXPECT_EQ(texture->GetTextureType(), TextureType::TextureCubeArray);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_WithMipMaps) {
|
|
TextureDesc desc = {};
|
|
desc.width = 512;
|
|
desc.height = 512;
|
|
desc.depth = 1;
|
|
desc.mipLevels = 9;
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetMipLevels(), 9u);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_MultipleSamples) {
|
|
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 = 4;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Create_DifferentFormats) {
|
|
Format formats[] = {
|
|
Format::R8G8B8A8_UNorm,
|
|
Format::R16G16B16A16_Float,
|
|
Format::R32_Float,
|
|
Format::D24_UNorm_S8_UInt,
|
|
Format::D32_Float
|
|
};
|
|
|
|
for (auto fmt : formats) {
|
|
TextureDesc desc = {};
|
|
desc.width = 256;
|
|
desc.height = 256;
|
|
desc.depth = 1;
|
|
desc.mipLevels = 1;
|
|
desc.arraySize = 1;
|
|
desc.format = static_cast<uint32_t>(fmt);
|
|
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
|
desc.sampleCount = 1;
|
|
desc.sampleQuality = 0;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
EXPECT_EQ(texture->GetFormat(), fmt);
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_StateTransitions) {
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture == nullptr) {
|
|
return;
|
|
}
|
|
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::Common);
|
|
|
|
texture->SetState(ResourceStates::RenderTarget);
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::RenderTarget);
|
|
|
|
texture->SetState(ResourceStates::PixelShaderResource);
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::PixelShaderResource);
|
|
|
|
texture->SetState(ResourceStates::CopyDst);
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::CopyDst);
|
|
|
|
texture->SetState(ResourceStates::Common);
|
|
EXPECT_EQ(texture->GetState(), ResourceStates::Common);
|
|
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
|
|
TEST_P(RHITestFixture, Texture_Shutdown_MultipleTimes) {
|
|
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;
|
|
|
|
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
|
if (texture != nullptr) {
|
|
texture->Shutdown();
|
|
texture->Shutdown();
|
|
delete texture;
|
|
}
|
|
}
|