Better feedback when shaders doesn't compile
Description
Improving the default error message from moderngl with more feedback by adding some of the actual source in stdout.
From demosys-py issue: Better feedback when shaders do not compile #62
Example of new output for shader build errors:
GLSL Compiler failed
tess_control_shader
===================
0001
0002 #version 400 core
0003
0004 layout(vertices = 4) out;
0005
0006 void main() {
0007 // set tesselation levels, TODO compute dynamically
0008 gl_TessLevelOuter[0] = 1;
0009 gl_TessLevelOuter[1] = 32;
0010
0011 l_TessLevelOuter[2] = toto;
error C1008: undefined variable "l_TessLevelOuter"
error C1008: undefined variable "toto"
0012
0013 // pass through vertex positions
0014 gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
0015 }
0016
List of changes
- added Program_Error.cpp tools for formatting shader information logs. New units tests in test_program_errors.py
- removed Nothing
- fixed Nothing
- changed Program.cpp to use this new feature
Hi! I really like this feature, I see it supports multiple log formats. However my old GPU sometimes messes up the line numbers. For example I can get:
Vertex info
(╗) : error C5145: must write to gl_Position
something like this.
I would like this feature to be configurable. For example with a flag at runtime.
What do you think?
Yep the result logs are pretty volatile depend of GPU family (and OpenGL Driver implementation). I can't support all OpenGL drivers (i don't have all GPU and drivers on my computer(s) ;-)). If you have some ideas to implement a more generic implementation of this feature, don't hesitate ;-) Maybe a possibility to send/express a generic parser could be useful ... i will try to figure out how to implement a feature like this. For a first attempt, we can accept this feature and using (GitHub) fix/pr to add manually other logs parser.
Can we rebase this against the experimental-2 branch? I would like to have the following setup:
All the compiler / linker errors will be passed to a user configurable function that returns a string with the error message, or set the proper exception.
The default would be to have this "transformation" of the error log. I would like to let the user choose if he wants the "raw" error log.
I thought it could be configured in the following way.
ctx = moderngl.context(...)
ctx.set_glsl_error_formatter(...) # to get the raw output set it to None
I think the the implementation could be in python. We should decide what parameters it could take. and what should it return / raise.
What kind of OS are you using? Can you build the experimental-2 branch?
Please let me know if not.
I'm in vacation (portugal) but i will check tonight if i can build the experimental-2 branch (and merge it). (I'm on notebook ubuntu-mate (16.04) with gcc ... dont remember the version ^^)
the experimental-2 should build on linux at the moment. I use travis to see build errors on linux.
Do you have some documentation about this branch: experimental-2 ?
The 'tests'/example folder are very ... slim :p
I'll see if I can revive this at some point, but not for 5.6.
@einarf i'v rebased this MR with master (from moderngl).
I had to deactivate (skip) utest on vertex shader error, because on CI (VM used by Github Action), this utest return strange error message (the error message is raw, not interpolated). the others utests work ... it's not perfect but it is what it is.
Moving the formatting message from the C part to Python could be a good thing, but it's more difficult (and more distant from the current master of moderngl). Maybe, i will try in other (next) step.
We will definitely have an option to add custom error parsers to moderngl. Thank you very much for this pull request.
it will work similarly to https://github.com/szabolcsdombi/zengl/blob/main/examples/custom_shader_errors.py
I am closing this as the implementation is in C++, Users will be able to hook the error generation and extend it or pretty format it like in the code you provided. there will be an example or an extra modergl module providing something basic. By default the original GL provided message will be shown.