blob: afe0d8417c423cdc228d4a0b56db413013aadbd1 [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
166#include <vulkan/vulkan.h>
167#include <vulkan/vk_android_native_buffer.h>
168
169namespace vulkan
170namespace driver
171
172{{Macro "driver.C++.DefineProcHookType"}}
173
Chia-I Wucc5e2762016-03-24 13:01:16 +0800174struct InstanceDriverTable {
175 // clang-format off
176 {{range $f := AllCommands $}}
177 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
178 {{Macro "C++.DeclareTableEntry" $f}};
179 {{end}}
180 {{end}}
181 // clang-format on
182};
183
184struct DeviceDriverTable {
185 // clang-format off
186 {{range $f := AllCommands $}}
187 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
188 {{Macro "C++.DeclareTableEntry" $f}};
189 {{end}}
190 {{end}}
191 // clang-format on
192};
193
Chia-I Wueb7db122016-03-24 09:11:06 +0800194const ProcHook* GetProcHook(const char* name);
195ProcHook::Extension GetProcHookExtension(const char* name);
196
Chia-I Wucc5e2762016-03-24 13:01:16 +0800197bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc);
198bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc);
199
Chia-I Wueb7db122016-03-24 09:11:06 +0800200»} // namespace driver
201»} // namespace vulkan
202
203#endif // LIBVULKAN_DRIVER_TABLE_H
204¶{{end}}
205
206
207{{/*
208-------------------------------------------------------------------------------
209 driver_gen.cpp
210-------------------------------------------------------------------------------
211*/}}
212{{define "driver_gen.cpp"}}
213{{Macro "Copyright"}}
214
215// WARNING: This file is generated. See ../README.md for instructions.
216
217#include <string.h>
218#include <algorithm>
219#include <log/log.h>
220
221#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800222
223namespace vulkan
224namespace driver
225
226namespace
227
228// clang-format off
229
230{{range $f := AllCommands $}}
231 {{Macro "driver.C++.DefineProcHookStubs" $f}}
232{{end}}
233// clang-format on
234
235const ProcHook g_proc_hooks[] = {
236 // clang-format off
237 {{range $f := SortBy (AllCommands $) "FunctionName"}}
238 {{if (Macro "driver.IsIntercepted" $f)}}
239 {{ if (Macro "IsGloballyDispatched" $f)}}
240 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
241 {{else if (Macro "IsInstanceDispatched" $f)}}
242 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
243 {{else if (Macro "IsDeviceDispatched" $f)}}
244 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
245 {{end}}
246 {{end}}
247 {{end}}
248 // clang-format on
249};
250
251»} // anonymous
252
253const ProcHook* GetProcHook(const char* name) {
254 const auto& begin = g_proc_hooks;
255 const auto& end = g_proc_hooks +
256 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
257 const auto hook = std::lower_bound(begin, end, name,
258 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
259 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
260}
261
262ProcHook::Extension GetProcHookExtension(const char* name) {
263 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
264 // clang-format off
265 {{range $e := $exts}}
266 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
267 {{end}}
268 // clang-format on
269 return ProcHook::EXTENSION_UNKNOWN;
270}
271
Chia-I Wucc5e2762016-03-24 13:01:16 +0800272{{Macro "C++.DefineInitProcMacro" "driver"}}
273
274{{Macro "driver.C++.DefineInitProcExtMacro"}}
275
276bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc)
277{
278 auto& data = GetData(instance);
279 bool success = true;
280
281 // clang-format off
282 {{range $f := AllCommands $}}
283 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
284 {{Macro "C++.InitProc" $f}}
285 {{end}}
286 {{end}}
287 // clang-format on
288
289 return success;
290}
291
292bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc)
293{
294 auto& data = GetData(dev);
295 bool success = true;
296
297 // clang-format off
298 {{range $f := AllCommands $}}
299 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
300 {{Macro "C++.InitProc" $f}}
301 {{end}}
302 {{end}}
303 // clang-format on
304
305 return success;
306}
307
Chia-I Wueb7db122016-03-24 09:11:06 +0800308»} // namespace driver
309»} // namespace vulkan
310
311// clang-format on
312¶{{end}}
313
314
315{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800316------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800317 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800318------------------------------------------------------------------------------
319*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800320{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800321 {{AssertType $ "Function"}}
322
323 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
324{{end}}
325
326
327{{/*
328-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800329 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800330-------------------------------------------------------------------------------
331*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800332{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800333 #define UNLIKELY(expr) __builtin_expect((expr), 0)
334
335 #define INIT_PROC(obj, proc) do { \
336 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
337 get_proc(obj, "vk" # proc)); \
338 if (UNLIKELY(!data.{{$}}.proc)) { \
339 ALOGE("missing " # obj " proc: vk" # proc); \
340 success = false; \
341 } \
342 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800343{{end}}
344
345
346{{/*
347-------------------------------------------------------------------------------
348 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
349-------------------------------------------------------------------------------
350*/}}
351{{define "C++.InitProc"}}
352 {{AssertType $ "Function"}}
353
354 {{$ext := GetAnnotation $ "extension"}}
355 {{if $ext}}
356 INIT_PROC_EXT({{Macro "BaseName" $ext}}, §
357 {{else}}
358 INIT_PROC
359 {{end}}
360
361 {{if (Macro "IsInstanceDispatched" $)}}
362 instance, §
363 {{else}}
364 dev, §
365 {{end}}
366
367 {{Macro "BaseName" $}});
368{{end}}
369
370
371{{/*
372------------------------------------------------------------------------------
373 Emits true if a function is exported and instance-dispatched.
374------------------------------------------------------------------------------
375*/}}
376{{define "api.IsInstanceDispatchTableEntry"}}
377 {{AssertType $ "Function"}}
378
379 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
380 true
381 {{end}}
382{{end}}
383
384
385{{/*
386------------------------------------------------------------------------------
387 Emits true if a function is exported and device-dispatched.
388------------------------------------------------------------------------------
389*/}}
390{{define "api.IsDeviceDispatchTableEntry"}}
391 {{AssertType $ "Function"}}
392
393 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
394 true
395 {{end}}
396{{end}}
397
398
399{{/*
400------------------------------------------------------------------------------
401 Emits true if a function is intercepted by vulkan::api.
402------------------------------------------------------------------------------
403*/}}
404{{define "api.IsIntercepted"}}
405 {{AssertType $ "Function"}}
406
407 {{if (Macro "IsFunctionSupported" $)}}
408 {{/* Global functions cannot be dispatched at all */}}
409 {{ if (Macro "IsGloballyDispatched" $)}}true
410
411 {{/* VkPhysicalDevice functions that manage device layers */}}
412 {{else if eq $.Name "vkCreateDevice"}}true
413 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
414 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
415
416 {{/* Destroy functions of dispatchable objects */}}
417 {{else if eq $.Name "vkDestroyInstance"}}true
418 {{else if eq $.Name "vkDestroyDevice"}}true
419
420 {{end}}
421 {{end}}
422{{end}}
423
424
425{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800426-------------------------------------------------------------------------------
427 Emits INIT_PROC_EXT macro for vulkan::api.
428-------------------------------------------------------------------------------
429*/}}
430{{define "api.C++.DefineInitProcExtMacro"}}
431 // TODO do we want to point to a stub or nullptr when ext is not enabled?
432 #define INIT_PROC_EXT(ext, obj, proc) do { \
433 INIT_PROC(obj, proc); \
434 } while(0)
435{{end}}
436
437
438{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800439------------------------------------------------------------------------------
440 Emits code for vkGetInstanceProcAddr for function interception.
441------------------------------------------------------------------------------
442*/}}
443{{define "api.C++.InterceptInstanceProcAddr"}}
444 {{AssertType $ "API"}}
445
446 // global functions
447 if (!instance) {
448 {{range $f := AllCommands $}}
449 {{if (Macro "IsGloballyDispatched" $f)}}
450 if (strcmp(pName, "{{$f.Name}}") == 0) return §
451 reinterpret_cast<PFN_vkVoidFunction>(§
452 vulkan::api::{{Macro "BaseName" $f}});
453 {{end}}
454 {{end}}
455
456 ALOGE("vkGetInstanceProcAddr called with %s without instance", pName);
457 return nullptr;
458 }
459
460 static const struct Hook {
461 const char* name;
462 PFN_vkVoidFunction proc;
463 } hooks[] = {
464 {{range $f := SortBy (AllCommands $) "FunctionName"}}
465 {{if (Macro "IsFunctionExported" $f)}}
466 {{/* hide global functions */}}
467 {{if (Macro "IsGloballyDispatched" $f)}}
468 { "{{$f.Name}}", nullptr },
469
470 {{/* redirect intercepted functions */}}
471 {{else if (Macro "api.IsIntercepted" $f)}}
472 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
473 vulkan::api::{{Macro "BaseName" $f}}) },
474
475 {{/* redirect vkGetInstanceProcAddr to itself */}}
476 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
477 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
478
479 {{/* redirect device functions to themselves as a workaround for
480 layers that do not intercept in their vkGetInstanceProcAddr */}}
481 {{else if (Macro "IsDeviceDispatched" $f)}}
482 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
483
484 {{end}}
485 {{end}}
486 {{end}}
487 };
488 // clang-format on
489 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
490 auto hook = std::lower_bound(
491 hooks, hooks + count, pName,
492 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
493 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
494 if (!hook->proc)
495 ALOGE("vkGetInstanceProcAddr called with %s with instance", pName);
496 return hook->proc;
497 }
498 // clang-format off
499
500{{end}}
501
502
503{{/*
504------------------------------------------------------------------------------
505 Emits code for vkGetDeviceProcAddr for function interception.
506------------------------------------------------------------------------------
507*/}}
508{{define "api.C++.InterceptDeviceProcAddr"}}
509 {{AssertType $ "API"}}
510
511 if (device == VK_NULL_HANDLE) {
512 ALOGE("vkGetDeviceProcAddr called with invalid device");
513 return nullptr;
514 }
515
516 static const char* const known_non_device_names[] = {
517 {{range $f := SortBy (AllCommands $) "FunctionName"}}
518 {{if (Macro "IsFunctionSupported" $f)}}
519 {{if not (Macro "IsDeviceDispatched" $f)}}
520 "{{$f.Name}}",
521 {{end}}
522 {{end}}
523 {{end}}
524 };
525 // clang-format on
526 constexpr size_t count = sizeof(known_non_device_names) /
527 sizeof(known_non_device_names[0]);
528 if (!pName ||
529 std::binary_search(
530 known_non_device_names, known_non_device_names + count, pName,
531 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
532 ALOGE("vkGetDeviceProcAddr called with %s", pName);
533 return nullptr;
534 }
535 // clang-format off
536
537{{end}}
538
539
540{{/*
541------------------------------------------------------------------------------
542 Emits code to dispatch a function.
543------------------------------------------------------------------------------
544*/}}
545{{define "api.C++.Dispatch"}}
546 {{AssertType $ "Function"}}
547
548 {{if (Macro "api.IsIntercepted" $)}}// call into api.cpp{{end}}
549 {{if not (IsVoid $.Return.Type)}}return §{{end}}
550
551 {{if (Macro "api.IsIntercepted" $)}}
552 vulkan::api::§
553 {{else}}
554 {{$p0 := index $.CallParameters 0}}
555 vulkan::api::GetData({{$p0.Name}}).dispatch
556 {{end}}
557
558 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
559{{end}}
560
561
562{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800563------------------------------------------------------------------------------
564 Emits a list of extensions intercepted by vulkan::driver.
565------------------------------------------------------------------------------
566*/}}
567{{define "driver.InterceptedExtensions"}}
568VK_ANDROID_native_buffer
569VK_EXT_debug_report
570VK_KHR_android_surface
571VK_KHR_surface
572VK_KHR_swapchain
573{{end}}
574
575
576{{/*
577------------------------------------------------------------------------------
578 Emits true if an extension is intercepted by vulkan::driver.
579------------------------------------------------------------------------------
580*/}}
581{{define "driver.IsExtensionIntercepted"}}
582 {{$ext_name := index $.Arguments 0}}
583 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
584
585 {{range $f := $filters}}
586 {{if eq $ext_name $f}}true{{end}}
587 {{end}}
588{{end}}
589
590
591{{/*
592------------------------------------------------------------------------------
593 Emits true if a function is intercepted by vulkan::driver.
594------------------------------------------------------------------------------
595*/}}
596{{define "driver.IsIntercepted"}}
597 {{AssertType $ "Function"}}
598
599 {{if (Macro "IsFunctionSupported" $)}}
600 {{/* Create functions of dispatchable objects */}}
601 {{ if eq $.Name "vkCreateInstance"}}true
602 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800603 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800604 {{else if eq $.Name "vkGetDeviceQueue"}}true
605 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
606
607 {{/* Destroy functions of dispatchable objects */}}
608 {{else if eq $.Name "vkDestroyInstance"}}true
609 {{else if eq $.Name "vkDestroyDevice"}}true
610
611 {{/* Enumeration of extensions */}}
612 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
613 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
614
Chia-I Wueb7db122016-03-24 09:11:06 +0800615 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
616 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
617
618 {{end}}
619
620 {{$ext := GetAnnotation $ "extension"}}
621 {{if $ext}}
622 {{Macro "driver.IsExtensionIntercepted" $ext}}
623 {{end}}
624
625 {{end}}
626{{end}}
627
628
629{{/*
630------------------------------------------------------------------------------
631 Emits true if a function needs ProcHook stubs.
632------------------------------------------------------------------------------
633*/}}
634{{define "driver.NeedProcHookStubs"}}
635 {{AssertType $ "Function"}}
636
637 {{if (Macro "driver.IsIntercepted" $)}}
638 {{$ext := GetAnnotation $ "extension"}}
639 {{if $ext}}
640 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
641 {{end}}
642 {{end}}
643{{end}}
644
645
646{{/*
647-------------------------------------------------------------------------------
648 Emits definition of struct ProcHook.
649-------------------------------------------------------------------------------
650*/}}
651{{define "driver.C++.DefineProcHookType"}}
652 struct ProcHook {
653 enum Type {
654 GLOBAL,
655 INSTANCE,
656 DEVICE,
657 };
658
659 enum Extension {
660 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
661 {{range $e := $exts}}
662 {{TrimPrefix "VK_" $e}},
663 {{end}}
664
665 EXTENSION_CORE, // valid bit
666 EXTENSION_COUNT,
667 EXTENSION_UNKNOWN,
668 };
669
670 const char* name;
671 Type type;
672 Extension extension;
673
674 PFN_vkVoidFunction proc;
675 PFN_vkVoidFunction disabled_proc; // nullptr for global hooks
676 PFN_vkVoidFunction checked_proc; // nullptr for global/instance hooks
677 };
678{{end}}
679
680
681{{/*
682-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800683 Emits INIT_PROC_EXT macro for vulkan::driver.
684-------------------------------------------------------------------------------
685*/}}
686{{define "driver.C++.DefineInitProcExtMacro"}}
687 #define INIT_PROC_EXT(ext, obj, proc) do { \
688 if (data.hal_extensions[ProcHook::ext]) \
689 INIT_PROC(obj, proc); \
690 } while(0)
691{{end}}
692
693
694{{/*
695-------------------------------------------------------------------------------
Chia-I Wueb7db122016-03-24 09:11:06 +0800696 Emits definitions of stub functions for ProcHook.
697-------------------------------------------------------------------------------
698*/}}
699{{define "driver.C++.DefineProcHookStubs"}}
700 {{AssertType $ "Function"}}
701
702 {{if (Macro "driver.NeedProcHookStubs" $)}}
703 {{$ext := GetAnnotation $ "extension"}}
704 {{$ext_name := index $ext.Arguments 0}}
705
706 {{$base := (Macro "BaseName" $)}}
707 {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}
708
709 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$unnamed_params}}) {
710 ALOGE("{{$ext_name}} not enabled. {{$.Name}} not executed.");
711 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
712 }
713 {{if (Macro "IsDeviceDispatched" $)}}
714
715 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
716 {{if not (IsVoid $.Return.Type)}}return §{{end}}
717
718 {{$p0 := index $.CallParameters 0}}
719 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
720 (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) ? §
Chia-I Wu62262232016-03-26 07:06:44 +0800721 {{$base}}({{Macro "Arguments" $}}) : §
Chia-I Wueb7db122016-03-24 09:11:06 +0800722 disabled{{$base}}({{Macro "Arguments" $}});
723 }
724 {{end}}
725
726 {{end}}
727{{end}}
728
729
730{{/*
731-------------------------------------------------------------------------------
732 Emits definition of a global ProcHook.
733-------------------------------------------------------------------------------
734*/}}
735{{define "driver.C++.DefineGlobalProcHook"}}
736 {{AssertType $ "Function"}}
737
738 {{$base := (Macro "BaseName" $)}}
739
740 {{$ext := GetAnnotation $ "extension"}}
741 {{if $ext}}
742 {{Error "invalid global extension"}}
743 {{end}}
744
745 {
746 "{{$.Name}}",
747 ProcHook::GLOBAL,
748 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800749 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800750 nullptr,
751 nullptr,
752 },
753{{end}}
754
755
756{{/*
757-------------------------------------------------------------------------------
758 Emits definition of an instance ProcHook.
759-------------------------------------------------------------------------------
760*/}}
761{{define "driver.C++.DefineInstanceProcHook"}}
762 {{AssertType $ "Function"}}
763
764 {{$base := (Macro "BaseName" $)}}
765
766 {
767 "{{$.Name}}",
768 ProcHook::INSTANCE,
769
770 {{$ext := GetAnnotation $ "extension"}}
771 {{if $ext}}
772 ProcHook::{{Macro "BaseName" $ext}},
773
774 {{if (Macro "IsExtensionInternal" $ext)}}
775 nullptr,
776 nullptr,
777 nullptr,
778 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800779 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800780 reinterpret_cast<PFN_vkVoidFunction>(disabled{{$base}}),
781 nullptr,
782 {{end}}
783 {{else}}
784 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800785 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800786 nullptr,
787 nullptr,
788 {{end}}
789 },
790{{end}}
791
792
793{{/*
794-------------------------------------------------------------------------------
795 Emits definition of a device ProcHook.
796-------------------------------------------------------------------------------
797*/}}
798{{define "driver.C++.DefineDeviceProcHook"}}
799 {{AssertType $ "Function"}}
800
801 {{$base := (Macro "BaseName" $)}}
802
803 {
804 "{{$.Name}}",
805 ProcHook::DEVICE,
806
807 {{$ext := GetAnnotation $ "extension"}}
808 {{if $ext}}
809 ProcHook::{{Macro "BaseName" $ext}},
810
811 {{if (Macro "IsExtensionInternal" $ext)}}
812 nullptr,
813 nullptr,
814 nullptr,
815 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800816 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800817 reinterpret_cast<PFN_vkVoidFunction>(disabled{{$base}}),
818 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
819 {{end}}
820 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800821 ProcHook::EXTENSION_CORE,
822 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
823 nullptr,
824 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800825 {{end}}
826 },
827{{end}}
828
829
830{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800831-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800832 Emits true if a function is needed by vulkan::driver.
833-------------------------------------------------------------------------------
834*/}}
835{{define "driver.IsDriverTableEntry"}}
836 {{AssertType $ "Function"}}
837
838 {{if (Macro "IsFunctionSupported" $)}}
839 {{/* Create functions of dispatchable objects */}}
840 {{ if eq $.Name "vkCreateDevice"}}true
841 {{else if eq $.Name "vkGetDeviceQueue"}}true
842 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
843
844 {{/* Destroy functions of dispatchable objects */}}
845 {{else if eq $.Name "vkDestroyInstance"}}true
846 {{else if eq $.Name "vkDestroyDevice"}}true
847
Chia-I Wu4901db72016-03-24 16:38:58 +0800848 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
849
Chia-I Wucc5e2762016-03-24 13:01:16 +0800850 {{/* Enumeration of extensions */}}
851 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
852
853 {{/* We cache physical devices in loader.cpp */}}
854 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
855
856 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
857 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
858
859 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
860 {{else if eq $.Name "vkCreateImage"}}true
861 {{else if eq $.Name "vkDestroyImage"}}true
862
863 {{end}}
864
865 {{$ext := GetAnnotation $ "extension"}}
866 {{if $ext}}
867 {{$ext_name := index $ext.Arguments 0}}
868 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
869 {{else if eq $ext_name "VK_EXT_debug_report"}}true
870 {{end}}
871 {{end}}
872 {{end}}
873{{end}}
874
875
876{{/*
877------------------------------------------------------------------------------
878 Emits true if an instance-dispatched function is needed by vulkan::driver.
879------------------------------------------------------------------------------
880*/}}
881{{define "driver.IsInstanceDriverTableEntry"}}
882 {{AssertType $ "Function"}}
883
884 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
885 true
886 {{end}}
887{{end}}
888
889
890{{/*
891------------------------------------------------------------------------------
892 Emits true if a device-dispatched function is needed by vulkan::driver.
893------------------------------------------------------------------------------
894*/}}
895{{define "driver.IsDeviceDriverTableEntry"}}
896 {{AssertType $ "Function"}}
897
898 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
899 true
900 {{end}}
901{{end}}
902
903
904{{/*
905-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +0800906 Emits a function/extension name without the "vk"/"VK_" prefix.
907-------------------------------------------------------------------------------
908*/}}
909{{define "BaseName"}}
910 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
911 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
912 {{else}}{{Error "invalid use of BaseName"}}
913 {{end}}
914{{end}}
915
916
917{{/*
918-------------------------------------------------------------------------------
919 Emits a comma-separated list of C parameter names for the given command.
920-------------------------------------------------------------------------------
921*/}}
922{{define "Arguments"}}
923 {{AssertType $ "Function"}}
924
925 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
926{{end}}
927
928
929{{/*
930------------------------------------------------------------------------------
931------------------------------------------------------------------------------
932*/}}
933{{define "IsGloballyDispatched"}}
934 {{AssertType $ "Function"}}
935 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
936 true
937 {{end}}
938{{end}}
939
940
941{{/*
942------------------------------------------------------------------------------
943 Emit "true" for supported functions that undergo table dispatch. Only global
944 functions and functions handled in the loader top without calling into
945 lower layers are not dispatched.
946------------------------------------------------------------------------------
947*/}}
948{{define "IsInstanceDispatched"}}
949 {{AssertType $ "Function"}}
950 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
951 true
952 {{end}}
953{{end}}
954
955
956{{/*
957------------------------------------------------------------------------------
958 Emit "true" for supported functions that can have device-specific dispatch.
959------------------------------------------------------------------------------
960*/}}
961{{define "IsDeviceDispatched"}}
962 {{AssertType $ "Function"}}
963 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
964 true
965 {{end}}
966{{end}}
967
968
969{{/*
970------------------------------------------------------------------------------
971 Emit "true" if a function is core or from a supportable extension.
972------------------------------------------------------------------------------
973*/}}
974{{define "IsFunctionSupported"}}
975 {{AssertType $ "Function"}}
976 {{if not (GetAnnotation $ "pfn")}}
977 {{$ext := GetAnnotation $ "extension"}}
978 {{if not $ext}}true
979 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
980 {{end}}
981 {{end}}
982{{end}}
983
984
985{{/*
986------------------------------------------------------------------------------
987 Decides whether a function should be exported from the Android Vulkan
988 library. Functions in the core API and in loader extensions are exported.
989------------------------------------------------------------------------------
990*/}}
991{{define "IsFunctionExported"}}
992 {{AssertType $ "Function"}}
993
994 {{if (Macro "IsFunctionSupported" $)}}
995 {{$ext := GetAnnotation $ "extension"}}
996 {{if $ext}}
997 {{Macro "IsExtensionExported" $ext}}
998 {{else}}
999 true
1000 {{end}}
1001 {{end}}
1002{{end}}
1003
1004
1005{{/*
1006------------------------------------------------------------------------------
1007 Emit "true" if an extension is unsupportable on Android.
1008------------------------------------------------------------------------------
1009*/}}
1010{{define "IsExtensionBlacklisted"}}
1011 {{$ext := index $.Arguments 0}}
1012 {{ if eq $ext "VK_KHR_display"}}true
1013 {{else if eq $ext "VK_KHR_display_swapchain"}}true
1014 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1015 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1016 {{else if eq $ext "VK_KHR_wayland_surface"}}true
1017 {{else if eq $ext "VK_KHR_mir_surface"}}true
1018 {{else if eq $ext "VK_KHR_win32_surface"}}true
1019 {{end}}
1020{{end}}
1021
1022
1023{{/*
1024------------------------------------------------------------------------------
1025 Reports whether an extension is implemented entirely by the loader,
1026 so drivers should not enumerate it.
1027------------------------------------------------------------------------------
1028*/}}
1029{{define "IsExtensionExported"}}
1030 {{$ext := index $.Arguments 0}}
1031 {{ if eq $ext "VK_KHR_surface"}}true
1032 {{else if eq $ext "VK_KHR_swapchain"}}true
1033 {{else if eq $ext "VK_KHR_android_surface"}}true
1034 {{end}}
1035{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001036
1037
1038{{/*
1039------------------------------------------------------------------------------
1040 Reports whether an extension is internal to the loader and drivers,
1041 so the loader should not enumerate it.
1042------------------------------------------------------------------------------
1043*/}}
1044{{define "IsExtensionInternal"}}
1045 {{$ext := index $.Arguments 0}}
1046 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1047 {{end}}
1048{{end}}