Skip to content

Commit

Permalink
Specify handling "defined" operators generated by macro replacement
Browse files Browse the repository at this point in the history
This is already tested by the dEQP shader preprocessor tests in the
conformance suite.

Five different corner cases of this behavior were tested against Nexus 5,
Nexus 6, Nexus 9 and Nexus Player native GLES3 implementations, as well
as the recent implementation in ANGLE TOT. The existing implementations
largely agree with the spec in this commit. The only exception is Nexus
Player, where in the following kind of case:

 #define CCC 1
 #define defined BBB
 #define AAA defined
 #if AAA CCC
 #endif

"defined" in the replacement list of "AAA" is replaced by "BBB" instead
of immediately handling it as the "defined" operator. In all the other
four implementations, the defined operator is evaluated in this case and
returns "1".
  • Loading branch information
Olli Etuaho committed Sep 29, 2015
1 parent 90ceaac commit c0a4e0b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion specs/latest/1.0/index.html
Expand Up @@ -28,7 +28,7 @@
<!--end-logo-->

<h1>WebGL Specification</h1>
<h2 class="no-toc">Editor's Draft 14 September 2015</h2>
<h2 class="no-toc">Editor's Draft 29 September 2015</h2>
<dl>
<dt>This version:
<dd>
Expand Down Expand Up @@ -3840,6 +3840,28 @@ <h3>GLSL ES Global Variable Initialization</h3>
content.
</div>

<h3><a name="PREPROCESSOR_DEFINED_IN_MACRO">GLSL ES Preprocessor "defined" Operator Generated By Macro Replacement</a></h3>

<p>
The C++ standard, which the GLSL ES preprocessor specification refers to, has undefined behavior
when the <code>defined</code> operator is generated by macro replacement when parsing the
controlling expression of an <code>#if</code> or <code>#elif</code> directive. When shader code
processed by the WebGL API generates the token <code>defined</code> during macro replacement
inside a preprocessor expression, that token must be immediately handled as the
<code>defined</code> operator before any further macro replacement.
</p>

<p>
This has no effect on macro expansion outside preprocessor directives that handle the
<code>defined</code> operator.
</p>

<div class="note rationale">
This behavior is enforced across GLES implementations by dEQP tests, so shaders created on other
platforms may rely on it. In addition, the ported dEQP tests in the WebGL conformance suite are
only valid if this behavior is specified.
</div>

<!-- ======================================================================================================= -->

<h2>References</h2>
Expand Down

0 comments on commit c0a4e0b

Please sign in to comment.