15

I've managed to implement OpenGL Debug Contexts (awesome, finally!) and most things seem all good and well, but I'm seeing a performance warning that I'm unable to find good information on.

[   0.0330 - 388.6340] OpenGL Version: 4.2.0 Quadro 600/PCIe/SSE2 NVIDIA Corporation
[   0.0000 - 549.1920] OpenGL: Program/shader state performance warning: Fragment Shader is going to be recompiled because the shader key based on GL state mismatches. [source=API type=PERFORMANCE severity=MEDIUM id=131218]

I do understand that it has got something to do with the OpenGL state being change since the last time I compiled the shader(s).

What we have is four shaders that are running on a texture that is shared between the contexts, and the error information only shows up after a new context has been created. So perhaps the context creation alters the state of the OpenGL state machine. Is it possible that it's even impossible to work around it, because each context starts with its own "clean" state machine?

It's probably not a big deal since it only occurs at context creation, but we're running many contexts (at least up to 15 of them at the same time) so it would be interesting to see if I'm able to fix the warning and get rid of it once and for all.

AzP
  • 1,002
  • 1
  • 15
  • 25
  • 5
    I *always* get this warning on NVIDIA cards. I have no idea what it means, nor do I have any idea how to correct it. And thus far, NVIDIA doesn't seem to keen on explaining what the problem is. – Nicol Bolas Aug 17 '12 at 13:17
  • I have the same impression from reading about it in forums. People talk about driver bugs, etc. – AzP Aug 17 '12 at 14:20
  • It's not a *bug*; it's just a performance warning about shader recompilation. – Nicol Bolas Aug 17 '12 at 14:47
  • Well Nicol, that's obvious. But NVidia still doesn't seem to want to give more information on the matter. I saw one thread where they mentioned driver issues, as if they were the actual driver developers. When I said "driver bugs" I meant the fact that the message is popping up, not that the message in itself is a bug. – AzP Aug 17 '12 at 14:51
  • Do you get the warning for a specific shader? Can you post it? If not, and it is for a context, are your contexts different in any way? – starmole Oct 19 '12 at 03:22
  • It seems to be once for each context, and it applies to all our contexts. But your question if it's for a specific shader is very interesting! I have to check it out. – AzP Oct 30 '12 at 16:54

2 Answers2

13

I got rid of that message by calling glUseProgram(0) after finishing drawing some geometry, otherwise the next glUseProgram() with a programId would have triggered that message.

  • This worked for me when I finally tried it! I could trace the source of the warning via the backtrace, add a couple of glUseProgram(0), and all the warnings disappeared. – AzP Nov 20 '14 at 14:17
5

From what little info I've been able to find, NVIDIA wants some piece of your OpenGL state at shader-compilation time to match the state when the shader is bound & used for rendering.

Personally, until we get more information, I just filter this particular message out in my debug callback function:

static void CALLBACK DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam)
{
    // Suppress some useless warnings
    switch(id)
    {
    case 131218: // NVIDIA: "shader will be recompiled due to GL state mismatches"
        return;
    default:
        break;
    }

    // Print/handle message as usual
}
postgoodism
  • 898
  • 8
  • 14
  • Thanks! I hadn't seen the final part of that thread. Will be interesting to see if Nvidia provides some feedback on this as well. – AzP Nov 08 '12 at 11:27