Merge remote-tracking branch 'aosp/upstream-master' into update-shaderc

Includes:
1a149f6 Fix shaderc_compile_to_spv examples in shaderc.h
cb4f0f6 Describe includer error convention in the struct.
48b5f88 Add comment to explain how to return an error in callback
9c3a4ee Use OpenCL extended instruction set from SPIRV-Headers
5c6247c Add validate_type_unique.cpp to SPIRV-Tools

Test: checkbuild.py on Linux; unit tests on Windows
Change-Id: Ic7c9daf661581eb7d3a573265be931afbe0b61a7
diff --git a/examples/online-compile/main.cc b/examples/online-compile/main.cc
index 92d9835..9e1ca5b 100644
--- a/examples/online-compile/main.cc
+++ b/examples/online-compile/main.cc
@@ -23,6 +23,7 @@
 //  - Setting basic options: setting a preprocessor symbol.
 //  - Checking compilation status and extracting an error message.
 
+#include <cstring>
 #include <iostream>
 #include <string>
 #include <vector>
@@ -143,5 +144,28 @@
     compile_file("bad_src", shaderc_glsl_vertex_shader, kBadShaderSource);
   }
 
+  {  // Compile using the C API.
+    std::cout << "\n\nCompiling with the C API" << std::endl;
+
+    // The first example has a compilation problem.  The second does not.
+    const char source[2][80] = {"void main() {}", "#version 450\nvoid main() {}"};
+
+    shaderc_compiler_t compiler = shaderc_compiler_initialize();
+    for (int i = 0; i < 2; ++i) {
+      std::cout << "  Source is:\n---\n" << source[i] << "\n---\n";
+      shaderc_compilation_result_t result = shaderc_compile_into_spv(
+          compiler, source[i], std::strlen(source[i]), shaderc_glsl_vertex_shader,
+          "main.vert", "main", nullptr);
+      auto status = shaderc_result_get_compilation_status(result);
+      std::cout << "  Result code " << int(status) << std::endl;
+      if (status != shaderc_compilation_status_success) {
+        std::cout << "error: " << shaderc_result_get_error_message(result)
+                  << std::endl;
+      }
+      shaderc_result_release(result);
+    }
+    shaderc_compiler_release(compiler);
+  }
+
   return 0;
 }
diff --git a/libshaderc/include/shaderc/shaderc.h b/libshaderc/include/shaderc/shaderc.h
index 9e23177..8d75c49 100644
--- a/libshaderc/include/shaderc/shaderc.h
+++ b/libshaderc/include/shaderc/shaderc.h
@@ -179,7 +179,8 @@
 // for each new use.
 //      shaderc_compiler_t compiler = shaderc_compiler_initialize();
 //      shaderc_compilation_result_t result = shaderc_compile_into_spv(
-//          compiler, "int main() {}", 13, shaderc_glsl_vertex_shader, "main");
+//          compiler, "#version 450\nvoid main() {}", 27,
+//          shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
 //      // Do stuff with compilation results.
 //      shaderc_result_release(result);
 //      shaderc_compiler_release(compiler);
@@ -189,7 +190,8 @@
 //      shaderc_compiler_t compiler = shaderc_compiler_initialize();
 //      // On the same, other or multiple simultaneous threads.
 //      shaderc_compilation_result_t result = shaderc_compile_into_spv(
-//          compiler, "int main() {}", 13, shaderc_glsl_vertex_shader, "main");
+//          compiler, "#version 450\nvoid main() {}", 27,
+//          shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
 //      // Do stuff with compilation results.
 //      shaderc_result_release(result);
 //      // Once no more compilations are to happen.
@@ -278,6 +280,8 @@
 // the contents of the result, and those contents must remain valid until the
 // second callback is invoked to release the result.  Both callbacks take a
 // user_data argument to specify the client context.
+// To return an error, set the source_name to an empty string and put your
+// error message in content.
 
 // An include result.
 typedef struct shaderc_include_result {
@@ -285,9 +289,11 @@
   // in the sense that it should be a unique name in the context of the
   // includer.  For example, if the includer maps source names to files in
   // a filesystem, then this name should be the absolute path of the file.
+  // For a failed inclusion, this string is empty.
   const char* source_name;
   size_t source_name_length;
-  // The text contents of the source file.
+  // The text contents of the source file in the normal case.
+  // For a failed inclusion, this contains the error message.
   const char* content;
   size_t content_length;
   // User data to be passed along with this request.
diff --git a/third_party/Android.mk b/third_party/Android.mk
index 3c67bf4..fff2bf4 100644
--- a/third_party/Android.mk
+++ b/third_party/Android.mk
@@ -116,8 +116,7 @@
 SPV_CORE10_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/spirv.core.grammar.json
 SPV_CORE11_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.1/spirv.core.grammar.json
 SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/extinst.glsl.std.450.grammar.json
-# OpenCL grammar has not yet been published to SPIRV-Headers
-SPV_OPENCL_GRAMMAR=$(SPVTOOLS_LOCAL_PATH)/source/extinst-1.0.opencl.std.grammar.json
+SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/extinst.opencl.std.100.grammar.json
 
 define gen_spvtools_grammar_tables
 $(call generate-file-dir,$(1)/core.insts-1.0.inc)
@@ -215,7 +214,8 @@
 		source/validate_decorations.cpp \
 		source/validate_id.cpp \
 		source/validate_instruction.cpp \
-		source/validate_layout.cpp
+		source/validate_layout.cpp \
+		source/validate_type_unique.cpp
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)