vulkan: initial loader and null driver

Change-Id: Id5ebb5f01e61e9b114990f49c64c88fbbb7b730e
(cherry picked from commit 4df205cdfc61e66de774ba50be9ef59a08cf88bb)
diff --git a/vulkan/nulldrv/null_driver_gen.cpp.tmpl b/vulkan/nulldrv/null_driver_gen.cpp.tmpl
new file mode 100644
index 0000000..03a3d96
--- /dev/null
+++ b/vulkan/nulldrv/null_driver_gen.cpp.tmpl
@@ -0,0 +1,97 @@
+{{Include "../api/templates/vulkan_common.tmpl"}}
+{{Global "clang-format" (Strings "clang-format" "-style=file")}}
+{{Macro "DefineGlobals" $}}
+{{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}}
+
+
+{{/*
+-------------------------------------------------------------------------------
+  Entry point
+-------------------------------------------------------------------------------
+*/}}
+{{define "null_driver_gen.cpp"}}
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */

+// This file is generated. Do not edit manually!
+// To regenerate: $ apic template ../api/vulkan.api null_driver_gen.cpp.tmpl
+// Requires apic from https://android.googlesource.com/platform/tools/gpu/.

+#include <algorithm>
+#include "null_driver.h"

+using namespace null_driver;

+namespace {

+struct NameProcEntry {
+    const char* name;
+    PFN_vkVoidFunction proc;
+};

+template <size_t N>
+PFN_vkVoidFunction LookupProcAddr(const NameProcEntry (&table)[N], const char* name) {
+    auto entry = std::lower_bound(
+        table, table + N, name,
+        [](const NameProcEntry& e, const char* n) { return strcmp(e.name, n) < 0; });
+    if (entry != (table + N) && strcmp(entry->name, name) == 0)
+        return entry->proc;
+    return nullptr;
+}

+const NameProcEntry kInstanceProcTbl[] = {«
+  // clang-format off
+  {{range $f := SortBy (AllCommands $) "FunctionName"}}
+    {{if eq (Macro "Vtbl" $f) "Instance"}}
+      {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "FunctionNameNoPrefix" $f}})},
+    {{end}}
+  {{end}}
+  // clang-format on
+»};

+const NameProcEntry kDeviceProcTbl[] = {«
+  // clang-format off
+  {{range $f := SortBy (AllCommands $) "FunctionName"}}
+    {{if eq (Macro "Vtbl" $f) "Device"}}
+      {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "FunctionNameNoPrefix" $f}})},
+    {{end}}
+  {{end}}
+  // clang-format on
+»};

+} // namespace

+namespace null_driver {

+PFN_vkVoidFunction LookupInstanceProcAddr(const char* name) {
+    return LookupProcAddr(kInstanceProcTbl, name);
+}

+PFN_vkVoidFunction LookupDeviceProcAddr(const char* name) {
+    return LookupProcAddr(kDeviceProcTbl, name);
+}

+} // namespace null_driver

+{{end}}
+
+
+{{/*
+-------------------------------------------------------------------------------
+  Emits the name of a function without the "vk" prefix.
+-------------------------------------------------------------------------------
+*/}}
+{{define "FunctionNameNoPrefix"}}{{AssertType $ "Function"}}{{TrimPrefix "vk" $.Name}}{{end}}