From c0a4e0bf98f49283665828dd6ddbde706cec2401 Mon Sep 17 00:00:00 2001 From: Olli Etuaho Date: Fri, 18 Sep 2015 16:26:28 +0300 Subject: [PATCH] Specify handling "defined" operators generated by macro replacement 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". --- specs/latest/1.0/index.html | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index 1f00be6b3a..34284e8de3 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -28,7 +28,7 @@

WebGL Specification

-

Editor's Draft 14 September 2015

+

Editor's Draft 29 September 2015

This version:
@@ -3840,6 +3840,28 @@

GLSL ES Global Variable Initialization

content. +

GLSL ES Preprocessor "defined" Operator Generated By Macro Replacement

+ +

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

+ +

+ This has no effect on macro expansion outside preprocessor directives that handle the + defined operator. +

+ +
+ 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. +
+

References