blob: 3eabe2edad333909fa45f3396e782b23e2669a83 [file] [log] [blame]
Jesse Hall04f4f472015-08-16 19:51:04 -07001{{Include "../api/templates/vulkan_common.tmpl"}}
2{{Macro "DefineGlobals" $}}
3{{$ | Macro "entry.cpp" | Reflow 4 | Write "entry.cpp"}}
4
5
6{{/*
7-------------------------------------------------------------------------------
8 Entry point
9-------------------------------------------------------------------------------
10*/}}
11{{define "entry.cpp"}}
12/*
13 * Copyright 2015 The Android Open Source Project
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 */
27
28// This file is generated. Do not edit manually!
29// To regenerate: $ apic template ../api/vulkan.api entry.cpp.tmpl
30// Requires apic from https://android.googlesource.com/platform/tools/gpu/.
31
32#include "loader.h"
33using namespace vulkan;
34
35// clang-format off
36
37namespace {
38 inline const InstanceVtbl& GetVtbl(VkInstance instance) {
39 return **reinterpret_cast<InstanceVtbl**>(instance);
40 }
41 inline const InstanceVtbl& GetVtbl(VkPhysicalDevice physicalDevice) {
42 return **reinterpret_cast<InstanceVtbl**>(physicalDevice);
43 }
44 inline const DeviceVtbl& GetVtbl(VkDevice device) {
45 return **reinterpret_cast<DeviceVtbl**>(device);
46 }
47 inline const DeviceVtbl& GetVtbl(VkQueue queue) {
48 return **reinterpret_cast<DeviceVtbl**>(queue);
49 }
50 inline const DeviceVtbl& GetVtbl(VkCmdBuffer cmdBuffer) {
51 return **reinterpret_cast<DeviceVtbl**>(cmdBuffer);
52 }
53} // namespace
54
55 {{range $f := AllCommands $}}
56 {{if not (GetAnnotation $f "pfn")}}
57 __attribute__((visibility("default")))
58 {{if eq (Macro "IsSpecialEntry" $f.Name) "true"}}
59 {{Macro "EmitSpecialEntry" $f}}
60 {{else}}
61 {{Macro "EmitEntry" $f}}
62 {{end}}
63 {{end}}
64 {{end}}
65{{end}}
66
67
68{{/*
69-------------------------------------------------------------------------------
70 Decides whether an entrypoint needs special-case handling. Emits the string
71 "true" if so, nothing otherwise.
72-------------------------------------------------------------------------------
73*/}}
74{{define "IsSpecialEntry"}}
75 {{/* TODO: figure out how to do this in a cleaner or at least multi-line way */}}
Jesse Hallc7a6eb52015-08-31 12:52:03 -070076 {{if or (eq $ "vkGetInstanceProcAddr") (or (eq $ "vkGetDeviceProcAddr") (or (eq $ "vkGetDeviceQueue") (or (eq $ "vkCreateCommandBuffer") (eq $ "vkDestroyDevice"))))}}
Jesse Hall04f4f472015-08-16 19:51:04 -070077 true
78 {{end}}
79{{end}}
80
81{{/*
82-------------------------------------------------------------------------------
83 Emits the entrypoint definition for the specified command, which always
84 dispatches statically because the function requires special-case handling.
85-------------------------------------------------------------------------------
86*/}}
87{{define "EmitSpecialEntry"}}
88 {{AssertType $ "Function"}}
89
90 {{Node "Type" $.Return}} {{Macro "FunctionName" $}}({{Macro "Parameters" $}}) {
91 {{if not (IsVoid $.Return.Type)}}return §{{end}}
92 vulkan::{{TrimPrefix "vk" $.Name}}({{Macro "Arguments" $}});
93 }
94
95{{end}}
96
97
98{{/*
99-------------------------------------------------------------------------------
100 Emits the entrypoint definition for the specified command. If the first
101 parameter is a handle to dispatchable object, it dispatches the call through
102 the object's function table. Otherwise, it dispatches statically.
103-------------------------------------------------------------------------------
104*/}}
105{{define "EmitEntry"}}
106 {{AssertType $ "Function"}}
107
108 {{Node "Type" $.Return}} {{Macro "FunctionName" $}}({{Macro "Parameters" $}}) {
109 {{if not (IsVoid $.Return.Type)}}return §{{end}}
110 {{Macro "Dispatch" $}}{{TrimPrefix "vk" $.Name}}({{Macro "Arguments" $}});
111 }
112
113{{end}}
114
115
116{{/*
117-------------------------------------------------------------------------------
118 Emit the dispatch lookup for a function based on its first parameter.
119-------------------------------------------------------------------------------
120*/}}
121{{define "Dispatch#VkInstance" }}GetVtbl({{$.Node.Name}}).{{end}}
122{{define "Dispatch#VkPhysicalDevice"}}GetVtbl({{$.Node.Name}}).{{end}}
123{{define "Dispatch#VkDevice" }}GetVtbl({{$.Node.Name}}).{{end}}
124{{define "Dispatch#VkQueue" }}GetVtbl({{$.Node.Name}}).{{end}}
125{{define "Dispatch#VkCmdBuffer" }}GetVtbl({{$.Node.Name}}).{{end}}
126{{define "Dispatch_Default" }}vulkan::{{end}}
127{{define "Dispatch"}}
128 {{AssertType $ "Function"}}
129
130 {{range $i, $p := $.CallParameters}}
131 {{if not $i}}{{Node "Dispatch" $p}}{{end}}
132 {{end}}
133{{end}}
134
135
136{{/*
137-------------------------------------------------------------------------------
138 Emits a comma-separated list of C parameter names for the given command.
139-------------------------------------------------------------------------------
140*/}}
141{{define "Arguments"}}
142 {{AssertType $ "Function"}}
143
144 {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}}
145{{end}}