Skip to content

enh(ci): allow to ignore certain preprocessor define directive when attempting to compile shaders

Description

It is now possible to add inline comments in shaders to avoid attempting to compile with exclusive #define combinations or with #defines internal to the shader.

The syntax is as such:

// sheldon:glslang discard-define(do_foo, do_bar)
// sheldon:glslang require-exclusive(SIGHT_OPTION_A, SIGHT_OPTION_B, SIGHT_OPTION_C)

// Spaces don't matter, the following also work (though I would question the readability of the second one)

// sheldon: glslang discard-define(do_hug, do_zog)
// sheldon : glslang require-exclusive(SIGHT_OPTION_D, SIGHT_OPTION_E)

Source files with .vert.glsl / .frag.glsl & co. are now also supported and are now longer compiled as fragment shaders.

Closes #74 (closed)

How to test it?

  1. Trust the CI (I added a test)

If you want to test it in your shaders, you may follow the following plan:

  1. Create a shader with something like this:
#if defined(SIGHT_PATH_A)

    #if defined(SIGHT_PATH_B)
        #error Invalid configuration. Expected at most one of SIGHT_PATH_A, SIGHT_PATH_B.
    #endif

#elif defined(SIGHT_PATH_B)

    #if defined(SIGHT_PATH_A)
        #error Invalid configuration. Expected at most one of SIGHT_PATH_A, SIGHT_PATH_B.
    #endif

#else
    #error Missing preprocessor define. Expected SIGHT_PATH_A or SIGHT_PATH_B.
#endif

#if defined(SIGHT_DO_FOO)
#error Should not be defined.
#endif

#if defined(SIGHT_DO_BAR)
#error Should not be defined.
#endif

#define SIGHT_DO_FOO
#define SIGHT_DO_BAR
  1. Confirm sheldon glslang hook refuses it.
  2. Add // sheldon: glslang require-exclusive(SIGHT_PATH_A, SIGHT_PATH_B)
  3. Add // sheldon: glslang discard-define(SIGHT_DO_FOO, SIGHT_DO_BAR)
  4. Confirm the shader is accepted (provided you wrote something correct without this of course)
Edited by Erwan DUHAMEL

Merge request reports