blob: 0f5301595c8d24ab0d194f7029a189b2a5d1e565 [file] [log] [blame]
Jesse Hall1f91d392015-12-11 16:28:44 -08001{{/*
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
17{{Include "../api/templates/vulkan_common.tmpl"}}
18{{Global "clang-format" (Strings "clang-format" "-style=file")}}
19{{Macro "DefineGlobals" $}}
20{{$ | Macro "null_driver_gen.h" | Format (Global "clang-format") | Write "null_driver_gen.h" }}
21{{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}}
22
23
24{{/*
25-------------------------------------------------------------------------------
26 null_driver_gen.h
27-------------------------------------------------------------------------------
28*/}}
29{{define "null_driver_gen.h"}}
30/*
31•* Copyright 2015 The Android Open Source Project
32•*
33•* Licensed under the Apache License, Version 2.0 (the "License");
34•* you may not use this file except in compliance with the License.
35•* You may obtain a copy of the License at
36•*
37•* http://www.apache.org/licenses/LICENSE-2.0
38•*
39•* Unless required by applicable law or agreed to in writing, software
40•* distributed under the License is distributed on an "AS IS" BASIS,
41•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42•* See the License for the specific language governing permissions and
43•* limitations under the License.
44•*/
45
Jesse Hall0a402092016-02-01 14:43:47 -080046// WARNING: This file is generated. See ../README.md for instructions.
Jesse Hall1f91d392015-12-11 16:28:44 -080047
48#ifndef NULLDRV_NULL_DRIVER_H
49#define NULLDRV_NULL_DRIVER_H 1
50
Jesse Hall1f91d392015-12-11 16:28:44 -080051#include <vulkan/vk_android_native_buffer.h>
52#include <vulkan/vulkan.h>
53
54namespace null_driver
55
56PFN_vkVoidFunction GetGlobalProcAddr(const char* name);
57PFN_vkVoidFunction GetInstanceProcAddr(const char* name);
58
59// clang-format off
60 {{range $f := AllCommands $}}
61 {{if (Macro "IsDriverFunction" $f)}}
62VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
63 {{end}}
64 {{end}}
65VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage);
66VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence);
Jesse Hall275d76c2016-01-08 22:39:16 -080067VKAPI_ATTR VkResult QueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd);
Jesse Hall1f91d392015-12-11 16:28:44 -080068// clang-format on
69
70»} // namespace null_driver
71
72#endif // NULLDRV_NULL_DRIVER_H
73¶{{end}}
74
75
76{{/*
77-------------------------------------------------------------------------------
78 null_driver_gen.cpp
79-------------------------------------------------------------------------------
80*/}}
81{{define "null_driver_gen.cpp"}}
82/*
83•* Copyright 2015 The Android Open Source Project
84•*
85•* Licensed under the Apache License, Version 2.0 (the "License");
86•* you may not use this file except in compliance with the License.
87•* You may obtain a copy of the License at
88•*
89•* http://www.apache.org/licenses/LICENSE-2.0
90•*
91•* Unless required by applicable law or agreed to in writing, software
92•* distributed under the License is distributed on an "AS IS" BASIS,
93•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94•* See the License for the specific language governing permissions and
95•* limitations under the License.
96•*/
97
Jesse Hall0a402092016-02-01 14:43:47 -080098// WARNING: This file is generated. See ../README.md for instructions.
Jesse Hall1f91d392015-12-11 16:28:44 -080099
Jesse Hall1f91d392015-12-11 16:28:44 -0800100#include <algorithm>
101
Yiwei Zhang6d78a572019-04-10 15:35:38 -0700102#include "null_driver_gen.h"
103
Jesse Hall1f91d392015-12-11 16:28:44 -0800104using namespace null_driver;
105
106namespace {
107
108struct NameProc {
109 const char* name;
110 PFN_vkVoidFunction proc;
111};
112
113PFN_vkVoidFunction Lookup(const char* name,
114 const NameProc* begin,
115 const NameProc* end) {
116 const auto& entry = std::lower_bound(
117 begin, end, name,
118 [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; });
119 if (entry == end || strcmp(entry->name, name) != 0)
120 return nullptr;
121 return entry->proc;
122}
123
124template <size_t N>
125PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) {
126 return Lookup(name, procs, procs + N);
127}
128
129const NameProc kGlobalProcs[] =
130 // clang-format off
131 {{range $f := SortBy (AllCommands $) "FunctionName"}}
132 {{if and (Macro "IsDriverFunction" $f) (eq (Macro "Vtbl" $f) "Global")}}
133 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
134 static_cast<{{Macro "FunctionPtrName" $f}}>(§
135 {{Macro "BaseName" $f}}))},
136 {{end}}
137 {{end}}
138 // clang-format on
139»};
140
141const NameProc kInstanceProcs[] =
142 // clang-format off
143 {{range $f := SortBy (AllCommands $) "FunctionName"}}
144 {{if (Macro "IsDriverFunction" $f)}}
145 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
146 static_cast<{{Macro "FunctionPtrName" $f}}>(§
147 {{Macro "BaseName" $f}}))},
148 {{end}}
149 {{end}}
150 // clang-format on
151»};
152
153} // namespace
154
155namespace null_driver {
156
157PFN_vkVoidFunction GetGlobalProcAddr(const char* name) {
158 return Lookup(name, kGlobalProcs);
159}
160
161PFN_vkVoidFunction GetInstanceProcAddr(const char* name)
Jesse Hall56d386a2016-07-26 15:20:40 -0700162 return Lookup(name, kInstanceProcs);
Jesse Hall1f91d392015-12-11 16:28:44 -0800163»}
164
165} // namespace null_driver
166
167{{end}}
168
169
170{{/*
171-------------------------------------------------------------------------------
172 Emits a function name without the "vk" prefix.
173-------------------------------------------------------------------------------
174*/}}
175{{define "BaseName"}}
176 {{AssertType $ "Function"}}
177 {{TrimPrefix "vk" $.Name}}
178{{end}}
179
180
181{{/*
182------------------------------------------------------------------------------
183 Emits 'true' if the API function is implemented by the driver.
184------------------------------------------------------------------------------
185*/}}
186{{define "IsDriverFunction"}}
187 {{AssertType $ "Function"}}
188
189 {{if not (GetAnnotation $ "pfn")}}
190 {{$ext := GetAnnotation $ "extension"}}
191 {{if $ext}}
192 {{Macro "IsDriverExtension" $ext}}
193 {{else}}
194 true
195 {{end}}
196 {{end}}
197{{end}}
198
199
200{{/*
201------------------------------------------------------------------------------
202 Reports whether an extension is implemented by the driver.
203------------------------------------------------------------------------------
204*/}}
205{{define "IsDriverExtension"}}
206 {{$ext := index $.Arguments 0}}
Jesse Hall715b86a2016-01-16 16:34:29 -0800207 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
208 {{else if eq $ext "VK_EXT_debug_report"}}true
Chris Forbes86bdfbe2017-01-26 12:45:49 +1300209 {{else if eq $ext "VK_KHR_get_physical_device_properties2"}}true
Jesse Hall1f91d392015-12-11 16:28:44 -0800210 {{end}}
211{{end}}