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 | #include <vulkan/vk_android_native_buffer.h> |
| 48 | #include <vulkan/vulkan.h> |
| 49 | ¶ |
| 50 | namespace vulkan { |
| 51 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 52 | struct DriverDispatchTable {« |
| 53 | // clang-format off |
| 54 | {{range $f := AllCommands $}} |
| 55 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 56 | {{if not (Macro "IsLoaderFunction" $f)}} |
| 57 | {{Macro "FunctionPtrName" $f}} {{Macro "BaseName" $f}}; |
| 58 | {{end}} |
| 59 | {{end}} |
| 60 | {{end}} |
| 61 | |
| 62 | PFN_vkGetDeviceProcAddr GetDeviceProcAddr; |
| 63 | |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame^] | 64 | PFN_vkDestroyDevice DestroyDevice; |
| 65 | PFN_vkGetDeviceQueue GetDeviceQueue; |
| 66 | PFN_vkAllocateCommandBuffers AllocateCommandBuffers; |
| 67 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 68 | {{/* TODO(jessehall): Needed by swapchain code. Figure out a better way of |
| 69 | handling this that avoids the special case. Probably should rework |
| 70 | things so the driver dispatch table has all driver functions. Probably |
| 71 | need separate instance- and device-level copies, fill in all device- |
| 72 | dispatched functions in the device-level copies only, and change |
| 73 | GetDeviceProcAddr_Bottom to look in the already-loaded driver |
| 74 | dispatch table rather than forwarding to the driver's |
| 75 | vkGetDeviceProcAddr. */}} |
| 76 | PFN_vkCreateImage CreateImage; |
| 77 | PFN_vkDestroyImage DestroyImage; |
| 78 | |
| 79 | PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; |
| 80 | PFN_vkAcquireImageANDROID AcquireImageANDROID; |
| 81 | PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; |
| 82 | // clang-format on |
| 83 | »}; |
| 84 | ¶ |
| 85 | } // namespace vulkan |
| 86 | ¶{{end}} |
| 87 | |
| 88 | |
| 89 | {{/* |
| 90 | ------------------------------------------------------------------------------- |
| 91 | dispatch_gen.cpp |
| 92 | ------------------------------------------------------------------------------- |
| 93 | */}} |
| 94 | {{define "dispatch_gen.cpp"}} |
| 95 | /* |
| 96 | •* Copyright 2015 The Android Open Source Project |
| 97 | •* |
| 98 | •* Licensed under the Apache License, Version 2.0 (the "License"); |
| 99 | •* you may not use this file except in compliance with the License. |
| 100 | •* You may obtain a copy of the License at |
| 101 | •* |
| 102 | •* http://www.apache.org/licenses/LICENSE-2.0 |
| 103 | •* |
| 104 | •* Unless required by applicable law or agreed to in writing, software |
| 105 | •* distributed under the License is distributed on an "AS IS" BASIS, |
| 106 | •* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 107 | •* See the License for the specific language governing permissions and |
| 108 | •* limitations under the License. |
| 109 | •*/ |
| 110 | ¶ |
Jesse Hall | 0a40209 | 2016-02-01 14:43:47 -0800 | [diff] [blame] | 111 | // WARNING: This file is generated. See ../README.md for instructions. |
| 112 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 113 | #include <log/log.h> |
| 114 | #include <algorithm> |
| 115 | #include "loader.h" |
| 116 | ¶ |
| 117 | #define UNLIKELY(expr) __builtin_expect((expr), 0) |
| 118 | ¶ |
| 119 | using namespace vulkan; |
| 120 | ¶ |
| 121 | namespace { |
| 122 | ¶ |
| 123 | struct NameProc { |
| 124 | const char* name; |
| 125 | PFN_vkVoidFunction proc; |
| 126 | }; |
| 127 | ¶ |
| 128 | PFN_vkVoidFunction Lookup(const char* name, const NameProc* begin, const NameProc* end) { |
| 129 | const auto& entry = std::lower_bound( |
| 130 | begin, end, name, |
| 131 | [](const NameProc& e, const char* n) { return strcmp(e.name, n) < 0; }); |
| 132 | if (entry == end || strcmp(entry->name, name) != 0) |
| 133 | return nullptr; |
| 134 | return entry->proc; |
| 135 | } |
| 136 | ¶ |
| 137 | template <size_t N> |
| 138 | PFN_vkVoidFunction Lookup(const char* name, const NameProc (&procs)[N]) { |
| 139 | return Lookup(name, procs, procs + N); |
| 140 | } |
| 141 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 142 | const NameProc kLoaderBottomProcs[] = {« |
| 143 | // clang-format off |
| 144 | {{range $f := SortBy (AllCommands $) "FunctionName"}} |
| 145 | {{if (Macro "HasLoaderBottomImpl" $f)}} |
| 146 | {"{{$f.Name}}", reinterpret_cast<PFN_vkVoidFunction>(§ |
| 147 | static_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 148 | {{Macro "BaseName" $f}}_Bottom))}, |
| 149 | {{end}} |
| 150 | {{end}} |
| 151 | // clang-format on |
| 152 | »}; |
| 153 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 154 | } // anonymous namespace |
| 155 | ¶ |
| 156 | namespace vulkan { |
| 157 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 158 | PFN_vkVoidFunction GetLoaderBottomProcAddr(const char* name) { |
| 159 | return Lookup(name, kLoaderBottomProcs); |
| 160 | } |
| 161 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 162 | bool LoadDriverDispatchTable(VkInstance instance, |
| 163 | PFN_vkGetInstanceProcAddr get_proc_addr, |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 164 | const InstanceExtensionSet& extensions, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 165 | DriverDispatchTable& dispatch) {« |
| 166 | bool success = true; |
| 167 | // clang-format off |
| 168 | {{range $f := AllCommands $}} |
| 169 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 170 | {{if not (Macro "IsLoaderFunction" $f)}} |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 171 | {{$ext := GetAnnotation $f "extension"}} |
| 172 | {{if $ext}} |
| 173 | if (extensions[{{Macro "ExtensionConstant" $ext}}]) { |
| 174 | {{end}} |
| 175 | dispatch.{{Macro "BaseName" $f}} = § |
| 176 | reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 177 | get_proc_addr(instance, "{{$f.Name}}")); |
| 178 | if (UNLIKELY(!dispatch.{{Macro "BaseName" $f}})) { |
| 179 | ALOGE("missing driver proc: %s", "{{$f.Name}}"); |
| 180 | success = false; |
| 181 | } |
| 182 | {{if $ext}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 183 | } |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 184 | {{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 185 | {{end}} |
| 186 | {{end}} |
| 187 | {{end}} |
| 188 | dispatch.GetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(get_proc_addr(instance, "vkGetDeviceProcAddr")); |
| 189 | if (UNLIKELY(!dispatch.GetDeviceProcAddr)) { |
| 190 | ALOGE("missing driver proc: %s", "vkGetDeviceProcAddr"); |
| 191 | success = false; |
| 192 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame^] | 193 | dispatch.DestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>(get_proc_addr(instance, "vkDestroyDevice")); |
| 194 | if (UNLIKELY(!dispatch.DestroyDevice)) { |
| 195 | ALOGE("missing driver proc: %s", "vkDestroyDevice"); |
| 196 | success = false; |
| 197 | } |
| 198 | dispatch.GetDeviceQueue = reinterpret_cast<PFN_vkGetDeviceQueue>(get_proc_addr(instance, "vkGetDeviceQueue")); |
| 199 | if (UNLIKELY(!dispatch.GetDeviceQueue)) { |
| 200 | ALOGE("missing driver proc: %s", "vkGetDeviceQueue"); |
| 201 | success = false; |
| 202 | } |
| 203 | dispatch.AllocateCommandBuffers = reinterpret_cast<PFN_vkAllocateCommandBuffers>(get_proc_addr(instance, "vkAllocateCommandBuffers")); |
| 204 | if (UNLIKELY(!dispatch.AllocateCommandBuffers)) { |
| 205 | ALOGE("missing driver proc: %s", "vkAllocateCommandBuffers"); |
| 206 | success = false; |
| 207 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 208 | dispatch.CreateImage = reinterpret_cast<PFN_vkCreateImage>(get_proc_addr(instance, "vkCreateImage")); |
| 209 | if (UNLIKELY(!dispatch.CreateImage)) { |
| 210 | ALOGE("missing driver proc: %s", "vkCreateImage"); |
| 211 | success = false; |
| 212 | } |
| 213 | dispatch.DestroyImage = reinterpret_cast<PFN_vkDestroyImage>(get_proc_addr(instance, "vkDestroyImage")); |
| 214 | if (UNLIKELY(!dispatch.DestroyImage)) { |
| 215 | ALOGE("missing driver proc: %s", "vkDestroyImage"); |
| 216 | success = false; |
| 217 | } |
Jesse Hall | d913282 | 2016-01-14 15:50:52 -0800 | [diff] [blame] | 218 | dispatch.GetSwapchainGrallocUsageANDROID = reinterpret_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(get_proc_addr(instance, "vkGetSwapchainGrallocUsageANDROID")); |
| 219 | if (UNLIKELY(!dispatch.GetSwapchainGrallocUsageANDROID)) { |
| 220 | ALOGE("missing driver proc: %s", "vkGetSwapchainGrallocUsageANDROID"); |
| 221 | success = false; |
| 222 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 223 | dispatch.AcquireImageANDROID = reinterpret_cast<PFN_vkAcquireImageANDROID>(get_proc_addr(instance, "vkAcquireImageANDROID")); |
| 224 | if (UNLIKELY(!dispatch.AcquireImageANDROID)) { |
| 225 | ALOGE("missing driver proc: %s", "vkAcquireImageANDROID"); |
| 226 | success = false; |
| 227 | } |
| 228 | dispatch.QueueSignalReleaseImageANDROID = reinterpret_cast<PFN_vkQueueSignalReleaseImageANDROID>(get_proc_addr(instance, "vkQueueSignalReleaseImageANDROID")); |
| 229 | if (UNLIKELY(!dispatch.QueueSignalReleaseImageANDROID)) { |
| 230 | ALOGE("missing driver proc: %s", "vkQueueSignalReleaseImageANDROID"); |
| 231 | success = false; |
| 232 | } |
| 233 | // clang-format on |
| 234 | return success; |
| 235 | »} |
| 236 | ¶ |
| 237 | } // namespace vulkan |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 238 | ¶{{end}} |
| 239 | |
| 240 | |
| 241 | {{/* |
| 242 | ------------------------------------------------------------------------------- |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 243 | Map an extension name to InstanceExtension or DeviceExtension enum value |
| 244 | ------------------------------------------------------------------------------- |
| 245 | */}} |
| 246 | {{define "ExtensionConstant"}} |
| 247 | {{$name := index $.Arguments 0}} |
| 248 | {{ if (eq $name "VK_KHR_surface")}}kKHR_surface |
| 249 | {{else if (eq $name "VK_KHR_android_surface")}}kKHR_android_surface |
| 250 | {{else if (eq $name "VK_EXT_debug_report")}}kEXT_debug_report |
| 251 | {{end}} |
| 252 | {{end}} |
| 253 | |
| 254 | |
| 255 | {{/* |
| 256 | ------------------------------------------------------------------------------- |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 257 | Emits a function name without the "vk" prefix. |
| 258 | ------------------------------------------------------------------------------- |
| 259 | */}} |
| 260 | {{define "BaseName"}} |
| 261 | {{AssertType $ "Function"}} |
| 262 | {{TrimPrefix "vk" $.Name}} |
| 263 | {{end}} |
| 264 | |
| 265 | |
| 266 | {{/* |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 267 | ------------------------------------------------------------------------------ |
| 268 | Emit "true" for supported functions that undergo table dispatch. Only global |
| 269 | functions and functions handled in the loader top without calling into |
| 270 | lower layers are not dispatched. |
| 271 | ------------------------------------------------------------------------------ |
| 272 | */}} |
| 273 | {{define "IsInstanceDispatched"}} |
| 274 | {{AssertType $ "Function"}} |
| 275 | {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}} |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame] | 276 | {{if and (ne $.Name "vkEnumerateDeviceLayerProperties") (ne $.Name "vkGetInstanceProcAddr")}}true{{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 277 | {{end}} |
| 278 | {{end}} |
| 279 | |
| 280 | |
| 281 | {{/* |
| 282 | ------------------------------------------------------------------------------ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 283 | Emit "true" if a function is core or from a supportable extension. |
| 284 | ------------------------------------------------------------------------------ |
| 285 | */}} |
| 286 | {{define "IsFunctionSupported"}} |
| 287 | {{AssertType $ "Function"}} |
| 288 | {{if not (GetAnnotation $ "pfn")}} |
| 289 | {{$ext := GetAnnotation $ "extension"}} |
| 290 | {{if not $ext}}true |
| 291 | {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true |
| 292 | {{end}} |
| 293 | {{end}} |
| 294 | {{end}} |
| 295 | |
| 296 | |
| 297 | {{/* |
| 298 | ------------------------------------------------------------------------------ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 299 | Reports whether an extension function is implemented entirely by the loader, |
| 300 | and not implemented by drivers. |
| 301 | ------------------------------------------------------------------------------ |
| 302 | */}} |
| 303 | {{define "IsLoaderFunction"}} |
| 304 | {{AssertType $ "Function"}} |
| 305 | |
| 306 | {{$ext := GetAnnotation $ "extension"}} |
| 307 | {{if $ext}} |
| 308 | {{Macro "IsLoaderExtension" $ext}} |
| 309 | {{end}} |
| 310 | {{end}} |
| 311 | |
| 312 | |
| 313 | {{/* |
| 314 | ------------------------------------------------------------------------------- |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 315 | Emit "true" if the loader has a bottom-level implementation for the function |
| 316 | which terminates the dispatch chain. |
| 317 | ------------------------------------------------------------------------------- |
| 318 | */}} |
| 319 | {{define "HasLoaderBottomImpl"}} |
| 320 | {{AssertType $ "Function"}} |
| 321 | |
| 322 | {{if (Macro "IsFunctionSupported" $)}} |
| 323 | {{ if (eq (Macro "Vtbl" $) "Instance")}}true |
| 324 | {{else if (Macro "IsLoaderFunction" $)}}true |
| 325 | {{else if (eq $.Name "vkCreateInstance")}}true |
| 326 | {{else if (eq $.Name "vkGetDeviceProcAddr")}}true |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame^] | 327 | {{else if (eq $.Name "vkDestroyDevice")}}true |
| 328 | {{else if (eq $.Name "vkGetDeviceQueue")}}true |
| 329 | {{else if (eq $.Name "vkAllocateCommandBuffers")}}true |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 330 | {{end}} |
| 331 | {{end}} |
| 332 | {{end}} |
| 333 | |
| 334 | |
| 335 | {{/* |
| 336 | ------------------------------------------------------------------------------ |
| 337 | Emit "true" if an extension is unsupportable on Android. |
| 338 | ------------------------------------------------------------------------------ |
| 339 | */}} |
| 340 | {{define "IsExtensionBlacklisted"}} |
| 341 | {{$ext := index $.Arguments 0}} |
| 342 | {{ if eq $ext "VK_KHR_display"}}true |
| 343 | {{else if eq $ext "VK_KHR_display_swapchain"}}true |
| 344 | {{else if eq $ext "VK_KHR_xlib_surface"}}true |
| 345 | {{else if eq $ext "VK_KHR_xcb_surface"}}true |
| 346 | {{else if eq $ext "VK_KHR_wayland_surface"}}true |
| 347 | {{else if eq $ext "VK_KHR_mir_surface"}}true |
| 348 | {{else if eq $ext "VK_KHR_win32_surface"}}true |
| 349 | {{end}} |
| 350 | {{end}} |
| 351 | |
| 352 | |
| 353 | {{/* |
| 354 | ------------------------------------------------------------------------------ |
| 355 | Reports whether an extension is implemented entirely by the loader, |
| 356 | so drivers should not enumerate it. |
| 357 | ------------------------------------------------------------------------------ |
| 358 | */}} |
| 359 | {{define "IsLoaderExtension"}} |
| 360 | {{$ext := index $.Arguments 0}} |
| 361 | {{ if eq $ext "VK_KHR_surface"}}true |
| 362 | {{else if eq $ext "VK_KHR_swapchain"}}true |
| 363 | {{else if eq $ext "VK_KHR_android_surface"}}true |
| 364 | {{end}} |
| 365 | {{end}} |