feat: add RHI abstraction layer unit tests
- Add RHITestFixture with RHI_BACKEND env var support for backend selection - Add unit tests for: Device, Buffer, Texture, SwapChain, CommandList, CommandQueue, Shader, Fence, Sampler - Tests can run against D3D12 or OpenGL backends via RHI_BACKEND env var - Add integration folder placeholder for future integration tests
This commit is contained in:
103
tests/RHI/unit/test_texture.cpp
Normal file
103
tests/RHI/unit/test_texture.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "fixtures/RHITestFixture.h"
|
||||
#include "XCEngine/RHI/RHITexture.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_F(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_F(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);
|
||||
|
||||
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_F(RHITestFixture, Texture_StateManagement) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
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_F(RHITestFixture, Texture_Naming) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
texture->SetName("TestTexture");
|
||||
EXPECT_EQ(texture->GetName(), "TestTexture");
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, Texture_GetNativeHandle) {
|
||||
TextureDesc desc = {};
|
||||
desc.width = 256;
|
||||
desc.height = 256;
|
||||
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
desc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
RHITexture* texture = GetDevice()->CreateTexture(desc);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
EXPECT_NE(texture->GetNativeHandle(), nullptr);
|
||||
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
}
|
||||
Reference in New Issue
Block a user