2
$\begingroup$

I'm planning the port of our DX based renderer to OpenGL. The target will be Desktop OpenGL 4.x. For DX we use shader reflection but as far as I know OpenGL just has glGetProgramInterfaceiv , glGetUniform and frieds. Theres also SPIR-V (I have never worked with it).

My main concerns right now are:

  • Using gl*: it will be done at runtime, so this will be potentially slow as there are a lot of shaders to load (+ the interface is ugly as fuck). EDIT: I guess this could be done on a prebuild step too (?).
  • Use SPIR-V: means that we need to add another build step and I don't see much doc around.

I would like to hear advice from people with experience with this. Thanks a lot!

$\endgroup$
  • 2
    $\begingroup$ what do you need reflected? uniform and attrib locations? $\endgroup$ – ratchet freak Mar 27 '18 at 15:36
  • $\begingroup$ Yes, I think I'm only looking for names + bindings (also from inside UBOs) also uniform types (UBOs,SSBOs,images etc) $\endgroup$ – Nacho Mar 27 '18 at 17:02
2
$\begingroup$

opengl has several methods that together let you reflect the shader IO.

However it is much simpler if the shader IO is uniform across all your shaders. IOW have a set of default bindings/locations for everything. Then you only need some meta data for each shader where you deviate from those defaults for some reason.

You then only need to query that the binding exists to see whether you need to provide the data. This has the added bonus that if an input gets optimized out you'll not waste time giving data it doesn't need.

$\endgroup$
  • $\begingroup$ For most of our shaders, we use fixed slots but in some cases we need to retrieve uniform bindings (eg. I'm generating UBOs for bindless textures). $\endgroup$ – Nacho Mar 28 '18 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.