enh(build): parse preprocessor defines and sheldon glslang hook directives recursively
Description
Our glslang
hook parses GLSL to pass them to glslangValidator
.
When loading a file, we parse its contents and look for preprocessor #define
tokens that are involved in the compilation process so that all combinations can be tested.
#74 (closed) added the possibility to register preprocessor #define
s to discard and mutually exclusive#define
s combinations using cspell-style comments // sheldon:glslang discard(FOO) require-exclusive(OPT_A, OPT_B)
.
Unfortunately, as it is implemented currently, none of this is done recursively across #include
d files.
This forces the user to duplicate the // sheldon:glslang
comments in the top-level file, and does not check the combinations that appear in the files it #includes
.
This is highly unpractical.
At the same time, I am a bit worried that doing this will make compilation times go wild, but will see.
Functional specifications
Preprocessor #define
s and // sheldon:glslang
comments are parsed recursively, with no public API change.
Technical specifications
glslangValidator
does not provide a way to get the preprocessed output.
BUT the GLSL preprocessor is supposed to be the same one as in C
(and thus C++
).
This means we can extract the preprocessed GLSL using the C++
compiler used by the system, with something like:
cpp the_file.glsl -E -P -I ... -o ...
NOTE: this requires a bit of extra work, because #version
will not be recognised as-is, so we will need an intermediate file in which these kinds of things get "formatted" for cpp
.
We can then read the preprocessed file and do the same things as we did before.
Test plan
Unit testing and test current shaders in Sight.