blob: 940b747f1bfa1a303f06b23540e49586d116d774 [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
Yiwei Zhang23143102019-04-10 18:24:05 -0700707VK_KHR_bind_memory2
Chris Forbes6aa30db2017-02-20 17:12:53 +1300708{{end}}
709
710
711{{/*
712------------------------------------------------------------------------------
Chia-I Wueb7db122016-03-24 09:11:06 +0800713 Emits true if an extension is intercepted by vulkan::driver.
714------------------------------------------------------------------------------
715*/}}
716{{define "driver.IsExtensionIntercepted"}}
717 {{$ext_name := index $.Arguments 0}}
718 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
719
720 {{range $f := $filters}}
721 {{if eq $ext_name $f}}true{{end}}
722 {{end}}
723{{end}}
724
725
726{{/*
727------------------------------------------------------------------------------
728 Emits true if a function is intercepted by vulkan::driver.
729------------------------------------------------------------------------------
730*/}}
731{{define "driver.IsIntercepted"}}
732 {{AssertType $ "Function"}}
733
734 {{if (Macro "IsFunctionSupported" $)}}
735 {{/* Create functions of dispatchable objects */}}
736 {{ if eq $.Name "vkCreateInstance"}}true
737 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800738 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400739 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800740 {{else if eq $.Name "vkGetDeviceQueue"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400741 {{else if eq $.Name "vkGetDeviceQueue2"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800742 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
743
744 {{/* Destroy functions of dispatchable objects */}}
745 {{else if eq $.Name "vkDestroyInstance"}}true
746 {{else if eq $.Name "vkDestroyDevice"}}true
747
748 {{/* Enumeration of extensions */}}
749 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
750 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
751
Chia-I Wueb7db122016-03-24 09:11:06 +0800752 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
753 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
754
Yiwei Zhang23143102019-04-10 18:24:05 -0700755 {{/* VK_KHR_swapchain v69 requirement */}}
756 {{else if eq $.Name "vkBindImageMemory2"}}true
757 {{else if eq $.Name "vkBindImageMemory2KHR"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800758 {{end}}
759
760 {{$ext := GetAnnotation $ "extension"}}
761 {{if $ext}}
762 {{Macro "driver.IsExtensionIntercepted" $ext}}
763 {{end}}
764
765 {{end}}
766{{end}}
767
768
769{{/*
770------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800771 Emits true if a function needs a ProcHook stub.
Chia-I Wueb7db122016-03-24 09:11:06 +0800772------------------------------------------------------------------------------
773*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800774{{define "driver.NeedProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800775 {{AssertType $ "Function"}}
776
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800777 {{if and (Macro "driver.IsIntercepted" $) (Macro "IsDeviceDispatched" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800778 {{$ext := GetAnnotation $ "extension"}}
779 {{if $ext}}
780 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
781 {{end}}
782 {{end}}
783{{end}}
784
785
786{{/*
787-------------------------------------------------------------------------------
788 Emits definition of struct ProcHook.
789-------------------------------------------------------------------------------
790*/}}
791{{define "driver.C++.DefineProcHookType"}}
792 struct ProcHook {
793 enum Type {
794 GLOBAL,
795 INSTANCE,
796 DEVICE,
797 };
798
799 enum Extension {
Chris Forbes6aa30db2017-02-20 17:12:53 +1300800 {{$exts := Strings (Macro "driver.KnownExtensions") | SplitOn "\n"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800801 {{range $e := $exts}}
802 {{TrimPrefix "VK_" $e}},
803 {{end}}
804
805 EXTENSION_CORE, // valid bit
806 EXTENSION_COUNT,
807 EXTENSION_UNKNOWN,
808 };
809
810 const char* name;
811 Type type;
812 Extension extension;
813
814 PFN_vkVoidFunction proc;
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800815 PFN_vkVoidFunction checked_proc; // always nullptr for non-device hooks
Chia-I Wueb7db122016-03-24 09:11:06 +0800816 };
817{{end}}
818
819
820{{/*
821-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800822 Emits INIT_PROC_EXT macro for vulkan::driver.
823-------------------------------------------------------------------------------
824*/}}
825{{define "driver.C++.DefineInitProcExtMacro"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300826 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800827 if (extensions[ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300828 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800829 } while(0)
830{{end}}
831
832
833{{/*
834-------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800835 Emits a stub for ProcHook::checked_proc.
Chia-I Wueb7db122016-03-24 09:11:06 +0800836-------------------------------------------------------------------------------
837*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800838{{define "driver.C++.DefineProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800839 {{AssertType $ "Function"}}
840
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800841 {{if (Macro "driver.NeedProcHookStub" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800842 {{$ext := GetAnnotation $ "extension"}}
843 {{$ext_name := index $ext.Arguments 0}}
844
845 {{$base := (Macro "BaseName" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800846
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800847 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
848 {{$p0 := index $.CallParameters 0}}
849 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800850
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800851 if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) {
852 {{if not (IsVoid $.Return.Type)}}return §{{end}}
853 {{$base}}({{Macro "Arguments" $}});
854 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800855 Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800856 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800857 }
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800858 }
Chia-I Wueb7db122016-03-24 09:11:06 +0800859
860 {{end}}
861{{end}}
862
863
864{{/*
865-------------------------------------------------------------------------------
866 Emits definition of a global ProcHook.
867-------------------------------------------------------------------------------
868*/}}
869{{define "driver.C++.DefineGlobalProcHook"}}
870 {{AssertType $ "Function"}}
871
872 {{$base := (Macro "BaseName" $)}}
873
874 {{$ext := GetAnnotation $ "extension"}}
875 {{if $ext}}
876 {{Error "invalid global extension"}}
877 {{end}}
878
879 {
880 "{{$.Name}}",
881 ProcHook::GLOBAL,
882 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800883 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800884 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800885 },
886{{end}}
887
888
889{{/*
890-------------------------------------------------------------------------------
891 Emits definition of an instance ProcHook.
892-------------------------------------------------------------------------------
893*/}}
894{{define "driver.C++.DefineInstanceProcHook"}}
895 {{AssertType $ "Function"}}
896
897 {{$base := (Macro "BaseName" $)}}
898
899 {
900 "{{$.Name}}",
901 ProcHook::INSTANCE,
902
903 {{$ext := GetAnnotation $ "extension"}}
904 {{if $ext}}
905 ProcHook::{{Macro "BaseName" $ext}},
906
907 {{if (Macro "IsExtensionInternal" $ext)}}
908 nullptr,
909 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800910 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800911 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800912 nullptr,
913 {{end}}
914 {{else}}
915 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800916 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800917 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800918 {{end}}
919 },
920{{end}}
921
922
923{{/*
924-------------------------------------------------------------------------------
925 Emits definition of a device ProcHook.
926-------------------------------------------------------------------------------
927*/}}
928{{define "driver.C++.DefineDeviceProcHook"}}
929 {{AssertType $ "Function"}}
930
931 {{$base := (Macro "BaseName" $)}}
932
933 {
934 "{{$.Name}}",
935 ProcHook::DEVICE,
936
937 {{$ext := GetAnnotation $ "extension"}}
938 {{if $ext}}
939 ProcHook::{{Macro "BaseName" $ext}},
940
941 {{if (Macro "IsExtensionInternal" $ext)}}
942 nullptr,
943 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800944 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800945 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800946 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
947 {{end}}
948 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800949 ProcHook::EXTENSION_CORE,
950 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
951 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800952 {{end}}
953 },
954{{end}}
955
956
957{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800958-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800959 Emits true if a function is needed by vulkan::driver.
960-------------------------------------------------------------------------------
961*/}}
962{{define "driver.IsDriverTableEntry"}}
963 {{AssertType $ "Function"}}
964
965 {{if (Macro "IsFunctionSupported" $)}}
966 {{/* Create functions of dispatchable objects */}}
967 {{ if eq $.Name "vkCreateDevice"}}true
968 {{else if eq $.Name "vkGetDeviceQueue"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400969 {{else if eq $.Name "vkGetDeviceQueue2"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800970 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
971
972 {{/* Destroy functions of dispatchable objects */}}
973 {{else if eq $.Name "vkDestroyInstance"}}true
974 {{else if eq $.Name "vkDestroyDevice"}}true
975
976 {{/* Enumeration of extensions */}}
977 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
978
979 {{/* We cache physical devices in loader.cpp */}}
980 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400981 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800982
983 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
984 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
985
986 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
987 {{else if eq $.Name "vkCreateImage"}}true
988 {{else if eq $.Name "vkDestroyImage"}}true
989
Jesse Hall85bb0c52017-02-09 22:13:02 -0800990 {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true
Yiwei Zhangc1c9d3c2018-03-13 17:12:11 -0700991 {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true
Chris Forbes6aa30db2017-02-20 17:12:53 +1300992 {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true
Yiwei Zhang23143102019-04-10 18:24:05 -0700993
994 {{/* VK_KHR_swapchain v69 requirement */}}
995 {{else if eq $.Name "vkBindImageMemory2"}}true
996 {{else if eq $.Name "vkBindImageMemory2KHR"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800997 {{end}}
998
999 {{$ext := GetAnnotation $ "extension"}}
1000 {{if $ext}}
1001 {{$ext_name := index $ext.Arguments 0}}
1002 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
1003 {{else if eq $ext_name "VK_EXT_debug_report"}}true
1004 {{end}}
1005 {{end}}
1006 {{end}}
1007{{end}}
1008
1009
1010{{/*
1011------------------------------------------------------------------------------
1012 Emits true if an instance-dispatched function is needed by vulkan::driver.
1013------------------------------------------------------------------------------
1014*/}}
1015{{define "driver.IsInstanceDriverTableEntry"}}
1016 {{AssertType $ "Function"}}
1017
1018 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1019 true
1020 {{end}}
1021{{end}}
1022
1023
1024{{/*
1025------------------------------------------------------------------------------
1026 Emits true if a device-dispatched function is needed by vulkan::driver.
1027------------------------------------------------------------------------------
1028*/}}
1029{{define "driver.IsDeviceDriverTableEntry"}}
1030 {{AssertType $ "Function"}}
1031
1032 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1033 true
1034 {{end}}
1035{{end}}
1036
1037
1038{{/*
1039-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001040 Emits a function/extension name without the "vk"/"VK_" prefix.
1041-------------------------------------------------------------------------------
1042*/}}
1043{{define "BaseName"}}
1044 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1045 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1046 {{else}}{{Error "invalid use of BaseName"}}
1047 {{end}}
1048{{end}}
1049
1050
1051{{/*
1052-------------------------------------------------------------------------------
1053 Emits a comma-separated list of C parameter names for the given command.
1054-------------------------------------------------------------------------------
1055*/}}
1056{{define "Arguments"}}
1057 {{AssertType $ "Function"}}
1058
1059 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1060{{end}}
1061
1062
1063{{/*
1064------------------------------------------------------------------------------
1065------------------------------------------------------------------------------
1066*/}}
1067{{define "IsGloballyDispatched"}}
1068 {{AssertType $ "Function"}}
1069 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1070 true
1071 {{end}}
1072{{end}}
1073
1074
1075{{/*
1076------------------------------------------------------------------------------
1077 Emit "true" for supported functions that undergo table dispatch. Only global
1078 functions and functions handled in the loader top without calling into
1079 lower layers are not dispatched.
1080------------------------------------------------------------------------------
1081*/}}
1082{{define "IsInstanceDispatched"}}
1083 {{AssertType $ "Function"}}
1084 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1085 true
1086 {{end}}
1087{{end}}
1088
1089
1090{{/*
1091------------------------------------------------------------------------------
1092 Emit "true" for supported functions that can have device-specific dispatch.
1093------------------------------------------------------------------------------
1094*/}}
1095{{define "IsDeviceDispatched"}}
1096 {{AssertType $ "Function"}}
1097 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1098 true
1099 {{end}}
1100{{end}}
1101
1102
1103{{/*
1104------------------------------------------------------------------------------
1105 Emit "true" if a function is core or from a supportable extension.
1106------------------------------------------------------------------------------
1107*/}}
1108{{define "IsFunctionSupported"}}
1109 {{AssertType $ "Function"}}
1110 {{if not (GetAnnotation $ "pfn")}}
1111 {{$ext := GetAnnotation $ "extension"}}
1112 {{if not $ext}}true
1113 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1114 {{end}}
1115 {{end}}
1116{{end}}
1117
1118
1119{{/*
1120------------------------------------------------------------------------------
1121 Decides whether a function should be exported from the Android Vulkan
1122 library. Functions in the core API and in loader extensions are exported.
1123------------------------------------------------------------------------------
1124*/}}
1125{{define "IsFunctionExported"}}
1126 {{AssertType $ "Function"}}
1127
1128 {{if (Macro "IsFunctionSupported" $)}}
1129 {{$ext := GetAnnotation $ "extension"}}
1130 {{if $ext}}
1131 {{Macro "IsExtensionExported" $ext}}
1132 {{else}}
1133 true
1134 {{end}}
1135 {{end}}
1136{{end}}
1137
1138
1139{{/*
1140------------------------------------------------------------------------------
1141 Emit "true" if an extension is unsupportable on Android.
1142------------------------------------------------------------------------------
1143*/}}
1144{{define "IsExtensionBlacklisted"}}
1145 {{$ext := index $.Arguments 0}}
1146 {{ if eq $ext "VK_KHR_display"}}true
1147 {{else if eq $ext "VK_KHR_display_swapchain"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001148 {{else if eq $ext "VK_KHR_mir_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001149 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1150 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1151 {{else if eq $ext "VK_KHR_wayland_surface"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001152 {{else if eq $ext "VK_KHR_win32_surface"}}true
Jesse Hall9492f992017-08-28 12:10:06 -07001153 {{else if eq $ext "VK_KHR_external_memory_win32"}}true
1154 {{else if eq $ext "VK_KHR_win32_keyed_mutex"}}true
1155 {{else if eq $ext "VK_KHR_external_semaphore_win32"}}true
1156 {{else if eq $ext "VK_KHR_external_fence_win32"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001157 {{else if eq $ext "VK_EXT_acquire_xlib_display"}}true
1158 {{else if eq $ext "VK_EXT_direct_mode_display"}}true
1159 {{else if eq $ext "VK_EXT_display_surface_counter"}}true
1160 {{else if eq $ext "VK_EXT_display_control"}}true
Jesse Hall497c46f2018-10-08 12:52:48 -07001161 {{else if eq $ext "VK_FUCHSIA_imagepipe_surface"}}true
Jesse Hallad250842017-03-10 18:35:38 -08001162 {{else if eq $ext "VK_MVK_ios_surface"}}true
1163 {{else if eq $ext "VK_MVK_macos_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001164 {{else if eq $ext "VK_NN_vi_surface"}}true
Jesse Halleb02c472017-02-24 15:13:45 -08001165 {{else if eq $ext "VK_NV_external_memory_win32"}}true
1166 {{else if eq $ext "VK_NV_win32_keyed_mutex"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001167 {{end}}
1168{{end}}
1169
1170
1171{{/*
1172------------------------------------------------------------------------------
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -07001173 Reports whether an extension has functions exported by the loader.
1174 E.g. applications can directly link to an extension function.
Chia-I Wu0c203242016-03-15 13:44:51 +08001175------------------------------------------------------------------------------
1176*/}}
1177{{define "IsExtensionExported"}}
1178 {{$ext := index $.Arguments 0}}
1179 {{ if eq $ext "VK_KHR_surface"}}true
1180 {{else if eq $ext "VK_KHR_swapchain"}}true
1181 {{else if eq $ext "VK_KHR_android_surface"}}true
Jesse Hallcaea4112018-01-18 15:40:46 -08001182 {{else if eq $ext "VK_ANDROID_external_memory_android_hardware_buffer"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001183 {{end}}
1184{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001185
1186
1187{{/*
1188------------------------------------------------------------------------------
1189 Reports whether an extension is internal to the loader and drivers,
1190 so the loader should not enumerate it.
1191------------------------------------------------------------------------------
1192*/}}
1193{{define "IsExtensionInternal"}}
1194 {{$ext := index $.Arguments 0}}
1195 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1196 {{end}}
1197{{end}}