3

In my OpenGL ES 2.0 program on iOS I compile my shaders as follows:

setShaderState(state);//enables or disables GL_BLEND
GLuint vertexShader = compileShaderPart(vertexShader, GL_VERTEX_SHADER, state);
GLuint fragmentShader = compileShaderPart(fragmentShader, GL_FRAGMENT_SHADER, state);

//linking
GLuint programHandle = glCreateProgram();
Assert(programHandle != 0, "Program handle 0");

for(auto shaderAttribute : shaderAttributeList){
  if(isVertexAttribute(shaderAttribute.attribute())){
    glBindAttribLocation(programHandle, shaderAttribute.attribute(), shaderAttribute.attributeName(1).c_str());
  }
}


glAttachShader(programHandle, vertexShader);
glAttachShader(programHandle, fragmentShader);
glLinkProgram(programHandle);
Assert(glGetError() == GL_NO_ERROR, "Could not link program");

GLint linkSuccess;
glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess);
if (linkSuccess == GL_FALSE) {
  GLchar messages[256];
  glGetProgramInfoLog(programHandle, sizeof(messages), 0, &messages[0]);
  ELog << messages;
  Assert(0, "Error compiling shader");
}

ShaderUniformHandleMap shaderUniformMap;    
Shader *shader = new Shader(programHandle, availableShader.name, shaderUniformMap, state);

glUseProgram(programHandle);
auto mesh = Mesh::load("quad");
shader->bindMesh(mesh);
auto temp_texture = Texture2D::load("checker");
for(auto uniform : shader->texture){
  glUniform1i(uniform.handle, shader->bindTexture(temp_texture->textureId()));
}
glDrawElements(GL_TRIANGLES, mesh->indexDataSize(), GL_UNSIGNED_SHORT, 0);

I left the uniform reading part out for readability and the compileShaderPart function is as straight forward as can be.

Running the app in the openGL ES Analyzer in instruments yields hundreds of occurances of the "Shader compiled outside of a prewarming phase" problem. Shouldn't the glDrawElements call take care of that?

I've read that changing states like GL_Blend can have that impact, so I'm compiling the same shader twice, once with GL_Blend enabled and once disabled, but it didn't make any difference.

What's the problem here? I also find it difficult to find Information about this prewarming stuff, so far I've gathered that the shader is only really compiled after the first draw call, which is why I'm drawing that quad in the end.

2
  • From what I can discern, pre-warming refers to setting up the render pipeline ahead of time. In the case of GLSL shaders, if the implementation defers compilation until first use then you would want to draw your scene with the shader, but do not actually display the results. Nov 17, 2013 at 1:51
  • We're running across the same issue. Our shaders are compiled/linked outside of the main loop. We do not have any shader compile/link happening inside the main loop and yet we see hundreds of these warnings each frame for the duration of our game. Not sure what's happening. Were you able to find out?
    – Samaursa
    Feb 20, 2015 at 19:42

2 Answers 2

1

Is this in your main rendering loop? You only need to compile a shader once, and then you use the glUseProgram call with the shader name to bind it when you need to use it again. From the looks of things, you're compiling it once every draw call, hence the hundreds of warnings. Also, I'm pretty sure OpenGL ES shader programs don't contain the state of different parts of the rendering pipeline like blend modes, so your second compilation is most likely also unnecessary.

1
  • thx for the answer, i double checked, the compilation is only done once in the beginning as expected. I thought the same about the blend modes, but that's what i read in a SO thread I really cant find at the moment.
    – cboe
    Nov 16, 2013 at 13:01
-1

instrument detail recommendation:

Your application caused a shader compilation that is not part of an initial prewarming phase. Shader compilation can be a time consuming operation. To avoid them, prewarm all shaders used for rendering. To do this, make a prewarming passwhen your application launches and execute a drawing call with each of the shader programs to be used, using any GL state settings the shader program will be used in conjunction with. States such as blending, color mask, logic ops, multisamping, texture formats, and point primitive state can all affect shader compilation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.