Add Vulkan backpack integration test

This commit is contained in:
2026-03-27 15:17:36 +08:00
parent 22ccdfb371
commit fe56117d8e
4 changed files with 145 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <math.h>
#include <memory>
#include <stdio.h>
@@ -92,8 +93,38 @@ std::filesystem::path ResolveRuntimePath(const char* relativePath) {
return GetExecutableDirectory() / relativePath;
}
std::vector<uint8_t> LoadBinaryFileRelative(const char* filename) {
const std::filesystem::path path = ResolveRuntimePath(filename);
std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
return {};
}
const std::streamsize size = file.tellg();
if (size <= 0) {
return {};
}
std::vector<uint8_t> bytes(static_cast<size_t>(size));
file.seekg(0, std::ios::beg);
if (!file.read(reinterpret_cast<char*>(bytes.data()), size)) {
return {};
}
return bytes;
}
const char* GetScreenshotFilename(RHIType type) {
return type == RHIType::D3D12 ? "backpack_d3d12.ppm" : "backpack_opengl.ppm";
switch (type) {
case RHIType::D3D12:
return "backpack_d3d12.ppm";
case RHIType::OpenGL:
return "backpack_opengl.ppm";
case RHIType::Vulkan:
return "backpack_vulkan.ppm";
default:
return "backpack_unknown.ppm";
}
}
int GetComparisonThreshold(RHIType type) {
@@ -374,7 +405,7 @@ void main() {
desc.fragmentShader.sourceLanguage = XCEngine::RHI::ShaderLanguage::HLSL;
desc.fragmentShader.entryPoint = L"MainPS";
desc.fragmentShader.profile = L"ps_5_0";
} else {
} else if (type == RHIType::OpenGL) {
desc.vertexShader.source.assign(kBackpackVertexShader,
kBackpackVertexShader + strlen(kBackpackVertexShader));
desc.vertexShader.sourceLanguage = XCEngine::RHI::ShaderLanguage::GLSL;
@@ -384,6 +415,14 @@ void main() {
kBackpackFragmentShader + strlen(kBackpackFragmentShader));
desc.fragmentShader.sourceLanguage = XCEngine::RHI::ShaderLanguage::GLSL;
desc.fragmentShader.profile = L"fs_4_30";
} else if (type == RHIType::Vulkan) {
desc.vertexShader.source = LoadBinaryFileRelative("backpack_vulkan.vert.spv");
desc.vertexShader.sourceLanguage = XCEngine::RHI::ShaderLanguage::SPIRV;
desc.vertexShader.entryPoint = L"main";
desc.fragmentShader.source = LoadBinaryFileRelative("backpack_vulkan.frag.spv");
desc.fragmentShader.sourceLanguage = XCEngine::RHI::ShaderLanguage::SPIRV;
desc.fragmentShader.entryPoint = L"main";
}
return desc;
@@ -950,6 +989,9 @@ TEST_P(BackpackTest, RenderBackpack) {
INSTANTIATE_TEST_SUITE_P(D3D12, BackpackTest, ::testing::Values(RHIType::D3D12));
INSTANTIATE_TEST_SUITE_P(OpenGL, BackpackTest, ::testing::Values(RHIType::OpenGL));
#if defined(XCENGINE_SUPPORT_VULKAN)
INSTANTIATE_TEST_SUITE_P(Vulkan, BackpackTest, ::testing::Values(RHIType::Vulkan));
#endif
GTEST_API_ int main(int argc, char** argv) {
Logger::Get().Initialize();