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