Forums - shader compilation error

3 posts / 0 new
Last post
shader compilation error
hb
Join Date: 16 Jul 14
Posts: 2
Posted: Fri, 2014-07-18 05:00
Hello!
 
I had a problem with shader compilation. The vertex and fragment shaders are in the same file between #ifdef macros and the same string is passed to compilation with different #defined macros.
 
For example:
 
shader:
/////////////
 
varying mediump vec2 texCoords;
varying lowp vec3 color;
 
#if defined(VERTEX_SHADER)
 
//attributes, uniforms
 
void main()
{
  //shader code, (I skipped the actual code because it didn't seem to make any difference)
}
 
#endif
#if defined(FRAGMENT_SHADER)
 
//attributes, uniforms
 
void main()
{
    //shader code
}
 
#endif
 
///////////////
 
then later in code:
const char *sources[] =
{
"#define VERTEX_SHADER\n",
"#define RUNTIME\n",
source // this is the shader itself
};
            
glShaderSource(vertexShader, 3, sources, NULL);
glCompileShader(vertexShader);
 
...
 
sources[0] = "#define FRAGMENT_SHADER\n";
glShaderSource(fragmentShader, 3, sources, NULL);
glCompileShader(fragmentShader);
 
This worked on pc, mac, ios and on android on Tegra and PowerVR chips but I got a shader compilation error on a Galaxy S4 device (i think it has an Adreno 320 chip). The shader error log was empty. According to some printf debug messages, the vertex shader compiles but the fragment shader doesn't. I attached a logcat excerpt but it doesn't seem very helpful.
 
I could compile the shader when I manually separated the fragment and vertex shader part. Is there some kind of limitation on the preprocessor directives? I checked the samples in the sdk and that also has #ifdef commands in some shaders so I don't understand the difference.
 
I guess I can go with the workaround I'm just curious.
Thanks!
  • Up0
  • Down0
mhfeldma Moderator
Join Date: 29 Nov 12
Posts: 310
Posted: Fri, 2014-07-18 10:59

Sounds like an odd problem, we'd like to look at in more detail.

1) Can you try removing the parathesis from the #if defined.. Also try using just #ifdef

2) Is there an apk you could share that we can try to duplicate on?

 

thanks,

 

  • Up0
  • Down0
hb
Join Date: 16 Jul 14
Posts: 2
Posted: Tue, 2014-07-22 03:04

Thank you for the reply. We solved the problem by inserting an endline character at the end of the source string. It was just a  bit strange because the same string worked on other devices and the shader compiler failed without an error log.

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.