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:
77
tests/RHI/unit/test_sampler.cpp
Normal file
77
tests/RHI/unit/test_sampler.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "fixtures/RHITestFixture.h"
|
||||
#include "XCEngine/RHI/RHISampler.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_F(RHITestFixture, Sampler_Create) {
|
||||
SamplerDesc desc = {};
|
||||
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
|
||||
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.mipLodBias = 0.0f;
|
||||
desc.maxAnisotropy = 16;
|
||||
desc.comparisonFunc = static_cast<uint32_t>(ComparisonFunc::Less);
|
||||
desc.borderColorR = 0.0f;
|
||||
desc.borderColorG = 0.0f;
|
||||
desc.borderColorB = 0.0f;
|
||||
desc.borderColorA = 0.0f;
|
||||
desc.minLod = 0.0f;
|
||||
desc.maxLod = 100.0f;
|
||||
|
||||
RHISampler* sampler = GetDevice()->CreateSampler(desc);
|
||||
ASSERT_NE(sampler, nullptr);
|
||||
|
||||
sampler->Shutdown();
|
||||
delete sampler;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, Sampler_Bind_Unbind) {
|
||||
SamplerDesc desc = {};
|
||||
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
|
||||
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
|
||||
RHISampler* sampler = GetDevice()->CreateSampler(desc);
|
||||
ASSERT_NE(sampler, nullptr);
|
||||
|
||||
sampler->Bind(0);
|
||||
sampler->Unbind(0);
|
||||
|
||||
sampler->Shutdown();
|
||||
delete sampler;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, Sampler_GetID) {
|
||||
SamplerDesc desc = {};
|
||||
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
|
||||
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
|
||||
RHISampler* sampler = GetDevice()->CreateSampler(desc);
|
||||
ASSERT_NE(sampler, nullptr);
|
||||
|
||||
unsigned int id = sampler->GetID();
|
||||
EXPECT_GE(id, 0u);
|
||||
|
||||
sampler->Shutdown();
|
||||
delete sampler;
|
||||
}
|
||||
|
||||
TEST_F(RHITestFixture, Sampler_GetNativeHandle) {
|
||||
SamplerDesc desc = {};
|
||||
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
|
||||
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Wrap);
|
||||
|
||||
RHISampler* sampler = GetDevice()->CreateSampler(desc);
|
||||
ASSERT_NE(sampler, nullptr);
|
||||
|
||||
EXPECT_NE(sampler->GetNativeHandle(), nullptr);
|
||||
|
||||
sampler->Shutdown();
|
||||
delete sampler;
|
||||
}
|
||||
Reference in New Issue
Block a user