code-generator.tmpl revision 0c2032490b80178ec823bf22a7f5d08398851cc3
10c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "Copyright"}}
20c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu/*
30c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* Copyright 2016 The Android Open Source Project
40c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•*
50c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* Licensed under the Apache License, Version 2.0 (the "License");
60c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* you may not use this file except in compliance with the License.
70c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* You may obtain a copy of the License at
80c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•*
90c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•*      http://www.apache.org/licenses/LICENSE-2.0
100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•*
110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* Unless required by applicable law or agreed to in writing, software
120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* distributed under the License is distributed on an "AS IS" BASIS,
130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* See the License for the specific language governing permissions and
150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•* limitations under the License.
160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu•*/
170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu¶{{end}}
180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Include "../api/templates/vulkan_common.tmpl"}}
200c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Global "clang-format" (Strings "clang-format" "-style=file")}}
210c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Macro "DefineGlobals" $}}
220c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{$ | Macro "api_gen.h"   | Format (Global "clang-format") | Write "api_gen.h"  }}
230c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{$ | Macro "api_gen.cpp" | Format (Global "clang-format") | Write "api_gen.cpp"}}
240c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
250c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
260c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
270c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  api_gen.h
280c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
290c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
300c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api_gen.h"}}
310c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Macro "Copyright"}}
320c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu330c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu// WARNING: This file is generated. See ../README.md for instructions.
340c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu350c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#ifndef LIBVULKAN_API_GEN_H
360c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#define LIBVULKAN_API_GEN_H
370c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu380c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#include <vulkan/vulkan.h>
390c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu400c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wunamespace vulkan {«
410c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wunamespace api {«
420c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu430c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wustruct InstanceDispatchTable {
440c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format off
450c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{range $f := AllCommands $}}
460c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
470c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{Macro "C++.DeclareDispatchTableEntry" $f}};
480c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
490c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
500c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format on
510c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu};
520c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu530c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wustruct DeviceDispatchTable {
540c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format off
550c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{range $f := AllCommands $}}
560c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
570c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{Macro "C++.DeclareDispatchTableEntry" $f}};
580c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
590c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
600c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format on
610c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu};
620c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu630c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wubool InitDispatchTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc);
640c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wubool InitDispatchTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc);
650c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu660c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu»} // namespace api
670c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu»} // namespace vulkan
680c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu690c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#endif // LIBVULKAN_API_GEN_H
700c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu¶{{end}}
710c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
720c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
730c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
740c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
750c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  api_gen.cpp
760c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
770c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
780c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api_gen.cpp"}}
790c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Macro "Copyright"}}
800c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu810c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu// WARNING: This file is generated. See ../README.md for instructions.
820c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu830c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#include <string.h>
840c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#include <algorithm>
850c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#include <log/log.h>
860c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu870c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu#include "api.h"
880c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu890c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wunamespace vulkan {«
900c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wunamespace api {«
910c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu920c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{Macro "C++.DefineInitProcMacros" "dispatch"}}
930c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu940c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wubool InitDispatchTable(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc) {
950c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    auto& data = GetData(instance);
960c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    bool success = true;
970c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu980c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    // clang-format off
990c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{range $f := AllCommands $}}
1000c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{if (Macro "api.IsInstanceDispatchTableEntry" $f)}}
1010c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{Macro "C++.InitProc" $f}}
1020c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
1030c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
1040c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    // clang-format on
1050c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1060c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return success;
1070c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu}
1080c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1090c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wubool InitDispatchTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc) {
1100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    auto& data = GetData(dev);
1110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    bool success = true;
1120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    // clang-format off
1140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{range $f := AllCommands $}}
1150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{if (Macro "api.IsDeviceDispatchTableEntry" $f)}}
1160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{Macro "C++.InitProc" $f}}
1170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
1180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
1190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    // clang-format on
1200c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1210c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return success;
1220c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu}
1230c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1240c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu»} // namespace api
1250c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu»} // namespace vulkan
1260c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1270c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu// clang-format off
1280c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1290c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{range $f := AllCommands $}}
1300c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "IsFunctionExported" $f)}}
1310c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    __attribute__((visibility("default")))
1320c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) {
1330c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{     if eq $f.Name "vkGetInstanceProcAddr"}}
1340c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{Macro "api.C++.InterceptInstanceProcAddr" $}}
1350c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{else if eq $f.Name "vkGetDeviceProcAddr"}}
1360c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{Macro "api.C++.InterceptDeviceProcAddr" $}}
1370c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
1380c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1390c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{Macro "api.C++.Dispatch" $f}}
1400c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    }
1410c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1420c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
1430c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
1440c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1450c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu// clang-format on
1460c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu¶{{end}}
1470c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1480c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1490c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
1500c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
1510c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits a declaration of a dispatch table entry.
1520c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
1530c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
1540c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "C++.DeclareDispatchTableEntry"}}
1550c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
1560c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1570c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{Macro "FunctionPtrName" $}} {{Macro "BaseName" $}}
1580c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
1590c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1600c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1610c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
1620c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
1630c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits macros to help initialize dispatch tables.
1640c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
1650c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
1660c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "C++.DefineInitProcMacros"}}
1670c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  #define UNLIKELY(expr) __builtin_expect((expr), 0)
1680c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1690c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  #define INIT_PROC(obj, proc) do {                             \
1700c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      data.{{$}}.proc = reinterpret_cast<PFN_vk ## proc>(       \
1710c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu              get_proc(obj, "vk" # proc));                      \
1720c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      if (UNLIKELY(!data.{{$}}.proc)) {                         \
1730c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          ALOGE("missing " # obj " proc: vk" # proc);           \
1740c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          success = false;                                      \
1750c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      }                                                         \
1760c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  } while(0)
1770c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu1780c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // TODO do we want to point to a stub or nullptr when ext is not enabled?
1790c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  #define INIT_PROC_EXT(ext, obj, proc) do {                    \
1800c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      INIT_PROC(obj, proc);                                     \
1810c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  } while(0)
1820c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
1830c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1840c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1850c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
1860c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
1870c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits code to invoke INIT_PROC or INIT_PROC_EXT.
1880c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
1890c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
1900c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "C++.InitProc"}}
1910c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
1920c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
1930c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{$ext := GetAnnotation $ "extension"}}
1940c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if $ext}}
1950c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    INIT_PROC_EXT({{Macro "BaseName" $ext}}, §
1960c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else}}
1970c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    INIT_PROC(§
1980c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
1990c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2000c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "IsInstanceDispatched" $)}}
2010c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    instance, §
2020c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else}}
2030c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    dev, §
2040c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
2050c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2060c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{Macro "BaseName" $}});
2070c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
2080c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2090c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
2110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits true if a function is exported and instance-dispatched.
2130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
2150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.IsInstanceDispatchTableEntry"}}
2160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
2170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if and (Macro "IsFunctionExported" $) (Macro "IsInstanceDispatched" $)}}
2190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    true
2200c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
2210c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
2220c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2230c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2240c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
2250c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2260c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits true if a function is exported and device-dispatched.
2270c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2280c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
2290c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.IsDeviceDispatchTableEntry"}}
2300c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
2310c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2320c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if and (Macro "IsFunctionExported" $) (Macro "IsDeviceDispatched" $)}}
2330c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    true
2340c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
2350c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
2360c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2370c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2380c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
2390c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2400c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits true if a function is intercepted by vulkan::api.
2410c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2420c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
2430c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.IsIntercepted"}}
2440c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
2450c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2460c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "IsFunctionSupported" $)}}
2470c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{/* Global functions cannot be dispatched at all */}}
2480c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{     if (Macro "IsGloballyDispatched" $)}}true
2490c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2500c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{/* VkPhysicalDevice functions that manage device layers */}}
2510c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if eq $.Name "vkCreateDevice"}}true
2520c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true
2530c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if eq $.Name "vkEnumerateDeviceExtensionProperties"}}true
2540c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2550c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{/* Destroy functions of dispatchable objects */}}
2560c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if eq $.Name "vkDestroyInstance"}}true
2570c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if eq $.Name "vkDestroyDevice"}}true
2580c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2590c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
2600c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
2610c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
2620c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2630c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2640c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
2650c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2660c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits code for vkGetInstanceProcAddr for function interception.
2670c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
2680c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
2690c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.C++.InterceptInstanceProcAddr"}}
2700c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "API"}}
2710c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2720c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // global functions
2730c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  if (!instance) {
2740c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{range $f := AllCommands $}}
2750c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{if (Macro "IsGloballyDispatched" $f)}}
2760c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        if (strcmp(pName, "{{$f.Name}}") == 0) return §
2770c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          reinterpret_cast<PFN_vkVoidFunction>(§
2780c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu            vulkan::api::{{Macro "BaseName" $f}});
2790c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
2800c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
2810c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu2820c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    ALOGE("vkGetInstanceProcAddr called with %s without instance",  pName);
2830c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return nullptr;
2840c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  }
2850c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu2860c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  static const struct Hook {
2870c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    const char* name;
2880c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    PFN_vkVoidFunction proc;
2890c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  } hooks[] = {
2900c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{range $f := SortBy (AllCommands $) "FunctionName"}}
2910c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{if (Macro "IsFunctionExported" $f)}}
2920c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{/* hide global functions */}}
2930c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{if (Macro "IsGloballyDispatched" $f)}}
2940c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          { "{{$f.Name}}", nullptr },
2950c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
2960c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{/* redirect intercepted functions */}}
2970c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{else if (Macro "api.IsIntercepted" $f)}}
2980c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
2990c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu            vulkan::api::{{Macro "BaseName" $f}}) },
3000c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3010c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{/* redirect vkGetInstanceProcAddr to itself */}}
3020c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{else if eq $f.Name "vkGetInstanceProcAddr"}}
3030c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
3040c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3050c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{/* redirect device functions to themselves as a workaround for
3060c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu             layers that do not intercept in their vkGetInstanceProcAddr */}}
3070c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{else if (Macro "IsDeviceDispatched" $f)}}
3080c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          { "{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}}) },
3090c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{end}}
3110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
3120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
3130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  };
3140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format on
3150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  constexpr size_t count = sizeof(hooks) / sizeof(hooks[0]);
3160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  auto hook = std::lower_bound(
3170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    hooks, hooks + count, pName,
3180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
3190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  if (hook <  hooks + count && strcmp(hook->name, pName) == 0) {
3200c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    if (!hook->proc)
3210c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      ALOGE("vkGetInstanceProcAddr called with %s with instance",  pName);
3220c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return hook->proc;
3230c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  }
3240c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format off
3250c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu3260c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
3270c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3280c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3290c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
3300c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
3310c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits code for vkGetDeviceProcAddr for function interception.
3320c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
3330c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
3340c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.C++.InterceptDeviceProcAddr"}}
3350c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "API"}}
3360c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3370c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  if (device == VK_NULL_HANDLE) {
3380c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    ALOGE("vkGetDeviceProcAddr called with invalid device");
3390c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return nullptr;
3400c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  }
3410c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu3420c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  static const char* const known_non_device_names[] = {
3430c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{range $f := SortBy (AllCommands $) "FunctionName"}}
3440c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{if (Macro "IsFunctionSupported" $f)}}
3450c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{if not (Macro "IsDeviceDispatched" $f)}}
3460c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu          "{{$f.Name}}",
3470c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        {{end}}
3480c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{end}}
3490c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
3500c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  };
3510c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format on
3520c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  constexpr size_t count = sizeof(known_non_device_names) /
3530c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    sizeof(known_non_device_names[0]);
3540c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  if (!pName ||
3550c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      std::binary_search(
3560c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        known_non_device_names, known_non_device_names + count, pName,
3570c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu        [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
3580c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    ALOGE("vkGetDeviceProcAddr called with %s", pName);
3590c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    return nullptr;
3600c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  }
3610c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  // clang-format off
3620c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu3630c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
3640c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3650c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3660c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
3670c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
3680c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits code to dispatch a function.
3690c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
3700c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
3710c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "api.C++.Dispatch"}}
3720c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
3730c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3740c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "api.IsIntercepted" $)}}// call into api.cpp{{end}}
3750c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if not (IsVoid $.Return.Type)}}return §{{end}}
3760c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3770c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "api.IsIntercepted" $)}}
3780c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    vulkan::api::§
3790c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else}}
3800c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{$p0 := index $.CallParameters 0}}
3810c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    vulkan::api::GetData({{$p0.Name}}).dispatch.§
3820c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
3830c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3840c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{Macro "BaseName" $}}({{Macro "Arguments" $}});
3850c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
3860c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3870c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
3880c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
3890c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
3900c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits a function/extension name without the "vk"/"VK_" prefix.
3910c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
3920c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
3930c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "BaseName"}}
3940c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{     if IsFunction $}}{{TrimPrefix "vk" $.Name}}
3950c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $.Name "extension"}}{{TrimPrefix "VK_" (index $.Arguments 0)}}
3960c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else}}{{Error "invalid use of BaseName"}}
3970c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
3980c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
3990c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4000c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4010c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4020c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
4030c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emits a comma-separated list of C parameter names for the given command.
4040c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu-------------------------------------------------------------------------------
4050c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4060c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "Arguments"}}
4070c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4080c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4090c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
4100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsGloballyDispatched"}}
4180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Global")}}
4200c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    true
4210c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
4220c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4230c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4240c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4250c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4260c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4270c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emit "true" for supported functions that undergo table dispatch. Only global
4280c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  functions and functions handled in the loader top without calling into
4290c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  lower layers are not dispatched.
4300c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4310c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4320c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsInstanceDispatched"}}
4330c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4340c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}}
4350c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    true
4360c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
4370c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4380c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4390c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4400c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4410c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4420c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emit "true" for supported functions that can have device-specific dispatch.
4430c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4440c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4450c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsDeviceDispatched"}}
4460c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4470c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Device")}}
4480c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    true
4490c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
4500c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4510c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4520c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4530c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4540c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4550c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emit "true" if a function is core or from a supportable extension.
4560c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4570c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4580c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsFunctionSupported"}}
4590c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4600c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if not (GetAnnotation $ "pfn")}}
4610c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{$ext := GetAnnotation $ "extension"}}
4620c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{if not $ext}}true
4630c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true
4640c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
4650c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
4660c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4670c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4680c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4690c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4700c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4710c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Decides whether a function should be exported from the Android Vulkan
4720c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  library. Functions in the core API and in loader extensions are exported.
4730c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4740c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4750c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsFunctionExported"}}
4760c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{AssertType $ "Function"}}
4770c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4780c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{if (Macro "IsFunctionSupported" $)}}
4790c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{$ext := GetAnnotation $ "extension"}}
4800c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{if $ext}}
4810c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      {{Macro "IsExtensionExported" $ext}}
4820c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{else}}
4830c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu      true
4840c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu    {{end}}
4850c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
4860c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
4870c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4880c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
4890c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
4900c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4910c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Emit "true" if an extension is unsupportable on Android.
4920c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
4930c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
4940c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsExtensionBlacklisted"}}
4950c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{$ext := index $.Arguments 0}}
4960c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{     if eq $ext "VK_KHR_display"}}true
4970c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_display_swapchain"}}true
4980c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_xlib_surface"}}true
4990c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_xcb_surface"}}true
5000c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_wayland_surface"}}true
5010c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_mir_surface"}}true
5020c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_win32_surface"}}true
5030c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
5040c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
5050c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
5060c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu
5070c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{/*
5080c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
5090c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  Reports whether an extension is implemented entirely by the loader,
5100c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  so drivers should not enumerate it.
5110c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu------------------------------------------------------------------------------
5120c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu*/}}
5130c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{define "IsExtensionExported"}}
5140c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{$ext := index $.Arguments 0}}
5150c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{     if eq $ext "VK_KHR_surface"}}true
5160c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_swapchain"}}true
5170c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{else if eq $ext "VK_KHR_android_surface"}}true
5180c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu  {{end}}
5190c2032490b80178ec823bf22a7f5d08398851cc3Chia-I Wu{{end}}
520