blob: e13ec0eabb46cd2925973321cff483cbd3cb5117 [file] [log] [blame]
Chia-I Wu0c203242016-03-15 13:44:51 +08001{{define "Copyright"}}
2/*
3•* Copyright 2016 The Android Open Source Project
4•*
5•* Licensed under the Apache License, Version 2.0 (the "License");
6•* you may not use this file except in compliance with the License.
7•* You may obtain a copy of the License at
8•*
9•* http://www.apache.org/licenses/LICENSE-2.0
10•*
11•* Unless required by applicable law or agreed to in writing, software
12•* distributed under the License is distributed on an "AS IS" BASIS,
13•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14•* See the License for the specific language governing permissions and
15•* limitations under the License.
16•*/
17¶{{end}}
18
19{{Include "../api/templates/vulkan_common.tmpl"}}
20{{Global "clang-format" (Strings "clang-format" "-style=file")}}
21{{Macro "DefineGlobals" $}}
22{{$ | Macro "api_gen.h" | Format (Global "clang-format") | Write "api_gen.h" }}
23{{$ | Macro "api_gen.cpp" | Format (Global "clang-format") | Write "api_gen.cpp"}}
Chia-I Wueb7db122016-03-24 09:11:06 +080024{{$ | Macro "driver_gen.h" | Format (Global "clang-format") | Write "driver_gen.h"}}
25{{$ | Macro "driver_gen.cpp" | Format (Global "clang-format") | Write "driver_gen.cpp"}}
Chia-I Wu0c203242016-03-15 13:44:51 +080026
27{{/*
28-------------------------------------------------------------------------------
29 api_gen.h
30-------------------------------------------------------------------------------
31*/}}
32{{define "api_gen.h"}}
33{{Macro "Copyright"}}
34
35// WARNING: This file is generated. See ../README.md for instructions.
36
37#ifndef LIBVULKAN_API_GEN_H
38#define LIBVULKAN_API_GEN_H
39
Chia-I Wu8925efd2016-04-13 15:13:21 +080040#include <bitset>
Chia-I Wu0c203242016-03-15 13:44:51 +080041#include <vulkan/vulkan.h>
Chia-I Wu8925efd2016-04-13 15:13:21 +080042#include "driver_gen.h"
Chia-I Wu0c203242016-03-15 13:44:51 +080043
44namespace vulkan
45namespace api
46
47struct InstanceDispatchTable {
48 // clang-format off
49 {{range $f := AllCommands $}}
50 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080051 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080052 {{end}}
53 {{end}}
54 // clang-format on
55};
56
57struct DeviceDispatchTable {
58 // clang-format off
59 {{range $f := AllCommands $}}
60 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
Chia-I Wucc5e2762016-03-24 13:01:16 +080061 {{Macro "C++.DeclareTableEntry" $f}};
Chia-I Wu0c203242016-03-15 13:44:51 +080062 {{end}}
63 {{end}}
64 // clang-format on
65};
66
Chia-I Wu8925efd2016-04-13 15:13:21 +080067bool InitDispatchTable(
68 VkInstance instance,
69 PFN_vkGetInstanceProcAddr get_proc,
70 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
71bool InitDispatchTable(
72 VkDevice dev,
73 PFN_vkGetDeviceProcAddr get_proc,
74 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wu0c203242016-03-15 13:44:51 +080075
76»} // namespace api
77»} // namespace vulkan
78
79#endif // LIBVULKAN_API_GEN_H
80¶{{end}}
81
82
83{{/*
84-------------------------------------------------------------------------------
85 api_gen.cpp
86-------------------------------------------------------------------------------
87*/}}
88{{define "api_gen.cpp"}}
89{{Macro "Copyright"}}
90
91// WARNING: This file is generated. See ../README.md for instructions.
92
93#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070094
Chia-I Wu0c203242016-03-15 13:44:51 +080095#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -070096
97#include <log/log.h>
Chia-I Wu0c203242016-03-15 13:44:51 +080098
Chia-I Wu3e654dc2016-05-20 16:15:06 +080099// to catch mismatches between vulkan.h and this file
100#undef VK_NO_PROTOTYPES
Chia-I Wu0c203242016-03-15 13:44:51 +0800101#include "api.h"
102
103namespace vulkan
104namespace api
105
Chia-I Wucc5e2762016-03-24 13:01:16 +0800106{{Macro "C++.DefineInitProcMacro" "dispatch"}}
107
108{{Macro "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800109
Chia-I Wu8925efd2016-04-13 15:13:21 +0800110namespace
111
112// clang-format off
113
114{{range $f := AllCommands $}}
115 {{Macro "api.C++.DefineExtensionStub" $f}}
116{{end}}
117// clang-format on
118
119»} // anonymous
120
121bool InitDispatchTable(
122 VkInstance instance,
123 PFN_vkGetInstanceProcAddr get_proc,
124 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800125 auto& data = GetData(instance);
126 bool success = true;
127
128 // clang-format off
129 {{range $f := AllCommands $}}
130 {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
131 {{Macro "C++.InitProc" $f}}
132 {{end}}
133 {{end}}
134 // clang-format on
135
136 return success;
137}
138
Chia-I Wu8925efd2016-04-13 15:13:21 +0800139bool InitDispatchTable(
140 VkDevice dev,
141 PFN_vkGetDeviceProcAddr get_proc,
142 const std::bitset<driver::ProcHook::EXTENSION_COUNT> &extensions) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800143 auto& data = GetData(dev);
144 bool success = true;
145
146 // clang-format off
147 {{range $f := AllCommands $}}
148 {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
149 {{Macro "C++.InitProc" $f}}
150 {{end}}
151 {{end}}
152 // clang-format on
153
154 return success;
155}
156
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800157// clang-format off
158
159namespace
160
161// forward declarations needed by GetInstanceProcAddr and GetDeviceProcAddr
162{{range $f := AllCommands $}}
163 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
164 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
165 {{end}}
166{{end}}
167
168{{range $f := AllCommands $}}
169 {{if and (Macro "IsFunctionExported" $f) (not (Macro "api.IsIntercepted" $f))}}
170 VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}}) {
171 {{ if eq $f.Name "vkGetInstanceProcAddr"}}
172 {{Macro "api.C++.InterceptInstanceProcAddr" $}}
173 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
174 {{Macro "api.C++.InterceptDeviceProcAddr" $}}
175 {{end}}
176
177 {{Macro "api.C++.Dispatch" $f}}
178 }
179
180 {{end}}
181{{end}}
182
183»} // anonymous namespace
184
185// clang-format on
186
Chia-I Wu0c203242016-03-15 13:44:51 +0800187»} // namespace api
188»} // namespace vulkan
189
190// clang-format off
191
192{{range $f := AllCommands $}}
193 {{if (Macro "IsFunctionExported" $f)}}
194 __attribute__((visibility("default")))
195 VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800196 {{if not (IsVoid $f.Return.Type)}}return §{{end}}
197 vulkan::api::{{Macro "BaseName" $f}}({{Macro "Arguments" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800198 }
199
200 {{end}}
201{{end}}
202
203// clang-format on
204¶{{end}}
205
206
207{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800208-------------------------------------------------------------------------------
209 driver_gen.h
210-------------------------------------------------------------------------------
211*/}}
212{{define "driver_gen.h"}}
213{{Macro "Copyright"}}
214
215// WARNING: This file is generated. See ../README.md for instructions.
216
217#ifndef LIBVULKAN_DRIVER_GEN_H
218#define LIBVULKAN_DRIVER_GEN_H
219
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800220#include <bitset>
Chia-I Wueb7db122016-03-24 09:11:06 +0800221#include <vulkan/vulkan.h>
222#include <vulkan/vk_android_native_buffer.h>
223
224namespace vulkan
225namespace driver
226
227{{Macro "driver.C++.DefineProcHookType"}}
228
Chia-I Wucc5e2762016-03-24 13:01:16 +0800229struct InstanceDriverTable {
230 // clang-format off
231 {{range $f := AllCommands $}}
232 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
233 {{Macro "C++.DeclareTableEntry" $f}};
234 {{end}}
235 {{end}}
236 // clang-format on
237};
238
239struct DeviceDriverTable {
240 // clang-format off
241 {{range $f := AllCommands $}}
242 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
243 {{Macro "C++.DeclareTableEntry" $f}};
244 {{end}}
245 {{end}}
246 // clang-format on
247};
248
Chia-I Wueb7db122016-03-24 09:11:06 +0800249const ProcHook* GetProcHook(const char* name);
250ProcHook::Extension GetProcHookExtension(const char* name);
251
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800252bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
253 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
254bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
255 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800256
Chia-I Wueb7db122016-03-24 09:11:06 +0800257»} // namespace driver
258»} // namespace vulkan
259
260#endif // LIBVULKAN_DRIVER_TABLE_H
261¶{{end}}
262
263
264{{/*
265-------------------------------------------------------------------------------
266 driver_gen.cpp
267-------------------------------------------------------------------------------
268*/}}
269{{define "driver_gen.cpp"}}
270{{Macro "Copyright"}}
271
272// WARNING: This file is generated. See ../README.md for instructions.
273
274#include <string.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700275
Chia-I Wueb7db122016-03-24 09:11:06 +0800276#include <algorithm>
Mark Salyzyn7823e122016-09-29 08:08:05 -0700277
278#include <log/log.h>
Chia-I Wueb7db122016-03-24 09:11:06 +0800279
280#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +0800281
282namespace vulkan
283namespace driver
284
285namespace
286
287// clang-format off
288
289{{range $f := AllCommands $}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800290 {{Macro "driver.C++.DefineProcHookStub" $f}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800291{{end}}
292// clang-format on
293
294const ProcHook g_proc_hooks[] = {
295 // clang-format off
296 {{range $f := SortBy (AllCommands $) "FunctionName"}}
297 {{if (Macro "driver.IsIntercepted" $f)}}
298 {{ if (Macro "IsGloballyDispatched" $f)}}
299 {{Macro "driver.C++.DefineGlobalProcHook" $f}}
300 {{else if (Macro "IsInstanceDispatched" $f)}}
301 {{Macro "driver.C++.DefineInstanceProcHook" $f}}
302 {{else if (Macro "IsDeviceDispatched" $f)}}
303 {{Macro "driver.C++.DefineDeviceProcHook" $f}}
304 {{end}}
305 {{end}}
306 {{end}}
307 // clang-format on
308};
309
310»} // anonymous
311
312const ProcHook* GetProcHook(const char* name) {
313 const auto& begin = g_proc_hooks;
314 const auto& end = g_proc_hooks +
315 sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
316 const auto hook = std::lower_bound(begin, end, name,
317 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
318 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
319}
320
321ProcHook::Extension GetProcHookExtension(const char* name) {
Chris Forbes6aa30db2017-02-20 17:12:53 +1300322 {{$exts := Strings (Macro "driver.KnownExtensions") | SplitOn "\n"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800323 // clang-format off
324 {{range $e := $exts}}
325 if (strcmp(name, "{{$e}}") == 0) return ProcHook::{{TrimPrefix "VK_" $e}};
326 {{end}}
327 // clang-format on
328 return ProcHook::EXTENSION_UNKNOWN;
329}
330
Chia-I Wucc5e2762016-03-24 13:01:16 +0800331{{Macro "C++.DefineInitProcMacro" "driver"}}
332
333{{Macro "driver.C++.DefineInitProcExtMacro"}}
334
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800335bool InitDriverTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc,
336 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800337{
338 auto& data = GetData(instance);
339 bool success = true;
340
341 // clang-format off
342 {{range $f := AllCommands $}}
343 {{if (Macro "driver.IsInstanceDriverTableEntry" $f)}}
344 {{Macro "C++.InitProc" $f}}
345 {{end}}
346 {{end}}
347 // clang-format on
348
349 return success;
350}
351
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800352bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
353 const std::bitset<ProcHook::EXTENSION_COUNT> &extensions)
Chia-I Wucc5e2762016-03-24 13:01:16 +0800354{
355 auto& data = GetData(dev);
356 bool success = true;
357
358 // clang-format off
359 {{range $f := AllCommands $}}
360 {{if (Macro "driver.IsDeviceDriverTableEntry" $f)}}
361 {{Macro "C++.InitProc" $f}}
362 {{end}}
363 {{end}}
364 // clang-format on
365
366 return success;
367}
368
Chia-I Wueb7db122016-03-24 09:11:06 +0800369»} // namespace driver
370»} // namespace vulkan
371
372// clang-format on
373¶{{end}}
374
375
376{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800377------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800378 Emits a declaration of a dispatch/driver table entry.
Chia-I Wu0c203242016-03-15 13:44:51 +0800379------------------------------------------------------------------------------
380*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800381{{define "C++.DeclareTableEntry"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800382 {{AssertType $ "Function"}}
383
384 {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
385{{end}}
386
387
388{{/*
389-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800390 Emits INIT_PROC macro.
Chia-I Wu0c203242016-03-15 13:44:51 +0800391-------------------------------------------------------------------------------
392*/}}
Chia-I Wucc5e2762016-03-24 13:01:16 +0800393{{define "C++.DefineInitProcMacro"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800394 #define UNLIKELY(expr) __builtin_expect((expr), 0)
395
Chris Forbes5948b3e2016-12-23 13:49:53 +1300396 #define INIT_PROC(required, obj, proc) do { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800397 data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>( \
398 get_proc(obj, "vk" # proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300399 if (UNLIKELY(required && !data.{{$}}.proc)) { \
Chia-I Wu0c203242016-03-15 13:44:51 +0800400 ALOGE("missing " # obj " proc: vk" # proc); \
401 success = false; \
402 } \
403 } while(0)
Chia-I Wu0c203242016-03-15 13:44:51 +0800404{{end}}
405
406
407{{/*
408-------------------------------------------------------------------------------
409 Emits code to invoke INIT_PROC or INIT_PROC_EXT.
410-------------------------------------------------------------------------------
411*/}}
412{{define "C++.InitProc"}}
413 {{AssertType $ "Function"}}
414
415 {{$ext := GetAnnotation $ "extension"}}
416 {{if $ext}}
Jesse Halld1abd742017-02-09 21:45:51 -0800417 INIT_PROC_EXT({{Macro "BaseName" $ext}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800418 {{else}}
Jesse Halld1abd742017-02-09 21:45:51 -0800419 INIT_PROC
Chia-I Wu0c203242016-03-15 13:44:51 +0800420 {{end}}
421
Jesse Halld1abd742017-02-09 21:45:51 -0800422 {{if GetAnnotation $ "optional"}}false{{else}}true{{end}}, §
423
Chia-I Wu0c203242016-03-15 13:44:51 +0800424 {{if (Macro "IsInstanceDispatched" $)}}
425 instance, §
426 {{else}}
427 dev, §
428 {{end}}
429
430 {{Macro "BaseName" $}});
431{{end}}
432
433
434{{/*
435------------------------------------------------------------------------------
436 Emits true if a function is exported and instance-dispatched.
437------------------------------------------------------------------------------
438*/}}
439{{define "api.IsInstanceDispatchTableEntry"}}
440 {{AssertType $ "Function"}}
441
442 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
Chia-I Wudbd33bc2016-06-02 11:25:47 +0800443 {{/* deprecated and unused internally */}}
444 {{if not (eq $.Name "vkEnumerateDeviceLayerProperties")}}
445 true
446 {{end}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800447 {{end}}
448{{end}}
449
450
451{{/*
452------------------------------------------------------------------------------
453 Emits true if a function is exported and device-dispatched.
454------------------------------------------------------------------------------
455*/}}
456{{define "api.IsDeviceDispatchTableEntry"}}
457 {{AssertType $ "Function"}}
458
459 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
460 true
461 {{end}}
462{{end}}
463
464
465{{/*
466------------------------------------------------------------------------------
467 Emits true if a function is intercepted by vulkan::api.
468------------------------------------------------------------------------------
469*/}}
470{{define "api.IsIntercepted"}}
471 {{AssertType $ "Function"}}
472
473 {{if (Macro "IsFunctionSupported" $)}}
474 {{/* Global functions cannot be dispatched at all */}}
475 {{ if (Macro "IsGloballyDispatched" $)}}true
476
477 {{/* VkPhysicalDevice functions that manage device layers */}}
478 {{else if eq $.Name "vkCreateDevice"}}true
479 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
480 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
481
482 {{/* Destroy functions of dispatchable objects */}}
483 {{else if eq $.Name "vkDestroyInstance"}}true
484 {{else if eq $.Name "vkDestroyDevice"}}true
485
486 {{end}}
487 {{end}}
488{{end}}
489
490
491{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800492-------------------------------------------------------------------------------
493 Emits INIT_PROC_EXT macro for vulkan::api.
494-------------------------------------------------------------------------------
495*/}}
496{{define "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800497 // Exported extension functions may be invoked even when their extensions
498 // are disabled. Dispatch to stubs when that happens.
Chris Forbes5948b3e2016-12-23 13:49:53 +1300499 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800500 if (extensions[driver::ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300501 INIT_PROC(required, obj, proc); \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800502 else \
503 data.dispatch.proc = disabled ## proc; \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800504 } while(0)
505{{end}}
506
507
508{{/*
Chia-I Wu8925efd2016-04-13 15:13:21 +0800509-------------------------------------------------------------------------------
510 Emits a stub for an exported extension function.
511-------------------------------------------------------------------------------
512*/}}
513{{define "api.C++.DefineExtensionStub"}}
514 {{AssertType $ "Function"}}
515
516 {{$ext := GetAnnotation $ "extension"}}
517 {{if and $ext (Macro "IsFunctionExported" $)}}
518 {{$ext_name := index $ext.Arguments 0}}
519
520 {{$base := (Macro "BaseName" $)}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800521
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800522 {{$p0 := (index $.CallParameters 0)}}
523 {{$ptail := (Tail 1 $.CallParameters)}}
524
525 {{$first_type := (Macro "Parameter" $p0)}}
526 {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
527
528 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
529 driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
530 "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
Chia-I Wu8925efd2016-04-13 15:13:21 +0800531 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
532 }
533
534 {{end}}
535{{end}}
536
537
538{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800539------------------------------------------------------------------------------
540 Emits code for vkGetInstanceProcAddr for function interception.
541------------------------------------------------------------------------------
542*/}}
543{{define "api.C++.InterceptInstanceProcAddr"}}
544 {{AssertType $ "API"}}
545
546 // global functions
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800547 if (instance == VK_NULL_HANDLE) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800548 {{range $f := AllCommands $}}
549 {{if (Macro "IsGloballyDispatched" $f)}}
550 if (strcmp(pName, "{{$f.Name}}") == 0) return §
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800551 reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800552 {{end}}
553 {{end}}
554
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800555 ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
Chia-I Wu0c203242016-03-15 13:44:51 +0800556 return nullptr;
557 }
558
559 static const struct Hook {
560 const char* name;
561 PFN_vkVoidFunction proc;
562 } hooks[] = {
563 {{range $f := SortBy (AllCommands $) "FunctionName"}}
564 {{if (Macro "IsFunctionExported" $f)}}
565 {{/* hide global functions */}}
566 {{if (Macro "IsGloballyDispatched" $f)}}
567 { "{{$f.Name}}", nullptr },
568
569 {{/* redirect intercepted functions */}}
570 {{else if (Macro "api.IsIntercepted" $f)}}
571 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800572 {{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800573
574 {{/* redirect vkGetInstanceProcAddr to itself */}}
575 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800576 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800577
578 {{/* redirect device functions to themselves as a workaround for
579 layers that do not intercept in their vkGetInstanceProcAddr */}}
580 {{else if (Macro "IsDeviceDispatched" $f)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800581 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800582
583 {{end}}
584 {{end}}
585 {{end}}
586 };
587 // clang-format on
588 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
589 auto hook = std::lower_bound(
590 hooks, hooks + count, pName,
591 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
592 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800593 if (!hook->proc) {
594 vulkan::driver::Logger(instance).Err(
595 instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
596 instance, pName);
597 }
Chia-I Wu0c203242016-03-15 13:44:51 +0800598 return hook->proc;
599 }
600 // clang-format off
601
602{{end}}
603
604
605{{/*
606------------------------------------------------------------------------------
607 Emits code for vkGetDeviceProcAddr for function interception.
608------------------------------------------------------------------------------
609*/}}
610{{define "api.C++.InterceptDeviceProcAddr"}}
611 {{AssertType $ "API"}}
612
613 if (device == VK_NULL_HANDLE) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800614 ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
Chia-I Wu0c203242016-03-15 13:44:51 +0800615 return nullptr;
616 }
617
618 static const char* const known_non_device_names[] = {
619 {{range $f := SortBy (AllCommands $) "FunctionName"}}
620 {{if (Macro "IsFunctionSupported" $f)}}
621 {{if not (Macro "IsDeviceDispatched" $f)}}
622 "{{$f.Name}}",
623 {{end}}
624 {{end}}
625 {{end}}
626 };
627 // clang-format on
628 constexpr size_t count = sizeof(known_non_device_names) /
629 sizeof(known_non_device_names[0]);
630 if (!pName ||
631 std::binary_search(
632 known_non_device_names, known_non_device_names + count, pName,
633 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800634 vulkan::driver::Logger(device).Err
635 device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device
636 (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800637 return nullptr;
638 }
639 // clang-format off
640
Chia-I Wuc56603e2016-04-12 11:16:17 +0800641 {{range $f := AllCommands $}}
642 {{if (Macro "IsDeviceDispatched" $f)}}
643 {{ if (Macro "api.IsIntercepted" $f)}}
644 if (strcmp(pName, "{{$f.Name}}") == 0) return §
645 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800646 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800647 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
648 if (strcmp(pName, "{{$f.Name}}") == 0) return §
649 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800650 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800651 {{end}}
652 {{end}}
653 {{end}}
654
Chia-I Wu0c203242016-03-15 13:44:51 +0800655{{end}}
656
657
658{{/*
659------------------------------------------------------------------------------
660 Emits code to dispatch a function.
661------------------------------------------------------------------------------
662*/}}
663{{define "api.C++.Dispatch"}}
664 {{AssertType $ "Function"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800665 {{if (Macro "api.IsIntercepted" $)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800666 {{Error "$.Name should not be generated"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800667 {{end}}
668
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800669 {{if not (IsVoid $.Return.Type)}}return §{{end}}
670
671 {{$p0 := index $.CallParameters 0}}
672 GetData({{$p0.Name}}).dispatch
Chia-I Wu0c203242016-03-15 13:44:51 +0800673 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
674{{end}}
675
676
677{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800678------------------------------------------------------------------------------
679 Emits a list of extensions intercepted by vulkan::driver.
680------------------------------------------------------------------------------
681*/}}
682{{define "driver.InterceptedExtensions"}}
683VK_ANDROID_native_buffer
684VK_EXT_debug_report
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700685VK_EXT_hdr_metadata
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700686VK_EXT_swapchain_colorspace
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700687VK_GOOGLE_display_timing
Chia-I Wueb7db122016-03-24 09:11:06 +0800688VK_KHR_android_surface
Ian Elliott948233a2017-01-06 12:13:23 -0700689VK_KHR_incremental_present
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700690VK_KHR_shared_presentable_image
Chia-I Wueb7db122016-03-24 09:11:06 +0800691VK_KHR_surface
692VK_KHR_swapchain
Chris Forbes2452cf72017-03-16 16:30:17 +1300693VK_KHR_get_surface_capabilities2
Chia-I Wueb7db122016-03-24 09:11:06 +0800694{{end}}
695
696
697{{/*
698------------------------------------------------------------------------------
Chris Forbes6aa30db2017-02-20 17:12:53 +1300699 Emits a list of extensions known to vulkan::driver.
700------------------------------------------------------------------------------
701*/}}
702{{define "driver.KnownExtensions"}}
703{{Macro "driver.InterceptedExtensions"}}
704VK_KHR_get_physical_device_properties2
705{{end}}
706
707
708{{/*
709------------------------------------------------------------------------------
Chia-I Wueb7db122016-03-24 09:11:06 +0800710 Emits true if an extension is intercepted by vulkan::driver.
711------------------------------------------------------------------------------
712*/}}
713{{define "driver.IsExtensionIntercepted"}}
714 {{$ext_name := index $.Arguments 0}}
715 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
716
717 {{range $f := $filters}}
718 {{if eq $ext_name $f}}true{{end}}
719 {{end}}
720{{end}}
721
722
723{{/*
724------------------------------------------------------------------------------
725 Emits true if a function is intercepted by vulkan::driver.
726------------------------------------------------------------------------------
727*/}}
728{{define "driver.IsIntercepted"}}
729 {{AssertType $ "Function"}}
730
731 {{if (Macro "IsFunctionSupported" $)}}
732 {{/* Create functions of dispatchable objects */}}
733 {{ if eq $.Name "vkCreateInstance"}}true
734 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800735 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400736 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
737 {{else if eq $.Name "vkGetDeviceGroupPresentCapabilitiesKHR"}}true
738 {{else if eq $.Name "vkGetDeviceGroupSurfacePresentModesKHR"}}true
739 {{else if eq $.Name "vkGetPhysicalDevicePresentRectanglesKHR"}}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
755 {{end}}
756
757 {{$ext := GetAnnotation $ "extension"}}
758 {{if $ext}}
759 {{Macro "driver.IsExtensionIntercepted" $ext}}
760 {{end}}
761
762 {{end}}
763{{end}}
764
765
766{{/*
767------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800768 Emits true if a function needs a ProcHook stub.
Chia-I Wueb7db122016-03-24 09:11:06 +0800769------------------------------------------------------------------------------
770*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800771{{define "driver.NeedProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800772 {{AssertType $ "Function"}}
773
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800774 {{if and (Macro "driver.IsIntercepted" $) (Macro "IsDeviceDispatched" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800775 {{$ext := GetAnnotation $ "extension"}}
776 {{if $ext}}
777 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
778 {{end}}
779 {{end}}
780{{end}}
781
782
783{{/*
784-------------------------------------------------------------------------------
785 Emits definition of struct ProcHook.
786-------------------------------------------------------------------------------
787*/}}
788{{define "driver.C++.DefineProcHookType"}}
789 struct ProcHook {
790 enum Type {
791 GLOBAL,
792 INSTANCE,
793 DEVICE,
794 };
795
796 enum Extension {
Chris Forbes6aa30db2017-02-20 17:12:53 +1300797 {{$exts := Strings (Macro "driver.KnownExtensions") | SplitOn "\n"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800798 {{range $e := $exts}}
799 {{TrimPrefix "VK_" $e}},
800 {{end}}
801
802 EXTENSION_CORE, // valid bit
803 EXTENSION_COUNT,
804 EXTENSION_UNKNOWN,
805 };
806
807 const char* name;
808 Type type;
809 Extension extension;
810
811 PFN_vkVoidFunction proc;
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800812 PFN_vkVoidFunction checked_proc; // always nullptr for non-device hooks
Chia-I Wueb7db122016-03-24 09:11:06 +0800813 };
814{{end}}
815
816
817{{/*
818-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800819 Emits INIT_PROC_EXT macro for vulkan::driver.
820-------------------------------------------------------------------------------
821*/}}
822{{define "driver.C++.DefineInitProcExtMacro"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300823 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800824 if (extensions[ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300825 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800826 } while(0)
827{{end}}
828
829
830{{/*
831-------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800832 Emits a stub for ProcHook::checked_proc.
Chia-I Wueb7db122016-03-24 09:11:06 +0800833-------------------------------------------------------------------------------
834*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800835{{define "driver.C++.DefineProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800836 {{AssertType $ "Function"}}
837
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800838 {{if (Macro "driver.NeedProcHookStub" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800839 {{$ext := GetAnnotation $ "extension"}}
840 {{$ext_name := index $ext.Arguments 0}}
841
842 {{$base := (Macro "BaseName" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800843
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800844 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
845 {{$p0 := index $.CallParameters 0}}
846 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800847
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800848 if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) {
849 {{if not (IsVoid $.Return.Type)}}return §{{end}}
850 {{$base}}({{Macro "Arguments" $}});
851 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800852 Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800853 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800854 }
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800855 }
Chia-I Wueb7db122016-03-24 09:11:06 +0800856
857 {{end}}
858{{end}}
859
860
861{{/*
862-------------------------------------------------------------------------------
863 Emits definition of a global ProcHook.
864-------------------------------------------------------------------------------
865*/}}
866{{define "driver.C++.DefineGlobalProcHook"}}
867 {{AssertType $ "Function"}}
868
869 {{$base := (Macro "BaseName" $)}}
870
871 {{$ext := GetAnnotation $ "extension"}}
872 {{if $ext}}
873 {{Error "invalid global extension"}}
874 {{end}}
875
876 {
877 "{{$.Name}}",
878 ProcHook::GLOBAL,
879 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800880 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800881 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800882 },
883{{end}}
884
885
886{{/*
887-------------------------------------------------------------------------------
888 Emits definition of an instance ProcHook.
889-------------------------------------------------------------------------------
890*/}}
891{{define "driver.C++.DefineInstanceProcHook"}}
892 {{AssertType $ "Function"}}
893
894 {{$base := (Macro "BaseName" $)}}
895
896 {
897 "{{$.Name}}",
898 ProcHook::INSTANCE,
899
900 {{$ext := GetAnnotation $ "extension"}}
901 {{if $ext}}
902 ProcHook::{{Macro "BaseName" $ext}},
903
904 {{if (Macro "IsExtensionInternal" $ext)}}
905 nullptr,
906 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800907 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800908 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800909 nullptr,
910 {{end}}
911 {{else}}
912 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800913 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800914 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800915 {{end}}
916 },
917{{end}}
918
919
920{{/*
921-------------------------------------------------------------------------------
922 Emits definition of a device ProcHook.
923-------------------------------------------------------------------------------
924*/}}
925{{define "driver.C++.DefineDeviceProcHook"}}
926 {{AssertType $ "Function"}}
927
928 {{$base := (Macro "BaseName" $)}}
929
930 {
931 "{{$.Name}}",
932 ProcHook::DEVICE,
933
934 {{$ext := GetAnnotation $ "extension"}}
935 {{if $ext}}
936 ProcHook::{{Macro "BaseName" $ext}},
937
938 {{if (Macro "IsExtensionInternal" $ext)}}
939 nullptr,
940 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800941 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800942 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800943 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
944 {{end}}
945 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800946 ProcHook::EXTENSION_CORE,
947 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
948 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800949 {{end}}
950 },
951{{end}}
952
953
954{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800955-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800956 Emits true if a function is needed by vulkan::driver.
957-------------------------------------------------------------------------------
958*/}}
959{{define "driver.IsDriverTableEntry"}}
960 {{AssertType $ "Function"}}
961
962 {{if (Macro "IsFunctionSupported" $)}}
963 {{/* Create functions of dispatchable objects */}}
964 {{ if eq $.Name "vkCreateDevice"}}true
965 {{else if eq $.Name "vkGetDeviceQueue"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400966 {{else if eq $.Name "vkGetDeviceQueue2"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800967 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
968
969 {{/* Destroy functions of dispatchable objects */}}
970 {{else if eq $.Name "vkDestroyInstance"}}true
971 {{else if eq $.Name "vkDestroyDevice"}}true
972
973 {{/* Enumeration of extensions */}}
974 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
975
976 {{/* We cache physical devices in loader.cpp */}}
977 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Daniel Koch09f7bf92017-10-05 00:26:58 -0400978 {{else if eq $.Name "vkEnumeratePhysicalDeviceGroups"}}true
979 {{else if eq $.Name "vkGetDeviceGroupPresentCapabilitiesKHR"}}true
980 {{else if eq $.Name "vkGetDeviceGroupSurfacePresentModesKHR"}}true
981 {{else if eq $.Name "vkGetPhysicalDevicePresentRectanglesKHR"}}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
Chris Forbes6aa30db2017-02-20 17:12:53 +1300991 {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true
Chia-I Wucc5e2762016-03-24 13:01:16 +0800992 {{end}}
993
994 {{$ext := GetAnnotation $ "extension"}}
995 {{if $ext}}
996 {{$ext_name := index $ext.Arguments 0}}
997 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
998 {{else if eq $ext_name "VK_EXT_debug_report"}}true
999 {{end}}
1000 {{end}}
1001 {{end}}
1002{{end}}
1003
1004
1005{{/*
1006------------------------------------------------------------------------------
1007 Emits true if an instance-dispatched function is needed by vulkan::driver.
1008------------------------------------------------------------------------------
1009*/}}
1010{{define "driver.IsInstanceDriverTableEntry"}}
1011 {{AssertType $ "Function"}}
1012
1013 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1014 true
1015 {{end}}
1016{{end}}
1017
1018
1019{{/*
1020------------------------------------------------------------------------------
1021 Emits true if a device-dispatched function is needed by vulkan::driver.
1022------------------------------------------------------------------------------
1023*/}}
1024{{define "driver.IsDeviceDriverTableEntry"}}
1025 {{AssertType $ "Function"}}
1026
1027 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1028 true
1029 {{end}}
1030{{end}}
1031
1032
1033{{/*
1034-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001035 Emits a function/extension name without the "vk"/"VK_" prefix.
1036-------------------------------------------------------------------------------
1037*/}}
1038{{define "BaseName"}}
1039 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1040 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1041 {{else}}{{Error "invalid use of BaseName"}}
1042 {{end}}
1043{{end}}
1044
1045
1046{{/*
1047-------------------------------------------------------------------------------
1048 Emits a comma-separated list of C parameter names for the given command.
1049-------------------------------------------------------------------------------
1050*/}}
1051{{define "Arguments"}}
1052 {{AssertType $ "Function"}}
1053
1054 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1055{{end}}
1056
1057
1058{{/*
1059------------------------------------------------------------------------------
1060------------------------------------------------------------------------------
1061*/}}
1062{{define "IsGloballyDispatched"}}
1063 {{AssertType $ "Function"}}
1064 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1065 true
1066 {{end}}
1067{{end}}
1068
1069
1070{{/*
1071------------------------------------------------------------------------------
1072 Emit "true" for supported functions that undergo table dispatch. Only global
1073 functions and functions handled in the loader top without calling into
1074 lower layers are not dispatched.
1075------------------------------------------------------------------------------
1076*/}}
1077{{define "IsInstanceDispatched"}}
1078 {{AssertType $ "Function"}}
1079 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1080 true
1081 {{end}}
1082{{end}}
1083
1084
1085{{/*
1086------------------------------------------------------------------------------
1087 Emit "true" for supported functions that can have device-specific dispatch.
1088------------------------------------------------------------------------------
1089*/}}
1090{{define "IsDeviceDispatched"}}
1091 {{AssertType $ "Function"}}
1092 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1093 true
1094 {{end}}
1095{{end}}
1096
1097
1098{{/*
1099------------------------------------------------------------------------------
1100 Emit "true" if a function is core or from a supportable extension.
1101------------------------------------------------------------------------------
1102*/}}
1103{{define "IsFunctionSupported"}}
1104 {{AssertType $ "Function"}}
1105 {{if not (GetAnnotation $ "pfn")}}
1106 {{$ext := GetAnnotation $ "extension"}}
1107 {{if not $ext}}true
1108 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1109 {{end}}
1110 {{end}}
1111{{end}}
1112
1113
1114{{/*
1115------------------------------------------------------------------------------
1116 Decides whether a function should be exported from the Android Vulkan
1117 library. Functions in the core API and in loader extensions are exported.
1118------------------------------------------------------------------------------
1119*/}}
1120{{define "IsFunctionExported"}}
1121 {{AssertType $ "Function"}}
1122
1123 {{if (Macro "IsFunctionSupported" $)}}
1124 {{$ext := GetAnnotation $ "extension"}}
1125 {{if $ext}}
1126 {{Macro "IsExtensionExported" $ext}}
1127 {{else}}
1128 true
1129 {{end}}
1130 {{end}}
1131{{end}}
1132
1133
1134{{/*
1135------------------------------------------------------------------------------
1136 Emit "true" if an extension is unsupportable on Android.
1137------------------------------------------------------------------------------
1138*/}}
1139{{define "IsExtensionBlacklisted"}}
1140 {{$ext := index $.Arguments 0}}
1141 {{ if eq $ext "VK_KHR_display"}}true
1142 {{else if eq $ext "VK_KHR_display_swapchain"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001143 {{else if eq $ext "VK_KHR_mir_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001144 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1145 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1146 {{else if eq $ext "VK_KHR_wayland_surface"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001147 {{else if eq $ext "VK_KHR_win32_surface"}}true
Jesse Hall9492f992017-08-28 12:10:06 -07001148 {{else if eq $ext "VK_KHR_external_memory_win32"}}true
1149 {{else if eq $ext "VK_KHR_win32_keyed_mutex"}}true
1150 {{else if eq $ext "VK_KHR_external_semaphore_win32"}}true
1151 {{else if eq $ext "VK_KHR_external_fence_win32"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001152 {{else if eq $ext "VK_EXT_acquire_xlib_display"}}true
1153 {{else if eq $ext "VK_EXT_direct_mode_display"}}true
1154 {{else if eq $ext "VK_EXT_display_surface_counter"}}true
1155 {{else if eq $ext "VK_EXT_display_control"}}true
Jesse Hallad250842017-03-10 18:35:38 -08001156 {{else if eq $ext "VK_MVK_ios_surface"}}true
1157 {{else if eq $ext "VK_MVK_macos_surface"}}true
Jesse Hall77ad05b2017-03-10 22:02:20 -08001158 {{else if eq $ext "VK_NN_vi_surface"}}true
Jesse Halleb02c472017-02-24 15:13:45 -08001159 {{else if eq $ext "VK_NV_external_memory_win32"}}true
1160 {{else if eq $ext "VK_NV_win32_keyed_mutex"}}true
Chia-I Wu0c203242016-03-15 13:44:51 +08001161 {{end}}
1162{{end}}
1163
1164
1165{{/*
1166------------------------------------------------------------------------------
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -07001167 Reports whether an extension has functions exported by the loader.
1168 E.g. applications can directly link to an extension function.
1169 Currently only support WSI extensions this way.
Chia-I Wu0c203242016-03-15 13:44:51 +08001170------------------------------------------------------------------------------
1171*/}}
1172{{define "IsExtensionExported"}}
1173 {{$ext := index $.Arguments 0}}
1174 {{ if eq $ext "VK_KHR_surface"}}true
1175 {{else if eq $ext "VK_KHR_swapchain"}}true
1176 {{else if eq $ext "VK_KHR_android_surface"}}true
1177 {{end}}
1178{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001179
1180
1181{{/*
1182------------------------------------------------------------------------------
1183 Reports whether an extension is internal to the loader and drivers,
1184 so the loader should not enumerate it.
1185------------------------------------------------------------------------------
1186*/}}
1187{{define "IsExtensionInternal"}}
1188 {{$ext := index $.Arguments 0}}
1189 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1190 {{end}}
1191{{end}}