3

My GLSL (OpenGL ES 2.0, "#version 100") shaders fail to compile on a Vivante GC800 GPU. The shaders compile fine on lots of other GPUs.

The error I get is:

(2:0) : error : Expect positive integer-line-number after #line.

I use

#line 0

to reset the line number after including a bunch of preamble code (like #version and some precision specifiers) before the "real" shader. Anyone know if this is a case of the Vivante shader compiler being broken, or of everyone else's shader compiler being too lenient?

My workaround is to only include this directive when debugging my shaders locally.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
P.T.
  • 24,557
  • 7
  • 64
  • 95

1 Answers1

4

The GLES Shading Language spec has this to say about the issue (section 3.4 "Preprocessor"):

#line must have, after macro substitution, one of the following two forms:

#line line
#line line source-string-number

where line and source-string-number are constant integer expressions. After processing this directive (including its new-line), the implementation will behave as if the following line has line number line and starts with source string number source-string-number. Subsequent source strings will be numbered sequentially, until another #line directive overrides that numbering.

That would not rule out 0 (or even negative values). However there is also

__LINE__ will substitute a decimal integer constant that is one more than the number of preceding newlines in the current source string.

One could argue that that means that the line number can never be below 1, since that implies a negative number of newlines. YMMV.

derhass
  • 43,833
  • 2
  • 57
  • 78
  • Ah, so I should use "#line 1". I thought that was different from C, but it seems "#line 0" isn't valid in the C preprocessor either: http://stackoverflow.com/a/9152887/960524. – P.T. Aug 12 '13 at 15:44
  • Wow... Is this different between GLSL and GLSL ES? I'm looking at the [GLSL 1.20.8 spec](http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf) and it says _"After processing this directive (including its new-line), the implementation will behave as if it is compiling at line number line+1"_. Not having plus 1 makes more sense, and I think this is how the C preprocessor does it as well. – falstro Nov 29 '13 at 08:25