https://github.com/stablecoder/vksbc
Program that takes in a Vulkan shader SPIR-V program and converts it to uint32_t's that can be used directly in the source code of a program. Can also generate C/C++ headers directly.
https://github.com/stablecoder/vksbc
shader spir-v vulkan
Last synced: 10 months ago
JSON representation
Program that takes in a Vulkan shader SPIR-V program and converts it to uint32_t's that can be used directly in the source code of a program. Can also generate C/C++ headers directly.
- Host: GitHub
- URL: https://github.com/stablecoder/vksbc
- Owner: StableCoder
- License: mit
- Created: 2018-10-21T18:45:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-06T13:17:51.000Z (over 5 years ago)
- Last Synced: 2025-01-13T13:52:29.314Z (12 months ago)
- Topics: shader, spir-v, vulkan
- Language: C++
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Vulkan Binary Converter
[](https://git.stabletec.com/utilities/vksbc/commits/master)
[](https://git.stabletec.com/utilities/vksbc/blob/master/LICENSE)
[](https://git.stabletec.com/utilities/vksbc/commits/master)
This program is used to convert a SPIR-V binary code file into a set of hexadecimal 4-byte values that can be pasted as an array on unsigned integers in code and used.
This is meant mostly for embedding non-changing shaders directly into code, mostly for testing purposes.
### Usage
Generate a Vulkan bytecode file (typically .spv) from a shader using the glslangvalidator program provided with the Vulkan SDK:
```bash
glslangvalidator -V -o fragShader.frag.spv fragShader.frag
```
Then, run this program on the output file of the above.
```bash
vksbc fragShader.frag.spv
```
A file should have been created, with content similar to this:
```
0x07230203, 0x00010000, 0x00080001, 0x0000000D, 0x00000000, 0x00020011, 0x00000001, 0x0006000B,
0x00000001, 0x4C534C47, 0x6474732E, 0x3035342E, 0x00000000, 0x0003000E, 0x00000000, 0x00000001,
0x0006000F, ...
```
## C/C++ style headers
New options allow for genenrating ready-to-use C and C++ style headers, by adding the `--ch` or `--cpph` options to running the program, generated standalone headers with the arrays and required header incudes for use.
```bash
./vksbc --ch --cpph fragShader.frag.spv
```
```c
// C header
#include
static const uint32_t vk_fragShader_size = 572;
static const uint32_t vk_fragShader[] = {
...
};
```
```c++
// C++ header
#include
#include
constexpr uint32_t vk_fragShader_size = 572;
constexpr std::array vk_fragShader = {
...
};
```
Usage of such a header can be as simple as
```c
#include "vk_shader.h"
...
VkShaderModuleCreateInfo moduleCI = {};
moduleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
moduleCI.pCode = vk_fragShader;
moduleCI.codeSize = vk_fragShader_size;
VkShaderModule shaderModule;
vkCreateShaderModule(device, &moduleCI, nullptr, &shaderModule);
```
And it should be ready to be used in the creation of Vulkan shaders in the program.