VkRunner 是一款专门用于运行 shader 测试脚本的工具。它支持通过 GLSL 或 SPIR-V 进行 shader 的编译与执行,并且能够将运行结果输出为 PPM 图像。此外,该工具还提供了 C 库接口,便于集成到其他测试套件中。
--device-id DEVID 选项指定 Vulkan 设备。-i IMG 选项将最终渲染结果保存为 PPM 图像。-d 选项显示 SPIR-V 反汇编信息。vertexShader 指令指定 GLSL 或 SPIR-V 文件。fragmentShader 指令指定 GLSL 或 SPIR-V 文件。computeShader 指令指定 GLSL 或 SPIR-V 文件。ubo N subdata TYPE VALUE 为 UBO 分配初始值。glslangValidator 和 spirv-as 工具将 GLSL 转换为 SPIR-V。draw arrays 或 draw indexed 指令进行图形渲染。[vertex data] 和 [indices] 部分定义顶点和索引缓冲区。[vertex data]
# 定义一个三角形的顶点坐标
0.0 0.0 1.0 # 第一个顶点 (x, y, z)
0.5 0.0 1.0 # 第二个顶点
0.25 0.5 1.0 # 第三个顶点
[vertex data]
# 定义第二个三角形的顶点坐标
-0.5 0.0 1.0
-0.75 0.5 1.0
-0.25 0.5 1.0
[index]
# 使用索引缓冲区绘制两个三角形
0 1 2 # 绘制第一个三角形
3 4 5 # 绘制第二个三角形
[test commands]
draw arrays triangleStrip
[ubo]
# 定义一个简单的 UBO 结构体
struct Buf {
data vec4;
};
buf Buf ubodata = (Buf){vec4(1.0, 0.0, 0.0, 1.0)};
[test commands]
computeShader compute.comp # 指定计算着色器文件
-o OUTPUT_DIR:指定输出目录。-g GLSLANG_PATH:指定 glslangValidator 的路径。-s SPIRV_AS_PATH:指定 spirv-as 的路径。# 预编译所有例子到 compiled-examples 目录
./precompile-script.py -o compiled-examples examples/*.shader_test
# 执行预编译后的测试用例
./src/vkrunner compiled-examples/*.shader_test