Skip to content

Standard shaders are binary blobs #718

@timoore

Description

@timoore

VSG's standard shaders, for pbr, phong, and flat lighting, are created at runtime by functions that read a binary .vsgb file that is embedded in C++ source and thence in libvsg. The binaries include all the common variants of the shaders, as detailed by @robertosfield in https://groups.google.com/g/vsg-users/c/VEENdu2gdbc . Unfortunately, the source code for the shaders lives in the vsgExamples tree, and the .cpp files that contain the binary data need to be built with a working version of vsg! There is no automatic rule for this, and I don't think the official list of variants exists in any file.

Thus, it's hard to make changes to the standard shaders and test them with much confidence. The only way to make a pull request to change a shader is to do a PR against vsgExamples, after which the maintainer has to regenerate the files in VulkanSceneGraph.

I see two approaches to fix this. I've done a bit of research into both and am willing to do the work to fix the situation, but I'd like some discussion first. The shader source code and the official list of variants would live in the VulkanSceneGraph repo in both approaches, and the .cpp files with the hex data would be generated during the build.

The first approach uses only the Vulkan SDK shader compiler and CMake to create the .cpp files. CMake can generate C++ files with hex data. Some amount of CMake code would have to be written to generate all the shader variants and assemble them into the library. The binary data would not be .vsgb, but .spv.

The second approach is to build a mini-VSG that doesn't include the built-in shaders, and then use that at build time to create the C++ source files. I've experimented with this and did create such a thing. It wasn't very mini, but it was feasible. This miniVSG would need to be generated with the host compiler in a cross-compile / embedded setup. That adds time and complexity to the build and the source files. I don't think the requirement to have host compilers is onerous.

The first approach is simpler, doesn't require a bootstrap phase, and allows much faster turn-around time for testing changes to VSG and the shaders. ON the other hand, as VSG's shader system evolves, it may become quite hard to generate the shader binaries using only CMake scripting.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions