blob: 2c70d465cc96b0e11eef92ae6d6d8dd431e7d264 [file] [log] [blame]
Chia-I Wu0c203242016-03-15 13:44:51 +08001{{define "Copyright"}}
2/*
3•* Copyright 2016 The Android Open Source Project
4•*
5•* Licensed under the Apache License, Version 2.0 (the "License");
6•* you may not use this file except in compliance with the License.
7•* You may obtain a copy of the License at
8•*
9•* http://www.apache.org/licenses/LICENSE-2.0
10•*
11•* Unless required by applicable law or agreed to in writing, software
12•* distributed under the License is distributed on an "AS IS" BASIS,
13•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14•* See the License for the specific language governing permissions and
15•* limitations under the License.
16•*/
17¶{{end}}
18
19{{Include "../api/templates/vulkan_common.tmpl"}}
20{{Global "clang-format" (Strings "clang-format" "-style=file")}}
21{{Macro "DefineGlobals" $}}
22{{$ | Macro "api_gen.h" | Format (Global "clang-format") | Write "api_gen.h" }}
23{{$ | Macro "api_gen.cpp" | Format (Global "clang-format") | Write "api_gen.cpp"}}
Chia-I Wueb7db122016-03-24 09:11:06 +080024{{$ | Macro "driver_gen.h" | Format (Global "clang-format") | Write "driver_gen.h"}}
25{{$ | Macro "driver_gen.cpp" | Format (Global "clang-format") | Write "driver_gen.cpp"}}
Chia-I Wu0c203242016-03-15 13:44:51 +080026
27{{/*
28-------------------------------------------------------------------------------
29 api_gen.h
30-------------------------------------------------------------------------------
31*/}}
32{{define "api_gen.h"}}
33{{Macro "Copyright"}}
34
35// WARNING: This file is generated. See ../README.md for instructions.
36
37#ifndef LIBVULKAN_API_GEN_H
38#define LIBVULKAN_API_GEN_H
39
Chia-I Wu8925efd2016-04-13 15:13:21 +080040#include <bitset>
Chia-I Wu0c203242016-03-15 13:44:51 +080041#include <vulkan/vulkan.h>
Chia-I Wu8925efd2016-04-13 15:13:21 +080042#include "driver_gen.h"
Chia-I Wu0c203242016-03-15 13:44:51 +080043
44namespace vulkan
45namespace api
46
47struct InstanceDispatchTable {
48 // clang-format off
49 {{range $f := AllCommands $}}
50 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080051 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080052 {{end}}
53 {{end}}
54 // clang-format on
55};
56
57struct DeviceDispatchTable {
58 // clang-format off
59 {{range $f := AllCommands $}}
60 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080061 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080062 {{end}}
63 {{end}}
64 // clang-format on
65};
66
Chia-I Wu8925efd2016-04-13 15:13:21 +080067bool InitDispatchTable(
68 VkInstance instance,
69 PFN_vkGetInstanceProcAddr get_proc,
70 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
71bool InitDispatchTable(
72 VkDevice dev,
73 PFN_vkGetDeviceProcAddr get_proc,
74 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wu0c203242016-03-15 13:44:51 +080075
76»} // namespace api
77»} // namespace vulkan
78
79#endif // LIBVULKAN_API_GEN_H
80¶{{end}}
81
82
83{{/*
84-------------------------------------------------------------------------------
85 api_gen.cpp
86-------------------------------------------------------------------------------
87*/}}
88{{define "api_gen.cpp"}}
89{{Macro "Copyright"}}
90
91// WARNING: This file is generated. See ../README.md for instructions.
92
93#include <string.h>
94#include <algorithm>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070095#include <android/log.h>
Chia-I Wu0c203242016-03-15 13:44:51 +080096
Chia-I Wu3e654dc2016-05-20 16:15:06 +080097// to catch mismatches between vulkan.h and this file
98#undef VK_NO_PROTOTYPES
Chia-I Wu0c203242016-03-15 13:44:51 +080099#include "api.h"
100
101namespace vulkan
102namespace api
103
Chia-I Wucc5e2762016-03-24 13:01:16 +0800104{{Macro "C++.DefineInitProcMacro" "dispatch"}}
105
106{{Macro "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800107
Chia-I Wu8925efd2016-04-13 15:13:21 +0800108namespace
109
110// clang-format off
111
112{{range $f := AllCommands $}}
113 {{Macro "api.C++.DefineExtensionStub" $f}}
114{{end}}
115// clang-format on
116
117»} // anonymous
118
119bool InitDispatchTable(
120 VkInstance instance,
121 PFN_vkGetInstanceProcAddr get_proc,
122 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800123 auto& data = GetData(instance);
124 bool success = true;
125
126 // clang-format off
127 {{range $f := AllCommands $}}
128 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
129 {{Macro "C++.InitProc" $f}}
130 {{end}}
131 {{end}}
132 // clang-format on
133
134 return success;
135}
136
Chia-I Wu8925efd2016-04-13 15:13:21 +0800137bool InitDispatchTable(
138 VkDevice dev,
139 PFN_vkGetDeviceProcAddr get_proc,
140 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800141 auto& data = GetData(dev);
142 bool success = true;
143
144 // clang-format off
145 {{range $f := AllCommands $}}
146 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
147 {{Macro "C++.InitProc" $f}}
148 {{end}}
149 {{end}}
150 // clang-format on
151
152 return success;
153}
154
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800155// clang-format off
156
157namespace
158
159// forward declarations needed by GetInstanceProcAddr and GetDeviceProcAddr
160{{range $f := AllCommands $}}
161 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
162 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
163 {{end}}
164{{end}}
165
166{{range $f := AllCommands $}}
167 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
168 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}) {
169 {{ if eq $f.Name "vkGetInstanceProcAddr"}}
170 {{Macro "api.C++.InterceptInstanceProcAddr" $}}
171 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
172 {{Macro "api.C++.InterceptDeviceProcAddr" $}}
173 {{end}}
174
175 {{Macro "api.C++.Dispatch" $f}}
176 }
177
178 {{end}}
179{{end}}
180
181»} // anonymous namespace
182
183// clang-format on
184
Chia-I Wu0c203242016-03-15 13:44:51 +0800185»} // namespace api
186»} // namespace vulkan
187
188// clang-format off
189
190{{range $f := AllCommands $}}
191 {{if (Macro "IsFunctionExported" $f)}}
192 __attribute__((visibility("default")))
193 VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800194 {{if not (IsVoid $f.Return.Type)}}return §{{end}}
195 vulkan::api::{{Macro "BaseName" $f}}({{Macro "Arguments" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800196 }
197
198 {{end}}
199{{end}}
200
201// clang-format on
202¶{{end}}
203
204
205{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800206-------------------------------------------------------------------------------
207 driver_gen.h
208-------------------------------------------------------------------------------
209*/}}
210{{define "driver_gen.h"}}
211{{Macro "Copyright"}}
212
213// WARNING: This file is generated. See ../README.md for instructions.
214
215#ifndef LIBVULKAN_DRIVER_GEN_H
216#define LIBVULKAN_DRIVER_GEN_H
217
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800218#include <bitset>
Chia-I Wueb7db122016-03-24 09:11:06 +0800219#include <vulkan/vulkan.h>
220#include <vulkan/vk_android_native_buffer.h>
221
222namespace vulkan
223namespace driver
224
225{{Macro "driver.C++.DefineProcHookType"}}
226
Chia-I Wucc5e2762016-03-24 13:01:16 +0800227struct InstanceDriverTable {
228 // clang-format off
229 {{range $f := AllCommands $}}
230 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
231 {{Macro "C++.DeclareTableEntry" $f}};
232 {{end}}
233 {{end}}
234 // clang-format on
235};
236
237struct DeviceDriverTable {
238 // clang-format off
239 {{range $f := AllCommands $}}
240 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
241 {{Macro "C++.DeclareTableEntry" $f}};
242 {{end}}
243 {{end}}
244 // clang-format on
245};
246
Chia-I Wueb7db122016-03-24 09:11:06 +0800247const ProcHook* GetProcHook(const char* name);
248ProcHook::Extension GetProcHookExtension(const char* name);
249
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800250bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
251 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
252bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
253 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800254
Chia-I Wueb7db122016-03-24 09:11:06 +0800255»} // namespace driver
256»} // namespace vulkan
257
258#endif // LIBVULKAN_DRIVER_TABLE_H
259¶{{end}}
260
261
262{{/*
263-------------------------------------------------------------------------------
264 driver_gen.cpp
265-------------------------------------------------------------------------------
266*/}}
267{{define "driver_gen.cpp"}}
268{{Macro "Copyright"}}
269
270// WARNING: This file is generated. See ../README.md for instructions.
271
272#include <string.h>
273#include <algorithm>
Mark Salyzyna5e161b2016-09-29 08:08:05 -0700274#include <android/log.h>
Chia-I Wueb7db122016-03-24 09:11:06 +0800275
276#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800277
278namespace vulkan
279namespace driver
280
281namespace
282
283// clang-format off
284
285{{range $f := AllCommands $}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800286 {{Macro "driver.C++.DefineProcHookStub" $f}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800287{{end}}
288// clang-format on
289
290const ProcHook g_proc_hooks[] = {
291 // clang-format off
292 {{range $f := SortBy (AllCommands $) "FunctionName"}}
293 {{if (Macro "driver.IsIntercepted" $f)}}
294 {{ if (Macro "IsGloballyDispatched" $f)}}
295 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
296 {{else if (Macro "IsInstanceDispatched" $f)}}
297 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
298 {{else if (Macro "IsDeviceDispatched" $f)}}
299 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
300 {{end}}
301 {{end}}
302 {{end}}
303 // clang-format on
304};
305
306»} // anonymous
307
308const ProcHook* GetProcHook(const char* name) {
309 const auto& begin = g_proc_hooks;
310 const auto& end = g_proc_hooks +
311 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
312 const auto hook = std::lower_bound(begin, end, name,
313 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
314 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
315}
316
317ProcHook::Extension GetProcHookExtension(const char* name) {
318 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
319 // clang-format off
320 {{range $e := $exts}}
321 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
322 {{end}}
323 // clang-format on
324 return ProcHook::EXTENSION_UNKNOWN;
325}
326
Chia-I Wucc5e2762016-03-24 13:01:16 +0800327{{Macro "C++.DefineInitProcMacro" "driver"}}
328
329{{Macro "driver.C++.DefineInitProcExtMacro"}}
330
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800331bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
332 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800333{
334 auto& data = GetData(instance);
335 bool success = true;
336
337 // clang-format off
338 {{range $f := AllCommands $}}
339 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
340 {{Macro "C++.InitProc" $f}}
341 {{end}}
342 {{end}}
343 // clang-format on
344
345 return success;
346}
347
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800348bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
349 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800350{
351 auto& data = GetData(dev);
352 bool success = true;
353
354 // clang-format off
355 {{range $f := AllCommands $}}
356 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
357 {{Macro "C++.InitProc" $f}}
358 {{end}}
359 {{end}}
360 // clang-format on
361
362 return success;
363}
364
Chia-I Wueb7db122016-03-24 09:11:06 +0800365»} // namespace driver
366»} // namespace vulkan
367
368// clang-format on
369¶{{end}}
370
371
372{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800373------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800374 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800375------------------------------------------------------------------------------
376*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800377{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800378 {{AssertType $ "Function"}}
379
380 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
381{{end}}
382
383
384{{/*
385-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800386 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800387-------------------------------------------------------------------------------
388*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800389{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800390 #define UNLIKELY(expr) __builtin_expect((expr), 0)
391
Chris Forbes5948b3e2016-12-23 13:49:53 +1300392 #define INIT_PROC(required, obj, proc) do { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800393 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
394 get_proc(obj, "vk" # proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300395 if (UNLIKELY(required && !data.{{$}}.proc)) { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800396 ALOGE("missing " # obj " proc: vk" # proc); \
397 success = false; \
398 } \
399 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800400{{end}}
401
402
403{{/*
404-------------------------------------------------------------------------------
405 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
406-------------------------------------------------------------------------------
407*/}}
408{{define "C++.InitProc"}}
409 {{AssertType $ "Function"}}
410
411 {{$ext := GetAnnotation $ "extension"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300412 {{$required := (Macro "IsRequiredFunction" $)}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800413 {{if $ext}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300414 INIT_PROC_EXT({{Macro "BaseName" $ext}}, {{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800415 {{else}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300416 INIT_PROC({{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800417 {{end}}
418
419 {{if (Macro "IsInstanceDispatched" $)}}
420 instance, §
421 {{else}}
422 dev, §
423 {{end}}
424
425 {{Macro "BaseName" $}});
426{{end}}
427
428
429{{/*
430------------------------------------------------------------------------------
Chris Forbes5948b3e2016-12-23 13:49:53 +1300431 Emits true if a function /must/ be resolved. The only time this is not
432 the case is for extension-added functions added in a later revision of the
433 extension, and where we have to cope with drivers written against an older
434 revision.
435------------------------------------------------------------------------------
436*/}}
437{{define "IsRequiredFunction"}}
438 {{AssertType $ "Function"}}
439
440 {{if eq $.Name "vkGetSwapchainGrallocUsage2ANDROID"}}
441 false
442 {{else}}
443 true
444 {{end}}
445{{end}}
446
447
448{{/*
449------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +0800450 Emits true if a function is exported and instance-dispatched.
451------------------------------------------------------------------------------
452*/}}
453{{define "api.IsInstanceDispatchTableEntry"}}
454 {{AssertType $ "Function"}}
455
456 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
Chia-I Wudbd33bc2016-06-02 11:25:47 +0800457 {{/* deprecated and unused internally */}}
458 {{if not (eq $.Name "vkEnumerateDeviceLayerProperties")}}
459 true
460 {{end}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800461 {{end}}
462{{end}}
463
464
465{{/*
466------------------------------------------------------------------------------
467 Emits true if a function is exported and device-dispatched.
468------------------------------------------------------------------------------
469*/}}
470{{define "api.IsDeviceDispatchTableEntry"}}
471 {{AssertType $ "Function"}}
472
473 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
474 true
475 {{end}}
476{{end}}
477
478
479{{/*
480------------------------------------------------------------------------------
481 Emits true if a function is intercepted by vulkan::api.
482------------------------------------------------------------------------------
483*/}}
484{{define "api.IsIntercepted"}}
485 {{AssertType $ "Function"}}
486
487 {{if (Macro "IsFunctionSupported" $)}}
488 {{/* Global functions cannot be dispatched at all */}}
489 {{ if (Macro "IsGloballyDispatched" $)}}true
490
491 {{/* VkPhysicalDevice functions that manage device layers */}}
492 {{else if eq $.Name "vkCreateDevice"}}true
493 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
494 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
495
496 {{/* Destroy functions of dispatchable objects */}}
497 {{else if eq $.Name "vkDestroyInstance"}}true
498 {{else if eq $.Name "vkDestroyDevice"}}true
499
500 {{end}}
501 {{end}}
502{{end}}
503
504
505{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800506-------------------------------------------------------------------------------
507 Emits INIT_PROC_EXT macro for vulkan::api.
508-------------------------------------------------------------------------------
509*/}}
510{{define "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800511 // Exported extension functions may be invoked even when their extensions
512 // are disabled. Dispatch to stubs when that happens.
Chris Forbes5948b3e2016-12-23 13:49:53 +1300513 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800514 if (extensions[driver::ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300515 INIT_PROC(required, obj, proc); \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800516 else \
517 data.dispatch.proc = disabled ## proc; \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800518 } while(0)
519{{end}}
520
521
522{{/*
Chia-I Wu8925efd2016-04-13 15:13:21 +0800523-------------------------------------------------------------------------------
524 Emits a stub for an exported extension function.
525-------------------------------------------------------------------------------
526*/}}
527{{define "api.C++.DefineExtensionStub"}}
528 {{AssertType $ "Function"}}
529
530 {{$ext := GetAnnotation $ "extension"}}
531 {{if and $ext (Macro "IsFunctionExported" $)}}
532 {{$ext_name := index $ext.Arguments 0}}
533
534 {{$base := (Macro "BaseName" $)}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800535
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800536 {{$p0 := (index $.CallParameters 0)}}
537 {{$ptail := (Tail 1 $.CallParameters)}}
538
539 {{$first_type := (Macro "Parameter" $p0)}}
540 {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
541
542 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
543 driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
544 "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
Chia-I Wu8925efd2016-04-13 15:13:21 +0800545 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
546 }
547
548 {{end}}
549{{end}}
550
551
552{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800553------------------------------------------------------------------------------
554 Emits code for vkGetInstanceProcAddr for function interception.
555------------------------------------------------------------------------------
556*/}}
557{{define "api.C++.InterceptInstanceProcAddr"}}
558 {{AssertType $ "API"}}
559
560 // global functions
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800561 if (instance == VK_NULL_HANDLE) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800562 {{range $f := AllCommands $}}
563 {{if (Macro "IsGloballyDispatched" $f)}}
564 if (strcmp(pName, "{{$f.Name}}") == 0) return §
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800565 reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800566 {{end}}
567 {{end}}
568
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800569 ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
Chia-I Wu0c203242016-03-15 13:44:51 +0800570 return nullptr;
571 }
572
573 static const struct Hook {
574 const char* name;
575 PFN_vkVoidFunction proc;
576 } hooks[] = {
577 {{range $f := SortBy (AllCommands $) "FunctionName"}}
578 {{if (Macro "IsFunctionExported" $f)}}
579 {{/* hide global functions */}}
580 {{if (Macro "IsGloballyDispatched" $f)}}
581 { "{{$f.Name}}", nullptr },
582
583 {{/* redirect intercepted functions */}}
584 {{else if (Macro "api.IsIntercepted" $f)}}
585 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800586 {{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800587
588 {{/* redirect vkGetInstanceProcAddr to itself */}}
589 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800590 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800591
592 {{/* redirect device functions to themselves as a workaround for
593 layers that do not intercept in their vkGetInstanceProcAddr */}}
594 {{else if (Macro "IsDeviceDispatched" $f)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800595 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800596
597 {{end}}
598 {{end}}
599 {{end}}
600 };
601 // clang-format on
602 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
603 auto hook = std::lower_bound(
604 hooks, hooks + count, pName,
605 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
606 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800607 if (!hook->proc) {
608 vulkan::driver::Logger(instance).Err(
609 instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
610 instance, pName);
611 }
Chia-I Wu0c203242016-03-15 13:44:51 +0800612 return hook->proc;
613 }
614 // clang-format off
615
616{{end}}
617
618
619{{/*
620------------------------------------------------------------------------------
621 Emits code for vkGetDeviceProcAddr for function interception.
622------------------------------------------------------------------------------
623*/}}
624{{define "api.C++.InterceptDeviceProcAddr"}}
625 {{AssertType $ "API"}}
626
627 if (device == VK_NULL_HANDLE) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800628 ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
Chia-I Wu0c203242016-03-15 13:44:51 +0800629 return nullptr;
630 }
631
632 static const char* const known_non_device_names[] = {
633 {{range $f := SortBy (AllCommands $) "FunctionName"}}
634 {{if (Macro "IsFunctionSupported" $f)}}
635 {{if not (Macro "IsDeviceDispatched" $f)}}
636 "{{$f.Name}}",
637 {{end}}
638 {{end}}
639 {{end}}
640 };
641 // clang-format on
642 constexpr size_t count = sizeof(known_non_device_names) /
643 sizeof(known_non_device_names[0]);
644 if (!pName ||
645 std::binary_search(
646 known_non_device_names, known_non_device_names + count, pName,
647 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800648 vulkan::driver::Logger(device).Err
649 device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device
650 (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800651 return nullptr;
652 }
653 // clang-format off
654
Chia-I Wuc56603e2016-04-12 11:16:17 +0800655 {{range $f := AllCommands $}}
656 {{if (Macro "IsDeviceDispatched" $f)}}
657 {{ if (Macro "api.IsIntercepted" $f)}}
658 if (strcmp(pName, "{{$f.Name}}") == 0) return §
659 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800660 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800661 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
662 if (strcmp(pName, "{{$f.Name}}") == 0) return §
663 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800664 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800665 {{end}}
666 {{end}}
667 {{end}}
668
Chia-I Wu0c203242016-03-15 13:44:51 +0800669{{end}}
670
671
672{{/*
673------------------------------------------------------------------------------
674 Emits code to dispatch a function.
675------------------------------------------------------------------------------
676*/}}
677{{define "api.C++.Dispatch"}}
678 {{AssertType $ "Function"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800679 {{if (Macro "api.IsIntercepted" $)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800680 {{Error "$.Name should not be generated"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800681 {{end}}
682
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800683 {{if not (IsVoid $.Return.Type)}}return §{{end}}
684
685 {{$p0 := index $.CallParameters 0}}
686 GetData({{$p0.Name}}).dispatch
Chia-I Wu0c203242016-03-15 13:44:51 +0800687 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
688{{end}}
689
690
691{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800692------------------------------------------------------------------------------
693 Emits a list of extensions intercepted by vulkan::driver.
694------------------------------------------------------------------------------
695*/}}
696{{define "driver.InterceptedExtensions"}}
697VK_ANDROID_native_buffer
698VK_EXT_debug_report
699VK_KHR_android_surface
Ian Elliott948233a2017-01-06 12:13:23 -0700700VK_KHR_incremental_present
Chia-I Wueb7db122016-03-24 09:11:06 +0800701VK_KHR_surface
702VK_KHR_swapchain
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700703VK_KHR_incremental_present
704VK_GOOGLE_display_timing
Chia-I Wueb7db122016-03-24 09:11:06 +0800705{{end}}
706
707
708{{/*
709------------------------------------------------------------------------------
710 Emits true if an extension is intercepted by vulkan::driver.
711------------------------------------------------------------------------------
712*/}}
713{{define "driver.IsExtensionIntercepted"}}
714 {{$ext_name := index $.Arguments 0}}
715 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
716
717 {{range $f := $filters}}
718 {{if eq $ext_name $f}}true{{end}}
719 {{end}}
720{{end}}
721
722
723{{/*
724------------------------------------------------------------------------------
725 Emits true if a function is intercepted by vulkan::driver.
726------------------------------------------------------------------------------
727*/}}
728{{define "driver.IsIntercepted"}}
729 {{AssertType $ "Function"}}
730
731 {{if (Macro "IsFunctionSupported" $)}}
732 {{/* Create functions of dispatchable objects */}}
733 {{ if eq $.Name "vkCreateInstance"}}true
734 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800735 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800736 {{else if eq $.Name "vkGetDeviceQueue"}}true
737 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
738
739 {{/* Destroy functions of dispatchable objects */}}
740 {{else if eq $.Name "vkDestroyInstance"}}true
741 {{else if eq $.Name "vkDestroyDevice"}}true
742
743 {{/* Enumeration of extensions */}}
744 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
745 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
746
Chia-I Wueb7db122016-03-24 09:11:06 +0800747 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
748 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
749
750 {{end}}
751
752 {{$ext := GetAnnotation $ "extension"}}
753 {{if $ext}}
754 {{Macro "driver.IsExtensionIntercepted" $ext}}
755 {{end}}
756
757 {{end}}
758{{end}}
759
760
761{{/*
762------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800763 Emits true if a function needs a ProcHook stub.
Chia-I Wueb7db122016-03-24 09:11:06 +0800764------------------------------------------------------------------------------
765*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800766{{define "driver.NeedProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800767 {{AssertType $ "Function"}}
768
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800769 {{if and (Macro "driver.IsIntercepted" $) (Macro "IsDeviceDispatched" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800770 {{$ext := GetAnnotation $ "extension"}}
771 {{if $ext}}
772 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
773 {{end}}
774 {{end}}
775{{end}}
776
777
778{{/*
779-------------------------------------------------------------------------------
780 Emits definition of struct ProcHook.
781-------------------------------------------------------------------------------
782*/}}
783{{define "driver.C++.DefineProcHookType"}}
784 struct ProcHook {
785 enum Type {
786 GLOBAL,
787 INSTANCE,
788 DEVICE,
789 };
790
791 enum Extension {
792 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
793 {{range $e := $exts}}
794 {{TrimPrefix "VK_" $e}},
795 {{end}}
796
797 EXTENSION_CORE, // valid bit
798 EXTENSION_COUNT,
799 EXTENSION_UNKNOWN,
800 };
801
802 const char* name;
803 Type type;
804 Extension extension;
805
806 PFN_vkVoidFunction proc;
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800807 PFN_vkVoidFunction checked_proc; // always nullptr for non-device hooks
Chia-I Wueb7db122016-03-24 09:11:06 +0800808 };
809{{end}}
810
811
812{{/*
813-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800814 Emits INIT_PROC_EXT macro for vulkan::driver.
815-------------------------------------------------------------------------------
816*/}}
817{{define "driver.C++.DefineInitProcExtMacro"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300818 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800819 if (extensions[ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300820 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800821 } while(0)
822{{end}}
823
824
825{{/*
826-------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800827 Emits a stub for ProcHook::checked_proc.
Chia-I Wueb7db122016-03-24 09:11:06 +0800828-------------------------------------------------------------------------------
829*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800830{{define "driver.C++.DefineProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800831 {{AssertType $ "Function"}}
832
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800833 {{if (Macro "driver.NeedProcHookStub" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800834 {{$ext := GetAnnotation $ "extension"}}
835 {{$ext_name := index $ext.Arguments 0}}
836
837 {{$base := (Macro "BaseName" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800838
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800839 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
840 {{$p0 := index $.CallParameters 0}}
841 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800842
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800843 if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) {
844 {{if not (IsVoid $.Return.Type)}}return §{{end}}
845 {{$base}}({{Macro "Arguments" $}});
846 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800847 Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800848 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800849 }
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800850 }
Chia-I Wueb7db122016-03-24 09:11:06 +0800851
852 {{end}}
853{{end}}
854
855
856{{/*
857-------------------------------------------------------------------------------
858 Emits definition of a global ProcHook.
859-------------------------------------------------------------------------------
860*/}}
861{{define "driver.C++.DefineGlobalProcHook"}}
862 {{AssertType $ "Function"}}
863
864 {{$base := (Macro "BaseName" $)}}
865
866 {{$ext := GetAnnotation $ "extension"}}
867 {{if $ext}}
868 {{Error "invalid global extension"}}
869 {{end}}
870
871 {
872 "{{$.Name}}",
873 ProcHook::GLOBAL,
874 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800875 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800876 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800877 },
878{{end}}
879
880
881{{/*
882-------------------------------------------------------------------------------
883 Emits definition of an instance ProcHook.
884-------------------------------------------------------------------------------
885*/}}
886{{define "driver.C++.DefineInstanceProcHook"}}
887 {{AssertType $ "Function"}}
888
889 {{$base := (Macro "BaseName" $)}}
890
891 {
892 "{{$.Name}}",
893 ProcHook::INSTANCE,
894
895 {{$ext := GetAnnotation $ "extension"}}
896 {{if $ext}}
897 ProcHook::{{Macro "BaseName" $ext}},
898
899 {{if (Macro "IsExtensionInternal" $ext)}}
900 nullptr,
901 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800902 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800903 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800904 nullptr,
905 {{end}}
906 {{else}}
907 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800908 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800909 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800910 {{end}}
911 },
912{{end}}
913
914
915{{/*
916-------------------------------------------------------------------------------
917 Emits definition of a device ProcHook.
918-------------------------------------------------------------------------------
919*/}}
920{{define "driver.C++.DefineDeviceProcHook"}}
921 {{AssertType $ "Function"}}
922
923 {{$base := (Macro "BaseName" $)}}
924
925 {
926 "{{$.Name}}",
927 ProcHook::DEVICE,
928
929 {{$ext := GetAnnotation $ "extension"}}
930 {{if $ext}}
931 ProcHook::{{Macro "BaseName" $ext}},
932
933 {{if (Macro "IsExtensionInternal" $ext)}}
934 nullptr,
935 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800936 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800937 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800938 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
939 {{end}}
940 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800941 ProcHook::EXTENSION_CORE,
942 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
943 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800944 {{end}}
945 },
946{{end}}
947
948
949{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800950-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800951 Emits true if a function is needed by vulkan::driver.
952-------------------------------------------------------------------------------
953*/}}
954{{define "driver.IsDriverTableEntry"}}
955 {{AssertType $ "Function"}}
956
957 {{if (Macro "IsFunctionSupported" $)}}
958 {{/* Create functions of dispatchable objects */}}
959 {{ if eq $.Name "vkCreateDevice"}}true
960 {{else if eq $.Name "vkGetDeviceQueue"}}true
961 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
962
963 {{/* Destroy functions of dispatchable objects */}}
964 {{else if eq $.Name "vkDestroyInstance"}}true
965 {{else if eq $.Name "vkDestroyDevice"}}true
966
967 {{/* Enumeration of extensions */}}
968 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
969
970 {{/* We cache physical devices in loader.cpp */}}
971 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
972
973 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
974 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
975
976 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
977 {{else if eq $.Name "vkCreateImage"}}true
978 {{else if eq $.Name "vkDestroyImage"}}true
979
980 {{end}}
981
982 {{$ext := GetAnnotation $ "extension"}}
983 {{if $ext}}
984 {{$ext_name := index $ext.Arguments 0}}
985 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
986 {{else if eq $ext_name "VK_EXT_debug_report"}}true
987 {{end}}
988 {{end}}
989 {{end}}
990{{end}}
991
992
993{{/*
994------------------------------------------------------------------------------
995 Emits true if an instance-dispatched function is needed by vulkan::driver.
996------------------------------------------------------------------------------
997*/}}
998{{define "driver.IsInstanceDriverTableEntry"}}
999 {{AssertType $ "Function"}}
1000
1001 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1002 true
1003 {{end}}
1004{{end}}
1005
1006
1007{{/*
1008------------------------------------------------------------------------------
1009 Emits true if a device-dispatched function is needed by vulkan::driver.
1010------------------------------------------------------------------------------
1011*/}}
1012{{define "driver.IsDeviceDriverTableEntry"}}
1013 {{AssertType $ "Function"}}
1014
1015 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1016 true
1017 {{end}}
1018{{end}}
1019
1020
1021{{/*
1022-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001023 Emits a function/extension name without the "vk"/"VK_" prefix.
1024-------------------------------------------------------------------------------
1025*/}}
1026{{define "BaseName"}}
1027 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1028 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1029 {{else}}{{Error "invalid use of BaseName"}}
1030 {{end}}
1031{{end}}
1032
1033
1034{{/*
1035-------------------------------------------------------------------------------
1036 Emits a comma-separated list of C parameter names for the given command.
1037-------------------------------------------------------------------------------
1038*/}}
1039{{define "Arguments"}}
1040 {{AssertType $ "Function"}}
1041
1042 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1043{{end}}
1044
1045
1046{{/*
1047------------------------------------------------------------------------------
1048------------------------------------------------------------------------------
1049*/}}
1050{{define "IsGloballyDispatched"}}
1051 {{AssertType $ "Function"}}
1052 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1053 true
1054 {{end}}
1055{{end}}
1056
1057
1058{{/*
1059------------------------------------------------------------------------------
1060 Emit "true" for supported functions that undergo table dispatch. Only global
1061 functions and functions handled in the loader top without calling into
1062 lower layers are not dispatched.
1063------------------------------------------------------------------------------
1064*/}}
1065{{define "IsInstanceDispatched"}}
1066 {{AssertType $ "Function"}}
1067 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1068 true
1069 {{end}}
1070{{end}}
1071
1072
1073{{/*
1074------------------------------------------------------------------------------
1075 Emit "true" for supported functions that can have device-specific dispatch.
1076------------------------------------------------------------------------------
1077*/}}
1078{{define "IsDeviceDispatched"}}
1079 {{AssertType $ "Function"}}
1080 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1081 true
1082 {{end}}
1083{{end}}
1084
1085
1086{{/*
1087------------------------------------------------------------------------------
1088 Emit "true" if a function is core or from a supportable extension.
1089------------------------------------------------------------------------------
1090*/}}
1091{{define "IsFunctionSupported"}}
1092 {{AssertType $ "Function"}}
1093 {{if not (GetAnnotation $ "pfn")}}
1094 {{$ext := GetAnnotation $ "extension"}}
1095 {{if not $ext}}true
1096 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1097 {{end}}
1098 {{end}}
1099{{end}}
1100
1101
1102{{/*
1103------------------------------------------------------------------------------
1104 Decides whether a function should be exported from the Android Vulkan
1105 library. Functions in the core API and in loader extensions are exported.
1106------------------------------------------------------------------------------
1107*/}}
1108{{define "IsFunctionExported"}}
1109 {{AssertType $ "Function"}}
1110
1111 {{if (Macro "IsFunctionSupported" $)}}
1112 {{$ext := GetAnnotation $ "extension"}}
1113 {{if $ext}}
1114 {{Macro "IsExtensionExported" $ext}}
1115 {{else}}
1116 true
1117 {{end}}
1118 {{end}}
1119{{end}}
1120
1121
1122{{/*
1123------------------------------------------------------------------------------
1124 Emit "true" if an extension is unsupportable on Android.
1125------------------------------------------------------------------------------
1126*/}}
1127{{define "IsExtensionBlacklisted"}}
1128 {{$ext := index $.Arguments 0}}
1129 {{ if eq $ext "VK_KHR_display"}}true
1130 {{else if eq $ext "VK_KHR_display_swapchain"}}true
1131 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1132 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1133 {{else if eq $ext "VK_KHR_wayland_surface"}}true
1134 {{else if eq $ext "VK_KHR_mir_surface"}}true
1135 {{else if eq $ext "VK_KHR_win32_surface"}}true
1136 {{end}}
1137{{end}}
1138
1139
1140{{/*
1141------------------------------------------------------------------------------
1142 Reports whether an extension is implemented entirely by the loader,
1143 so drivers should not enumerate it.
1144------------------------------------------------------------------------------
1145*/}}
1146{{define "IsExtensionExported"}}
1147 {{$ext := index $.Arguments 0}}
1148 {{ if eq $ext "VK_KHR_surface"}}true
1149 {{else if eq $ext "VK_KHR_swapchain"}}true
1150 {{else if eq $ext "VK_KHR_android_surface"}}true
Ian Elliott948233a2017-01-06 12:13:23 -07001151 {{else if eq $ext "VK_KHR_incremental_present"}}true
Ian Elliott4c8bb2a2016-12-29 11:07:26 -07001152 {{else if eq $ext "VK_GOOGLE_display_timing"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001153 {{end}}
1154{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001155
1156
1157{{/*
1158------------------------------------------------------------------------------
1159 Reports whether an extension is internal to the loader and drivers,
1160 so the loader should not enumerate it.
1161------------------------------------------------------------------------------
1162*/}}
1163{{define "IsExtensionInternal"}}
1164 {{$ext := index $.Arguments 0}}
1165 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1166 {{end}}
1167{{end}}