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 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 121 | namespace vulkan { |
| 122 | ¶ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 123 | bool LoadDriverDispatchTable(VkInstance instance, |
| 124 | PFN_vkGetInstanceProcAddr get_proc_addr, |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 125 | const InstanceExtensionSet& extensions, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 126 | DriverDispatchTable& dispatch) {« |
| 127 | bool success = true; |
| 128 | // clang-format off |
| 129 | {{range $f := AllCommands $}} |
| 130 | {{if (Macro "IsInstanceDispatched" $f)}} |
| 131 | {{if not (Macro "IsLoaderFunction" $f)}} |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 132 | {{$ext := GetAnnotation $f "extension"}} |
| 133 | {{if $ext}} |
| 134 | if (extensions[{{Macro "ExtensionConstant" $ext}}]) { |
| 135 | {{end}} |
| 136 | dispatch.{{Macro "BaseName" $f}} = § |
| 137 | reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§ |
| 138 | get_proc_addr(instance, "{{$f.Name}}")); |
| 139 | if (UNLIKELY(!dispatch.{{Macro "BaseName" $f}})) { |
| 140 | ALOGE("missing driver proc: %s", "{{$f.Name}}"); |
| 141 | success = false; |
| 142 | } |
| 143 | {{if $ext}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 144 | } |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 145 | {{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 146 | {{end}} |
| 147 | {{end}} |
| 148 | {{end}} |
| 149 | dispatch.GetDeviceProcAddr = reinterpret_cast<PFN_vkGetDeviceProcAddr>(get_proc_addr(instance, "vkGetDeviceProcAddr")); |
| 150 | if (UNLIKELY(!dispatch.GetDeviceProcAddr)) { |
| 151 | ALOGE("missing driver proc: %s", "vkGetDeviceProcAddr"); |
| 152 | success = false; |
| 153 | } |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 154 | dispatch.DestroyDevice = reinterpret_cast<PFN_vkDestroyDevice>(get_proc_addr(instance, "vkDestroyDevice")); |
| 155 | if (UNLIKELY(!dispatch.DestroyDevice)) { |
| 156 | ALOGE("missing driver proc: %s", "vkDestroyDevice"); |
| 157 | success = false; |
| 158 | } |
| 159 | dispatch.GetDeviceQueue = reinterpret_cast<PFN_vkGetDeviceQueue>(get_proc_addr(instance, "vkGetDeviceQueue")); |
| 160 | if (UNLIKELY(!dispatch.GetDeviceQueue)) { |
| 161 | ALOGE("missing driver proc: %s", "vkGetDeviceQueue"); |
| 162 | success = false; |
| 163 | } |
| 164 | dispatch.AllocateCommandBuffers = reinterpret_cast<PFN_vkAllocateCommandBuffers>(get_proc_addr(instance, "vkAllocateCommandBuffers")); |
| 165 | if (UNLIKELY(!dispatch.AllocateCommandBuffers)) { |
| 166 | ALOGE("missing driver proc: %s", "vkAllocateCommandBuffers"); |
| 167 | success = false; |
| 168 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 169 | dispatch.CreateImage = reinterpret_cast<PFN_vkCreateImage>(get_proc_addr(instance, "vkCreateImage")); |
| 170 | if (UNLIKELY(!dispatch.CreateImage)) { |
| 171 | ALOGE("missing driver proc: %s", "vkCreateImage"); |
| 172 | success = false; |
| 173 | } |
| 174 | dispatch.DestroyImage = reinterpret_cast<PFN_vkDestroyImage>(get_proc_addr(instance, "vkDestroyImage")); |
| 175 | if (UNLIKELY(!dispatch.DestroyImage)) { |
| 176 | ALOGE("missing driver proc: %s", "vkDestroyImage"); |
| 177 | success = false; |
| 178 | } |
Jesse Hall | d913282 | 2016-01-14 15:50:52 -0800 | [diff] [blame] | 179 | dispatch.GetSwapchainGrallocUsageANDROID = reinterpret_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(get_proc_addr(instance, "vkGetSwapchainGrallocUsageANDROID")); |
| 180 | if (UNLIKELY(!dispatch.GetSwapchainGrallocUsageANDROID)) { |
| 181 | ALOGE("missing driver proc: %s", "vkGetSwapchainGrallocUsageANDROID"); |
| 182 | success = false; |
| 183 | } |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 184 | dispatch.AcquireImageANDROID = reinterpret_cast<PFN_vkAcquireImageANDROID>(get_proc_addr(instance, "vkAcquireImageANDROID")); |
| 185 | if (UNLIKELY(!dispatch.AcquireImageANDROID)) { |
| 186 | ALOGE("missing driver proc: %s", "vkAcquireImageANDROID"); |
| 187 | success = false; |
| 188 | } |
| 189 | dispatch.QueueSignalReleaseImageANDROID = reinterpret_cast<PFN_vkQueueSignalReleaseImageANDROID>(get_proc_addr(instance, "vkQueueSignalReleaseImageANDROID")); |
| 190 | if (UNLIKELY(!dispatch.QueueSignalReleaseImageANDROID)) { |
| 191 | ALOGE("missing driver proc: %s", "vkQueueSignalReleaseImageANDROID"); |
| 192 | success = false; |
| 193 | } |
| 194 | // clang-format on |
| 195 | return success; |
| 196 | »} |
| 197 | ¶ |
| 198 | } // namespace vulkan |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 199 | ¶{{end}} |
| 200 | |
| 201 | |
| 202 | {{/* |
| 203 | ------------------------------------------------------------------------------- |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 204 | Map an extension name to InstanceExtension or DeviceExtension enum value |
| 205 | ------------------------------------------------------------------------------- |
| 206 | */}} |
| 207 | {{define "ExtensionConstant"}} |
| 208 | {{$name := index $.Arguments 0}} |
| 209 | {{ if (eq $name "VK_KHR_surface")}}kKHR_surface |
| 210 | {{else if (eq $name "VK_KHR_android_surface")}}kKHR_android_surface |
| 211 | {{else if (eq $name "VK_EXT_debug_report")}}kEXT_debug_report |
| 212 | {{end}} |
| 213 | {{end}} |
| 214 | |
| 215 | |
| 216 | {{/* |
| 217 | ------------------------------------------------------------------------------- |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 218 | Emits a function name without the "vk" prefix. |
| 219 | ------------------------------------------------------------------------------- |
| 220 | */}} |
| 221 | {{define "BaseName"}} |
| 222 | {{AssertType $ "Function"}} |
| 223 | {{TrimPrefix "vk" $.Name}} |
| 224 | {{end}} |
| 225 | |
| 226 | |
| 227 | {{/* |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 228 | ------------------------------------------------------------------------------ |
| 229 | Emit "true" for supported functions that undergo table dispatch. Only global |
| 230 | functions and functions handled in the loader top without calling into |
| 231 | lower layers are not dispatched. |
| 232 | ------------------------------------------------------------------------------ |
| 233 | */}} |
| 234 | {{define "IsInstanceDispatched"}} |
| 235 | {{AssertType $ "Function"}} |
| 236 | {{if and (Macro "IsFunctionSupported" $) (eq (Macro "Vtbl" $) "Instance")}} |
Courtney Goeltzenleuchter | 1cc0d37 | 2016-02-05 17:10:59 -0700 | [diff] [blame] | 237 | {{if and (ne $.Name "vkEnumerateDeviceLayerProperties") (ne $.Name "vkGetInstanceProcAddr")}}true{{end}} |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 238 | {{end}} |
| 239 | {{end}} |
| 240 | |
| 241 | |
| 242 | {{/* |
| 243 | ------------------------------------------------------------------------------ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 244 | Emit "true" if a function is core or from a supportable extension. |
| 245 | ------------------------------------------------------------------------------ |
| 246 | */}} |
| 247 | {{define "IsFunctionSupported"}} |
| 248 | {{AssertType $ "Function"}} |
| 249 | {{if not (GetAnnotation $ "pfn")}} |
| 250 | {{$ext := GetAnnotation $ "extension"}} |
| 251 | {{if not $ext}}true |
| 252 | {{else if not (Macro "IsExtensionBlacklisted" $ext)}}true |
| 253 | {{end}} |
| 254 | {{end}} |
| 255 | {{end}} |
| 256 | |
| 257 | |
| 258 | {{/* |
| 259 | ------------------------------------------------------------------------------ |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 260 | Reports whether an extension function is implemented entirely by the loader, |
| 261 | and not implemented by drivers. |
| 262 | ------------------------------------------------------------------------------ |
| 263 | */}} |
| 264 | {{define "IsLoaderFunction"}} |
| 265 | {{AssertType $ "Function"}} |
| 266 | |
| 267 | {{$ext := GetAnnotation $ "extension"}} |
| 268 | {{if $ext}} |
| 269 | {{Macro "IsLoaderExtension" $ext}} |
| 270 | {{end}} |
| 271 | {{end}} |
| 272 | |
| 273 | |
| 274 | {{/* |
| 275 | ------------------------------------------------------------------------------- |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 276 | Emit "true" if the loader has a bottom-level implementation for the function |
| 277 | which terminates the dispatch chain. |
| 278 | ------------------------------------------------------------------------------- |
| 279 | */}} |
| 280 | {{define "HasLoaderBottomImpl"}} |
| 281 | {{AssertType $ "Function"}} |
| 282 | |
| 283 | {{if (Macro "IsFunctionSupported" $)}} |
| 284 | {{ if (eq (Macro "Vtbl" $) "Instance")}}true |
| 285 | {{else if (Macro "IsLoaderFunction" $)}}true |
| 286 | {{else if (eq $.Name "vkCreateInstance")}}true |
| 287 | {{else if (eq $.Name "vkGetDeviceProcAddr")}}true |
Chia-I Wu | 0c20324 | 2016-03-15 13:44:51 +0800 | [diff] [blame] | 288 | {{else if (eq $.Name "vkDestroyDevice")}}true |
| 289 | {{else if (eq $.Name "vkGetDeviceQueue")}}true |
| 290 | {{else if (eq $.Name "vkAllocateCommandBuffers")}}true |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 291 | {{end}} |
| 292 | {{end}} |
| 293 | {{end}} |
| 294 | |
| 295 | |
| 296 | {{/* |
| 297 | ------------------------------------------------------------------------------ |
| 298 | Emit "true" if an extension is unsupportable on Android. |
| 299 | ------------------------------------------------------------------------------ |
| 300 | */}} |
| 301 | {{define "IsExtensionBlacklisted"}} |
| 302 | {{$ext := index $.Arguments 0}} |
| 303 | {{ if eq $ext "VK_KHR_display"}}true |
| 304 | {{else if eq $ext "VK_KHR_display_swapchain"}}true |
| 305 | {{else if eq $ext "VK_KHR_xlib_surface"}}true |
| 306 | {{else if eq $ext "VK_KHR_xcb_surface"}}true |
| 307 | {{else if eq $ext "VK_KHR_wayland_surface"}}true |
| 308 | {{else if eq $ext "VK_KHR_mir_surface"}}true |
| 309 | {{else if eq $ext "VK_KHR_win32_surface"}}true |
| 310 | {{end}} |
| 311 | {{end}} |
| 312 | |
| 313 | |
| 314 | {{/* |
| 315 | ------------------------------------------------------------------------------ |
| 316 | Reports whether an extension is implemented entirely by the loader, |
| 317 | so drivers should not enumerate it. |
| 318 | ------------------------------------------------------------------------------ |
| 319 | */}} |
| 320 | {{define "IsLoaderExtension"}} |
| 321 | {{$ext := index $.Arguments 0}} |
| 322 | {{ if eq $ext "VK_KHR_surface"}}true |
| 323 | {{else if eq $ext "VK_KHR_swapchain"}}true |
| 324 | {{else if eq $ext "VK_KHR_android_surface"}}true |
| 325 | {{end}} |
| 326 | {{end}} |