blob: ce155172e9098e578b9d5c4863321d16415fad2f [file] [log] [blame]
Jesse Hall1f91d392015-12-11 16:28:44 -08001{{/*
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
17{{Include "../api/templates/vulkan_common.tmpl"}}
18{{Global "clang-format" (Strings "clang-format" "-style=file")}}
19{{Macro "DefineGlobals" $}}
20{{$ | Macro "null_driver_gen.h" | Format (Global "clang-format") | Write "null_driver_gen.h" }}
21{{$ | Macro "null_driver_gen.cpp" | Format (Global "clang-format") | Write "null_driver_gen.cpp"}}
22
23
24{{/*
25-------------------------------------------------------------------------------
26 null_driver_gen.h
27-------------------------------------------------------------------------------
28*/}}
29{{define "null_driver_gen.h"}}
30/*
31•* Copyright 2015 The Android Open Source Project
32•*
33•* Licensed under the Apache License, Version 2.0 (the "License");
34•* you may not use this file except in compliance with the License.
35•* You may obtain a copy of the License at
36•*
37•* http://www.apache.org/licenses/LICENSE-2.0
38•*
39•* Unless required by applicable law or agreed to in writing, software
40•* distributed under the License is distributed on an "AS IS" BASIS,
41•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42•* See the License for the specific language governing permissions and
43•* limitations under the License.
44•*/
45
Jesse Hall0a402092016-02-01 14:43:47 -080046// WARNING: This file is generated. See ../README.md for instructions.
Jesse Hall1f91d392015-12-11 16:28:44 -080047
48#ifndef NULLDRV_NULL_DRIVER_H
49#define NULLDRV_NULL_DRIVER_H 1
50
Jesse Hall1f91d392015-12-11 16:28:44 -080051#include <vulkan/vk_android_native_buffer.h>
52#include <vulkan/vulkan.h>
53
54namespace null_driver
55
56PFN_vkVoidFunction GetGlobalProcAddr(const char* name);
57PFN_vkVoidFunction GetInstanceProcAddr(const char* name);
58
59// clang-format off
60 {{range $f := AllCommands $}}
61 {{if (Macro "IsDriverFunction" $f)}}
62VKAPI_ATTR {{Node "Type" $f.Return}} {{Macro "BaseName" $f}}({{Macro "Parameters" $f}});
63 {{end}}
64 {{end}}
65VKAPI_ATTR VkResult GetSwapchainGrallocUsageANDROID(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage);
66VKAPI_ATTR VkResult AcquireImageANDROID(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence);
Jesse Hall275d76c2016-01-08 22:39:16 -080067VKAPI_ATTR VkResult QueueSignalReleaseImageANDROID(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd);
Jesse Hall1f91d392015-12-11 16:28:44 -080068// clang-format on
69
70»} // namespace null_driver
71
72#endif // NULLDRV_NULL_DRIVER_H
73¶{{end}}
74
75
76{{/*
77-------------------------------------------------------------------------------
78 null_driver_gen.cpp
79-------------------------------------------------------------------------------
80*/}}
81{{define "null_driver_gen.cpp"}}
82/*
83•* Copyright 2015 The Android Open Source Project
84•*
85•* Licensed under the Apache License, Version 2.0 (the "License");
86•* you may not use this file except in compliance with the License.
87•* You may obtain a copy of the License at
88•*
89•* http://www.apache.org/licenses/LICENSE-2.0
90•*
91•* Unless required by applicable law or agreed to in writing, software
92•* distributed under the License is distributed on an "AS IS" BASIS,
93•* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
94•* See the License for the specific language governing permissions and
95•* limitations under the License.
96•*/
97
Jesse Hall0a402092016-02-01 14:43:47 -080098// WARNING: This file is generated. See ../README.md for instructions.
Jesse Hall1f91d392015-12-11 16:28:44 -080099
100#include "null_driver_gen.h"
101#include <algorithm>
102
103using namespace null_driver;
104
105namespace {
106
107struct NameProc {
108 const char* name;
109 PFN_vkVoidFunction proc;
110};
111
112PFN_vkVoidFunction Lookup(const char* name,
113 const NameProc* begin,
114 const NameProc* end) {
115 const auto& entry = std::lower_bound(
116 begin, end, name,
117 [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; });
118 if (entry == end || strcmp(entry->name, name) != 0)
119 return nullptr;
120 return entry->proc;
121}
122
123template <size_t N>
124PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) {
125 return Lookup(name, procs, procs + N);
126}
127
128const NameProc kGlobalProcs[] =
129 // clang-format off
130 {{range $f := SortBy (AllCommands $) "FunctionName"}}
131 {{if and (Macro "IsDriverFunction" $f) (eq (Macro "Vtbl" $f) "Global")}}
132 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
133 static_cast<{{Macro "FunctionPtrName" $f}}>(§
134 {{Macro "BaseName" $f}}))},
135 {{end}}
136 {{end}}
137 // clang-format on
138»};
139
140const NameProc kInstanceProcs[] =
141 // clang-format off
142 {{range $f := SortBy (AllCommands $) "FunctionName"}}
143 {{if (Macro "IsDriverFunction" $f)}}
144 {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§
145 static_cast<{{Macro "FunctionPtrName" $f}}>(§
146 {{Macro "BaseName" $f}}))},
147 {{end}}
148 {{end}}
149 // clang-format on
150»};
151
152} // namespace
153
154namespace null_driver {
155
156PFN_vkVoidFunction GetGlobalProcAddr(const char* name) {
157 return Lookup(name, kGlobalProcs);
158}
159
160PFN_vkVoidFunction GetInstanceProcAddr(const char* name)
Jesse Hall56d386a2016-07-26 15:20:40 -0700161 return Lookup(name, kInstanceProcs);
Jesse Hall1f91d392015-12-11 16:28:44 -0800162»}
163
164} // namespace null_driver
165
166{{end}}
167
168
169{{/*
170-------------------------------------------------------------------------------
171 Emits a function name without the "vk" prefix.
172-------------------------------------------------------------------------------
173*/}}
174{{define "BaseName"}}
175 {{AssertType $ "Function"}}
176 {{TrimPrefix "vk" $.Name}}
177{{end}}
178
179
180{{/*
181------------------------------------------------------------------------------
182 Emits 'true' if the API function is implemented by the driver.
183------------------------------------------------------------------------------
184*/}}
185{{define "IsDriverFunction"}}
186 {{AssertType $ "Function"}}
187
188 {{if not (GetAnnotation $ "pfn")}}
189 {{$ext := GetAnnotation $ "extension"}}
190 {{if $ext}}
191 {{Macro "IsDriverExtension" $ext}}
192 {{else}}
193 true
194 {{end}}
195 {{end}}
196{{end}}
197
198
199{{/*
200------------------------------------------------------------------------------
201 Reports whether an extension is implemented by the driver.
202------------------------------------------------------------------------------
203*/}}
204{{define "IsDriverExtension"}}
205 {{$ext := index $.Arguments 0}}
Jesse Hall715b86a2016-01-16 16:34:29 -0800206 {{ if eq $ext "VK_ANDROID_native_buffer"}}true
207 {{else if eq $ext "VK_EXT_debug_report"}}true
Chris Forbes86bdfbe2017-01-26 12:45:49 +1300208 {{else if eq $ext "VK_KHR_get_physical_device_properties2"}}true
Jesse Hall1f91d392015-12-11 16:28:44 -0800209 {{end}}
210{{end}}