Skip to content

(hooks): validate glsl code

Kevin GAUDET requested to merge glsl-validator-hook into dev

What does this MR do?

Add a new hook checking glsl version and validity.

  • Check if a glsl file is valid for every possible per-processor macro combination
  • Check if the glsl version is supported on all platforms
  • Check the glsl version by default with sheldon

How to test it?

  • You will first need to install glslang : https://github.com/KhronosGroup/glslang/releases/tag/7.11.3113
  • Set the path to glslandValidator in your git config git config --global glslang-hook.glslang-validator-path /path/to/glslang/bin/glslangValidator
  • Run the unit tests python -m unittest tests\test_glslang_validator.py
  • Try modifying some shader code in sight and see how it reacts.

Some results

Unit test output :

λ python -m unittest tests\test_glslang_validator.py
* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/ColorFormats.glsl
*** [ERROR] Unsupported glsl version: 430 ***
*** [ERROR] Supported versions are: 110 120 130 140 150 330 400 410 ***
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/ColorFormats.glsl with: ()
C:\Users\kgaudet\AppData\Local\Temp\tmpal_r_sg0
ERROR: 0:21: '=' :  cannot convert from ' temp float' to ' temp int'
ERROR: 0:21: '' : compilation terminated
ERROR: 2 compilation errors.  No code generated.



*** [ERROR] glslangValidator failure on file: C:\Users\kgaudet\AppData\Local\Temp\tmpal_r_sg0 ***
*** [ERROR] Aborting ***
* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/NormalsDisplay_GP.glsl
*** [ERROR] Unsupported glsl version: 430 ***
*** [ERROR] Supported versions are: 110 120 130 140 150 330 400 410 ***
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/NormalsDisplay_GP.glsl with: ()
C:\Users\kgaudet\AppData\Local\Temp\tmp1z9vm0ps
ERROR: 0:9: 'triangles' : cannot apply to 'out'
ERROR: 1 compilation errors.  No code generated.



*** [ERROR] glslangValidator failure on file: C:\Users\kgaudet\AppData\Local\Temp\tmp1z9vm0ps ***
*** [ERROR] Aborting ***
* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/RayTracedVolume_FP.glsl
*** [ERROR] Unsupported glsl version: 420 ***
*** [ERROR] Supported versions are: 110 120 130 140 150 330 400 410 ***
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/RayTracedVolume_FP.glsl with: ()
C:\Users\kgaudet\AppData\Local\Temp\tmpuk76_fp7
ERROR: 0:188: '' :  syntax error, unexpected RIGHT_BRACE, expecting COMMA or SEMICOLON
ERROR: 1 compilation errors.  No code generated.



*** [ERROR] glslangValidator failure on file: C:\Users\kgaudet\AppData\Local\Temp\tmpuk76_fp7 ***
*** [ERROR] Aborting ***
* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/Render_VP.glsl
*** [ERROR] Unsupported glsl version: 450 ***
*** [ERROR] Supported versions are: 110 120 130 140 150 330 400 410 ***
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/invalid/Render_VP.glsl with: ()
C:\Users\kgaudet\AppData\Local\Temp\tmpvues5mjx
ERROR: 0:8: '*' :  wrong operand types: no operation '*' exists that takes a left-hand operand of type ' uniform 3X3 matrix of float' and a right operand of type ' in 4-component vector of float' (or there is no acceptable conversion)
ERROR: 0:8: 'assign' :  cannot convert from ' uniform 3X3 matrix of float' to ' gl_Position 4-component vector of float Position'
ERROR: 0:8: '' : compilation terminated
ERROR: 3 compilation errors.  No code generated.



*** [ERROR] glslangValidator failure on file: C:\Users\kgaudet\AppData\Local\Temp\tmpvues5mjx ***
*** [ERROR] Aborting ***
.* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/ColorFormats.glsl with: ()

* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/ColorFormats.glsl
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/NormalsDisplay_GP.glsl with: ()

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/NormalsDisplay_GP.glsl with: ('-DPOINT=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/NormalsDisplay_GP.glsl with: ('-DDEPTH=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/NormalsDisplay_GP.glsl with: ('-DPOINT=1', '-DDEPTH=1')

* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/NormalsDisplay_GP.glsl
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ()

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAMBIENT_OCCLUSION=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DPREINTEGRATION=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DSHADOWS=1',)

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DAMBIENT_OCCLUSION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAMBIENT_OCCLUSION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DAMBIENT_OCCLUSION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl with: ('-DAUTOSTEREO=1', '-DCOLOR_BLEEDING=1', '-DAMBIENT_OCCLUSION=1', '-DPREINTEGRATION=1', '-DSHADOWS=1')

* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/RayTracedVolume_FP.glsl
* [Sheldon] Checking file C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/Render_VP.glsl with: ()

* [Sheldon] Checking glsl version in : C:\Users\kgaudet\Dev\sight\tools\sight-git\hooks\tests/data/glsl/valid/Render_VP.glsl
.
----------------------------------------------------------------------
Ran 2 tests in 5.479s

OK

Associated Issues/Merge Requests

Resolves #7 (closed)

Edited by Kevin GAUDET

Merge request reports