#shader processor - Compile & package shaders at compile-time

5 messages · Page 1 of 1 (latest)

wanton snow
#

I decided to put some CMake scripts I wrote a long time ago for my "engine" into a dedicated library, and I can now present to you "shader processor".

It's simple - it reads a JSON file and then compiles your shaders and embeds them into a binary file next to your executable. It currently supports GLSL and slang (kinda also supports Metal), and will compile them into SPIR-V 1.2 which gets embedded a .shader file. The library then offers a C++20 header that you can then use to read and decode the binary and use the shaders.

This also means you get incremental builds on your shaders, meaning that the shaders will only ever get recompiled if you change either the JSON or the specific source files. (Note that with CMake 3.20 or newer it will only rebuild the affected source files and not all of them. Before 3.20 it will rebuild all shaders if one changed.)

I also have planned to support HLSL (and other languages) and perhaps some sort of compression. Also perhaps some suggestions from others if this project is useful?

https://github.com/spnda/shader_processor

GitHub

CMake library that automatically compiles & packages shaders at compile-time - GitHub - spnda/shader_processor: CMake library that automatically compiles & packages shaders at compile-time

#

hope anyone could perhaps find this useful

split ether
#

i did a similar thing but it was kinda specific to my engine thing

#

but i also had stuff like pipeline params baked in so I could just give it a binary file and say "hey pls create this pipeline"

wanton snow
#

this is an example output with Ninja:

...
[61/69] Linking CXX executable submodules\shader_processor\src\shaderprocessor.exe
[62/69] Processing E:/git/spnda/game/shaders/physics/physics.json
Processing ..\..\..\shaders\physics\physics.json
>> "planet_force.comp.glsl"
>> "planet_position.comp.glsl"
[63/69] Processing E:/git/spnda/game/shaders/main.json
Processing ..\..\..\shaders\main.json
>> "main.frag.glsl"
>> "main.vert.glsl"
[64/69] Building CXX object src\CMakeFiles\game.dir\vulkan\vk_instance.cpp.obj
...