blob: d749c6ecc958a3cdbb3e4d454d60de2dd1a989b0 [file] [log] [blame]
Jesse Halld02edcb2015-09-08 07:44:48 -07001{{/*
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 Hall04f4f472015-08-16 19:51:04 -070017{{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
52using namespace null_driver;
53
54namespace {
55
56struct NameProcEntry {
57 const char* name;
58 PFN_vkVoidFunction proc;
59};
60
61template <size_t N>
62PFN_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 Hallcf25c412015-10-29 17:14:50 -070071// 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 Hall04f4f472015-08-16 19:51:04 -070076const NameProcEntry kInstanceProcTbl[] =
77 // clang-format off
78 {{range $f := SortBy (AllCommands $) "FunctionName"}}
Jesse Hall2818f932015-11-19 21:19:17 -080079 {{if not (GetAnnotation $f "extension")}}
80 {{if eq (Macro "Vtbl" $f) "Instance"}}
81 {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))},
82 {{end}}
Jesse Hall04f4f472015-08-16 19:51:04 -070083 {{end}}
84 {{end}}
85 // clang-format on
86»};
87
88const NameProcEntry kDeviceProcTbl[] =
89 // clang-format off
90 {{range $f := SortBy (AllCommands $) "FunctionName"}}
Jesse Hall2818f932015-11-19 21:19:17 -080091 {{if not (GetAnnotation $f "extension")}}
92 {{if eq (Macro "Vtbl" $f) "Device"}}
93 {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))},
94 {{end}}
Jesse Hall04f4f472015-08-16 19:51:04 -070095 {{end}}
96 {{end}}
97 // clang-format on
98»};
99
100} // namespace
101
102namespace null_driver {
103
104PFN_vkVoidFunction LookupInstanceProcAddr(const char* name) {
105 return LookupProcAddr(kInstanceProcTbl, name);
106}
107
108PFN_vkVoidFunction LookupDeviceProcAddr(const char* name) {
109 return LookupProcAddr(kDeviceProcTbl, name);
110}
111
112} // namespace null_driver
113
114{{end}}
115
116
117{{/*
118-------------------------------------------------------------------------------
119 Emits the name of a function without the "vk" prefix.
120-------------------------------------------------------------------------------
121*/}}
122{{define "FunctionNameNoPrefix"}}{{AssertType $ "Function"}}{{TrimPrefix "vk" $.Name}}{{end}}