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