Sign in to follow this  
nesdavid

vertex color clamping (glDebugMessageCallback)

Recommended Posts

Hi,

I'm just reading the output generated by glDebugMessageCallback and I'm seeing a message that I don't understand, "vertex color clamping 1 -> 0" in the performance category.

It only happens once. Maybe was launched by the shader compilation or the context creation and initialization.

Have you ever seen this message in any of your program?

Share this post


Link to post
Share on other sites
I'm replying you here so the answer is available for everyone who is also looking for this:
Fortunately you're using the open source driver Mesa3D for Linux, so finding in the files makes MUCH easier understanding what it means:
https://github.com/mesa3d/mesa/blob/master/src/mesa/drivers/dri/i965/brw_vs.c#L114
 
Now it's crystal clear what's going on: The driver is telling you it has to internally recompile a shader because some GL state has changed.
You probably called glClampColorARB( GL_CLAMP_VERTEX_COLOR_ARB, TRUE ); and then later on called glClampColorARB( GL_CLAMP_VERTEX_COLOR_ARB, FALSE ); or something like that. But for this chip, there is no fixed function hardware to deal with that, so it is done directly with shader instructions.
If you alter this setting, the driver internally has to use two different shaders. That's why Vulkan created PSOs, so that bullsh*t like this wouldn't end up in one shader actually mapping to multiple shaders depending on settings such as vertex format and render targets.
 
If you changed the setting by accident and you don't need it; then avoid it. It's costing you CPU cycles. If you cannot do that, then you'll have to ignore the warning. However with this knowledge, you may take advantage of that. If you have a loading screen, draw with vertex clamping disabled & then enabled; so that you give the driver the chance to compile both shaders and avoid a hiccup later on during rendering.
 
Edit: Another way to avoid this warning is to have two copies of the shader with identical source code; but one you will use it with colour clamping exclusively, the other one without colour clamping. Edited by Matias Goldberg

Share this post


Link to post
Share on other sites

Thanks for the reply, but things are a bit more interesting than that ;)

This is the complete message, which come split in 2 "Recompiling vertex shader for program 14 vertex color clamping 1->0". The thing is that I never created so many programs, that Id doesn't belong to any of my code, and in order to verify this I commented all the shader creation of my code, and the warning *still* happens (with a lower id). So I believe it should be an internal shader created by the driver or something like that.

I believe I will ignore this warning completely.

Share this post


Link to post
Share on other sites

Ok, thanks for your replies. I got another one (maybe I should change the title topic :rolleyes:). The mesaage says "Recompiling fragment shader for program 9 EXT_texture_swizzle or DEPTH_TEXTURE_MODE 1672->292".

That program is mine and it renders text. The font atlas has only one color channel and for that I had to swizzle the channels like this.

glBindTexture(GL_TEXTURE_2D, Texture);
GLint swizzleMask[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);

I only do that when the texture is created and uploaded to the GPU and the error is only shown once, on the first render with that shader.

I want to understand the reasoning behind these of messages, because it seems that is not much I can do in order to prevent the internal recompiling of the shader, unless there's some hinting to the fragment shader that the colors will be swizzled.

Am i missing something?

Share this post


Link to post
Share on other sites

My other two cents are: you use the same texture unit for different textures and the driver might recompile the internal shader each time the tex parameter is changed for that same texture unit.

Try to do use a specific texture unit for this swizzle and see if things change.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this