Jesse Hall | d02edcb | 2015-09-08 07:44:48 -0700 | [diff] [blame] | 1 | {{/* |
| 2 | * Copyright 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */}} |
| 16 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 17 | {{Include "../api/templates/vulkan_common.tmpl"}} |
| 18 | {{Global "clang-format" (Strings "clang-format" "-style=file")}} |
| 19 | {{Macro "DefineGlobals" $}} |
| 20 | {{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}} |
| 21 | |
| 22 | |
| 23 | {{/* |
| 24 | ------------------------------------------------------------------------------- |
| 25 | Entry point |
| 26 | ------------------------------------------------------------------------------- |
| 27 | */}} |
| 28 | {{define "null_driver_gen.cpp"}} |
| 29 | /* |
| 30 | * Copyright 2015 The Android Open Source Project |
| 31 | * |
| 32 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 33 | * you may not use this file except in compliance with the License. |
| 34 | * You may obtain a copy of the License at |
| 35 | * |
| 36 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 37 | * |
| 38 | * Unless required by applicable law or agreed to in writing, software |
| 39 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 41 | * See the License for the specific language governing permissions and |
| 42 | * limitations under the License. |
| 43 | */ |
| 44 | ¶ |
| 45 | // This file is generated. Do not edit manually! |
| 46 | // To regenerate: $ apic template ../api/vulkan.api null_driver_gen.cpp.tmpl |
| 47 | // Requires apic from https://android.googlesource.com/platform/tools/gpu/. |
| 48 | ¶ |
| 49 | #include <algorithm> |
| 50 | #include "null_driver.h" |
| 51 | ¶ |
| 52 | using namespace null_driver; |
| 53 | ¶ |
| 54 | namespace { |
| 55 | ¶ |
| 56 | struct NameProcEntry { |
| 57 | const char* name; |
| 58 | PFN_vkVoidFunction proc; |
| 59 | }; |
| 60 | ¶ |
| 61 | template <size_t N> |
| 62 | PFN_vkVoidFunction LookupProcAddr(const NameProcEntry (&table)[N], const char* name) { |
| 63 | auto entry = std::lower_bound( |
| 64 | table, table + N, name, |
| 65 | [](const NameProcEntry& e, const char* n) { return strcmp(e.name, n) < 0; }); |
| 66 | if (entry != (table + N) && strcmp(entry->name, name) == 0) |
| 67 | return entry->proc; |
| 68 | return nullptr; |
| 69 | } |
| 70 | ¶ |
Jesse Hall | cf25c41 | 2015-10-29 17:14:50 -0700 | [diff] [blame^] | 71 | // The reinterpret_cast<..>(static_cast<..>(..)) business is there to ensure |
| 72 | // that the function declaration in null_driver.h matches the function pointer |
| 73 | // type in vulkan.h. If we just used reinterpret_cast<>, the compiler wouldn't |
| 74 | // tell us if there's a mistake in null_driver.h. A better solution would be to |
| 75 | // generate the declarations in null_driver.h. |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 76 | const NameProcEntry kInstanceProcTbl[] = {« |
| 77 | // clang-format off |
| 78 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 79 | {{if eq (Macro "Vtbl" $f) "Instance"}} |
Jesse Hall | cf25c41 | 2015-10-29 17:14:50 -0700 | [diff] [blame^] | 80 | {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))}, |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 81 | {{end}} |
| 82 | {{end}} |
| 83 | // clang-format on |
| 84 | »}; |
| 85 | ¶ |
| 86 | const NameProcEntry kDeviceProcTbl[] = {« |
| 87 | // clang-format off |
| 88 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 89 | {{if eq (Macro "Vtbl" $f) "Device"}} |
Jesse Hall | cf25c41 | 2015-10-29 17:14:50 -0700 | [diff] [blame^] | 90 | {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))}, |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 91 | {{end}} |
| 92 | {{end}} |
| 93 | // clang-format on |
| 94 | »}; |
| 95 | ¶ |
| 96 | } // namespace |
| 97 | ¶ |
| 98 | namespace null_driver { |
| 99 | ¶ |
| 100 | PFN_vkVoidFunction LookupInstanceProcAddr(const char* name) { |
| 101 | return LookupProcAddr(kInstanceProcTbl, name); |
| 102 | } |
| 103 | ¶ |
| 104 | PFN_vkVoidFunction LookupDeviceProcAddr(const char* name) { |
| 105 | return LookupProcAddr(kDeviceProcTbl, name); |
| 106 | } |
| 107 | ¶ |
| 108 | } // namespace null_driver |
| 109 | ¶ |
| 110 | {{end}} |
| 111 | |
| 112 | |
| 113 | {{/* |
| 114 | ------------------------------------------------------------------------------- |
| 115 | Emits the name of a function without the "vk" prefix. |
| 116 | ------------------------------------------------------------------------------- |
| 117 | */}} |
| 118 | {{define "FunctionNameNoPrefix"}}{{AssertType $ "Function"}}{{TrimPrefix "vk" $.Name}}{{end}} |