[Mesa-dev] [PATCH] RFC: glsl/glcpp: Allow for '#' characters to appear in shader body
Michel Dänzer
michel at daenzer.net
Thu Jul 31 19:48:09 PDT 2014
On 01.08.2014 03:22, Carl Worth wrote:
> Strictly speaking, the GLSL specification only allows for the '#' to appear in
> a shader in two places:
>
> 1. To introduce a pre-processing directive
>
> In this case, the '#' must be the first character on a line after
> ignoring any comments and horizontal whitespace.
>
> 2. As part of the token-pasting operator
>
> In this case, the '#' must appear as part of the sequence "##" and
> can only appear in the replacement list of a macro definition.
>
> Since commit f062f0506a5b827667b7eb52136d8420b7e8113b, glcpp has been strict
> about '#' characters, such that any occurence outside of either of the above
> two cases would result in a syntax error of "Unexpected HASH_TOKEN" from the
> grammar.
>
> (Prior to that commit, these illegal '#' would be silently ignored and printed
> to stdout. And if it hadn't been for that commit, these illegal '#' would have
> triggered internal errors with later commits.)
>
> With this commit, glcpp relaxes its strictness and treats such appearances of
> '#' as just another piece of punctuation. This would make it legal to do
> something like:
>
> #define FOO # something here
>
> and then use "#ifdef FOO" and similar, (though if FOO were ever directly
> expanded, this should trigger a syntax error in the main GLSL compiler).
>
> Relaxing strict conformance compared to GLSL seems somewhat dubious here, but
> might be justified for a few reasons:
>
> 1. GCC's preprocessor allows this, (though C is not GLSL, of course)
>
> 2. glcpp is generally soft about illegal characters, (compare to
> non-ASCII characters which glcpp happily passes through, trusting
> the GLSL compiler to catch them).
>
> 3. At least one game in the wild (Reactive Quake) has been observed
It's 'Reaction Quake'.
> with a bogus '#' in it:
>
> #define USE_DISCARD#line 0
>
> Note that the shader (that we've seen) with this line does not ever
> *use* the USE_DISCARD macro. Note also that this shader is accepted
> by both Nvidia's OpenGL implementation as well as Mesa prior to
> the commit referenced above.
This change makes the game work again. I'm afraid I don't care about the
game enough to report the problem to its developers. :)
Tested-by: Michel Dänzer <michel.daenzer at amd.com>
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer
More information about the mesa-dev
mailing list