blob: 11dda93427a803af2f3c4d37cec5ca665924b385 [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"}}
79 {{if eq (Macro "Vtbl" $f) "Instance"}}
Jesse Hallcf25c412015-10-29 17:14:50 -070080 {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))},
Jesse Hall04f4f472015-08-16 19:51:04 -070081 {{end}}
82 {{end}}
83 // clang-format on
84»};
85
86const NameProcEntry kDeviceProcTbl[] =
87 // clang-format off
88 {{range $f := SortBy (AllCommands $) "FunctionName"}}
89 {{if eq (Macro "Vtbl" $f) "Device"}}
Jesse Hallcf25c412015-10-29 17:14:50 -070090 {"{{Macro "FunctionName" $f}}", reinterpret_cast<PFN_vkVoidFunction>(static_cast<PFN_vk{{Macro "FunctionNameNoPrefix" $f}}>({{Macro "FunctionNameNoPrefix" $f}}))},
Jesse Hall04f4f472015-08-16 19:51:04 -070091 {{end}}
92 {{end}}
93 // clang-format on
94»};
95
96} // namespace
97
98namespace null_driver {
99
100PFN_vkVoidFunction LookupInstanceProcAddr(const char* name) {
101 return LookupProcAddr(kInstanceProcTbl, name);
102}
103
104PFN_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}}