blob: e05124438440fd6526aa51edd84fe84a8428cd28 [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) {
322 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
323 // 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"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300416 {{$required := (Macro "IsRequiredFunction" $)}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800417 {{if $ext}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300418 INIT_PROC_EXT({{Macro "BaseName" $ext}}, {{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800419 {{else}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300420 INIT_PROC({{$required}}, §
Chia-I Wu0c203242016-03-15 13:44:51 +0800421 {{end}}
422
423 {{if (Macro "IsInstanceDispatched" $)}}
424 instance, §
425 {{else}}
426 dev, §
427 {{end}}
428
429 {{Macro "BaseName" $}});
430{{end}}
431
432
433{{/*
434------------------------------------------------------------------------------
Chris Forbes5948b3e2016-12-23 13:49:53 +1300435 Emits true if a function /must/ be resolved. The only time this is not
436 the case is for extension-added functions added in a later revision of the
437 extension, and where we have to cope with drivers written against an older
438 revision.
439------------------------------------------------------------------------------
440*/}}
441{{define "IsRequiredFunction"}}
442 {{AssertType $ "Function"}}
443
444 {{if eq $.Name "vkGetSwapchainGrallocUsage2ANDROID"}}
445 false
Chris Forbesd8277912017-02-10 14:59:59 +1300446 {{else if eq $.Name "vkGetSwapchainGrallocUsageANDROID"}}
447 false
Chris Forbes5948b3e2016-12-23 13:49:53 +1300448 {{else}}
449 true
450 {{end}}
451{{end}}
452
453
454{{/*
455------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +0800456 Emits true if a function is exported and instance-dispatched.
457------------------------------------------------------------------------------
458*/}}
459{{define "api.IsInstanceDispatchTableEntry"}}
460 {{AssertType $ "Function"}}
461
462 {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
Chia-I Wudbd33bc2016-06-02 11:25:47 +0800463 {{/* deprecated and unused internally */}}
464 {{if not (eq $.Name "vkEnumerateDeviceLayerProperties")}}
465 true
466 {{end}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800467 {{end}}
468{{end}}
469
470
471{{/*
472------------------------------------------------------------------------------
473 Emits true if a function is exported and device-dispatched.
474------------------------------------------------------------------------------
475*/}}
476{{define "api.IsDeviceDispatchTableEntry"}}
477 {{AssertType $ "Function"}}
478
479 {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
480 true
481 {{end}}
482{{end}}
483
484
485{{/*
486------------------------------------------------------------------------------
487 Emits true if a function is intercepted by vulkan::api.
488------------------------------------------------------------------------------
489*/}}
490{{define "api.IsIntercepted"}}
491 {{AssertType $ "Function"}}
492
493 {{if (Macro "IsFunctionSupported" $)}}
494 {{/* Global functions cannot be dispatched at all */}}
495 {{ if (Macro "IsGloballyDispatched" $)}}true
496
497 {{/* VkPhysicalDevice functions that manage device layers */}}
498 {{else if eq $.Name "vkCreateDevice"}}true
499 {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
500 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
501
502 {{/* Destroy functions of dispatchable objects */}}
503 {{else if eq $.Name "vkDestroyInstance"}}true
504 {{else if eq $.Name "vkDestroyDevice"}}true
505
506 {{end}}
507 {{end}}
508{{end}}
509
510
511{{/*
Chia-I Wucc5e2762016-03-24 13:01:16 +0800512-------------------------------------------------------------------------------
513 Emits INIT_PROC_EXT macro for vulkan::api.
514-------------------------------------------------------------------------------
515*/}}
516{{define "api.C++.DefineInitProcExtMacro"}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800517 // Exported extension functions may be invoked even when their extensions
518 // are disabled. Dispatch to stubs when that happens.
Chris Forbes5948b3e2016-12-23 13:49:53 +1300519 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800520 if (extensions[driver::ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300521 INIT_PROC(required, obj, proc); \
Chia-I Wu8925efd2016-04-13 15:13:21 +0800522 else \
523 data.dispatch.proc = disabled ## proc; \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800524 } while(0)
525{{end}}
526
527
528{{/*
Chia-I Wu8925efd2016-04-13 15:13:21 +0800529-------------------------------------------------------------------------------
530 Emits a stub for an exported extension function.
531-------------------------------------------------------------------------------
532*/}}
533{{define "api.C++.DefineExtensionStub"}}
534 {{AssertType $ "Function"}}
535
536 {{$ext := GetAnnotation $ "extension"}}
537 {{if and $ext (Macro "IsFunctionExported" $)}}
538 {{$ext_name := index $ext.Arguments 0}}
539
540 {{$base := (Macro "BaseName" $)}}
Chia-I Wu8925efd2016-04-13 15:13:21 +0800541
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800542 {{$p0 := (index $.CallParameters 0)}}
543 {{$ptail := (Tail 1 $.CallParameters)}}
544
545 {{$first_type := (Macro "Parameter" $p0)}}
546 {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
547
548 VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
549 driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
550 "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
Chia-I Wu8925efd2016-04-13 15:13:21 +0800551 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
552 }
553
554 {{end}}
555{{end}}
556
557
558{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800559------------------------------------------------------------------------------
560 Emits code for vkGetInstanceProcAddr for function interception.
561------------------------------------------------------------------------------
562*/}}
563{{define "api.C++.InterceptInstanceProcAddr"}}
564 {{AssertType $ "API"}}
565
566 // global functions
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800567 if (instance == VK_NULL_HANDLE) {
Chia-I Wu0c203242016-03-15 13:44:51 +0800568 {{range $f := AllCommands $}}
569 {{if (Macro "IsGloballyDispatched" $f)}}
570 if (strcmp(pName, "{{$f.Name}}") == 0) return §
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800571 reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}});
Chia-I Wu0c203242016-03-15 13:44:51 +0800572 {{end}}
573 {{end}}
574
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800575 ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
Chia-I Wu0c203242016-03-15 13:44:51 +0800576 return nullptr;
577 }
578
579 static const struct Hook {
580 const char* name;
581 PFN_vkVoidFunction proc;
582 } hooks[] = {
583 {{range $f := SortBy (AllCommands $) "FunctionName"}}
584 {{if (Macro "IsFunctionExported" $f)}}
585 {{/* hide global functions */}}
586 {{if (Macro "IsGloballyDispatched" $f)}}
587 { "{{$f.Name}}", nullptr },
588
589 {{/* redirect intercepted functions */}}
590 {{else if (Macro "api.IsIntercepted" $f)}}
591 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800592 {{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800593
594 {{/* redirect vkGetInstanceProcAddr to itself */}}
595 {{else if eq $f.Name "vkGetInstanceProcAddr"}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800596 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800597
598 {{/* redirect device functions to themselves as a workaround for
599 layers that do not intercept in their vkGetInstanceProcAddr */}}
600 {{else if (Macro "IsDeviceDispatched" $f)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800601 { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{Macro "BaseName" $f}}) },
Chia-I Wu0c203242016-03-15 13:44:51 +0800602
603 {{end}}
604 {{end}}
605 {{end}}
606 };
607 // clang-format on
608 constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
609 auto hook = std::lower_bound(
610 hooks, hooks + count, pName,
611 [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
612 if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800613 if (!hook->proc) {
614 vulkan::driver::Logger(instance).Err(
615 instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
616 instance, pName);
617 }
Chia-I Wu0c203242016-03-15 13:44:51 +0800618 return hook->proc;
619 }
620 // clang-format off
621
622{{end}}
623
624
625{{/*
626------------------------------------------------------------------------------
627 Emits code for vkGetDeviceProcAddr for function interception.
628------------------------------------------------------------------------------
629*/}}
630{{define "api.C++.InterceptDeviceProcAddr"}}
631 {{AssertType $ "API"}}
632
633 if (device == VK_NULL_HANDLE) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800634 ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
Chia-I Wu0c203242016-03-15 13:44:51 +0800635 return nullptr;
636 }
637
638 static const char* const known_non_device_names[] = {
639 {{range $f := SortBy (AllCommands $) "FunctionName"}}
640 {{if (Macro "IsFunctionSupported" $f)}}
641 {{if not (Macro "IsDeviceDispatched" $f)}}
642 "{{$f.Name}}",
643 {{end}}
644 {{end}}
645 {{end}}
646 };
647 // clang-format on
648 constexpr size_t count = sizeof(known_non_device_names) /
649 sizeof(known_non_device_names[0]);
650 if (!pName ||
651 std::binary_search(
652 known_non_device_names, known_non_device_names + count, pName,
653 [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800654 vulkan::driver::Logger(device).Err
655 device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device
656 (pName) ? pName : "(null)");
Chia-I Wu0c203242016-03-15 13:44:51 +0800657 return nullptr;
658 }
659 // clang-format off
660
Chia-I Wuc56603e2016-04-12 11:16:17 +0800661 {{range $f := AllCommands $}}
662 {{if (Macro "IsDeviceDispatched" $f)}}
663 {{ if (Macro "api.IsIntercepted" $f)}}
664 if (strcmp(pName, "{{$f.Name}}") == 0) return §
665 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800666 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800667 {{else if eq $f.Name "vkGetDeviceProcAddr"}}
668 if (strcmp(pName, "{{$f.Name}}") == 0) return §
669 reinterpret_cast<PFN_vkVoidFunction>(§
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800670 {{Macro "BaseName" $f}});
Chia-I Wuc56603e2016-04-12 11:16:17 +0800671 {{end}}
672 {{end}}
673 {{end}}
674
Chia-I Wu0c203242016-03-15 13:44:51 +0800675{{end}}
676
677
678{{/*
679------------------------------------------------------------------------------
680 Emits code to dispatch a function.
681------------------------------------------------------------------------------
682*/}}
683{{define "api.C++.Dispatch"}}
684 {{AssertType $ "Function"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800685 {{if (Macro "api.IsIntercepted" $)}}
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800686 {{Error "$.Name should not be generated"}}
Chia-I Wu0c203242016-03-15 13:44:51 +0800687 {{end}}
688
Chia-I Wu3e654dc2016-05-20 16:15:06 +0800689 {{if not (IsVoid $.Return.Type)}}return §{{end}}
690
691 {{$p0 := index $.CallParameters 0}}
692 GetData({{$p0.Name}}).dispatch
Chia-I Wu0c203242016-03-15 13:44:51 +0800693 {{Macro "BaseName" $}}({{Macro "Arguments" $}});
694{{end}}
695
696
697{{/*
Chia-I Wueb7db122016-03-24 09:11:06 +0800698------------------------------------------------------------------------------
699 Emits a list of extensions intercepted by vulkan::driver.
700------------------------------------------------------------------------------
701*/}}
702{{define "driver.InterceptedExtensions"}}
703VK_ANDROID_native_buffer
704VK_EXT_debug_report
705VK_KHR_android_surface
Ian Elliott948233a2017-01-06 12:13:23 -0700706VK_KHR_incremental_present
Chia-I Wueb7db122016-03-24 09:11:06 +0800707VK_KHR_surface
708VK_KHR_swapchain
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700709VK_GOOGLE_display_timing
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300710VK_KHR_shared_presentable_image
Chia-I Wueb7db122016-03-24 09:11:06 +0800711{{end}}
712
713
714{{/*
715------------------------------------------------------------------------------
716 Emits true if an extension is intercepted by vulkan::driver.
717------------------------------------------------------------------------------
718*/}}
719{{define "driver.IsExtensionIntercepted"}}
720 {{$ext_name := index $.Arguments 0}}
721 {{$filters := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
722
723 {{range $f := $filters}}
724 {{if eq $ext_name $f}}true{{end}}
725 {{end}}
726{{end}}
727
728
729{{/*
730------------------------------------------------------------------------------
731 Emits true if a function is intercepted by vulkan::driver.
732------------------------------------------------------------------------------
733*/}}
734{{define "driver.IsIntercepted"}}
735 {{AssertType $ "Function"}}
736
737 {{if (Macro "IsFunctionSupported" $)}}
738 {{/* Create functions of dispatchable objects */}}
739 {{ if eq $.Name "vkCreateInstance"}}true
740 {{else if eq $.Name "vkCreateDevice"}}true
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800741 {{else if eq $.Name "vkEnumeratePhysicalDevices"}}true
Chia-I Wueb7db122016-03-24 09:11:06 +0800742 {{else if eq $.Name "vkGetDeviceQueue"}}true
743 {{else if eq $.Name "vkAllocateCommandBuffers"}}true
744
745 {{/* Destroy functions of dispatchable objects */}}
746 {{else if eq $.Name "vkDestroyInstance"}}true
747 {{else if eq $.Name "vkDestroyDevice"}}true
748
749 {{/* Enumeration of extensions */}}
750 {{else if eq $.Name "vkEnumerateInstanceExtensionProperties"}}true
751 {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
752
Chia-I Wueb7db122016-03-24 09:11:06 +0800753 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
754 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
755
756 {{end}}
757
758 {{$ext := GetAnnotation $ "extension"}}
759 {{if $ext}}
760 {{Macro "driver.IsExtensionIntercepted" $ext}}
761 {{end}}
762
763 {{end}}
764{{end}}
765
766
767{{/*
768------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800769 Emits true if a function needs a ProcHook stub.
Chia-I Wueb7db122016-03-24 09:11:06 +0800770------------------------------------------------------------------------------
771*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800772{{define "driver.NeedProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800773 {{AssertType $ "Function"}}
774
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800775 {{if and (Macro "driver.IsIntercepted" $) (Macro "IsDeviceDispatched" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800776 {{$ext := GetAnnotation $ "extension"}}
777 {{if $ext}}
778 {{if not (Macro "IsExtensionInternal" $ext)}}true{{end}}
779 {{end}}
780 {{end}}
781{{end}}
782
783
784{{/*
785-------------------------------------------------------------------------------
786 Emits definition of struct ProcHook.
787-------------------------------------------------------------------------------
788*/}}
789{{define "driver.C++.DefineProcHookType"}}
790 struct ProcHook {
791 enum Type {
792 GLOBAL,
793 INSTANCE,
794 DEVICE,
795 };
796
797 enum Extension {
798 {{$exts := Strings (Macro "driver.InterceptedExtensions") | SplitOn "\n"}}
799 {{range $e := $exts}}
800 {{TrimPrefix "VK_" $e}},
801 {{end}}
802
803 EXTENSION_CORE, // valid bit
804 EXTENSION_COUNT,
805 EXTENSION_UNKNOWN,
806 };
807
808 const char* name;
809 Type type;
810 Extension extension;
811
812 PFN_vkVoidFunction proc;
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800813 PFN_vkVoidFunction checked_proc; // always nullptr for non-device hooks
Chia-I Wueb7db122016-03-24 09:11:06 +0800814 };
815{{end}}
816
817
818{{/*
819-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800820 Emits INIT_PROC_EXT macro for vulkan::driver.
821-------------------------------------------------------------------------------
822*/}}
823{{define "driver.C++.DefineInitProcExtMacro"}}
Chris Forbes5948b3e2016-12-23 13:49:53 +1300824 #define INIT_PROC_EXT(ext, required, obj, proc) do { \
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800825 if (extensions[ProcHook::ext]) \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300826 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800827 } while(0)
828{{end}}
829
830
831{{/*
832-------------------------------------------------------------------------------
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800833 Emits a stub for ProcHook::checked_proc.
Chia-I Wueb7db122016-03-24 09:11:06 +0800834-------------------------------------------------------------------------------
835*/}}
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800836{{define "driver.C++.DefineProcHookStub"}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800837 {{AssertType $ "Function"}}
838
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800839 {{if (Macro "driver.NeedProcHookStub" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800840 {{$ext := GetAnnotation $ "extension"}}
841 {{$ext_name := index $ext.Arguments 0}}
842
843 {{$base := (Macro "BaseName" $)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800844
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800845 VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
846 {{$p0 := index $.CallParameters 0}}
847 {{$ext_hook := Strings ("ProcHook::") (Macro "BaseName" $ext)}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800848
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800849 if (GetData({{$p0.Name}}).hook_extensions[{{$ext_hook}}]) {
850 {{if not (IsVoid $.Return.Type)}}return §{{end}}
851 {{$base}}({{Macro "Arguments" $}});
852 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +0800853 Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800854 {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +0800855 }
Chia-I Wu36cc00a2016-04-13 16:52:06 +0800856 }
Chia-I Wueb7db122016-03-24 09:11:06 +0800857
858 {{end}}
859{{end}}
860
861
862{{/*
863-------------------------------------------------------------------------------
864 Emits definition of a global ProcHook.
865-------------------------------------------------------------------------------
866*/}}
867{{define "driver.C++.DefineGlobalProcHook"}}
868 {{AssertType $ "Function"}}
869
870 {{$base := (Macro "BaseName" $)}}
871
872 {{$ext := GetAnnotation $ "extension"}}
873 {{if $ext}}
874 {{Error "invalid global extension"}}
875 {{end}}
876
877 {
878 "{{$.Name}}",
879 ProcHook::GLOBAL,
880 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800881 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800882 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800883 },
884{{end}}
885
886
887{{/*
888-------------------------------------------------------------------------------
889 Emits definition of an instance ProcHook.
890-------------------------------------------------------------------------------
891*/}}
892{{define "driver.C++.DefineInstanceProcHook"}}
893 {{AssertType $ "Function"}}
894
895 {{$base := (Macro "BaseName" $)}}
896
897 {
898 "{{$.Name}}",
899 ProcHook::INSTANCE,
900
901 {{$ext := GetAnnotation $ "extension"}}
902 {{if $ext}}
903 ProcHook::{{Macro "BaseName" $ext}},
904
905 {{if (Macro "IsExtensionInternal" $ext)}}
906 nullptr,
907 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800908 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800909 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800910 nullptr,
911 {{end}}
912 {{else}}
913 ProcHook::EXTENSION_CORE,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800914 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800915 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800916 {{end}}
917 },
918{{end}}
919
920
921{{/*
922-------------------------------------------------------------------------------
923 Emits definition of a device ProcHook.
924-------------------------------------------------------------------------------
925*/}}
926{{define "driver.C++.DefineDeviceProcHook"}}
927 {{AssertType $ "Function"}}
928
929 {{$base := (Macro "BaseName" $)}}
930
931 {
932 "{{$.Name}}",
933 ProcHook::DEVICE,
934
935 {{$ext := GetAnnotation $ "extension"}}
936 {{if $ext}}
937 ProcHook::{{Macro "BaseName" $ext}},
938
939 {{if (Macro "IsExtensionInternal" $ext)}}
940 nullptr,
941 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800942 {{else}}
Chia-I Wu62262232016-03-26 07:06:44 +0800943 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
Chia-I Wueb7db122016-03-24 09:11:06 +0800944 reinterpret_cast<PFN_vkVoidFunction>(checked{{$base}}),
945 {{end}}
946 {{else}}
Chia-I Wu4901db72016-03-24 16:38:58 +0800947 ProcHook::EXTENSION_CORE,
948 reinterpret_cast<PFN_vkVoidFunction>({{$base}}),
949 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800950 {{end}}
951 },
952{{end}}
953
954
955{{/*
Chia-I Wu0c203242016-03-15 13:44:51 +0800956-------------------------------------------------------------------------------
Chia-I Wucc5e2762016-03-24 13:01:16 +0800957 Emits true if a function is needed by vulkan::driver.
958-------------------------------------------------------------------------------
959*/}}
960{{define "driver.IsDriverTableEntry"}}
961 {{AssertType $ "Function"}}
962
963 {{if (Macro "IsFunctionSupported" $)}}
964 {{/* Create functions of dispatchable objects */}}
965 {{ if eq $.Name "vkCreateDevice"}}true
966 {{else if eq $.Name "vkGetDeviceQueue"}}true
967 {{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
978
979 {{else if eq $.Name "vkGetInstanceProcAddr"}}true
980 {{else if eq $.Name "vkGetDeviceProcAddr"}}true
981
982 {{/* VK_KHR_swapchain->VK_ANDROID_native_buffer translation */}}
983 {{else if eq $.Name "vkCreateImage"}}true
984 {{else if eq $.Name "vkDestroyImage"}}true
985
986 {{end}}
987
988 {{$ext := GetAnnotation $ "extension"}}
989 {{if $ext}}
990 {{$ext_name := index $ext.Arguments 0}}
991 {{ if eq $ext_name "VK_ANDROID_native_buffer"}}true
992 {{else if eq $ext_name "VK_EXT_debug_report"}}true
993 {{end}}
994 {{end}}
995 {{end}}
996{{end}}
997
998
999{{/*
1000------------------------------------------------------------------------------
1001 Emits true if an instance-dispatched function is needed by vulkan::driver.
1002------------------------------------------------------------------------------
1003*/}}
1004{{define "driver.IsInstanceDriverTableEntry"}}
1005 {{AssertType $ "Function"}}
1006
1007 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsInstanceDispatched" $)}}
1008 true
1009 {{end}}
1010{{end}}
1011
1012
1013{{/*
1014------------------------------------------------------------------------------
1015 Emits true if a device-dispatched function is needed by vulkan::driver.
1016------------------------------------------------------------------------------
1017*/}}
1018{{define "driver.IsDeviceDriverTableEntry"}}
1019 {{AssertType $ "Function"}}
1020
1021 {{if and (Macro "driver.IsDriverTableEntry" $) (Macro "IsDeviceDispatched" $)}}
1022 true
1023 {{end}}
1024{{end}}
1025
1026
1027{{/*
1028-------------------------------------------------------------------------------
Chia-I Wu0c203242016-03-15 13:44:51 +08001029 Emits a function/extension name without the "vk"/"VK_" prefix.
1030-------------------------------------------------------------------------------
1031*/}}
1032{{define "BaseName"}}
1033 {{ if IsFunction $}}{{TrimPrefix "vk" $.Name}}
1034 {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
1035 {{else}}{{Error "invalid use of BaseName"}}
1036 {{end}}
1037{{end}}
1038
1039
1040{{/*
1041-------------------------------------------------------------------------------
1042 Emits a comma-separated list of C parameter names for the given command.
1043-------------------------------------------------------------------------------
1044*/}}
1045{{define "Arguments"}}
1046 {{AssertType $ "Function"}}
1047
1048 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
1049{{end}}
1050
1051
1052{{/*
1053------------------------------------------------------------------------------
1054------------------------------------------------------------------------------
1055*/}}
1056{{define "IsGloballyDispatched"}}
1057 {{AssertType $ "Function"}}
1058 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
1059 true
1060 {{end}}
1061{{end}}
1062
1063
1064{{/*
1065------------------------------------------------------------------------------
1066 Emit "true" for supported functions that undergo table dispatch. Only global
1067 functions and functions handled in the loader top without calling into
1068 lower layers are not dispatched.
1069------------------------------------------------------------------------------
1070*/}}
1071{{define "IsInstanceDispatched"}}
1072 {{AssertType $ "Function"}}
1073 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
1074 true
1075 {{end}}
1076{{end}}
1077
1078
1079{{/*
1080------------------------------------------------------------------------------
1081 Emit "true" for supported functions that can have device-specific dispatch.
1082------------------------------------------------------------------------------
1083*/}}
1084{{define "IsDeviceDispatched"}}
1085 {{AssertType $ "Function"}}
1086 {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
1087 true
1088 {{end}}
1089{{end}}
1090
1091
1092{{/*
1093------------------------------------------------------------------------------
1094 Emit "true" if a function is core or from a supportable extension.
1095------------------------------------------------------------------------------
1096*/}}
1097{{define "IsFunctionSupported"}}
1098 {{AssertType $ "Function"}}
1099 {{if not (GetAnnotation $ "pfn")}}
1100 {{$ext := GetAnnotation $ "extension"}}
1101 {{if not $ext}}true
1102 {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
1103 {{end}}
1104 {{end}}
1105{{end}}
1106
1107
1108{{/*
1109------------------------------------------------------------------------------
1110 Decides whether a function should be exported from the Android Vulkan
1111 library. Functions in the core API and in loader extensions are exported.
1112------------------------------------------------------------------------------
1113*/}}
1114{{define "IsFunctionExported"}}
1115 {{AssertType $ "Function"}}
1116
1117 {{if (Macro "IsFunctionSupported" $)}}
1118 {{$ext := GetAnnotation $ "extension"}}
1119 {{if $ext}}
1120 {{Macro "IsExtensionExported" $ext}}
1121 {{else}}
1122 true
1123 {{end}}
1124 {{end}}
1125{{end}}
1126
1127
1128{{/*
1129------------------------------------------------------------------------------
1130 Emit "true" if an extension is unsupportable on Android.
1131------------------------------------------------------------------------------
1132*/}}
1133{{define "IsExtensionBlacklisted"}}
1134 {{$ext := index $.Arguments 0}}
1135 {{ if eq $ext "VK_KHR_display"}}true
1136 {{else if eq $ext "VK_KHR_display_swapchain"}}true
1137 {{else if eq $ext "VK_KHR_xlib_surface"}}true
1138 {{else if eq $ext "VK_KHR_xcb_surface"}}true
1139 {{else if eq $ext "VK_KHR_wayland_surface"}}true
1140 {{else if eq $ext "VK_KHR_mir_surface"}}true
1141 {{else if eq $ext "VK_KHR_win32_surface"}}true
1142 {{end}}
1143{{end}}
1144
1145
1146{{/*
1147------------------------------------------------------------------------------
1148 Reports whether an extension is implemented entirely by the loader,
1149 so drivers should not enumerate it.
1150------------------------------------------------------------------------------
1151*/}}
1152{{define "IsExtensionExported"}}
1153 {{$ext := index $.Arguments 0}}
1154 {{ if eq $ext "VK_KHR_surface"}}true
1155 {{else if eq $ext "VK_KHR_swapchain"}}true
1156 {{else if eq $ext "VK_KHR_android_surface"}}true
1157 {{end}}
1158{{end}}
Chia-I Wueb7db122016-03-24 09:11:06 +08001159
1160
1161{{/*
1162------------------------------------------------------------------------------
1163 Reports whether an extension is internal to the loader and drivers,
1164 so the loader should not enumerate it.
1165------------------------------------------------------------------------------
1166*/}}
1167{{define "IsExtensionInternal"}}
1168 {{$ext := index $.Arguments 0}}
1169 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
1170 {{end}}
1171{{end}}