[WebGL] ANGLE Extension directive location incorrectly enforced for webgl 1.0
https://bugs.webkit.org/show_bug.cgi?id=198811

Reviewed by Dean Jackson.

Source/ThirdParty/ANGLE:

Apply ANGLE change from https://chromium-review.googlesource.com/c/angle/angle/+/1648661 to
prevent enforcing ESSL late extension rule on WebGL 1.0 shaders.

* src/compiler/preprocessor/DiagnosticsBase.cpp:
(angle::pp::Diagnostics::message):
* src/compiler/preprocessor/DiagnosticsBase.h:
* src/compiler/preprocessor/DirectiveParser.cpp:
(angle::pp::DirectiveParser::parseExtension):

LayoutTests:

ANGLE was updated so that this case should not be an error.

* webgl/webgl-extension-directive-location-no-error-expected.txt: Added.
* webgl/webgl-extension-directive-location-no-error.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@246393 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 00c8196..1e5c720 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2019-06-12  Justin Fan  <justin_fan@apple.com>
+
+        [WebGL] ANGLE Extension directive location incorrectly enforced for webgl 1.0
+        https://bugs.webkit.org/show_bug.cgi?id=198811
+
+        Reviewed by Dean Jackson.
+
+        ANGLE was updated so that this case should not be an error.
+
+        * webgl/webgl-extension-directive-location-no-error-expected.txt: Added.
+        * webgl/webgl-extension-directive-location-no-error.html: Added.
+
 2019-06-12  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [cairo][SVG] If clipPath has multiple elements, clip-path doesn't work with transform
diff --git a/LayoutTests/webgl/webgl-extension-directive-location-no-error-expected.txt b/LayoutTests/webgl/webgl-extension-directive-location-no-error-expected.txt
new file mode 100644
index 0000000..641e237
--- /dev/null
+++ b/LayoutTests/webgl/webgl-extension-directive-location-no-error-expected.txt
@@ -0,0 +1,3 @@
+Ensure that if a shader extension directive is specified after non-preprocessor symbols, no errors are logged.
+
+
diff --git a/LayoutTests/webgl/webgl-extension-directive-location-no-error.html b/LayoutTests/webgl/webgl-extension-directive-location-no-error.html
new file mode 100644
index 0000000..03259b7
--- /dev/null
+++ b/LayoutTests/webgl/webgl-extension-directive-location-no-error.html
@@ -0,0 +1,29 @@
+<body>
+<p>Ensure that if a shader extension directive is specified after non-preprocessor symbols, no errors are logged.</p>
+<canvas></canvas>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+const fragmentShaderSource = `
+    precision highp float;
+    #extension GL_OES_standard_derivatives : enable
+
+    void main() {
+        gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
+    }
+    `;
+
+const canvas = document.querySelector('canvas');
+const gl = canvas.getContext("webgl");
+
+gl.getExtension('OES_standard_derivatives');
+
+const shader = gl.createShader(gl.FRAGMENT_SHADER);
+gl.shaderSource(shader, fragmentShaderSource);
+gl.compileShader(shader);
+const success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
+if (!success)
+    console.log(gl.getShaderInfoLog(shader));
+</script>
+</body>
\ No newline at end of file
diff --git a/Source/ThirdParty/ANGLE/ChangeLog b/Source/ThirdParty/ANGLE/ChangeLog
index dd1e479..5b50ceb 100644
--- a/Source/ThirdParty/ANGLE/ChangeLog
+++ b/Source/ThirdParty/ANGLE/ChangeLog
@@ -1,3 +1,19 @@
+2019-06-12  Justin Fan  <justin_fan@apple.com>
+
+        [WebGL] ANGLE Extension directive location incorrectly enforced for webgl 1.0
+        https://bugs.webkit.org/show_bug.cgi?id=198811
+
+        Reviewed by Dean Jackson.
+
+        Apply ANGLE change from https://chromium-review.googlesource.com/c/angle/angle/+/1648661 to
+        prevent enforcing ESSL late extension rule on WebGL 1.0 shaders.
+
+        * src/compiler/preprocessor/DiagnosticsBase.cpp:
+        (angle::pp::Diagnostics::message):
+        * src/compiler/preprocessor/DiagnosticsBase.h:
+        * src/compiler/preprocessor/DirectiveParser.cpp:
+        (angle::pp::DirectiveParser::parseExtension):
+
 2019-05-23  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake] Use target oriented design for bmalloc
diff --git a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.cpp b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.cpp
index 575b151..c4832c6 100644
--- a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.cpp
+++ b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.cpp
@@ -115,6 +115,8 @@
             return "invalid file number";
         case PP_INVALID_LINE_DIRECTIVE:
             return "invalid line directive";
+        case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
+            return "extension directive must occur before any non-preprocessor tokens in ESSL1";
         case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3:
             return "extension directive must occur before any non-preprocessor tokens in ESSL3";
         case PP_UNDEFINED_SHIFT:
@@ -129,7 +131,7 @@
             return "unexpected token after conditional expression";
         case PP_UNRECOGNIZED_PRAGMA:
             return "unrecognized pragma";
-        case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
+        case PP_NON_PP_TOKEN_BEFORE_EXTENSION_WEBGL:
             return "extension directive should occur before any non-preprocessor tokens";
         case PP_WARNING_MACRO_NAME_RESERVED:
             return "macro name with a double underscore is reserved - unintented behavior is "
diff --git a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.h b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.h
index bb90bf0..6be5c72 100644
--- a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.h
+++ b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DiagnosticsBase.h
@@ -73,6 +73,7 @@
         PP_WARNING_BEGIN,
         PP_EOF_IN_DIRECTIVE,
         PP_UNRECOGNIZED_PRAGMA,
+        PP_NON_PP_TOKEN_BEFORE_EXTENSION_WEBGL,
         PP_WARNING_MACRO_NAME_RESERVED,
         PP_WARNING_END
     };
diff --git a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DirectiveParser.cpp b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DirectiveParser.cpp
index e99d843b..b7f8d91 100644
--- a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/DirectiveParser.cpp
@@ -676,8 +676,16 @@
         }
         else
         {
-            mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
-                                 token->location, token->text);
+            if (mSettings.shaderSpec == SH_WEBGL_SPEC)
+            {
+                mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_WEBGL,
+                                     token->location, token->text);
+            }
+            else
+            {
+                mDiagnostics->report(Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
+                                     token->location, token->text);
+            }
         }
     }
     if (valid)