ShaderProgram.getLog()

Discussions for core devs and contributors. Read only for normal forum members to keep the noise low

ShaderProgram.getLog()

Postby davedes » Sat May 25, 2013 9:55 pm

I think the recent changes to ShaderProgram.getLog() are not ideal. It introduces a lot more complexity in user code and without much benefit, unless I'm missing something. It also overrides the vert/frag shader log with the program log; but only if it compiled successfully. So right now there seems to be no way of querying the vert/shader log upon successful compile.

The code now looks like this:
Code: Select all
ShaderProgram prog = new ShaderProgram(...);
if (prog.isCompiled()) {
    prog.begin();

    String info = prog.getLog();
    if (info!=null && info.length()!=0)
        System.out.println(info);

    prog.end();
} else {
    throw new GdxRuntimeException("program did not compile: "+prog.getLog());
}


And before it looked like this:
Code: Select all
ShaderProgram prog = new ShaderProgram(...);

if (!prog.isCompiled())
    throw new GdxRuntimeException("program did not compile: "+prog.getLog());

if (prog.getLog()!=null && prog.getLog().length()!=0)
    System.out.println("Shader log:\n"+prog.getLog());


Why not leave the old functionality and introduce some new methods that actually query the state of each: queryShaderLog and queryProgramLog? Or something. Querying is only going to be done by advanced users, anyways, whereas 99% of users just want a string that contains some debugging info, like in my second example.
Last edited by davedes on Sun May 26, 2013 5:51 pm, edited 1 time in total.
davedes
 
Posts: 434
Joined: Thu Oct 11, 2012 7:51 pm

Re: ShaderProgram.getLog()

Postby bitiotic » Sat May 25, 2013 11:36 pm

Can you point out the diff that changes ShaderProgram? This change sounds interesting to me (from your description, I share your concerns), but poking around the current github source, everything looks fine to me, and scanning through the history I don't see anything changed around logging.
bitiotic
 
Posts: 81
Joined: Tue Feb 05, 2013 2:59 pm

Re: ShaderProgram.getLog()

Postby mzechner » Sun May 26, 2013 10:19 am

I too would be interested in a link to the commit, i'm not aware of any changes to that portion of the code.
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: ShaderProgram.getLog()

Postby davedes » Sun May 26, 2013 3:23 pm

First commit:
https://github.com/libgdx/libgdx/commit ... fd69a1656a

And here:
https://github.com/libgdx/libgdx/commit ... 699372ab26

Here is how it looks now:
https://github.com/libgdx/libgdx/blob/m ... .java#L252

Here is how it used to look:
https://github.com/libgdx/libgdx/blob/2 ... .java#L216

As you can see in the old version, the log was queried during compilation & linking, and contains both the shader log and the program log. :)
davedes
 
Posts: 434
Joined: Thu Oct 11, 2012 7:51 pm

Re: ShaderProgram.getLog()

Postby BurningHand » Sun May 26, 2013 4:32 pm

Those commits are years old...
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: ShaderProgram.getLog()

Postby davedes » Sun May 26, 2013 5:51 pm

Heh, sorry. I take back what I said about them being recent. :P I guess I have not looked at the source in a while.

Still, I'm not sure why the change was made.
davedes
 
Posts: 434
Joined: Thu Oct 11, 2012 7:51 pm

Re: ShaderProgram.getLog()

Postby bitiotic » Sun May 26, 2013 7:34 pm

To be clear, you'd like to be able to access the result of "glGetShaderInfoLog" after a successful compile? (Instead of being directed at the result of "glGetProgramInfoLog"?)

First, these logs (according to the doc), only ever contain the results of compilation/linking. (They don't provide any logging of actual execution of a shader... right?) Here's the doc:
http://www.khronos.org/opengles/sdk/doc ... nfoLog.xml
http://www.khronos.org/opengles/sdk/doc ... nfoLog.xml

Is there a case you know of where there is something useful in a vert/frag shader log after a successful compile that isn't included in the program info log?

I think the Libgdx approach is assuming that logs are only useful if a compile fails.

To access the logs you're interested in, a method that used the "vertexShaderHandle" or "fragmentShaderHandle" to get the shader-specific log would work? Something like:

Code: Select all
public String getVertexShaderLog() {
   GL20 gl = Gdx.graphics.getGL20();
   if (vertexShaderHandle != -1) { return gl.glGetShaderInfoLog(vertexShaderHandle); }
   return null;
}

(And similarly for fragmentShaderHandle.)

I like the current Libgdx simplification (it hides the shader/program distinction). But, if there is something valuable in this log then it seems easy enough to surface it?
bitiotic
 
Posts: 81
Joined: Tue Feb 05, 2013 2:59 pm

Re: ShaderProgram.getLog()

Postby davedes » Sun May 26, 2013 9:07 pm

Is there a case you know of where there is something useful in a vert/frag shader log after a successful compile that isn't included in the program info log?

It's up to the driver to decide what to spit out. It might be a useful warning, or something about deprecation or implicit casting, or just a message that says compilation / linking was successful. Ideally ShaderProgram should just follow the advice of the spec: "the information log can be helpful to application developers during the development process, even when compilation is successful".

One example would be GLSL #extension directive. Sometimes this will emit warnings or info for a specific shader (fragment or vertex) rather than the program itself. You might use this for texture rectangles, or texture arrays.

But beyond that, the main problem is that we query GL every time getLog() is called. Why is this necessary? As far as I can tell the log does not change after compilation/linking; and so why not cache the value? This way you also don't need to call begin() and end() just to get the shader log, nor do we need to provide different functionality depending on the success of the compilation.
davedes
 
Posts: 434
Joined: Thu Oct 11, 2012 7:51 pm

Re: ShaderProgram.getLog()

Postby mzechner » Sun May 26, 2013 11:06 pm

I propose someone sends a pull request! :D
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: ShaderProgram.getLog()

Postby bitiotic » Sun May 26, 2013 11:44 pm

davedes wrote:But beyond that, the main problem is that we query GL every time getLog() is called. Why is this necessary? As far as I can tell the log does not change after compilation/linking; and so why not cache the value?


I'm sure ShaderProgram could cache the log, but why would anyone call "getLog()" more than once? It only contains the compilation results and is only useful the (one time) the shader is compiled (right?). The downside of caching it is that the resulting log String would live as long as the shader does.

davedes wrote:This way you also don't need to call begin() and end() just to get the shader log, nor do we need to provide different functionality depending on the success of the compilation.


I'm pretty sure begin()/end() are not required to check the shader log. My current code gets the log outside of a begin()/end() block and seems to work ...

Perhaps we should augment getLog() so that it will get the two shader logs and the program log and return the combined result? (I'd be really curious what this looks like in practice, though. It could be annoying if it ends up with each error/warning repeated.)
bitiotic
 
Posts: 81
Joined: Tue Feb 05, 2013 2:59 pm


Return to Libgdx Development

Who is online

Users browsing this forum: No registered users and 1 guest