Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 1 | {{/* |
| 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 "dispatch_gen.h" | Format (Global "clang-format") | Write "dispatch_gen.h" }} |
| 21 | {{$ | Macro "dispatch_gen.cpp" | Format (Global "clang-format") | Write "dispatch_gen.cpp"}} |
| 22 | |
| 23 | {{/* |
| 24 | ------------------------------------------------------------------------------- |
| 25 | dispatch_gen.h |
| 26 | ------------------------------------------------------------------------------- |
| 27 | */}} |
| 28 | {{define "dispatch_gen.h"}} |
| 29 | /* |
| 30 | •* Copyright 2015 The Android Open Source Project |
| 31 | •* |
| 32 | •* Licensed under the Apache License, Version 2.0 (the "License"); |
| 33 | •* you may not use this file except in compliance with the License. |
| 34 | •* You may obtain a copy of the License at |
| 35 | •* |
| 36 | •* http://www.apache.org/licenses/LICENSE-2.0 |
| 37 | •* |
| 38 | •* Unless required by applicable law or agreed to in writing, software |
| 39 | •* distributed under the License is distributed on an "AS IS" BASIS, |
| 40 | •* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 41 | •* See the License for the specific language governing permissions and |
| 42 | •* limitations under the License. |
| 43 | •*/ |
| 44 | ¶ |
Jesse Hall | 0a40209 | 2016-02-01 14:43:47 -0800 | [diff] [blame] | 45 | // WARNING: This file is generated. See ../README.md for instructions. |
| 46 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 47 | #define VK_USE_PLATFORM_ANDROID_KHR |
| 48 | #include <vulkan/vk_android_native_buffer.h> |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 49 | #include <vulkan/vk_ext_debug_report.h> |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 50 | #include <vulkan/vulkan.h> |
| 51 | ¶ |
| 52 | namespace vulkan { |
| 53 | ¶ |
| 54 | struct InstanceDispatchTable {« |
| 55 | // clang-format off |
| 56 | {{range $f := AllCommands $}} |
| 57 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 58 | {{Macro "FunctionPtrName" $f}} {{Macro "BaseName" $f}}; |
| 59 | {{end}} |
| 60 | {{end}} |
| 61 | // clang-format on |
| 62 | »}; |
| 63 | ¶ |
| 64 | struct DeviceDispatchTable {« |
| 65 | // clang-format off |
| 66 | {{range $f := AllCommands $}} |
| 67 | {{if (Macro "IsDeviceDispatched" $f)}} |
| 68 | {{Macro "FunctionPtrName" $f}} {{Macro "BaseName" $f}}; |
| 69 | {{end}} |
| 70 | {{end}} |
| 71 | // clang-format on |
| 72 | »}; |
| 73 | ¶ |
| 74 | struct DriverDispatchTable {« |
| 75 | // clang-format off |
| 76 | {{range $f := AllCommands $}} |
| 77 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 78 | {{if not (Macro "IsLoaderFunction" $f)}} |
| 79 | {{Macro "FunctionPtrName" $f}} {{Macro "BaseName" $f}}; |
| 80 | {{end}} |
| 81 | {{end}} |
| 82 | {{end}} |
| 83 | |
| 84 | PFN_vkGetDeviceProcAddr GetDeviceProcAddr; |
| 85 | |
| 86 | {{/* TODO(jessehall): Needed by swapchain code. Figure out a better way of |
| 87 | handling this that avoids the special case. Probably should rework |
| 88 | things so the driver dispatch table has all driver functions. Probably |
| 89 | need separate instance- and device-level copies, fill in all device- |
| 90 | dispatched functions in the device-level copies only, and change |
| 91 | GetDeviceProcAddr_Bottom to look in the already-loaded driver |
| 92 | dispatch table rather than forwarding to the driver's |
| 93 | vkGetDeviceProcAddr. */}} |
| 94 | PFN_vkCreateImage CreateImage; |
| 95 | PFN_vkDestroyImage DestroyImage; |
| 96 | |
| 97 | PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; |
| 98 | PFN_vkAcquireImageANDROID AcquireImageANDROID; |
| 99 | PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; |
| 100 | // clang-format on |
| 101 | »}; |
| 102 | ¶ |
| 103 | } // namespace vulkan |
| 104 | ¶{{end}} |
| 105 | |
| 106 | |
| 107 | {{/* |
| 108 | ------------------------------------------------------------------------------- |
| 109 | dispatch_gen.cpp |
| 110 | ------------------------------------------------------------------------------- |
| 111 | */}} |
| 112 | {{define "dispatch_gen.cpp"}} |
| 113 | /* |
| 114 | •* Copyright 2015 The Android Open Source Project |
| 115 | •* |
| 116 | •* Licensed under the Apache License, Version 2.0 (the "License"); |
| 117 | •* you may not use this file except in compliance with the License. |
| 118 | •* You may obtain a copy of the License at |
| 119 | •* |
| 120 | •* http://www.apache.org/licenses/LICENSE-2.0 |
| 121 | •* |
| 122 | •* Unless required by applicable law or agreed to in writing, software |
| 123 | •* distributed under the License is distributed on an "AS IS" BASIS, |
| 124 | •* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 125 | •* See the License for the specific language governing permissions and |
| 126 | •* limitations under the License. |
| 127 | •*/ |
| 128 | ¶ |
Jesse Hall | 0a40209 | 2016-02-01 14:43:47 -0800 | [diff] [blame] | 129 | // WARNING: This file is generated. See ../README.md for instructions. |
| 130 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 131 | #include <log/log.h> |
| 132 | #include <algorithm> |
| 133 | #include "loader.h" |
| 134 | ¶ |
| 135 | #define UNLIKELY(expr) __builtin_expect((expr), 0) |
| 136 | ¶ |
| 137 | using namespace vulkan; |
| 138 | ¶ |
| 139 | namespace { |
| 140 | ¶ |
| 141 | struct NameProc { |
| 142 | const char* name; |
| 143 | PFN_vkVoidFunction proc; |
| 144 | }; |
| 145 | ¶ |
| 146 | PFN_vkVoidFunction Lookup(const char* name, const NameProc* begin, const NameProc* end) { |
| 147 | const auto& entry = std::lower_bound( |
| 148 | begin, end, name, |
| 149 | [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; }); |
| 150 | if (entry == end || strcmp(entry->name, name) != 0) |
| 151 | return nullptr; |
| 152 | return entry->proc; |
| 153 | } |
| 154 | ¶ |
| 155 | template <size_t N> |
| 156 | PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) { |
| 157 | return Lookup(name, procs, procs + N); |
| 158 | } |
| 159 | ¶ |
| 160 | const NameProc kLoaderExportProcs[] = {« |
| 161 | // clang-format off |
| 162 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 163 | {{if (Macro "IsExported" $f)}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 164 | {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>({{$f.Name}})}, |
| 165 | {{end}} |
| 166 | {{end}} |
| 167 | // clang-format on |
| 168 | »}; |
| 169 | ¶ |
| 170 | const NameProc kLoaderGlobalProcs[] = {« |
| 171 | // clang-format off |
| 172 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 173 | {{if and (Macro "HasLoaderTopImpl" $f) (eq (Macro "Vtbl" $f) "Global")}} |
| 174 | {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ |
| 175 | static_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 176 | {{Macro "BaseName" $f}}_Top))}, |
| 177 | {{end}} |
| 178 | {{end}} |
| 179 | // clang-format on |
| 180 | »}; |
| 181 | ¶ |
| 182 | const NameProc kLoaderTopProcs[] = {« |
| 183 | // clang-format off |
| 184 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 185 | {{if (Macro "HasLoaderTopImpl" $f)}} |
| 186 | {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ |
| 187 | static_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 188 | {{Macro "BaseName" $f}}_Top))}, |
| 189 | {{end}} |
| 190 | {{end}} |
| 191 | // clang-format on |
| 192 | »}; |
| 193 | ¶ |
| 194 | const NameProc kLoaderBottomProcs[] = {« |
| 195 | // clang-format off |
| 196 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 197 | {{if (Macro "HasLoaderBottomImpl" $f)}} |
| 198 | {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ |
| 199 | static_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 200 | {{Macro "BaseName" $f}}_Bottom))}, |
| 201 | {{end}} |
| 202 | {{end}} |
| 203 | // clang-format on |
| 204 | »}; |
| 205 | ¶ |
| 206 | struct NameOffset { |
| 207 | const char* name; |
| 208 | size_t offset; |
| 209 | }; |
| 210 | ¶ |
| 211 | ssize_t Lookup(const char* name, |
| 212 | const NameOffset* begin, |
| 213 | const NameOffset* end) { |
| 214 | const auto& entry = std::lower_bound( |
| 215 | begin, end, name, [](const NameOffset& e, const char* n) { |
| 216 | return strcmp(e.name, n) < 0; |
| 217 | }); |
| 218 | if (entry == end || strcmp(entry->name, name) != 0) |
| 219 | return -1; |
| 220 | return static_cast<ssize_t>(entry->offset); |
| 221 | } |
| 222 | ¶ |
| 223 | template <size_t N, class Table> |
| 224 | PFN_vkVoidFunction Lookup(const char* name, |
| 225 | const NameOffset (&offsets)[N], |
| 226 | const Table& table) { |
| 227 | ssize_t offset = Lookup(name, offsets, offsets + N); |
| 228 | if (offset < 0) |
| 229 | return nullptr; |
| 230 | uintptr_t base = reinterpret_cast<uintptr_t>(&table); |
| 231 | return *reinterpret_cast<PFN_vkVoidFunction*>(base + |
| 232 | static_cast<size_t>(offset)); |
| 233 | } |
| 234 | ¶ |
| 235 | const NameOffset kInstanceDispatchOffsets[] = {« |
| 236 | // clang-format off |
| 237 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 238 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 239 | {"{{$f.Name}}", offsetof(InstanceDispatchTable, {{Macro "BaseName" $f}})}, |
| 240 | {{end}} |
| 241 | {{end}} |
| 242 | // clang-format on |
| 243 | »}; |
| 244 | ¶ |
| 245 | const NameOffset kDeviceDispatchOffsets[] = {« |
| 246 | // clang-format off |
| 247 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 248 | {{if (Macro "IsDeviceDispatched" $f)}} |
| 249 | {"{{$f.Name}}", offsetof(DeviceDispatchTable, {{Macro "BaseName" $f}})}, |
| 250 | {{end}} |
| 251 | {{end}} |
| 252 | // clang-format on |
| 253 | »}; |
| 254 | ¶ |
| 255 | } // anonymous namespace |
| 256 | ¶ |
| 257 | namespace vulkan { |
| 258 | ¶ |
| 259 | PFN_vkVoidFunction GetLoaderExportProcAddr(const char* name) { |
| 260 | return Lookup(name, kLoaderExportProcs); |
| 261 | } |
| 262 | ¶ |
| 263 | PFN_vkVoidFunction GetLoaderGlobalProcAddr(const char* name) { |
| 264 | return Lookup(name, kLoaderGlobalProcs); |
| 265 | } |
| 266 | ¶ |
| 267 | PFN_vkVoidFunction GetLoaderTopProcAddr(const char* name) { |
| 268 | return Lookup(name, kLoaderTopProcs); |
| 269 | } |
| 270 | ¶ |
| 271 | PFN_vkVoidFunction GetLoaderBottomProcAddr(const char* name) { |
| 272 | return Lookup(name, kLoaderBottomProcs); |
| 273 | } |
| 274 | ¶ |
| 275 | PFN_vkVoidFunction GetDispatchProcAddr(const InstanceDispatchTable& dispatch, |
| 276 | const char* name) { |
| 277 | return Lookup(name, kInstanceDispatchOffsets, dispatch); |
| 278 | } |
| 279 | ¶ |
| 280 | PFN_vkVoidFunction GetDispatchProcAddr(const DeviceDispatchTable& dispatch, |
| 281 | const char* name) { |
| 282 | return Lookup(name, kDeviceDispatchOffsets, dispatch); |
| 283 | } |
| 284 | ¶ |
| 285 | bool LoadInstanceDispatchTable(VkInstance instance, |
| 286 | PFN_vkGetInstanceProcAddr get_proc_addr, |
| 287 | InstanceDispatchTable& dispatch) {« |
| 288 | bool success = true; |
| 289 | // clang-format off |
| 290 | {{range $f := AllCommands $}} |
| 291 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 292 | dispatch.{{Macro "BaseName" $f}} = § |
| 293 | reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 294 | get_proc_addr(instance, "{{$f.Name}}")); |
| 295 | if (UNLIKELY(!dispatch.{{Macro "BaseName" $f}})) { |
| 296 | ALOGE("missing instance proc: %s", "{{$f.Name}}"); |
| 297 | success = false; |
| 298 | } |
| 299 | {{end}} |
| 300 | {{end}} |
| 301 | // clang-format on |
| 302 | return success; |
| 303 | »} |
| 304 | ¶ |
| 305 | bool LoadDeviceDispatchTable(VkDevice device, |
| 306 | PFN_vkGetDeviceProcAddr get_proc_addr, |
| 307 | DeviceDispatchTable& dispatch) {« |
| 308 | bool success = true; |
| 309 | // clang-format off |
| 310 | {{range $f := AllCommands $}} |
| 311 | {{if (Macro "IsDeviceDispatched" $f)}} |
| 312 | dispatch.{{Macro "BaseName" $f}} = § |
| 313 | reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 314 | get_proc_addr(device, "{{$f.Name}}")); |
| 315 | if (UNLIKELY(!dispatch.{{Macro "BaseName" $f}})) { |
| 316 | ALOGE("missing device proc: %s", "{{$f.Name}}"); |
| 317 | success = false; |
| 318 | } |
| 319 | {{end}} |
| 320 | {{end}} |
| 321 | // clang-format on |
| 322 | return success; |
| 323 | »} |
| 324 | ¶ |
| 325 | bool LoadDriverDispatchTable(VkInstance instance, |
| 326 | PFN_vkGetInstanceProcAddr get_proc_addr, |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 327 | const InstanceExtensionSet& extensions, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 328 | DriverDispatchTable& dispatch) {« |
| 329 | bool success = true; |
| 330 | // clang-format off |
| 331 | {{range $f := AllCommands $}} |
| 332 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 333 | {{if not (Macro "IsLoaderFunction" $f)}} |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 334 | {{$ext := GetAnnotation $f "extension"}} |
| 335 | {{if $ext}} |
| 336 | if (extensions[{{Macro "ExtensionConstant" $ext}}]) { |
| 337 | {{end}} |
| 338 | dispatch.{{Macro "BaseName" $f}} = § |
| 339 | reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 340 | get_proc_addr(instance, "{{$f.Name}}")); |
| 341 | if (UNLIKELY(!dispatch.{{Macro "BaseName" $f}})) { |
| 342 | ALOGE("missing driver proc: %s", "{{$f.Name}}"); |
| 343 | success = false; |
| 344 | } |
| 345 | {{if $ext}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 346 | } |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 347 | {{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 348 | {{end}} |
| 349 | {{end}} |
| 350 | {{end}} |
| 351 | dispatch.GetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(get_proc_addr(instance, "vkGetDeviceProcAddr")); |
| 352 | if (UNLIKELY(!dispatch.GetDeviceProcAddr)) { |
| 353 | ALOGE("missing driver proc: %s", "vkGetDeviceProcAddr"); |
| 354 | success = false; |
| 355 | } |
| 356 | dispatch.CreateImage = reinterpret_cast<PFN_vkCreateImage>(get_proc_addr(instance, "vkCreateImage")); |
| 357 | if (UNLIKELY(!dispatch.CreateImage)) { |
| 358 | ALOGE("missing driver proc: %s", "vkCreateImage"); |
| 359 | success = false; |
| 360 | } |
| 361 | dispatch.DestroyImage = reinterpret_cast<PFN_vkDestroyImage>(get_proc_addr(instance, "vkDestroyImage")); |
| 362 | if (UNLIKELY(!dispatch.DestroyImage)) { |
| 363 | ALOGE("missing driver proc: %s", "vkDestroyImage"); |
| 364 | success = false; |
| 365 | } |
Jesse Hall | d913282 | 2016-01-14 15:50:52 -0800 | [diff] [blame] | 366 | dispatch.GetSwapchainGrallocUsageANDROID = reinterpret_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(get_proc_addr(instance, "vkGetSwapchainGrallocUsageANDROID")); |
| 367 | if (UNLIKELY(!dispatch.GetSwapchainGrallocUsageANDROID)) { |
| 368 | ALOGE("missing driver proc: %s", "vkGetSwapchainGrallocUsageANDROID"); |
| 369 | success = false; |
| 370 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 371 | dispatch.AcquireImageANDROID = reinterpret_cast<PFN_vkAcquireImageANDROID>(get_proc_addr(instance, "vkAcquireImageANDROID")); |
| 372 | if (UNLIKELY(!dispatch.AcquireImageANDROID)) { |
| 373 | ALOGE("missing driver proc: %s", "vkAcquireImageANDROID"); |
| 374 | success = false; |
| 375 | } |
| 376 | dispatch.QueueSignalReleaseImageANDROID = reinterpret_cast<PFN_vkQueueSignalReleaseImageANDROID>(get_proc_addr(instance, "vkQueueSignalReleaseImageANDROID")); |
| 377 | if (UNLIKELY(!dispatch.QueueSignalReleaseImageANDROID)) { |
| 378 | ALOGE("missing driver proc: %s", "vkQueueSignalReleaseImageANDROID"); |
| 379 | success = false; |
| 380 | } |
| 381 | // clang-format on |
| 382 | return success; |
| 383 | »} |
| 384 | ¶ |
| 385 | } // namespace vulkan |
| 386 | ¶ |
| 387 | // clang-format off |
| 388 | ¶ |
| 389 | {{range $f := AllCommands $}} |
| 390 | {{if and (not (GetAnnotation $f "pfn")) (Macro "IsExported" $f)}} |
| 391 | __attribute__((visibility("default"))) |
| 392 | VKAPI_ATTR {{Node "Type" $f.Return}} {{$f.Name}}({{Macro "Parameters" $f}}) { |
| 393 | {{if not (IsVoid $f.Return.Type)}}return §{{end}} |
| 394 | {{Macro "Dispatch" $f}}({{Macro "Arguments" $f}}); |
| 395 | } |
| 396 | ¶ |
| 397 | {{end}} |
| 398 | {{end}} |
| 399 | ¶ |
| 400 | // clang-format on |
| 401 | ¶{{end}} |
| 402 | |
| 403 | |
| 404 | {{/* |
| 405 | ------------------------------------------------------------------------------- |
| 406 | Emit the dispatch lookup for a function based on its first parameter. |
| 407 | ------------------------------------------------------------------------------- |
| 408 | */}} |
| 409 | {{define "Dispatch"}} |
| 410 | {{AssertType $ "Function"}} |
| 411 | |
| 412 | {{if (Macro "HasLoaderTopImpl" $)}} |
| 413 | {{Macro "BaseName" $}}_Top§ |
| 414 | {{else}} |
| 415 | {{$p0 := index $.CallParameters 0}} |
| 416 | GetDispatchTable({{$p0.Name}}).{{Macro "BaseName" $}}§ |
| 417 | {{end}} |
| 418 | {{end}} |
| 419 | |
| 420 | |
| 421 | {{/* |
| 422 | ------------------------------------------------------------------------------- |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 423 | Map an extension name to InstanceExtension or DeviceExtension enum value |
| 424 | ------------------------------------------------------------------------------- |
| 425 | */}} |
| 426 | {{define "ExtensionConstant"}} |
| 427 | {{$name := index $.Arguments 0}} |
| 428 | {{ if (eq $name "VK_KHR_surface")}}kKHR_surface |
| 429 | {{else if (eq $name "VK_KHR_android_surface")}}kKHR_android_surface |
| 430 | {{else if (eq $name "VK_EXT_debug_report")}}kEXT_debug_report |
| 431 | {{end}} |
| 432 | {{end}} |
| 433 | |
| 434 | |
| 435 | {{/* |
| 436 | ------------------------------------------------------------------------------- |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 437 | Emits a function name without the "vk" prefix. |
| 438 | ------------------------------------------------------------------------------- |
| 439 | */}} |
| 440 | {{define "BaseName"}} |
| 441 | {{AssertType $ "Function"}} |
| 442 | {{TrimPrefix "vk" $.Name}} |
| 443 | {{end}} |
| 444 | |
| 445 | |
| 446 | {{/* |
| 447 | ------------------------------------------------------------------------------- |
| 448 | Emits a comma-separated list of C parameter names for the given command. |
| 449 | ------------------------------------------------------------------------------- |
| 450 | */}} |
| 451 | {{define "Arguments"}} |
| 452 | {{AssertType $ "Function"}} |
| 453 | |
| 454 | {{ForEach $.CallParameters "ParameterName" | JoinWith ", "}} |
| 455 | {{end}} |
| 456 | |
| 457 | |
| 458 | {{/* |
| 459 | ------------------------------------------------------------------------------ |
| 460 | Emit "true" for supported functions that undergo table dispatch. Only global |
| 461 | functions and functions handled in the loader top without calling into |
| 462 | lower layers are not dispatched. |
| 463 | ------------------------------------------------------------------------------ |
| 464 | */}} |
| 465 | {{define "IsInstanceDispatched"}} |
| 466 | {{AssertType $ "Function"}} |
| 467 | {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}} |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame^] | 468 | {{if and (ne $.Name "vkEnumerateDeviceLayerProperties") (ne $.Name "vkGetInstanceProcAddr")}}true{{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 469 | {{end}} |
| 470 | {{end}} |
| 471 | |
| 472 | |
| 473 | {{/* |
| 474 | ------------------------------------------------------------------------------ |
| 475 | Emit "true" for supported functions that can have device-specific dispatch. |
| 476 | ------------------------------------------------------------------------------ |
| 477 | */}} |
| 478 | {{define "IsDeviceDispatched"}} |
| 479 | {{AssertType $ "Function"}} |
| 480 | {{if (Macro "IsFunctionSupported" $)}} |
| 481 | {{if eq (Macro "Vtbl" $) "Device"}} |
| 482 | {{if ne $.Name "vkGetDeviceProcAddr"}} |
| 483 | true |
| 484 | {{end}} |
| 485 | {{end}} |
| 486 | {{end}} |
| 487 | {{end}} |
| 488 | |
| 489 | |
| 490 | {{/* |
| 491 | ------------------------------------------------------------------------------ |
| 492 | Emit "true" if a function is core or from a supportable extension. |
| 493 | ------------------------------------------------------------------------------ |
| 494 | */}} |
| 495 | {{define "IsFunctionSupported"}} |
| 496 | {{AssertType $ "Function"}} |
| 497 | {{if not (GetAnnotation $ "pfn")}} |
| 498 | {{$ext := GetAnnotation $ "extension"}} |
| 499 | {{if not $ext}}true |
| 500 | {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true |
| 501 | {{end}} |
| 502 | {{end}} |
| 503 | {{end}} |
| 504 | |
| 505 | |
| 506 | {{/* |
| 507 | ------------------------------------------------------------------------------ |
| 508 | Decides whether a function should be exported from the Android Vulkan |
| 509 | library. Functions in the core API and in loader extensions are exported. |
| 510 | ------------------------------------------------------------------------------ |
| 511 | */}} |
| 512 | {{define "IsExported"}} |
| 513 | {{AssertType $ "Function"}} |
| 514 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 515 | {{if (Macro "IsFunctionSupported" $)}} |
| 516 | {{$ext := GetAnnotation $ "extension"}} |
| 517 | {{if $ext}} |
| 518 | {{Macro "IsLoaderExtension" $ext}} |
| 519 | {{else}} |
| 520 | true |
| 521 | {{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 522 | {{end}} |
| 523 | {{end}} |
| 524 | |
| 525 | |
| 526 | {{/* |
| 527 | ------------------------------------------------------------------------------ |
| 528 | Reports whether an extension function is implemented entirely by the loader, |
| 529 | and not implemented by drivers. |
| 530 | ------------------------------------------------------------------------------ |
| 531 | */}} |
| 532 | {{define "IsLoaderFunction"}} |
| 533 | {{AssertType $ "Function"}} |
| 534 | |
| 535 | {{$ext := GetAnnotation $ "extension"}} |
| 536 | {{if $ext}} |
| 537 | {{Macro "IsLoaderExtension" $ext}} |
| 538 | {{end}} |
| 539 | {{end}} |
| 540 | |
| 541 | |
| 542 | {{/* |
| 543 | ------------------------------------------------------------------------------- |
| 544 | Emit "true" if the loader has a top-level implementation for the function |
| 545 | that should be called directly rather than dispatching to the first layer. |
| 546 | ------------------------------------------------------------------------------- |
| 547 | */}} |
| 548 | {{define "HasLoaderTopImpl"}} |
| 549 | {{AssertType $ "Function"}} |
| 550 | |
| 551 | {{/* Global functions can't be dispatched */}} |
| 552 | {{ if and (not (GetAnnotation $ "pfn")) (eq (Macro "Vtbl" $) "Global")}}true |
| 553 | |
| 554 | {{/* G*PA are implemented by reading the dispatch table, not by dispatching |
| 555 | through it. */}} |
| 556 | {{else if eq $.Name "vkGetInstanceProcAddr"}}true |
| 557 | {{else if eq $.Name "vkGetDeviceProcAddr"}}true |
| 558 | |
| 559 | {{/* Loader top needs to initialize dispatch for device-level dispatchable |
| 560 | objects */}} |
| 561 | {{else if eq $.Name "vkGetDeviceQueue"}}true |
| 562 | {{else if eq $.Name "vkAllocateCommandBuffers"}}true |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 563 | {{else if eq $.Name "vkCreateDevice"}}true |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame^] | 564 | {{else if eq $.Name "vkEnumerateDeviceLayerProperties"}}true |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 565 | |
| 566 | {{/* vkDestroy for dispatchable objects needs to handle VK_NULL_HANDLE; |
| 567 | trying to dispatch through that would crash. */}} |
| 568 | {{else if eq $.Name "vkDestroyInstance"}}true |
| 569 | {{else if eq $.Name "vkDestroyDevice"}}true |
| 570 | |
| 571 | {{end}} |
| 572 | {{end}} |
| 573 | |
| 574 | |
| 575 | {{/* |
| 576 | ------------------------------------------------------------------------------- |
| 577 | Emit "true" if the loader has a bottom-level implementation for the function |
| 578 | which terminates the dispatch chain. |
| 579 | ------------------------------------------------------------------------------- |
| 580 | */}} |
| 581 | {{define "HasLoaderBottomImpl"}} |
| 582 | {{AssertType $ "Function"}} |
| 583 | |
| 584 | {{if (Macro "IsFunctionSupported" $)}} |
| 585 | {{ if (eq (Macro "Vtbl" $) "Instance")}}true |
| 586 | {{else if (Macro "IsLoaderFunction" $)}}true |
| 587 | {{else if (eq $.Name "vkCreateInstance")}}true |
| 588 | {{else if (eq $.Name "vkGetDeviceProcAddr")}}true |
| 589 | {{end}} |
| 590 | {{end}} |
| 591 | {{end}} |
| 592 | |
| 593 | |
| 594 | {{/* |
| 595 | ------------------------------------------------------------------------------ |
| 596 | Emit "true" if an extension is unsupportable on Android. |
| 597 | ------------------------------------------------------------------------------ |
| 598 | */}} |
| 599 | {{define "IsExtensionBlacklisted"}} |
| 600 | {{$ext := index $.Arguments 0}} |
| 601 | {{ if eq $ext "VK_KHR_display"}}true |
| 602 | {{else if eq $ext "VK_KHR_display_swapchain"}}true |
| 603 | {{else if eq $ext "VK_KHR_xlib_surface"}}true |
| 604 | {{else if eq $ext "VK_KHR_xcb_surface"}}true |
| 605 | {{else if eq $ext "VK_KHR_wayland_surface"}}true |
| 606 | {{else if eq $ext "VK_KHR_mir_surface"}}true |
| 607 | {{else if eq $ext "VK_KHR_win32_surface"}}true |
| 608 | {{end}} |
| 609 | {{end}} |
| 610 | |
| 611 | |
| 612 | {{/* |
| 613 | ------------------------------------------------------------------------------ |
| 614 | Reports whether an extension is implemented entirely by the loader, |
| 615 | so drivers should not enumerate it. |
| 616 | ------------------------------------------------------------------------------ |
| 617 | */}} |
| 618 | {{define "IsLoaderExtension"}} |
| 619 | {{$ext := index $.Arguments 0}} |
| 620 | {{ if eq $ext "VK_KHR_surface"}}true |
| 621 | {{else if eq $ext "VK_KHR_swapchain"}}true |
| 622 | {{else if eq $ext "VK_KHR_android_surface"}}true |
| 623 | {{end}} |
| 624 | {{end}} |