为每个着色器生成 Vulkan 头文件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南介绍如何从着色器文件为每个主机操作系统生成 Vulkan C++ 头文件。
在本地机器上下载 Khronos Group Glslang Tool: Candidate of 2020。
解压缩。
检查其版本:
Windows
bin\glslangValidator --version
macOS
./bin/glslangValidator --version
Linux
./bin/glslangValidator --version
在 Cardboard 仓库中,找到 sdk/rendering/android/shaders
文件夹并保存其路径。
使用 C++ 生成 Vulkan 头文件:
Windows
bin\glslangValidator -V --vn distortion_frag %SHADERS_FOLDER_PATH%\distortion.frag -o distortion_frag.spv.h
bin\glslangValidator -V --vn distortion_vert %SHADERS_FOLDER_PATH%\distortion.vert -o distortion_vert.spv.h
macOS
./bin/glslangValidator -V --vn distortion_frag $SHADERS_FOLDER_PATH/distortion.frag -o distortion_frag.spv.h
./bin/glslangValidator -V --vn distortion_vert $SHADERS_FOLDER_PATH/distortion.vert -o distortion_vert.spv.h
Linux
./bin/glslangValidator -V --vn distortion_frag $SHADERS_FOLDER_PATH/distortion.frag -o distortion_frag.spv.h
./bin/glslangValidator -V --vn distortion_vert $SHADERS_FOLDER_PATH/distortion.vert -o distortion_vert.spv.h
您现在应该拥有 distortion_frag.spv.h 和 distortion_vert.spv.h。
保留所有权利。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThis guide provides instructions on generating Vulkan C++ header files from shader files for use in your application.\u003c/p\u003e\n"],["\u003cp\u003eYou will need to download and install the Khronos Group Glslang tool to convert shader files into header files.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves locating your shader files and using the glslangValidator tool with specific commands to generate the corresponding header files.\u003c/p\u003e\n"],["\u003cp\u003eThe generated header files, \u003ccode\u003edistortion_frag.spv.h\u003c/code\u003e and \u003ccode\u003edistortion_vert.spv.h\u003c/code\u003e, will contain the Vulkan-compatible code derived from your shaders.\u003c/p\u003e\n"]]],[],null,["# Generate Vulkan header files for each shader\n\nThis guide shows you how to generate the Vulkan C++ headers for each host OS from the shader files.\n\nGenerate C++ headers from the shader files\n------------------------------------------\n\n1. Download the [Khronos Group Glslang Tool: Candidate of July 26, 2020](https://github.com/KhronosGroup/glslang/releases/tag/SDK-candidate-26-Jul-2020) on your local machine.\n\n2. Unzip it.\n\n3. Check its version:\n\n - Windows\n\n ```\n bin\\glslangValidator --version\n ```\n\n \u003cbr /\u003e\n\n - macOS\n\n ```\n ./bin/glslangValidator --version\n ```\n\n \u003cbr /\u003e\n\n - Linux\n\n ```\n ./bin/glslangValidator --version\n ```\n\n \u003cbr /\u003e\n\n4. In the Cardboard repository, locate the `sdk/rendering/android/shaders` folder and save its path.\n\n5. Generate the Vulkan header files in C++:\n\n - Windows\n\n bin\\glslangValidator -V --vn distortion_frag \u003cvar translate=\"no\"\u003e%SHADERS_FOLDER_PATH%\u003c/var\u003e\\distortion.frag -o distortion_frag.spv.h\n bin\\glslangValidator -V --vn distortion_vert \u003cvar translate=\"no\"\u003e%SHADERS_FOLDER_PATH%\u003c/var\u003e\\distortion.vert -o distortion_vert.spv.h\n\n \u003cbr /\u003e\n\n - macOS\n\n ./bin/glslangValidator -V --vn distortion_frag \u003cvar translate=\"no\"\u003e$SHADERS_FOLDER_PATH\u003c/var\u003e/distortion.frag -o distortion_frag.spv.h\n\n ./bin/glslangValidator -V --vn distortion_vert \u003cvar translate=\"no\"\u003e$SHADERS_FOLDER_PATH\u003c/var\u003e/distortion.vert -o distortion_vert.spv.h\n\n \u003cbr /\u003e\n\n - Linux\n\n ./bin/glslangValidator -V --vn distortion_frag \u003cvar translate=\"no\"\u003e$SHADERS_FOLDER_PATH\u003c/var\u003e/distortion.frag -o distortion_frag.spv.h\n\n ./bin/glslangValidator -V --vn distortion_vert \u003cvar translate=\"no\"\u003e$SHADERS_FOLDER_PATH\u003c/var\u003e/distortion.vert -o distortion_vert.spv.h\n\n \u003cbr /\u003e\n\nYou should now have **distortion_frag.spv.h** and **distortion_vert.spv.h**."]]