blob: ad1693a095e7bec46c4ddb4afc426cc397e801a1 [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
40#include <vulkan/vulkan.h>
41
42namespace vulkan
43namespace api
44
45struct InstanceDispatchTable {
46 // clang-format off
47 {{range $f := AllCommands $}}
48 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080049 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080050 {{end}}
51 {{end}}
52 // clang-format on
53};
54
55struct DeviceDispatchTable {
56 // clang-format off
57 {{range $f := AllCommands $}}
58 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080059 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080060 {{end}}
61 {{end}}
62 // clang-format on
63};
64
65bool InitDispatchTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc);
66bool InitDispatchTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc);
67
68»} // namespace api
69»} // namespace vulkan
70
71#endif // LIBVULKAN_API_GEN_H
72¶{{end}}
73
74
75{{/*
76-------------------------------------------------------------------------------
77 api_gen.cpp
78-------------------------------------------------------------------------------
79*/}}
80{{define "api_gen.cpp"}}
81{{Macro "Copyright"}}
82
83// WARNING: This file is generated. See ../README.md for instructions.
84
85#include <string.h>
86#include <algorithm>
87#include <log/log.h>
88
89#include "api.h"
90
91namespace vulkan
92namespace api
93
Chia-I Wucc5e2762016-03-24 13:01:16 +080094{{Macro "C++.DefineInitProcMacro" "dispatch"}}
95
96{{Macro "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +080097
98bool InitDispatchTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc) {
99 auto& data = GetData(instance);
100 bool success = true;
101
102 // clang-format off
103 {{range $f := AllCommands $}}
104 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
105 {{Macro "C++.InitProc" $f}}
106 {{end}}
107 {{end}}
108 // clang-format on
109
110 return success;
111}
112
113bool InitDispatchTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc) {
114 auto& data = GetData(dev);
115 bool success = true;
116
117 // clang-format off
118 {{range $f := AllCommands $}}
119 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
120 {{Macro "C++.InitProc" $f}}
121 {{end}}
122 {{end}}
123 // clang-format on
124
125 return success;
126}
127
128»} // namespace api
129»} // namespace vulkan
130
131// clang-format off
132
133{{range $f := AllCommands $}}
134 {{if (Macro "IsFunctionExported" $f)}}
135 __attribute__((visibility("default")))
136 VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
137 {{ if eq $f.Name "vkGetInstanceProcAddr"}}
138 {{Macro "api.C++.InterceptInstanceProcAddr" $}}
139 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
140 {{Macro "api.C++.InterceptDeviceProcAddr" $}}
141 {{end}}
142
143 {{Macro "api.C++.Dispatch" $f}}
144 }
145
146 {{end}}
147{{end}}
148
149// clang-format on
150¶{{end}}
151
152
153{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800154-------------------------------------------------------------------------------
155 driver_gen.h
156-------------------------------------------------------------------------------
157*/}}
158{{define "driver_gen.h"}}
159{{Macro "Copyright"}}
160
161// WARNING: This file is generated. See ../README.md for instructions.
162
163#ifndef LIBVULKAN_DRIVER_GEN_H
164#define LIBVULKAN_DRIVER_GEN_H
165
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800166#include <bitset>
Chia-I Wueb7db122016-03-24 09:11:06 +0800167#include <vulkan/vulkan.h>
168#include <vulkan/vk_android_native_buffer.h>
169
170namespace vulkan
171namespace driver
172
173{{Macro "driver.C++.DefineProcHookType"}}
174
Chia-I Wucc5e2762016-03-24 13:01:16 +0800175struct InstanceDriverTable {
176 // clang-format off
177 {{range $f := AllCommands $}}
178 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
179 {{Macro "C++.DeclareTableEntry" $f}};
180 {{end}}
181 {{end}}
182 // clang-format on
183};
184
185struct DeviceDriverTable {
186 // clang-format off
187 {{range $f := AllCommands $}}
188 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
189 {{Macro "C++.DeclareTableEntry" $f}};
190 {{end}}
191 {{end}}
192 // clang-format on
193};
194
Chia-I Wueb7db122016-03-24 09:11:06 +0800195const ProcHook* GetProcHook(const char* name);
196ProcHook::Extension GetProcHookExtension(const char* name);
197
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800198bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
199 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
200bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
201 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800202
Chia-I Wueb7db122016-03-24 09:11:06 +0800203»} // namespace driver
204»} // namespace vulkan
205
206#endif // LIBVULKAN_DRIVER_TABLE_H
207¶{{end}}
208
209
210{{/*
211-------------------------------------------------------------------------------
212 driver_gen.cpp
213-------------------------------------------------------------------------------
214*/}}
215{{define "driver_gen.cpp"}}
216{{Macro "Copyright"}}
217
218// WARNING: This file is generated. See ../README.md for instructions.
219
220#include <string.h>
221#include <algorithm>
222#include <log/log.h>
223
224#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800225
226namespace vulkan
227namespace driver
228
229namespace
230
231// clang-format off
232
233{{range $f := AllCommands $}}
234 {{Macro "driver.C++.DefineProcHookStubs" $f}}
235{{end}}
236// clang-format on
237
238const ProcHook g_proc_hooks[] = {
239 // clang-format off
240 {{range $f := SortBy (AllCommands $) "FunctionName"}}
241 {{if (Macro "driver.IsIntercepted" $f)}}
242 {{ if (Macro "IsGloballyDispatched" $f)}}
243 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
244 {{else if (Macro "IsInstanceDispatched" $f)}}
245 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
246 {{else if (Macro "IsDeviceDispatched" $f)}}
247 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
248 {{end}}
249 {{end}}
250 {{end}}
251 // clang-format on
252};
253
254»} // anonymous
255
256const ProcHook* GetProcHook(const char* name) {
257 const auto& begin = g_proc_hooks;
258 const auto& end = g_proc_hooks +
259 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
260 const auto hook = std::lower_bound(begin, end, name,
261 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
262 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
263}
264
265ProcHook::Extension GetProcHookExtension(const char* name) {
266 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
267 // clang-format off
268 {{range $e := $exts}}
269 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
270 {{end}}
271 // clang-format on
272 return ProcHook::EXTENSION_UNKNOWN;
273}
274
Chia-I Wucc5e2762016-03-24 13:01:16 +0800275{{Macro "C++.DefineInitProcMacro" "driver"}}
276
277{{Macro "driver.C++.DefineInitProcExtMacro"}}
278
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800279bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
280 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800281{
282 auto& data = GetData(instance);
283 bool success = true;
284
285 // clang-format off
286 {{range $f := AllCommands $}}
287 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
288 {{Macro "C++.InitProc" $f}}
289 {{end}}
290 {{end}}
291 // clang-format on
292
293 return success;
294}
295
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800296bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
297 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800298{
299 auto& data = GetData(dev);
300 bool success = true;
301
302 // clang-format off
303 {{range $f := AllCommands $}}
304 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
305 {{Macro "C++.InitProc" $f}}
306 {{end}}
307 {{end}}
308 // clang-format on
309
310 return success;
311}
312
Chia-I Wueb7db122016-03-24 09:11:06 +0800313»} // namespace driver
314»} // namespace vulkan
315
316// clang-format on
317¶{{end}}
318
319
320{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800321------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800322 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800323------------------------------------------------------------------------------
324*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800325{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800326 {{AssertType $ "Function"}}
327
328 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
329{{end}}
330
331
332{{/*
333-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800334 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800335-------------------------------------------------------------------------------
336*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800337{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800338 #define UNLIKELY(expr) __builtin_expect((expr), 0)
339
340 #define INIT_PROC(obj, proc) do { \
341 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
342 get_proc(obj, "vk" # proc)); \
343 if (UNLIKELY(!data.{{$}}.proc)) { \
344 ALOGE("missing " # obj " proc: vk" # proc); \
345 success = false; \
346 } \
347 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800348{{end}}
349
350
351{{/*
352-------------------------------------------------------------------------------
353 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
354-------------------------------------------------------------------------------
355*/}}
356{{define "C++.InitProc"}}
357 {{AssertType $ "Function"}}
358
359 {{$ext := GetAnnotation $ "extension"}}
360 {{if $ext}}
361 INIT_PROC_EXT({{Macro "BaseName" $ext}}, §
362 {{else}}
363 INIT_PROC
364 {{end}}
365
366 {{if (Macro "IsInstanceDispatched" $)}}
367 instance, §
368 {{else}}
369 dev, §
370 {{end}}
371
372 {{Macro "BaseName" $}});
373{{end}}
374
375
376{{/*
377------------------------------------------------------------------------------
378 Emits true if a function is exported and instance-dispatched.
379------------------------------------------------------------------------------
380*/}}
381{{define "api.IsInstanceDispatchTableEntry"}}
382 {{AssertType $ "Function"}}
383
384 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
385 true
386 {{end}}
387{{end}}
388
389
390{{/*
391------------------------------------------------------------------------------
392 Emits true if a function is exported and device-dispatched.
393------------------------------------------------------------------------------
394*/}}
395{{define "api.IsDeviceDispatchTableEntry"}}
396 {{AssertType $ "Function"}}
397
398 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
399 true
400 {{end}}
401{{end}}
402
403
404{{/*
405------------------------------------------------------------------------------
406 Emits true if a function is intercepted by vulkan::api.
407------------------------------------------------------------------------------
408*/}}
409{{define "api.IsIntercepted"}}
410 {{AssertType $ "Function"}}
411
412 {{if (Macro "IsFunctionSupported" $)}}
413 {{/* Global functions cannot be dispatched at all */}}
414 {{ if (Macro "IsGloballyDispatched" $)}}true
415
416 {{/* VkPhysicalDevice functions that manage device layers */}}
417 {{else if eq $.Name "vkCreateDevice"}}true
418 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
419 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
420
421 {{/* Destroy functions of dispatchable objects */}}
422 {{else if eq $.Name "vkDestroyInstance"}}true
423 {{else if eq $.Name "vkDestroyDevice"}}true
424
425 {{end}}
426 {{end}}
427{{end}}
428
429
430{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800431-------------------------------------------------------------------------------
432 Emits INIT_PROC_EXT macro for vulkan::api.
433-------------------------------------------------------------------------------
434*/}}
435{{define "api.C++.DefineInitProcExtMacro"}}
436 // TODO do we want to point to a stub or nullptr when ext is not enabled?
437 #define INIT_PROC_EXT(ext, obj, proc) do { \
438 INIT_PROC(obj, proc); \
439 } while(0)
440{{end}}
441
442
443{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800444------------------------------------------------------------------------------
445 Emits code for vkGetInstanceProcAddr for function interception.
446------------------------------------------------------------------------------
447*/}}
448{{define "api.C++.InterceptInstanceProcAddr"}}
449 {{AssertType $ "API"}}
450
451 // global functions
452 if (!instance) {
453 {{range $f := AllCommands $}}
454 {{if (Macro "IsGloballyDispatched" $f)}}
455 if (strcmp(pName, "{{$f.Name}}") == 0) return §
456 reinterpret_cast<PFN_vkVoidFunction>(§
457 vulkan::api::{{Macro "BaseName" $f}});
458 {{end}}
459 {{end}}
460
461 ALOGE("vkGetInstanceProcAddr called with %s without instance", pName);
462 return nullptr;
463 }
464
465 static const struct Hook {
466 const char* name;
467 PFN_vkVoidFunction proc;
468 } hooks[] = {
469 {{range $f := SortBy (AllCommands $) "FunctionName"}}
470 {{if (Macro "IsFunctionExported" $f)}}
471 {{/* hide global functions */}}
472 {{if (Macro "IsGloballyDispatched" $f)}}
473 { "{{$f.Name}}", nullptr },
474
475 {{/* redirect intercepted functions */}}
476 {{else if (Macro "api.IsIntercepted" $f)}}
477 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
478 vulkan::api::{{Macro "BaseName" $f}}) },
479
480 {{/* redirect vkGetInstanceProcAddr to itself */}}
481 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
482 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
483
484 {{/* redirect device functions to themselves as a workaround for
485 layers that do not intercept in their vkGetInstanceProcAddr */}}
486 {{else if (Macro "IsDeviceDispatched" $f)}}
487 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
488
489 {{end}}
490 {{end}}
491 {{end}}
492 };
493 // clang-format on
494 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
495 auto hook = std::lower_bound(
496 hooks, hooks + count, pName,
497 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
498 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
499 if (!hook->proc)
500 ALOGE("vkGetInstanceProcAddr called with %s with instance", pName);
501 return hook->proc;
502 }
503 // clang-format off
504
505{{end}}
506
507
508{{/*
509------------------------------------------------------------------------------
510 Emits code for vkGetDeviceProcAddr for function interception.
511------------------------------------------------------------------------------
512*/}}
513{{define "api.C++.InterceptDeviceProcAddr"}}
514 {{AssertType $ "API"}}
515
516 if (device == VK_NULL_HANDLE) {
517 ALOGE("vkGetDeviceProcAddr called with invalid device");
518 return nullptr;
519 }
520
521 static const char* const known_non_device_names[] = {
522 {{range $f := SortBy (AllCommands $) "FunctionName"}}
523 {{if (Macro "IsFunctionSupported" $f)}}
524 {{if not (Macro "IsDeviceDispatched" $f)}}
525 "{{$f.Name}}",
526 {{end}}
527 {{end}}
528 {{end}}
529 };
530 // clang-format on
531 constexpr size_t count = sizeof(known_non_device_names) /
532 sizeof(known_non_device_names[0]);
533 if (!pName ||
534 std::binary_search(
535 known_non_device_names, known_non_device_names + count, pName,
536 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wuc56603e2016-04-12 11:16:17 +0800537 ALOGE("vkGetDeviceProcAddr called with %s", (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800538 return nullptr;
539 }
540 // clang-format off
541
Chia-I Wuc56603e2016-04-12 11:16:17 +0800542 {{range $f := AllCommands $}}
543 {{if (Macro "IsDeviceDispatched" $f)}}
544 {{ if (Macro "api.IsIntercepted" $f)}}
545 if (strcmp(pName, "{{$f.Name}}") == 0) return §
546 reinterpret_cast<PFN_vkVoidFunction>(§
547 vulkan::api::{{Macro "BaseName" $f}});
548 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
549 if (strcmp(pName, "{{$f.Name}}") == 0) return §
550 reinterpret_cast<PFN_vkVoidFunction>(§
551 {{$f.Name}});
552 {{end}}
553 {{end}}
554 {{end}}
555
Chia-I Wu0c203242016-03-15 13:44:51 +0800556{{end}}
557
558
559{{/*
560------------------------------------------------------------------------------
561 Emits code to dispatch a function.
562------------------------------------------------------------------------------
563*/}}
564{{define "api.C++.Dispatch"}}
565 {{AssertType $ "Function"}}
566
567 {{if (Macro "api.IsIntercepted" $)}}// call into api.cpp{{end}}
568 {{if not (IsVoid $.Return.Type)}}return §{{end}}
569
570 {{if (Macro "api.IsIntercepted" $)}}
571 vulkan::api::§
572 {{else}}
573 {{$p0 := index $.CallParameters 0}}
574 vulkan::api::GetData({{$p0.Name}}).dispatch
575 {{end}}
576
577 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
578{{end}}
579
580
581{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800582------------------------------------------------------------------------------
583 Emits a list of extensions intercepted by vulkan::driver.
584------------------------------------------------------------------------------
585*/}}
586{{define "driver.InterceptedExtensions"}}
587VK_ANDROID_native_buffer
588VK_EXT_debug_report
589VK_KHR_android_surface
590VK_KHR_surface
591VK_KHR_swapchain
592{{end}}
593
594
595{{/*
596------------------------------------------------------------------------------
597 Emits true if an extension is intercepted by vulkan::driver.
598------------------------------------------------------------------------------
599*/}}
600{{define "driver.IsExtensionIntercepted"}}
601 {{$ext_name := index $.Arguments 0}}
602 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
603
604 {{range $f := $filters}}
605 {{if eq $ext_name $f}}true{{end}}
606 {{end}}
607{{end}}
608
609
610{{/*
611------------------------------------------------------------------------------
612 Emits true if a function is intercepted by vulkan::driver.
613------------------------------------------------------------------------------
614*/}}
615{{define "driver.IsIntercepted"}}
616 {{AssertType $ "Function"}}
617
618 {{if (Macro "IsFunctionSupported" $)}}
619 {{/* Create functions of dispatchable objects */}}
620 {{ if eq $.Name "vkCreateInstance"}}true
621 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800622 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800623 {{else if eq $.Name "vkGetDeviceQueue"}}true
624 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
625
626 {{/* Destroy functions of dispatchable objects */}}
627 {{else if eq $.Name "vkDestroyInstance"}}true
628 {{else if eq $.Name "vkDestroyDevice"}}true
629
630 {{/* Enumeration of extensions */}}
631 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
632 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
633
Chia-I Wueb7db122016-03-24 09:11:06 +0800634 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
635 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
636
637 {{end}}
638
639 {{$ext := GetAnnotation $ "extension"}}
640 {{if $ext}}
641 {{Macro "driver.IsExtensionIntercepted" $ext}}
642 {{end}}
643
644 {{end}}
645{{end}}
646
647
648{{/*
649------------------------------------------------------------------------------
650 Emits true if a function needs ProcHook stubs.
651------------------------------------------------------------------------------
652*/}}
653{{define "driver.NeedProcHookStubs"}}
654 {{AssertType $ "Function"}}
655
656 {{if (Macro "driver.IsIntercepted" $)}}
657 {{$ext := GetAnnotation $ "extension"}}
658 {{if $ext}}
659 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
660 {{end}}
661 {{end}}
662{{end}}
663
664
665{{/*
666-------------------------------------------------------------------------------
667 Emits definition of struct ProcHook.
668-------------------------------------------------------------------------------
669*/}}
670{{define "driver.C++.DefineProcHookType"}}
671 struct ProcHook {
672 enum Type {
673 GLOBAL,
674 INSTANCE,
675 DEVICE,
676 };
677
678 enum Extension {
679 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
680 {{range $e := $exts}}
681 {{TrimPrefix "VK_" $e}},
682 {{end}}
683
684 EXTENSION_CORE, // valid bit
685 EXTENSION_COUNT,
686 EXTENSION_UNKNOWN,
687 };
688
689 const char* name;
690 Type type;
691 Extension extension;
692
693 PFN_vkVoidFunction proc;
694 PFN_vkVoidFunction disabled_proc; // nullptr for global hooks
695 PFN_vkVoidFunction checked_proc; // nullptr for global/instance hooks
696 };
697{{end}}
698
699
700{{/*
701-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800702 Emits INIT_PROC_EXT macro for vulkan::driver.
703-------------------------------------------------------------------------------
704*/}}
705{{define "driver.C++.DefineInitProcExtMacro"}}
706 #define INIT_PROC_EXT(ext, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800707 if (extensions[ProcHook::ext]) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800708 INIT_PROC(obj, proc); \
709 } while(0)
710{{end}}
711
712
713{{/*
714-------------------------------------------------------------------------------
Chia-I Wueb7db122016-03-24 09:11:06 +0800715 Emits definitions of stub functions for ProcHook.
716-------------------------------------------------------------------------------
717*/}}
718{{define "driver.C++.DefineProcHookStubs"}}
719 {{AssertType $ "Function"}}
720
721 {{if (Macro "driver.NeedProcHookStubs" $)}}
722 {{$ext := GetAnnotation $ "extension"}}
723 {{$ext_name := index $ext.Arguments 0}}
724
725 {{$base := (Macro "BaseName" $)}}
726 {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}
727
728 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$unnamed_params}}) {
729 ALOGE("{{$ext_name}} not enabled. {{$.Name}} not executed.");
730 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
731 }
732 {{if (Macro "IsDeviceDispatched" $)}}
733
734 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
735 {{if not (IsVoid $.Return.Type)}}return §{{end}}
736
737 {{$p0 := index $.CallParameters 0}}
738 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
739 (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) ? §
Chia-I Wu62262232016-03-26 07:06:44 +0800740 {{$base}}({{Macro "Arguments" $}}) : §
Chia-I Wueb7db122016-03-24 09:11:06 +0800741 disabled{{$base}}({{Macro "Arguments" $}});
742 }
743 {{end}}
744
745 {{end}}
746{{end}}
747
748
749{{/*
750-------------------------------------------------------------------------------
751 Emits definition of a global ProcHook.
752-------------------------------------------------------------------------------
753*/}}
754{{define "driver.C++.DefineGlobalProcHook"}}
755 {{AssertType $ "Function"}}
756
757 {{$base := (Macro "BaseName" $)}}
758
759 {{$ext := GetAnnotation $ "extension"}}
760 {{if $ext}}
761 {{Error "invalid global extension"}}
762 {{end}}
763
764 {
765 "{{$.Name}}",
766 ProcHook::GLOBAL,
767 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800768 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800769 nullptr,
770 nullptr,
771 },
772{{end}}
773
774
775{{/*
776-------------------------------------------------------------------------------
777 Emits definition of an instance ProcHook.
778-------------------------------------------------------------------------------
779*/}}
780{{define "driver.C++.DefineInstanceProcHook"}}
781 {{AssertType $ "Function"}}
782
783 {{$base := (Macro "BaseName" $)}}
784
785 {
786 "{{$.Name}}",
787 ProcHook::INSTANCE,
788
789 {{$ext := GetAnnotation $ "extension"}}
790 {{if $ext}}
791 ProcHook::{{Macro "BaseName" $ext}},
792
793 {{if (Macro "IsExtensionInternal" $ext)}}
794 nullptr,
795 nullptr,
796 nullptr,
797 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800798 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800799 reinterpret_cast<PFN_vkVoidFunction>(disabled{{$base}}),
800 nullptr,
801 {{end}}
802 {{else}}
803 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800804 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800805 nullptr,
806 nullptr,
807 {{end}}
808 },
809{{end}}
810
811
812{{/*
813-------------------------------------------------------------------------------
814 Emits definition of a device ProcHook.
815-------------------------------------------------------------------------------
816*/}}
817{{define "driver.C++.DefineDeviceProcHook"}}
818 {{AssertType $ "Function"}}
819
820 {{$base := (Macro "BaseName" $)}}
821
822 {
823 "{{$.Name}}",
824 ProcHook::DEVICE,
825
826 {{$ext := GetAnnotation $ "extension"}}
827 {{if $ext}}
828 ProcHook::{{Macro "BaseName" $ext}},
829
830 {{if (Macro "IsExtensionInternal" $ext)}}
831 nullptr,
832 nullptr,
833 nullptr,
834 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800835 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800836 reinterpret_cast<PFN_vkVoidFunction>(disabled{{$base}}),
837 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
838 {{end}}
839 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800840 ProcHook::EXTENSION_CORE,
841 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
842 nullptr,
843 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800844 {{end}}
845 },
846{{end}}
847
848
849{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800850-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800851 Emits true if a function is needed by vulkan::driver.
852-------------------------------------------------------------------------------
853*/}}
854{{define "driver.IsDriverTableEntry"}}
855 {{AssertType $ "Function"}}
856
857 {{if (Macro "IsFunctionSupported" $)}}
858 {{/* Create functions of dispatchable objects */}}
859 {{ if eq $.Name "vkCreateDevice"}}true
860 {{else if eq $.Name "vkGetDeviceQueue"}}true
861 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
862
863 {{/* Destroy functions of dispatchable objects */}}
864 {{else if eq $.Name "vkDestroyInstance"}}true
865 {{else if eq $.Name "vkDestroyDevice"}}true
866
Chia-I Wu4901db72016-03-24 16:38:58 +0800867 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
868
Chia-I Wucc5e2762016-03-24 13:01:16 +0800869 {{/* Enumeration of extensions */}}
870 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
871
872 {{/* We cache physical devices in loader.cpp */}}
873 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
874
875 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
876 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
877
878 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
879 {{else if eq $.Name "vkCreateImage"}}true
880 {{else if eq $.Name "vkDestroyImage"}}true
881
882 {{end}}
883
884 {{$ext := GetAnnotation $ "extension"}}
885 {{if $ext}}
886 {{$ext_name := index $ext.Arguments 0}}
887 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
888 {{else if eq $ext_name "VK_EXT_debug_report"}}true
889 {{end}}
890 {{end}}
891 {{end}}
892{{end}}
893
894
895{{/*
896------------------------------------------------------------------------------
897 Emits true if an instance-dispatched function is needed by vulkan::driver.
898------------------------------------------------------------------------------
899*/}}
900{{define "driver.IsInstanceDriverTableEntry"}}
901 {{AssertType $ "Function"}}
902
903 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
904 true
905 {{end}}
906{{end}}
907
908
909{{/*
910------------------------------------------------------------------------------
911 Emits true if a device-dispatched function is needed by vulkan::driver.
912------------------------------------------------------------------------------
913*/}}
914{{define "driver.IsDeviceDriverTableEntry"}}
915 {{AssertType $ "Function"}}
916
917 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
918 true
919 {{end}}
920{{end}}
921
922
923{{/*
924-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +0800925 Emits a function/extension name without the "vk"/"VK_" prefix.
926-------------------------------------------------------------------------------
927*/}}
928{{define "BaseName"}}
929 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
930 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
931 {{else}}{{Error "invalid use of BaseName"}}
932 {{end}}
933{{end}}
934
935
936{{/*
937-------------------------------------------------------------------------------
938 Emits a comma-separated list of C parameter names for the given command.
939-------------------------------------------------------------------------------
940*/}}
941{{define "Arguments"}}
942 {{AssertType $ "Function"}}
943
944 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
945{{end}}
946
947
948{{/*
949------------------------------------------------------------------------------
950------------------------------------------------------------------------------
951*/}}
952{{define "IsGloballyDispatched"}}
953 {{AssertType $ "Function"}}
954 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
955 true
956 {{end}}
957{{end}}
958
959
960{{/*
961------------------------------------------------------------------------------
962 Emit "true" for supported functions that undergo table dispatch. Only global
963 functions and functions handled in the loader top without calling into
964 lower layers are not dispatched.
965------------------------------------------------------------------------------
966*/}}
967{{define "IsInstanceDispatched"}}
968 {{AssertType $ "Function"}}
969 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
970 true
971 {{end}}
972{{end}}
973
974
975{{/*
976------------------------------------------------------------------------------
977 Emit "true" for supported functions that can have device-specific dispatch.
978------------------------------------------------------------------------------
979*/}}
980{{define "IsDeviceDispatched"}}
981 {{AssertType $ "Function"}}
982 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
983 true
984 {{end}}
985{{end}}
986
987
988{{/*
989------------------------------------------------------------------------------
990 Emit "true" if a function is core or from a supportable extension.
991------------------------------------------------------------------------------
992*/}}
993{{define "IsFunctionSupported"}}
994 {{AssertType $ "Function"}}
995 {{if not (GetAnnotation $ "pfn")}}
996 {{$ext := GetAnnotation $ "extension"}}
997 {{if not $ext}}true
998 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
999 {{end}}
1000 {{end}}
1001{{end}}
1002
1003
1004{{/*
1005------------------------------------------------------------------------------
1006 Decides whether a function should be exported from the Android Vulkan
1007 library. Functions in the core API and in loader extensions are exported.
1008------------------------------------------------------------------------------
1009*/}}
1010{{define "IsFunctionExported"}}
1011 {{AssertType $ "Function"}}
1012
1013 {{if (Macro "IsFunctionSupported" $)}}
1014 {{$ext := GetAnnotation $ "extension"}}
1015 {{if $ext}}
1016 {{Macro "IsExtensionExported" $ext}}
1017 {{else}}
1018 true
1019 {{end}}
1020 {{end}}
1021{{end}}
1022
1023
1024{{/*
1025------------------------------------------------------------------------------
1026 Emit "true" if an extension is unsupportable on Android.
1027------------------------------------------------------------------------------
1028*/}}
1029{{define "IsExtensionBlacklisted"}}
1030 {{$ext := index $.Arguments 0}}
1031 {{ if eq $ext "VK_KHR_display"}}true
1032 {{else if eq $ext "VK_KHR_display_swapchain"}}true
1033 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1034 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1035 {{else if eq $ext "VK_KHR_wayland_surface"}}true
1036 {{else if eq $ext "VK_KHR_mir_surface"}}true
1037 {{else if eq $ext "VK_KHR_win32_surface"}}true
1038 {{end}}
1039{{end}}
1040
1041
1042{{/*
1043------------------------------------------------------------------------------
1044 Reports whether an extension is implemented entirely by the loader,
1045 so drivers should not enumerate it.
1046------------------------------------------------------------------------------
1047*/}}
1048{{define "IsExtensionExported"}}
1049 {{$ext := index $.Arguments 0}}
1050 {{ if eq $ext "VK_KHR_surface"}}true
1051 {{else if eq $ext "VK_KHR_swapchain"}}true
1052 {{else if eq $ext "VK_KHR_android_surface"}}true
1053 {{end}}
1054{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001055
1056
1057{{/*
1058------------------------------------------------------------------------------
1059 Reports whether an extension is internal to the loader and drivers,
1060 so the loader should not enumerate it.
1061------------------------------------------------------------------------------
1062*/}}
1063{{define "IsExtensionInternal"}}
1064 {{$ext := index $.Arguments 0}}
1065 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1066 {{end}}
1067{{end}}