blob: dd0de048fb6e190f5b591388190fb16184f000ae [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>
Yiwei Zhang6d78a572019-04-10 15:35:38 -070041
42#include <bitset>
43
Chia-I Wu8925efd2016-04-13 15:13:21 +080044#include "driver_gen.h"
Chia-I Wu0c203242016-03-15 13:44:51 +080045
46namespace vulkan
47namespace api
48
49struct InstanceDispatchTable {
50 // clang-format off
51 {{range $f := AllCommands $}}
52 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080053 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080054 {{end}}
55 {{end}}
56 // clang-format on
57};
58
59struct DeviceDispatchTable {
60 // clang-format off
61 {{range $f := AllCommands $}}
62 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080063 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080064 {{end}}
65 {{end}}
66 // clang-format on
67};
68
Chia-I Wu8925efd2016-04-13 15:13:21 +080069bool InitDispatchTable(
70 VkInstance instance,
71 PFN_vkGetInstanceProcAddr get_proc,
72 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
73bool InitDispatchTable(
74 VkDevice dev,
75 PFN_vkGetDeviceProcAddr get_proc,
76 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wu0c203242016-03-15 13:44:51 +080077
78»} // namespace api
79»} // namespace vulkan
80
81#endif // LIBVULKAN_API_GEN_H
82¶{{end}}
83
84
85{{/*
86-------------------------------------------------------------------------------
87 api_gen.cpp
88-------------------------------------------------------------------------------
89*/}}
90{{define "api_gen.cpp"}}
91{{Macro "Copyright"}}
92
93// WARNING: This file is generated. See ../README.md for instructions.
94
Yiwei Zhang6d78a572019-04-10 15:35:38 -070095#include <log/log.h>
Chia-I Wu0c203242016-03-15 13:44:51 +080096#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070097
Chia-I Wu0c203242016-03-15 13:44:51 +080098#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -070099
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800100// to catch mismatches between vulkan.h and this file
101#undef VK_NO_PROTOTYPES
Chia-I Wu0c203242016-03-15 13:44:51 +0800102#include "api.h"
103
104namespace vulkan
105namespace api
106
Chia-I Wucc5e2762016-03-24 13:01:16 +0800107{{Macro "C++.DefineInitProcMacro" "dispatch"}}
108
109{{Macro "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800110
Chia-I Wu8925efd2016-04-13 15:13:21 +0800111namespace
112
113// clang-format off
114
115{{range $f := AllCommands $}}
116 {{Macro "api.C++.DefineExtensionStub" $f}}
117{{end}}
118// clang-format on
119
120»} // anonymous
121
122bool InitDispatchTable(
123 VkInstance instance,
124 PFN_vkGetInstanceProcAddr get_proc,
125 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800126 auto& data = GetData(instance);
127 bool success = true;
128
129 // clang-format off
130 {{range $f := AllCommands $}}
131 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
132 {{Macro "C++.InitProc" $f}}
133 {{end}}
134 {{end}}
135 // clang-format on
136
137 return success;
138}
139
Chia-I Wu8925efd2016-04-13 15:13:21 +0800140bool InitDispatchTable(
141 VkDevice dev,
142 PFN_vkGetDeviceProcAddr get_proc,
143 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800144 auto& data = GetData(dev);
145 bool success = true;
146
147 // clang-format off
148 {{range $f := AllCommands $}}
149 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
150 {{Macro "C++.InitProc" $f}}
151 {{end}}
152 {{end}}
153 // clang-format on
154
155 return success;
156}
157
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800158// clang-format off
159
160namespace
161
162// forward declarations needed by GetInstanceProcAddr and GetDeviceProcAddr
163{{range $f := AllCommands $}}
164 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
165 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
166 {{end}}
167{{end}}
168
169{{range $f := AllCommands $}}
170 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
171 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}) {
172 {{ if eq $f.Name "vkGetInstanceProcAddr"}}
173 {{Macro "api.C++.InterceptInstanceProcAddr" $}}
174 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
175 {{Macro "api.C++.InterceptDeviceProcAddr" $}}
176 {{end}}
177
178 {{Macro "api.C++.Dispatch" $f}}
179 }
180
181 {{end}}
182{{end}}
183
184»} // anonymous namespace
185
186// clang-format on
187
Chia-I Wu0c203242016-03-15 13:44:51 +0800188»} // namespace api
189»} // namespace vulkan
190
191// clang-format off
192
193{{range $f := AllCommands $}}
194 {{if (Macro "IsFunctionExported" $f)}}
195 __attribute__((visibility("default")))
196 VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800197 {{if not (IsVoid $f.Return.Type)}}return §{{end}}
198 vulkan::api::{{Macro "BaseName" $f}}({{Macro "Arguments" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800199 }
200
201 {{end}}
202{{end}}
203
204// clang-format on
205¶{{end}}
206
207
208{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800209-------------------------------------------------------------------------------
210 driver_gen.h
211-------------------------------------------------------------------------------
212*/}}
213{{define "driver_gen.h"}}
214{{Macro "Copyright"}}
215
216// WARNING: This file is generated. See ../README.md for instructions.
217
218#ifndef LIBVULKAN_DRIVER_GEN_H
219#define LIBVULKAN_DRIVER_GEN_H
220
Chia-I Wueb7db122016-03-24 09:11:06 +0800221#include <vulkan/vk_android_native_buffer.h>
Yiwei Zhang6d78a572019-04-10 15:35:38 -0700222#include <vulkan/vulkan.h>
223
224#include <bitset>
Chia-I Wueb7db122016-03-24 09:11:06 +0800225
226namespace vulkan
227namespace driver
228
229{{Macro "driver.C++.DefineProcHookType"}}
230
Chia-I Wucc5e2762016-03-24 13:01:16 +0800231struct InstanceDriverTable {
232 // clang-format off
233 {{range $f := AllCommands $}}
234 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
235 {{Macro "C++.DeclareTableEntry" $f}};
236 {{end}}
237 {{end}}
238 // clang-format on
239};
240
241struct DeviceDriverTable {
242 // clang-format off
243 {{range $f := AllCommands $}}
244 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
245 {{Macro "C++.DeclareTableEntry" $f}};
246 {{end}}
247 {{end}}
248 // clang-format on
249};
250
Chia-I Wueb7db122016-03-24 09:11:06 +0800251const ProcHook* GetProcHook(const char* name);
252ProcHook::Extension GetProcHookExtension(const char* name);
253
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800254bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
255 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
256bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
257 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800258
Chia-I Wueb7db122016-03-24 09:11:06 +0800259»} // namespace driver
260»} // namespace vulkan
261
262#endif // LIBVULKAN_DRIVER_TABLE_H
263¶{{end}}
264
265
266{{/*
267-------------------------------------------------------------------------------
268 driver_gen.cpp
269-------------------------------------------------------------------------------
270*/}}
271{{define "driver_gen.cpp"}}
272{{Macro "Copyright"}}
273
274// WARNING: This file is generated. See ../README.md for instructions.
275
Yiwei Zhang6d78a572019-04-10 15:35:38 -0700276#include <log/log.h>
Chia-I Wueb7db122016-03-24 09:11:06 +0800277#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700278
Chia-I Wueb7db122016-03-24 09:11:06 +0800279#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700280
Chia-I Wueb7db122016-03-24 09:11:06 +0800281#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800282
283namespace vulkan
284namespace driver
285
286namespace
287
288// clang-format off
289
290{{range $f := AllCommands $}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800291 {{Macro "driver.C++.DefineProcHookStub" $f}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800292{{end}}
293// clang-format on
294
295const ProcHook g_proc_hooks[] = {
296 // clang-format off
297 {{range $f := SortBy (AllCommands $) "FunctionName"}}
298 {{if (Macro "driver.IsIntercepted" $f)}}
299 {{ if (Macro "IsGloballyDispatched" $f)}}
300 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
301 {{else if (Macro "IsInstanceDispatched" $f)}}
302 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
303 {{else if (Macro "IsDeviceDispatched" $f)}}
304 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
305 {{end}}
306 {{end}}
307 {{end}}
308 // clang-format on
309};
310
311»} // anonymous
312
313const ProcHook* GetProcHook(const char* name) {
314 const auto& begin = g_proc_hooks;
315 const auto& end = g_proc_hooks +
316 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
317 const auto hook = std::lower_bound(begin, end, name,
318 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
319 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
320}
321
322ProcHook::Extension GetProcHookExtension(const char* name) {
Chris Forbes6aa30db2017-02-20 17:12:53 +1300323 {{$exts := Strings (Macro "driver.KnownExtensions") | SplitOn "\n"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800324 // clang-format off
325 {{range $e := $exts}}
326 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
327 {{end}}
328 // clang-format on
329 return ProcHook::EXTENSION_UNKNOWN;
330}
331
Chia-I Wucc5e2762016-03-24 13:01:16 +0800332{{Macro "C++.DefineInitProcMacro" "driver"}}
333
334{{Macro "driver.C++.DefineInitProcExtMacro"}}
335
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800336bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
337 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800338{
339 auto& data = GetData(instance);
340 bool success = true;
341
342 // clang-format off
343 {{range $f := AllCommands $}}
344 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
345 {{Macro "C++.InitProc" $f}}
346 {{end}}
347 {{end}}
348 // clang-format on
349
350 return success;
351}
352
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800353bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
354 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800355{
356 auto& data = GetData(dev);
357 bool success = true;
358
359 // clang-format off
360 {{range $f := AllCommands $}}
361 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
362 {{Macro "C++.InitProc" $f}}
363 {{end}}
364 {{end}}
365 // clang-format on
366
367 return success;
368}
369
Chia-I Wueb7db122016-03-24 09:11:06 +0800370»} // namespace driver
371»} // namespace vulkan
372
373// clang-format on
374¶{{end}}
375
376
377{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800378------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800379 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800380------------------------------------------------------------------------------
381*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800382{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800383 {{AssertType $ "Function"}}
384
385 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
386{{end}}
387
388
389{{/*
390-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800391 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800392-------------------------------------------------------------------------------
393*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800394{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800395 #define UNLIKELY(expr) __builtin_expect((expr), 0)
396
Chris Forbes5948b3e2016-12-23 13:49:53 +1300397 #define INIT_PROC(required, obj, proc) do { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800398 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
399 get_proc(obj, "vk" # proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300400 if (UNLIKELY(required && !data.{{$}}.proc)) { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800401 ALOGE("missing " # obj " proc: vk" # proc); \
402 success = false; \
403 } \
404 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800405{{end}}
406
407
408{{/*
409-------------------------------------------------------------------------------
410 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
411-------------------------------------------------------------------------------
412*/}}
413{{define "C++.InitProc"}}
414 {{AssertType $ "Function"}}
415
416 {{$ext := GetAnnotation $ "extension"}}
417 {{if $ext}}
Jesse Halld1abd742017-02-09 21:45:51 -0800418 INIT_PROC_EXT({{Macro "BaseName" $ext}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800419 {{else}}
Jesse Halld1abd742017-02-09 21:45:51 -0800420 INIT_PROC
Chia-I Wu0c203242016-03-15 13:44:51 +0800421 {{end}}
422
Ian Elliott28bd2c32017-10-13 09:21:12 -0600423 {{if GetAnnotation $ "optional"}}false{{else if GetAnnotation $ "vulkan1_1"}}false{{else}}true{{end}}, §
Jesse Halld1abd742017-02-09 21:45:51 -0800424
Chia-I Wu0c203242016-03-15 13:44:51 +0800425 {{if (Macro "IsInstanceDispatched" $)}}
426 instance, §
427 {{else}}
428 dev, §
429 {{end}}
430
431 {{Macro "BaseName" $}});
432{{end}}
433
434
435{{/*
436------------------------------------------------------------------------------
437 Emits true if a function is exported and instance-dispatched.
438------------------------------------------------------------------------------
439*/}}
440{{define "api.IsInstanceDispatchTableEntry"}}
441 {{AssertType $ "Function"}}
442
443 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
Chia-I Wudbd33bc2016-06-02 11:25:47 +0800444 {{/* deprecated and unused internally */}}
445 {{if not (eq $.Name "vkEnumerateDeviceLayerProperties")}}
446 true
447 {{end}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800448 {{end}}
449{{end}}
450
451
452{{/*
453------------------------------------------------------------------------------
454 Emits true if a function is exported and device-dispatched.
455------------------------------------------------------------------------------
456*/}}
457{{define "api.IsDeviceDispatchTableEntry"}}
458 {{AssertType $ "Function"}}
459
460 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
461 true
462 {{end}}
463{{end}}
464
465
466{{/*
467------------------------------------------------------------------------------
468 Emits true if a function is intercepted by vulkan::api.
469------------------------------------------------------------------------------
470*/}}
471{{define "api.IsIntercepted"}}
472 {{AssertType $ "Function"}}
473
474 {{if (Macro "IsFunctionSupported" $)}}
475 {{/* Global functions cannot be dispatched at all */}}
476 {{ if (Macro "IsGloballyDispatched" $)}}true
477
478 {{/* VkPhysicalDevice functions that manage device layers */}}
479 {{else if eq $.Name "vkCreateDevice"}}true
480 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
481 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
482
483 {{/* Destroy functions of dispatchable objects */}}
484 {{else if eq $.Name "vkDestroyInstance"}}true
485 {{else if eq $.Name "vkDestroyDevice"}}true
486
487 {{end}}
488 {{end}}
489{{end}}
490
491
492{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800493-------------------------------------------------------------------------------
494 Emits INIT_PROC_EXT macro for vulkan::api.
495-------------------------------------------------------------------------------
496*/}}
497{{define "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800498 // Exported extension functions may be invoked even when their extensions
499 // are disabled. Dispatch to stubs when that happens.
Chris Forbes5948b3e2016-12-23 13:49:53 +1300500 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800501 if (extensions[driver::ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300502 INIT_PROC(required, obj, proc); \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800503 else \
504 data.dispatch.proc = disabled ## proc; \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800505 } while(0)
506{{end}}
507
508
509{{/*
Chia-I Wu8925efd2016-04-13 15:13:21 +0800510-------------------------------------------------------------------------------
511 Emits a stub for an exported extension function.
512-------------------------------------------------------------------------------
513*/}}
514{{define "api.C++.DefineExtensionStub"}}
515 {{AssertType $ "Function"}}
516
517 {{$ext := GetAnnotation $ "extension"}}
518 {{if and $ext (Macro "IsFunctionExported" $)}}
519 {{$ext_name := index $ext.Arguments 0}}
520
521 {{$base := (Macro "BaseName" $)}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800522
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800523 {{$p0 := (index $.CallParameters 0)}}
524 {{$ptail := (Tail 1 $.CallParameters)}}
525
526 {{$first_type := (Macro "Parameter" $p0)}}
527 {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
528
529 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
530 driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
531 "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
Chia-I Wu8925efd2016-04-13 15:13:21 +0800532 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
533 }
534
535 {{end}}
536{{end}}
537
538
539{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800540------------------------------------------------------------------------------
541 Emits code for vkGetInstanceProcAddr for function interception.
542------------------------------------------------------------------------------
543*/}}
544{{define "api.C++.InterceptInstanceProcAddr"}}
545 {{AssertType $ "API"}}
546
547 // global functions
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800548 if (instance == VK_NULL_HANDLE) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800549 {{range $f := AllCommands $}}
550 {{if (Macro "IsGloballyDispatched" $f)}}
551 if (strcmp(pName, "{{$f.Name}}") == 0) return §
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800552 reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800553 {{end}}
554 {{end}}
555
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800556 ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
Chia-I Wu0c203242016-03-15 13:44:51 +0800557 return nullptr;
558 }
559
560 static const struct Hook {
561 const char* name;
562 PFN_vkVoidFunction proc;
563 } hooks[] = {
564 {{range $f := SortBy (AllCommands $) "FunctionName"}}
565 {{if (Macro "IsFunctionExported" $f)}}
566 {{/* hide global functions */}}
567 {{if (Macro "IsGloballyDispatched" $f)}}
568 { "{{$f.Name}}", nullptr },
569
570 {{/* redirect intercepted functions */}}
571 {{else if (Macro "api.IsIntercepted" $f)}}
572 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800573 {{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800574
575 {{/* redirect vkGetInstanceProcAddr to itself */}}
576 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800577 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800578
579 {{/* redirect device functions to themselves as a workaround for
580 layers that do not intercept in their vkGetInstanceProcAddr */}}
581 {{else if (Macro "IsDeviceDispatched" $f)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800582 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800583
584 {{end}}
585 {{end}}
586 {{end}}
587 };
588 // clang-format on
589 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
590 auto hook = std::lower_bound(
591 hooks, hooks + count, pName,
592 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
593 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800594 if (!hook->proc) {
595 vulkan::driver::Logger(instance).Err(
596 instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
597 instance, pName);
598 }
Chia-I Wu0c203242016-03-15 13:44:51 +0800599 return hook->proc;
600 }
601 // clang-format off
602
603{{end}}
604
605
606{{/*
607------------------------------------------------------------------------------
608 Emits code for vkGetDeviceProcAddr for function interception.
609------------------------------------------------------------------------------
610*/}}
611{{define "api.C++.InterceptDeviceProcAddr"}}
612 {{AssertType $ "API"}}
613
614 if (device == VK_NULL_HANDLE) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800615 ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
Chia-I Wu0c203242016-03-15 13:44:51 +0800616 return nullptr;
617 }
618
619 static const char* const known_non_device_names[] = {
620 {{range $f := SortBy (AllCommands $) "FunctionName"}}
621 {{if (Macro "IsFunctionSupported" $f)}}
622 {{if not (Macro "IsDeviceDispatched" $f)}}
623 "{{$f.Name}}",
624 {{end}}
625 {{end}}
626 {{end}}
627 };
628 // clang-format on
629 constexpr size_t count = sizeof(known_non_device_names) /
630 sizeof(known_non_device_names[0]);
631 if (!pName ||
632 std::binary_search(
633 known_non_device_names, known_non_device_names + count, pName,
634 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800635 vulkan::driver::Logger(device).Err
636 device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device
637 (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800638 return nullptr;
639 }
640 // clang-format off
641
Chia-I Wuc56603e2016-04-12 11:16:17 +0800642 {{range $f := AllCommands $}}
643 {{if (Macro "IsDeviceDispatched" $f)}}
644 {{ if (Macro "api.IsIntercepted" $f)}}
645 if (strcmp(pName, "{{$f.Name}}") == 0) return §
646 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800647 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800648 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
649 if (strcmp(pName, "{{$f.Name}}") == 0) return §
650 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800651 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800652 {{end}}
653 {{end}}
654 {{end}}
655
Chia-I Wu0c203242016-03-15 13:44:51 +0800656{{end}}
657
658
659{{/*
660------------------------------------------------------------------------------
661 Emits code to dispatch a function.
662------------------------------------------------------------------------------
663*/}}
664{{define "api.C++.Dispatch"}}
665 {{AssertType $ "Function"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800666 {{if (Macro "api.IsIntercepted" $)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800667 {{Error "$.Name should not be generated"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800668 {{end}}
669
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800670 {{if not (IsVoid $.Return.Type)}}return §{{end}}
671
672 {{$p0 := index $.CallParameters 0}}
673 GetData({{$p0.Name}}).dispatch
Chia-I Wu0c203242016-03-15 13:44:51 +0800674 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
675{{end}}
676
677
678{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800679------------------------------------------------------------------------------
680 Emits a list of extensions intercepted by vulkan::driver.
681------------------------------------------------------------------------------
682*/}}
683{{define "driver.InterceptedExtensions"}}
684VK_ANDROID_native_buffer
685VK_EXT_debug_report
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700686VK_EXT_hdr_metadata
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700687VK_EXT_swapchain_colorspace
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700688VK_GOOGLE_display_timing
Chia-I Wueb7db122016-03-24 09:11:06 +0800689VK_KHR_android_surface
Ian Elliott948233a2017-01-06 12:13:23 -0700690VK_KHR_incremental_present
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700691VK_KHR_shared_presentable_image
Chia-I Wueb7db122016-03-24 09:11:06 +0800692VK_KHR_surface
693VK_KHR_swapchain
Chris Forbes2452cf72017-03-16 16:30:17 +1300694VK_KHR_get_surface_capabilities2
Chia-I Wueb7db122016-03-24 09:11:06 +0800695{{end}}
696
697
698{{/*
699------------------------------------------------------------------------------
Chris Forbes6aa30db2017-02-20 17:12:53 +1300700 Emits a list of extensions known to vulkan::driver.
701------------------------------------------------------------------------------
702*/}}
703{{define "driver.KnownExtensions"}}
704{{Macro "driver.InterceptedExtensions"}}
705VK_KHR_get_physical_device_properties2
Jesse Hallcaea4112018-01-18 15:40:46 -0800706VK_ANDROID_external_memory_android_hardware_buffer
Chris Forbes6aa30db2017-02-20 17:12:53 +1300707{{end}}
708
709
710{{/*
711------------------------------------------------------------------------------
Chia-I Wueb7db122016-03-24 09:11:06 +0800712 Emits true if an extension is intercepted by vulkan::driver.
713------------------------------------------------------------------------------
714*/}}
715{{define "driver.IsExtensionIntercepted"}}
716 {{$ext_name := index $.Arguments 0}}
717 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
718
719 {{range $f := $filters}}
720 {{if eq $ext_name $f}}true{{end}}
721 {{end}}
722{{end}}
723
724
725{{/*
726------------------------------------------------------------------------------
727 Emits true if a function is intercepted by vulkan::driver.
728------------------------------------------------------------------------------
729*/}}
730{{define "driver.IsIntercepted"}}
731 {{AssertType $ "Function"}}
732
733 {{if (Macro "IsFunctionSupported" $)}}
734 {{/* Create functions of dispatchable objects */}}
735 {{ if eq $.Name "vkCreateInstance"}}true
736 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800737 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400738 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800739 {{else if eq $.Name "vkGetDeviceQueue"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400740 {{else if eq $.Name "vkGetDeviceQueue2"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800741 {{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 {
Chris Forbes6aa30db2017-02-20 17:12:53 +1300796 {{$exts := Strings (Macro "driver.KnownExtensions") | SplitOn "\n"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800797 {{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
Daniel Koch09f7bf92017-10-05 00:26:58 -0400965 {{else if eq $.Name "vkGetDeviceQueue2"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800966 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
967
968 {{/* Destroy functions of dispatchable objects */}}
969 {{else if eq $.Name "vkDestroyInstance"}}true
970 {{else if eq $.Name "vkDestroyDevice"}}true
971
972 {{/* Enumeration of extensions */}}
973 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
974
975 {{/* We cache physical devices in loader.cpp */}}
976 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400977 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800978
979 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
980 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
981
982 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
983 {{else if eq $.Name "vkCreateImage"}}true
984 {{else if eq $.Name "vkDestroyImage"}}true
985
Jesse Hall85bb0c52017-02-09 22:13:02 -0800986 {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true
Yiwei Zhangc1c9d3c2018-03-13 17:12:11 -0700987 {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true
Chris Forbes6aa30db2017-02-20 17:12:53 +1300988 {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800989 {{end}}
990
991 {{$ext := GetAnnotation $ "extension"}}
992 {{if $ext}}
993 {{$ext_name := index $ext.Arguments 0}}
994 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
995 {{else if eq $ext_name "VK_EXT_debug_report"}}true
996 {{end}}
997 {{end}}
998 {{end}}
999{{end}}
1000
1001
1002{{/*
1003------------------------------------------------------------------------------
1004 Emits true if an instance-dispatched function is needed by vulkan::driver.
1005------------------------------------------------------------------------------
1006*/}}
1007{{define "driver.IsInstanceDriverTableEntry"}}
1008 {{AssertType $ "Function"}}
1009
1010 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1011 true
1012 {{end}}
1013{{end}}
1014
1015
1016{{/*
1017------------------------------------------------------------------------------
1018 Emits true if a device-dispatched function is needed by vulkan::driver.
1019------------------------------------------------------------------------------
1020*/}}
1021{{define "driver.IsDeviceDriverTableEntry"}}
1022 {{AssertType $ "Function"}}
1023
1024 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1025 true
1026 {{end}}
1027{{end}}
1028
1029
1030{{/*
1031-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001032 Emits a function/extension name without the "vk"/"VK_" prefix.
1033-------------------------------------------------------------------------------
1034*/}}
1035{{define "BaseName"}}
1036 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1037 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1038 {{else}}{{Error "invalid use of BaseName"}}
1039 {{end}}
1040{{end}}
1041
1042
1043{{/*
1044-------------------------------------------------------------------------------
1045 Emits a comma-separated list of C parameter names for the given command.
1046-------------------------------------------------------------------------------
1047*/}}
1048{{define "Arguments"}}
1049 {{AssertType $ "Function"}}
1050
1051 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1052{{end}}
1053
1054
1055{{/*
1056------------------------------------------------------------------------------
1057------------------------------------------------------------------------------
1058*/}}
1059{{define "IsGloballyDispatched"}}
1060 {{AssertType $ "Function"}}
1061 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1062 true
1063 {{end}}
1064{{end}}
1065
1066
1067{{/*
1068------------------------------------------------------------------------------
1069 Emit "true" for supported functions that undergo table dispatch. Only global
1070 functions and functions handled in the loader top without calling into
1071 lower layers are not dispatched.
1072------------------------------------------------------------------------------
1073*/}}
1074{{define "IsInstanceDispatched"}}
1075 {{AssertType $ "Function"}}
1076 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1077 true
1078 {{end}}
1079{{end}}
1080
1081
1082{{/*
1083------------------------------------------------------------------------------
1084 Emit "true" for supported functions that can have device-specific dispatch.
1085------------------------------------------------------------------------------
1086*/}}
1087{{define "IsDeviceDispatched"}}
1088 {{AssertType $ "Function"}}
1089 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1090 true
1091 {{end}}
1092{{end}}
1093
1094
1095{{/*
1096------------------------------------------------------------------------------
1097 Emit "true" if a function is core or from a supportable extension.
1098------------------------------------------------------------------------------
1099*/}}
1100{{define "IsFunctionSupported"}}
1101 {{AssertType $ "Function"}}
1102 {{if not (GetAnnotation $ "pfn")}}
1103 {{$ext := GetAnnotation $ "extension"}}
1104 {{if not $ext}}true
1105 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1106 {{end}}
1107 {{end}}
1108{{end}}
1109
1110
1111{{/*
1112------------------------------------------------------------------------------
1113 Decides whether a function should be exported from the Android Vulkan
1114 library. Functions in the core API and in loader extensions are exported.
1115------------------------------------------------------------------------------
1116*/}}
1117{{define "IsFunctionExported"}}
1118 {{AssertType $ "Function"}}
1119
1120 {{if (Macro "IsFunctionSupported" $)}}
1121 {{$ext := GetAnnotation $ "extension"}}
1122 {{if $ext}}
1123 {{Macro "IsExtensionExported" $ext}}
1124 {{else}}
1125 true
1126 {{end}}
1127 {{end}}
1128{{end}}
1129
1130
1131{{/*
1132------------------------------------------------------------------------------
1133 Emit "true" if an extension is unsupportable on Android.
1134------------------------------------------------------------------------------
1135*/}}
1136{{define "IsExtensionBlacklisted"}}
1137 {{$ext := index $.Arguments 0}}
1138 {{ if eq $ext "VK_KHR_display"}}true
1139 {{else if eq $ext "VK_KHR_display_swapchain"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001140 {{else if eq $ext "VK_KHR_mir_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001141 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1142 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1143 {{else if eq $ext "VK_KHR_wayland_surface"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001144 {{else if eq $ext "VK_KHR_win32_surface"}}true
Jesse Hall9492f992017-08-28 12:10:06 -07001145 {{else if eq $ext "VK_KHR_external_memory_win32"}}true
1146 {{else if eq $ext "VK_KHR_win32_keyed_mutex"}}true
1147 {{else if eq $ext "VK_KHR_external_semaphore_win32"}}true
1148 {{else if eq $ext "VK_KHR_external_fence_win32"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001149 {{else if eq $ext "VK_EXT_acquire_xlib_display"}}true
1150 {{else if eq $ext "VK_EXT_direct_mode_display"}}true
1151 {{else if eq $ext "VK_EXT_display_surface_counter"}}true
1152 {{else if eq $ext "VK_EXT_display_control"}}true
Jesse Hall497c46f2018-10-08 12:52:48 -07001153 {{else if eq $ext "VK_FUCHSIA_imagepipe_surface"}}true
Jesse Hallad250842017-03-10 18:35:38 -08001154 {{else if eq $ext "VK_MVK_ios_surface"}}true
1155 {{else if eq $ext "VK_MVK_macos_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001156 {{else if eq $ext "VK_NN_vi_surface"}}true
Jesse Halleb02c472017-02-24 15:13:45 -08001157 {{else if eq $ext "VK_NV_external_memory_win32"}}true
1158 {{else if eq $ext "VK_NV_win32_keyed_mutex"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001159 {{end}}
1160{{end}}
1161
1162
1163{{/*
1164------------------------------------------------------------------------------
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -07001165 Reports whether an extension has functions exported by the loader.
1166 E.g. applications can directly link to an extension function.
Chia-I Wu0c203242016-03-15 13:44:51 +08001167------------------------------------------------------------------------------
1168*/}}
1169{{define "IsExtensionExported"}}
1170 {{$ext := index $.Arguments 0}}
1171 {{ if eq $ext "VK_KHR_surface"}}true
1172 {{else if eq $ext "VK_KHR_swapchain"}}true
1173 {{else if eq $ext "VK_KHR_android_surface"}}true
Jesse Hallcaea4112018-01-18 15:40:46 -08001174 {{else if eq $ext "VK_ANDROID_external_memory_android_hardware_buffer"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001175 {{end}}
1176{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001177
1178
1179{{/*
1180------------------------------------------------------------------------------
1181 Reports whether an extension is internal to the loader and drivers,
1182 so the loader should not enumerate it.
1183------------------------------------------------------------------------------
1184*/}}
1185{{define "IsExtensionInternal"}}
1186 {{$ext := index $.Arguments 0}}
1187 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1188 {{end}}
1189{{end}}