blob: 9021972389836820490a75a9787079f90782716f [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>
Mark Salyzyn7823e122016-09-29 08:08:05 -070094
Chia-I Wu0c203242016-03-15 13:44:51 +080095#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -070096
97#include <log/log.h>
Chia-I Wu0c203242016-03-15 13:44:51 +080098
Chia-I Wu3e654dc2016-05-20 16:15:06 +080099// to catch mismatches between vulkan.h and this file
100#undef VK_NO_PROTOTYPES
Chia-I Wu0c203242016-03-15 13:44:51 +0800101#include "api.h"
102
103namespace vulkan
104namespace api
105
Chia-I Wucc5e2762016-03-24 13:01:16 +0800106{{Macro "C++.DefineInitProcMacro" "dispatch"}}
107
108{{Macro "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800109
Chia-I Wu8925efd2016-04-13 15:13:21 +0800110namespace
111
112// clang-format off
113
114{{range $f := AllCommands $}}
115 {{Macro "api.C++.DefineExtensionStub" $f}}
116{{end}}
117// clang-format on
118
119»} // anonymous
120
121bool InitDispatchTable(
122 VkInstance instance,
123 PFN_vkGetInstanceProcAddr get_proc,
124 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800125 auto& data = GetData(instance);
126 bool success = true;
127
128 // clang-format off
129 {{range $f := AllCommands $}}
130 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
131 {{Macro "C++.InitProc" $f}}
132 {{end}}
133 {{end}}
134 // clang-format on
135
136 return success;
137}
138
Chia-I Wu8925efd2016-04-13 15:13:21 +0800139bool InitDispatchTable(
140 VkDevice dev,
141 PFN_vkGetDeviceProcAddr get_proc,
142 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800143 auto& data = GetData(dev);
144 bool success = true;
145
146 // clang-format off
147 {{range $f := AllCommands $}}
148 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
149 {{Macro "C++.InitProc" $f}}
150 {{end}}
151 {{end}}
152 // clang-format on
153
154 return success;
155}
156
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800157// clang-format off
158
159namespace
160
161// forward declarations needed by GetInstanceProcAddr and GetDeviceProcAddr
162{{range $f := AllCommands $}}
163 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
164 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
165 {{end}}
166{{end}}
167
168{{range $f := AllCommands $}}
169 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
170 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}) {
171 {{ if eq $f.Name "vkGetInstanceProcAddr"}}
172 {{Macro "api.C++.InterceptInstanceProcAddr" $}}
173 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
174 {{Macro "api.C++.InterceptDeviceProcAddr" $}}
175 {{end}}
176
177 {{Macro "api.C++.Dispatch" $f}}
178 }
179
180 {{end}}
181{{end}}
182
183»} // anonymous namespace
184
185// clang-format on
186
Chia-I Wu0c203242016-03-15 13:44:51 +0800187»} // namespace api
188»} // namespace vulkan
189
190// clang-format off
191
192{{range $f := AllCommands $}}
193 {{if (Macro "IsFunctionExported" $f)}}
194 __attribute__((visibility("default")))
195 VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800196 {{if not (IsVoid $f.Return.Type)}}return §{{end}}
197 vulkan::api::{{Macro "BaseName" $f}}({{Macro "Arguments" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800198 }
199
200 {{end}}
201{{end}}
202
203// clang-format on
204¶{{end}}
205
206
207{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800208-------------------------------------------------------------------------------
209 driver_gen.h
210-------------------------------------------------------------------------------
211*/}}
212{{define "driver_gen.h"}}
213{{Macro "Copyright"}}
214
215// WARNING: This file is generated. See ../README.md for instructions.
216
217#ifndef LIBVULKAN_DRIVER_GEN_H
218#define LIBVULKAN_DRIVER_GEN_H
219
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800220#include <bitset>
Chia-I Wueb7db122016-03-24 09:11:06 +0800221#include <vulkan/vulkan.h>
222#include <vulkan/vk_android_native_buffer.h>
223
224namespace vulkan
225namespace driver
226
227{{Macro "driver.C++.DefineProcHookType"}}
228
Chia-I Wucc5e2762016-03-24 13:01:16 +0800229struct InstanceDriverTable {
230 // clang-format off
231 {{range $f := AllCommands $}}
232 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
233 {{Macro "C++.DeclareTableEntry" $f}};
234 {{end}}
235 {{end}}
236 // clang-format on
237};
238
239struct DeviceDriverTable {
240 // clang-format off
241 {{range $f := AllCommands $}}
242 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
243 {{Macro "C++.DeclareTableEntry" $f}};
244 {{end}}
245 {{end}}
246 // clang-format on
247};
248
Chia-I Wueb7db122016-03-24 09:11:06 +0800249const ProcHook* GetProcHook(const char* name);
250ProcHook::Extension GetProcHookExtension(const char* name);
251
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800252bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
253 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
254bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
255 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800256
Chia-I Wueb7db122016-03-24 09:11:06 +0800257»} // namespace driver
258»} // namespace vulkan
259
260#endif // LIBVULKAN_DRIVER_TABLE_H
261¶{{end}}
262
263
264{{/*
265-------------------------------------------------------------------------------
266 driver_gen.cpp
267-------------------------------------------------------------------------------
268*/}}
269{{define "driver_gen.cpp"}}
270{{Macro "Copyright"}}
271
272// WARNING: This file is generated. See ../README.md for instructions.
273
274#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700275
Chia-I Wueb7db122016-03-24 09:11:06 +0800276#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700277
278#include <log/log.h>
Chia-I Wueb7db122016-03-24 09:11:06 +0800279
280#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800281
282namespace vulkan
283namespace driver
284
285namespace
286
287// clang-format off
288
289{{range $f := AllCommands $}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800290 {{Macro "driver.C++.DefineProcHookStub" $f}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800291{{end}}
292// clang-format on
293
294const ProcHook g_proc_hooks[] = {
295 // clang-format off
296 {{range $f := SortBy (AllCommands $) "FunctionName"}}
297 {{if (Macro "driver.IsIntercepted" $f)}}
298 {{ if (Macro "IsGloballyDispatched" $f)}}
299 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
300 {{else if (Macro "IsInstanceDispatched" $f)}}
301 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
302 {{else if (Macro "IsDeviceDispatched" $f)}}
303 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
304 {{end}}
305 {{end}}
306 {{end}}
307 // clang-format on
308};
309
310»} // anonymous
311
312const ProcHook* GetProcHook(const char* name) {
313 const auto& begin = g_proc_hooks;
314 const auto& end = g_proc_hooks +
315 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
316 const auto hook = std::lower_bound(begin, end, name,
317 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
318 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
319}
320
321ProcHook::Extension GetProcHookExtension(const char* name) {
322 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
323 // clang-format off
324 {{range $e := $exts}}
325 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
326 {{end}}
327 // clang-format on
328 return ProcHook::EXTENSION_UNKNOWN;
329}
330
Chia-I Wucc5e2762016-03-24 13:01:16 +0800331{{Macro "C++.DefineInitProcMacro" "driver"}}
332
333{{Macro "driver.C++.DefineInitProcExtMacro"}}
334
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800335bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
336 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800337{
338 auto& data = GetData(instance);
339 bool success = true;
340
341 // clang-format off
342 {{range $f := AllCommands $}}
343 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
344 {{Macro "C++.InitProc" $f}}
345 {{end}}
346 {{end}}
347 // clang-format on
348
349 return success;
350}
351
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800352bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
353 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800354{
355 auto& data = GetData(dev);
356 bool success = true;
357
358 // clang-format off
359 {{range $f := AllCommands $}}
360 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
361 {{Macro "C++.InitProc" $f}}
362 {{end}}
363 {{end}}
364 // clang-format on
365
366 return success;
367}
368
Chia-I Wueb7db122016-03-24 09:11:06 +0800369»} // namespace driver
370»} // namespace vulkan
371
372// clang-format on
373¶{{end}}
374
375
376{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800377------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800378 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800379------------------------------------------------------------------------------
380*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800381{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800382 {{AssertType $ "Function"}}
383
384 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
385{{end}}
386
387
388{{/*
389-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800390 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800391-------------------------------------------------------------------------------
392*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800393{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800394 #define UNLIKELY(expr) __builtin_expect((expr), 0)
395
Chris Forbes5948b3e2016-12-23 13:49:53 +1300396 #define INIT_PROC(required, obj, proc) do { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800397 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
398 get_proc(obj, "vk" # proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300399 if (UNLIKELY(required && !data.{{$}}.proc)) { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800400 ALOGE("missing " # obj " proc: vk" # proc); \
401 success = false; \
402 } \
403 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800404{{end}}
405
406
407{{/*
408-------------------------------------------------------------------------------
409 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
410-------------------------------------------------------------------------------
411*/}}
412{{define "C++.InitProc"}}
413 {{AssertType $ "Function"}}
414
415 {{$ext := GetAnnotation $ "extension"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300416 {{$required := (Macro "IsRequiredFunction" $)}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800417 {{if $ext}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300418 INIT_PROC_EXT({{Macro "BaseName" $ext}}, {{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800419 {{else}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300420 INIT_PROC({{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800421 {{end}}
422
423 {{if (Macro "IsInstanceDispatched" $)}}
424 instance, §
425 {{else}}
426 dev, §
427 {{end}}
428
429 {{Macro "BaseName" $}});
430{{end}}
431
432
433{{/*
434------------------------------------------------------------------------------
Chris Forbes5948b3e2016-12-23 13:49:53 +1300435 Emits true if a function /must/ be resolved. The only time this is not
436 the case is for extension-added functions added in a later revision of the
437 extension, and where we have to cope with drivers written against an older
438 revision.
439------------------------------------------------------------------------------
440*/}}
441{{define "IsRequiredFunction"}}
442 {{AssertType $ "Function"}}
443
444 {{if eq $.Name "vkGetSwapchainGrallocUsage2ANDROID"}}
445 false
446 {{else}}
447 true
448 {{end}}
449{{end}}
450
451
452{{/*
453------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +0800454 Emits true if a function is exported and instance-dispatched.
455------------------------------------------------------------------------------
456*/}}
457{{define "api.IsInstanceDispatchTableEntry"}}
458 {{AssertType $ "Function"}}
459
460 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
Chia-I Wudbd33bc2016-06-02 11:25:47 +0800461 {{/* deprecated and unused internally */}}
462 {{if not (eq $.Name "vkEnumerateDeviceLayerProperties")}}
463 true
464 {{end}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800465 {{end}}
466{{end}}
467
468
469{{/*
470------------------------------------------------------------------------------
471 Emits true if a function is exported and device-dispatched.
472------------------------------------------------------------------------------
473*/}}
474{{define "api.IsDeviceDispatchTableEntry"}}
475 {{AssertType $ "Function"}}
476
477 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
478 true
479 {{end}}
480{{end}}
481
482
483{{/*
484------------------------------------------------------------------------------
485 Emits true if a function is intercepted by vulkan::api.
486------------------------------------------------------------------------------
487*/}}
488{{define "api.IsIntercepted"}}
489 {{AssertType $ "Function"}}
490
491 {{if (Macro "IsFunctionSupported" $)}}
492 {{/* Global functions cannot be dispatched at all */}}
493 {{ if (Macro "IsGloballyDispatched" $)}}true
494
495 {{/* VkPhysicalDevice functions that manage device layers */}}
496 {{else if eq $.Name "vkCreateDevice"}}true
497 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
498 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
499
500 {{/* Destroy functions of dispatchable objects */}}
501 {{else if eq $.Name "vkDestroyInstance"}}true
502 {{else if eq $.Name "vkDestroyDevice"}}true
503
504 {{end}}
505 {{end}}
506{{end}}
507
508
509{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800510-------------------------------------------------------------------------------
511 Emits INIT_PROC_EXT macro for vulkan::api.
512-------------------------------------------------------------------------------
513*/}}
514{{define "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800515 // Exported extension functions may be invoked even when their extensions
516 // are disabled. Dispatch to stubs when that happens.
Chris Forbes5948b3e2016-12-23 13:49:53 +1300517 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800518 if (extensions[driver::ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300519 INIT_PROC(required, obj, proc); \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800520 else \
521 data.dispatch.proc = disabled ## proc; \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800522 } while(0)
523{{end}}
524
525
526{{/*
Chia-I Wu8925efd2016-04-13 15:13:21 +0800527-------------------------------------------------------------------------------
528 Emits a stub for an exported extension function.
529-------------------------------------------------------------------------------
530*/}}
531{{define "api.C++.DefineExtensionStub"}}
532 {{AssertType $ "Function"}}
533
534 {{$ext := GetAnnotation $ "extension"}}
535 {{if and $ext (Macro "IsFunctionExported" $)}}
536 {{$ext_name := index $ext.Arguments 0}}
537
538 {{$base := (Macro "BaseName" $)}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800539
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800540 {{$p0 := (index $.CallParameters 0)}}
541 {{$ptail := (Tail 1 $.CallParameters)}}
542
543 {{$first_type := (Macro "Parameter" $p0)}}
544 {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
545
546 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
547 driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
548 "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
Chia-I Wu8925efd2016-04-13 15:13:21 +0800549 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
550 }
551
552 {{end}}
553{{end}}
554
555
556{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800557------------------------------------------------------------------------------
558 Emits code for vkGetInstanceProcAddr for function interception.
559------------------------------------------------------------------------------
560*/}}
561{{define "api.C++.InterceptInstanceProcAddr"}}
562 {{AssertType $ "API"}}
563
564 // global functions
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800565 if (instance == VK_NULL_HANDLE) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800566 {{range $f := AllCommands $}}
567 {{if (Macro "IsGloballyDispatched" $f)}}
568 if (strcmp(pName, "{{$f.Name}}") == 0) return §
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800569 reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800570 {{end}}
571 {{end}}
572
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800573 ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
Chia-I Wu0c203242016-03-15 13:44:51 +0800574 return nullptr;
575 }
576
577 static const struct Hook {
578 const char* name;
579 PFN_vkVoidFunction proc;
580 } hooks[] = {
581 {{range $f := SortBy (AllCommands $) "FunctionName"}}
582 {{if (Macro "IsFunctionExported" $f)}}
583 {{/* hide global functions */}}
584 {{if (Macro "IsGloballyDispatched" $f)}}
585 { "{{$f.Name}}", nullptr },
586
587 {{/* redirect intercepted functions */}}
588 {{else if (Macro "api.IsIntercepted" $f)}}
589 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800590 {{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800591
592 {{/* redirect vkGetInstanceProcAddr to itself */}}
593 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800594 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800595
596 {{/* redirect device functions to themselves as a workaround for
597 layers that do not intercept in their vkGetInstanceProcAddr */}}
598 {{else if (Macro "IsDeviceDispatched" $f)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800599 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800600
601 {{end}}
602 {{end}}
603 {{end}}
604 };
605 // clang-format on
606 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
607 auto hook = std::lower_bound(
608 hooks, hooks + count, pName,
609 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
610 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800611 if (!hook->proc) {
612 vulkan::driver::Logger(instance).Err(
613 instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
614 instance, pName);
615 }
Chia-I Wu0c203242016-03-15 13:44:51 +0800616 return hook->proc;
617 }
618 // clang-format off
619
620{{end}}
621
622
623{{/*
624------------------------------------------------------------------------------
625 Emits code for vkGetDeviceProcAddr for function interception.
626------------------------------------------------------------------------------
627*/}}
628{{define "api.C++.InterceptDeviceProcAddr"}}
629 {{AssertType $ "API"}}
630
631 if (device == VK_NULL_HANDLE) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800632 ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
Chia-I Wu0c203242016-03-15 13:44:51 +0800633 return nullptr;
634 }
635
636 static const char* const known_non_device_names[] = {
637 {{range $f := SortBy (AllCommands $) "FunctionName"}}
638 {{if (Macro "IsFunctionSupported" $f)}}
639 {{if not (Macro "IsDeviceDispatched" $f)}}
640 "{{$f.Name}}",
641 {{end}}
642 {{end}}
643 {{end}}
644 };
645 // clang-format on
646 constexpr size_t count = sizeof(known_non_device_names) /
647 sizeof(known_non_device_names[0]);
648 if (!pName ||
649 std::binary_search(
650 known_non_device_names, known_non_device_names + count, pName,
651 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800652 vulkan::driver::Logger(device).Err
653 device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device
654 (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800655 return nullptr;
656 }
657 // clang-format off
658
Chia-I Wuc56603e2016-04-12 11:16:17 +0800659 {{range $f := AllCommands $}}
660 {{if (Macro "IsDeviceDispatched" $f)}}
661 {{ if (Macro "api.IsIntercepted" $f)}}
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 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
666 if (strcmp(pName, "{{$f.Name}}") == 0) return §
667 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800668 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800669 {{end}}
670 {{end}}
671 {{end}}
672
Chia-I Wu0c203242016-03-15 13:44:51 +0800673{{end}}
674
675
676{{/*
677------------------------------------------------------------------------------
678 Emits code to dispatch a function.
679------------------------------------------------------------------------------
680*/}}
681{{define "api.C++.Dispatch"}}
682 {{AssertType $ "Function"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800683 {{if (Macro "api.IsIntercepted" $)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800684 {{Error "$.Name should not be generated"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800685 {{end}}
686
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800687 {{if not (IsVoid $.Return.Type)}}return §{{end}}
688
689 {{$p0 := index $.CallParameters 0}}
690 GetData({{$p0.Name}}).dispatch
Chia-I Wu0c203242016-03-15 13:44:51 +0800691 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
692{{end}}
693
694
695{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800696------------------------------------------------------------------------------
697 Emits a list of extensions intercepted by vulkan::driver.
698------------------------------------------------------------------------------
699*/}}
700{{define "driver.InterceptedExtensions"}}
701VK_ANDROID_native_buffer
702VK_EXT_debug_report
703VK_KHR_android_surface
Ian Elliott948233a2017-01-06 12:13:23 -0700704VK_KHR_incremental_present
Chia-I Wueb7db122016-03-24 09:11:06 +0800705VK_KHR_surface
706VK_KHR_swapchain
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700707VK_GOOGLE_display_timing
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300708VK_KHR_swapchain_front_buffered
Chia-I Wueb7db122016-03-24 09:11:06 +0800709{{end}}
710
711
712{{/*
713------------------------------------------------------------------------------
714 Emits true if an extension is intercepted by vulkan::driver.
715------------------------------------------------------------------------------
716*/}}
717{{define "driver.IsExtensionIntercepted"}}
718 {{$ext_name := index $.Arguments 0}}
719 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
720
721 {{range $f := $filters}}
722 {{if eq $ext_name $f}}true{{end}}
723 {{end}}
724{{end}}
725
726
727{{/*
728------------------------------------------------------------------------------
729 Emits true if a function is intercepted by vulkan::driver.
730------------------------------------------------------------------------------
731*/}}
732{{define "driver.IsIntercepted"}}
733 {{AssertType $ "Function"}}
734
735 {{if (Macro "IsFunctionSupported" $)}}
736 {{/* Create functions of dispatchable objects */}}
737 {{ if eq $.Name "vkCreateInstance"}}true
738 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800739 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800740 {{else if eq $.Name "vkGetDeviceQueue"}}true
741 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
742
743 {{/* Destroy functions of dispatchable objects */}}
744 {{else if eq $.Name "vkDestroyInstance"}}true
745 {{else if eq $.Name "vkDestroyDevice"}}true
746
747 {{/* Enumeration of extensions */}}
748 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
749 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
750
Chia-I Wueb7db122016-03-24 09:11:06 +0800751 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
752 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
753
754 {{end}}
755
756 {{$ext := GetAnnotation $ "extension"}}
757 {{if $ext}}
758 {{Macro "driver.IsExtensionIntercepted" $ext}}
759 {{end}}
760
761 {{end}}
762{{end}}
763
764
765{{/*
766------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800767 Emits true if a function needs a ProcHook stub.
Chia-I Wueb7db122016-03-24 09:11:06 +0800768------------------------------------------------------------------------------
769*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800770{{define "driver.NeedProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800771 {{AssertType $ "Function"}}
772
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800773 {{if and (Macro "driver.IsIntercepted" $) (Macro "IsDeviceDispatched" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800774 {{$ext := GetAnnotation $ "extension"}}
775 {{if $ext}}
776 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
777 {{end}}
778 {{end}}
779{{end}}
780
781
782{{/*
783-------------------------------------------------------------------------------
784 Emits definition of struct ProcHook.
785-------------------------------------------------------------------------------
786*/}}
787{{define "driver.C++.DefineProcHookType"}}
788 struct ProcHook {
789 enum Type {
790 GLOBAL,
791 INSTANCE,
792 DEVICE,
793 };
794
795 enum Extension {
796 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
797 {{range $e := $exts}}
798 {{TrimPrefix "VK_" $e}},
799 {{end}}
800
801 EXTENSION_CORE, // valid bit
802 EXTENSION_COUNT,
803 EXTENSION_UNKNOWN,
804 };
805
806 const char* name;
807 Type type;
808 Extension extension;
809
810 PFN_vkVoidFunction proc;
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800811 PFN_vkVoidFunction checked_proc; // always nullptr for non-device hooks
Chia-I Wueb7db122016-03-24 09:11:06 +0800812 };
813{{end}}
814
815
816{{/*
817-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800818 Emits INIT_PROC_EXT macro for vulkan::driver.
819-------------------------------------------------------------------------------
820*/}}
821{{define "driver.C++.DefineInitProcExtMacro"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300822 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800823 if (extensions[ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300824 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800825 } while(0)
826{{end}}
827
828
829{{/*
830-------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800831 Emits a stub for ProcHook::checked_proc.
Chia-I Wueb7db122016-03-24 09:11:06 +0800832-------------------------------------------------------------------------------
833*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800834{{define "driver.C++.DefineProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800835 {{AssertType $ "Function"}}
836
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800837 {{if (Macro "driver.NeedProcHookStub" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800838 {{$ext := GetAnnotation $ "extension"}}
839 {{$ext_name := index $ext.Arguments 0}}
840
841 {{$base := (Macro "BaseName" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800842
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800843 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
844 {{$p0 := index $.CallParameters 0}}
845 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800846
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800847 if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) {
848 {{if not (IsVoid $.Return.Type)}}return §{{end}}
849 {{$base}}({{Macro "Arguments" $}});
850 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800851 Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800852 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800853 }
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800854 }
Chia-I Wueb7db122016-03-24 09:11:06 +0800855
856 {{end}}
857{{end}}
858
859
860{{/*
861-------------------------------------------------------------------------------
862 Emits definition of a global ProcHook.
863-------------------------------------------------------------------------------
864*/}}
865{{define "driver.C++.DefineGlobalProcHook"}}
866 {{AssertType $ "Function"}}
867
868 {{$base := (Macro "BaseName" $)}}
869
870 {{$ext := GetAnnotation $ "extension"}}
871 {{if $ext}}
872 {{Error "invalid global extension"}}
873 {{end}}
874
875 {
876 "{{$.Name}}",
877 ProcHook::GLOBAL,
878 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800879 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800880 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800881 },
882{{end}}
883
884
885{{/*
886-------------------------------------------------------------------------------
887 Emits definition of an instance ProcHook.
888-------------------------------------------------------------------------------
889*/}}
890{{define "driver.C++.DefineInstanceProcHook"}}
891 {{AssertType $ "Function"}}
892
893 {{$base := (Macro "BaseName" $)}}
894
895 {
896 "{{$.Name}}",
897 ProcHook::INSTANCE,
898
899 {{$ext := GetAnnotation $ "extension"}}
900 {{if $ext}}
901 ProcHook::{{Macro "BaseName" $ext}},
902
903 {{if (Macro "IsExtensionInternal" $ext)}}
904 nullptr,
905 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800906 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800907 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800908 nullptr,
909 {{end}}
910 {{else}}
911 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800912 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800913 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800914 {{end}}
915 },
916{{end}}
917
918
919{{/*
920-------------------------------------------------------------------------------
921 Emits definition of a device ProcHook.
922-------------------------------------------------------------------------------
923*/}}
924{{define "driver.C++.DefineDeviceProcHook"}}
925 {{AssertType $ "Function"}}
926
927 {{$base := (Macro "BaseName" $)}}
928
929 {
930 "{{$.Name}}",
931 ProcHook::DEVICE,
932
933 {{$ext := GetAnnotation $ "extension"}}
934 {{if $ext}}
935 ProcHook::{{Macro "BaseName" $ext}},
936
937 {{if (Macro "IsExtensionInternal" $ext)}}
938 nullptr,
939 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800940 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800941 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800942 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
943 {{end}}
944 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800945 ProcHook::EXTENSION_CORE,
946 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
947 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800948 {{end}}
949 },
950{{end}}
951
952
953{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800954-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800955 Emits true if a function is needed by vulkan::driver.
956-------------------------------------------------------------------------------
957*/}}
958{{define "driver.IsDriverTableEntry"}}
959 {{AssertType $ "Function"}}
960
961 {{if (Macro "IsFunctionSupported" $)}}
962 {{/* Create functions of dispatchable objects */}}
963 {{ if eq $.Name "vkCreateDevice"}}true
964 {{else if eq $.Name "vkGetDeviceQueue"}}true
965 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
966
967 {{/* Destroy functions of dispatchable objects */}}
968 {{else if eq $.Name "vkDestroyInstance"}}true
969 {{else if eq $.Name "vkDestroyDevice"}}true
970
971 {{/* Enumeration of extensions */}}
972 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
973
974 {{/* We cache physical devices in loader.cpp */}}
975 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
976
977 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
978 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
979
980 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
981 {{else if eq $.Name "vkCreateImage"}}true
982 {{else if eq $.Name "vkDestroyImage"}}true
983
984 {{end}}
985
986 {{$ext := GetAnnotation $ "extension"}}
987 {{if $ext}}
988 {{$ext_name := index $ext.Arguments 0}}
989 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
990 {{else if eq $ext_name "VK_EXT_debug_report"}}true
991 {{end}}
992 {{end}}
993 {{end}}
994{{end}}
995
996
997{{/*
998------------------------------------------------------------------------------
999 Emits true if an instance-dispatched function is needed by vulkan::driver.
1000------------------------------------------------------------------------------
1001*/}}
1002{{define "driver.IsInstanceDriverTableEntry"}}
1003 {{AssertType $ "Function"}}
1004
1005 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1006 true
1007 {{end}}
1008{{end}}
1009
1010
1011{{/*
1012------------------------------------------------------------------------------
1013 Emits true if a device-dispatched function is needed by vulkan::driver.
1014------------------------------------------------------------------------------
1015*/}}
1016{{define "driver.IsDeviceDriverTableEntry"}}
1017 {{AssertType $ "Function"}}
1018
1019 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1020 true
1021 {{end}}
1022{{end}}
1023
1024
1025{{/*
1026-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001027 Emits a function/extension name without the "vk"/"VK_" prefix.
1028-------------------------------------------------------------------------------
1029*/}}
1030{{define "BaseName"}}
1031 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1032 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1033 {{else}}{{Error "invalid use of BaseName"}}
1034 {{end}}
1035{{end}}
1036
1037
1038{{/*
1039-------------------------------------------------------------------------------
1040 Emits a comma-separated list of C parameter names for the given command.
1041-------------------------------------------------------------------------------
1042*/}}
1043{{define "Arguments"}}
1044 {{AssertType $ "Function"}}
1045
1046 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1047{{end}}
1048
1049
1050{{/*
1051------------------------------------------------------------------------------
1052------------------------------------------------------------------------------
1053*/}}
1054{{define "IsGloballyDispatched"}}
1055 {{AssertType $ "Function"}}
1056 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1057 true
1058 {{end}}
1059{{end}}
1060
1061
1062{{/*
1063------------------------------------------------------------------------------
1064 Emit "true" for supported functions that undergo table dispatch. Only global
1065 functions and functions handled in the loader top without calling into
1066 lower layers are not dispatched.
1067------------------------------------------------------------------------------
1068*/}}
1069{{define "IsInstanceDispatched"}}
1070 {{AssertType $ "Function"}}
1071 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1072 true
1073 {{end}}
1074{{end}}
1075
1076
1077{{/*
1078------------------------------------------------------------------------------
1079 Emit "true" for supported functions that can have device-specific dispatch.
1080------------------------------------------------------------------------------
1081*/}}
1082{{define "IsDeviceDispatched"}}
1083 {{AssertType $ "Function"}}
1084 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1085 true
1086 {{end}}
1087{{end}}
1088
1089
1090{{/*
1091------------------------------------------------------------------------------
1092 Emit "true" if a function is core or from a supportable extension.
1093------------------------------------------------------------------------------
1094*/}}
1095{{define "IsFunctionSupported"}}
1096 {{AssertType $ "Function"}}
1097 {{if not (GetAnnotation $ "pfn")}}
1098 {{$ext := GetAnnotation $ "extension"}}
1099 {{if not $ext}}true
1100 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1101 {{end}}
1102 {{end}}
1103{{end}}
1104
1105
1106{{/*
1107------------------------------------------------------------------------------
1108 Decides whether a function should be exported from the Android Vulkan
1109 library. Functions in the core API and in loader extensions are exported.
1110------------------------------------------------------------------------------
1111*/}}
1112{{define "IsFunctionExported"}}
1113 {{AssertType $ "Function"}}
1114
1115 {{if (Macro "IsFunctionSupported" $)}}
1116 {{$ext := GetAnnotation $ "extension"}}
1117 {{if $ext}}
1118 {{Macro "IsExtensionExported" $ext}}
1119 {{else}}
1120 true
1121 {{end}}
1122 {{end}}
1123{{end}}
1124
1125
1126{{/*
1127------------------------------------------------------------------------------
1128 Emit "true" if an extension is unsupportable on Android.
1129------------------------------------------------------------------------------
1130*/}}
1131{{define "IsExtensionBlacklisted"}}
1132 {{$ext := index $.Arguments 0}}
1133 {{ if eq $ext "VK_KHR_display"}}true
1134 {{else if eq $ext "VK_KHR_display_swapchain"}}true
1135 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1136 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1137 {{else if eq $ext "VK_KHR_wayland_surface"}}true
1138 {{else if eq $ext "VK_KHR_mir_surface"}}true
1139 {{else if eq $ext "VK_KHR_win32_surface"}}true
1140 {{end}}
1141{{end}}
1142
1143
1144{{/*
1145------------------------------------------------------------------------------
1146 Reports whether an extension is implemented entirely by the loader,
1147 so drivers should not enumerate it.
1148------------------------------------------------------------------------------
1149*/}}
1150{{define "IsExtensionExported"}}
1151 {{$ext := index $.Arguments 0}}
1152 {{ if eq $ext "VK_KHR_surface"}}true
1153 {{else if eq $ext "VK_KHR_swapchain"}}true
1154 {{else if eq $ext "VK_KHR_android_surface"}}true
1155 {{end}}
1156{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001157
1158
1159{{/*
1160------------------------------------------------------------------------------
1161 Reports whether an extension is internal to the loader and drivers,
1162 so the loader should not enumerate it.
1163------------------------------------------------------------------------------
1164*/}}
1165{{define "IsExtensionInternal"}}
1166 {{$ext := index $.Arguments 0}}
1167 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1168 {{end}}
1169{{end}}