varjo icon indicating copy to clipboard operation
varjo copied to clipboard

Shader subroutine support

Open djeis97 opened this issue 6 years ago • 1 comments

Rather new glsl feature, but one that would be immensely useful.

https://www.khronos.org/opengl/wiki/Shader_Subroutine http://www.lighthouse3d.com/tutorials/glsl-tutorial/subroutines/

Basic idea is that you can declare "subroutines" instead of functions and declare "subroutine uniforms" which can be called like functions in the shader. Then, when prepping to draw with the shader, you can assign subroutines to the subroutine uniforms in order to set the behavior of the shader.

Here's my instinct for the simplest way to make these usable:

  • provide a way to generate a glsl subroutine string from an external function, so existing external function infrastructure could mostly just be reused
  • add uniforms with function types which generate subroutine uniforms (along with some introspection API for detecting these)
  • add an argument to make-stage for the list of subroutines, since there's no way for varjo to detect which subroutines to include automatically.

That would let wrappers like CEPL or Shadow provide their own system for managing/integrating subroutines.

There's also this concept of "subroutine types", which are basically just abbreviations for a function signatures that both a subroutine and the corresponding subroutine uniform need to reference, but I'm thinking varjo could probably generate these automatically? Maybe make them from the uniforms and then include them on each subroutine which has a compatible type?

djeis97 avatar May 27 '18 20:05 djeis97

Alternately, maybe the uniforms and subroutines should state the subroutine type explicitly, because I think having varjo be overeager assigning subroutine types will lead to glsl complaining about the potential for recursion if a subroutine tries to call another subroutine. Ofc, that means some consistency check would need to be made to ensure that the subroutine type is used properly...

djeis97 avatar May 27 '18 21:05 djeis97