openglspir-v

Spir-V and OpenGL: Entry points and pipeline stages


Is there a built-in way in OpenGL to find which entry points and shader stages a compiled spir-v shader supports, or do I have to use a separate library like https://github.com/KhronosGroup/SPIRV-Reflect ?

Edit: I ended up using SPIRV-Reflect:

My asset pipeline links all stages that need to be linked into a program into a single binary blob, then I'm using

uint32_t                      GetEntryPointCount() const;
const char*                   GetEntryPointName(uint32_t index) const;
SpvReflectShaderStageFlagBits GetEntryPointShaderStage(uint32_t index) const;

to enumerate the entry points and attach the corresponding shader to the program.


Solution

  • OpenGL only has introspection facilities for linked programs. Program linking requires compiling shader objects first. And SPIR-V loading produces shader objects which replace "compilation" with specialization. And specialization of a SPIR-V shader requires knowing what entry point you want to use.

    So no, OpenGL has no way to look at what entrypoints are available in a SPIR-V module. Besides, it wouldn't be that useful. SPIR-V can only be loaded into shader objects, and shader objects are created for a specific shader stage. So unless you had multiple entrypoints for the same stage, there's only really one entrypoint you could be looking for: the one whose stage matches the shader object type.

    So OpenGL already expects that you have some additional information associated with any particular SPIR-V module loading operation. Just put the entrypoint name in that additional information, or establish a convention for the names of entrypoints for particular shader stages.