0

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.

user1387
  • 187
  • 10
  • Am curious how you are getting on with SPIR-V on OpenGL. The last time I tried, I had all kinds of driver incompatibilities (mostly AMD). https://community.khronos.org/t/understanding-sampler-objects-with-spirv-and-opengl-4-6/106109/5 – Tim Kane Dec 26 '22 at 22:46
  • Fine so far - it worked exactly how I hoped. I've got a GeForce GTX 3070 Ti. The biggest problem is that RenderDoc doesn't support shader debugging with OpenGL+SPIR-V, so I may port the whole thing to Vulkan at some point. At the moment I am mostly engine-limited and not API limited, so there is little benefit for the extra complexity of Vulkan. – user1387 Dec 27 '22 at 23:38

1 Answers1

1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982