Add Vulkan resource view unit coverage

This commit is contained in:
2026-03-28 00:13:02 +08:00
parent 114985d698
commit 539df6a03a
3 changed files with 89 additions and 0 deletions

View File

@@ -53,6 +53,8 @@ tests/RHI/Vulkan/
- SPIR-V / GLSL 两条 shader 创建路径
- 基于 GLSL 的 graphics pipeline 创建
- UAV 视图创建与 compute dispatch 写纹理链路
- RTV / DSV / SRV 视图创建与原生 image-view 句柄有效性
- `Sampler` 创建与原生 sampler 句柄有效性
- `DescriptorSet` 的原生句柄、绑定布局元数据与常量缓冲脏标记行为
- `PipelineLayout` 的显式 set-layout 聚合与 flat-count 合成逻辑

View File

@@ -16,6 +16,7 @@ set(TEST_SOURCES
test_pipeline_layout.cpp
test_render_pass.cpp
test_shader.cpp
test_views.cpp
)
add_executable(rhi_vulkan_tests ${TEST_SOURCES})

View File

@@ -0,0 +1,86 @@
#if defined(XCENGINE_SUPPORT_VULKAN)
#include "fixtures/VulkanTestFixture.h"
#include "XCEngine/RHI/RHIResourceView.h"
#include "XCEngine/RHI/RHISampler.h"
#include "XCEngine/RHI/Vulkan/VulkanResourceView.h"
#include "XCEngine/RHI/Vulkan/VulkanSampler.h"
using namespace XCEngine::RHI;
namespace {
TEST_F(VulkanGraphicsFixture, CreateRenderTargetViewProducesValidNativeImageView) {
RHITexture* texture = m_device->CreateTexture(CreateColorTextureDesc(8, 8));
ASSERT_NE(texture, nullptr);
RHIResourceView* rtv = m_device->CreateRenderTargetView(texture, {});
ASSERT_NE(rtv, nullptr);
EXPECT_TRUE(rtv->IsValid());
EXPECT_EQ(rtv->GetViewType(), ResourceViewType::RenderTarget);
EXPECT_NE(rtv->GetNativeHandle(), nullptr);
EXPECT_NE(static_cast<VulkanResourceView*>(rtv)->GetImageView(), VK_NULL_HANDLE);
rtv->Shutdown();
delete rtv;
texture->Shutdown();
delete texture;
}
TEST_F(VulkanGraphicsFixture, CreateDepthStencilViewProducesValidNativeImageView) {
RHITexture* texture = m_device->CreateTexture(CreateDepthTextureDesc(8, 8));
ASSERT_NE(texture, nullptr);
RHIResourceView* dsv = m_device->CreateDepthStencilView(texture, {});
ASSERT_NE(dsv, nullptr);
EXPECT_TRUE(dsv->IsValid());
EXPECT_EQ(dsv->GetViewType(), ResourceViewType::DepthStencil);
EXPECT_NE(dsv->GetNativeHandle(), nullptr);
EXPECT_NE(static_cast<VulkanResourceView*>(dsv)->GetImageView(), VK_NULL_HANDLE);
dsv->Shutdown();
delete dsv;
texture->Shutdown();
delete texture;
}
TEST_F(VulkanGraphicsFixture, CreateShaderResourceViewProducesValidNativeImageView) {
RHITexture* texture = m_device->CreateTexture(CreateColorTextureDesc(8, 8));
ASSERT_NE(texture, nullptr);
RHIResourceView* srv = m_device->CreateShaderResourceView(texture, {});
ASSERT_NE(srv, nullptr);
EXPECT_TRUE(srv->IsValid());
EXPECT_EQ(srv->GetViewType(), ResourceViewType::ShaderResource);
EXPECT_NE(srv->GetNativeHandle(), nullptr);
EXPECT_NE(static_cast<VulkanResourceView*>(srv)->GetImageView(), VK_NULL_HANDLE);
srv->Shutdown();
delete srv;
texture->Shutdown();
delete texture;
}
TEST_F(VulkanGraphicsFixture, CreateSamplerProducesValidNativeSampler) {
SamplerDesc desc = {};
desc.filter = static_cast<uint32_t>(FilterMode::Linear);
desc.addressU = static_cast<uint32_t>(TextureAddressMode::Clamp);
desc.addressV = static_cast<uint32_t>(TextureAddressMode::Clamp);
desc.addressW = static_cast<uint32_t>(TextureAddressMode::Clamp);
desc.comparisonFunc = static_cast<uint32_t>(ComparisonFunc::Always);
desc.maxAnisotropy = 1;
desc.minLod = 0.0f;
desc.maxLod = 1000.0f;
RHISampler* sampler = m_device->CreateSampler(desc);
ASSERT_NE(sampler, nullptr);
EXPECT_NE(sampler->GetNativeHandle(), nullptr);
EXPECT_NE(static_cast<VulkanSampler*>(sampler)->GetSampler(), VK_NULL_HANDLE);
sampler->Shutdown();
delete sampler;
}
} // namespace
#endif