blob: 8f090083f8d14fe1bf1488b1f4d87bf0c134a309 [file] [log] [blame]
Chia-I Wueb7db122016-03-24 09:11:06 +08001/*
2 * Copyright 2016 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// WARNING: This file is generated. See ../README.md for instructions.
18
Yiwei Zhang6d78a572019-04-10 15:35:38 -070019#include <log/log.h>
Chia-I Wueb7db122016-03-24 09:11:06 +080020#include <string.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070021
Chia-I Wueb7db122016-03-24 09:11:06 +080022#include <algorithm>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070023
Chia-I Wueb7db122016-03-24 09:11:06 +080024#include "driver.h"
Chia-I Wueb7db122016-03-24 09:11:06 +080025
26namespace vulkan {
27namespace driver {
28
29namespace {
30
31// clang-format off
32
Chia-I Wueb7db122016-03-24 09:11:06 +080033VKAPI_ATTR VkResult checkedCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080034 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
35 return CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
36 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080037 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080038 return VK_SUCCESS;
39 }
Chia-I Wueb7db122016-03-24 09:11:06 +080040}
41
42VKAPI_ATTR void checkedDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080043 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
44 DestroySwapchainKHR(device, swapchain, pAllocator);
45 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080046 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080047 }
Chia-I Wueb7db122016-03-24 09:11:06 +080048}
49
50VKAPI_ATTR VkResult checkedGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080051 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
52 return GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
53 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080054 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080055 return VK_SUCCESS;
56 }
Chia-I Wueb7db122016-03-24 09:11:06 +080057}
58
59VKAPI_ATTR VkResult checkedAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080060 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
61 return AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
62 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080063 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080064 return VK_SUCCESS;
65 }
Chia-I Wueb7db122016-03-24 09:11:06 +080066}
67
68VKAPI_ATTR VkResult checkedQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080069 if (GetData(queue).hook_extensions[ProcHook::KHR_swapchain]) {
70 return QueuePresentKHR(queue, pPresentInfo);
71 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080072 Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080073 return VK_SUCCESS;
74 }
Chia-I Wueb7db122016-03-24 09:11:06 +080075}
76
Yiwei Zhang7cc36a52019-10-11 19:02:09 -070077VKAPI_ATTR VkResult checkedBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) {
78 if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) {
79 return BindImageMemory2(device, bindInfoCount, pBindInfos);
80 } else {
81 Logger(device).Err(device, "VK_VERSION_1_1 not enabled. vkBindImageMemory2 not executed.");
82 return VK_SUCCESS;
83 }
84}
85
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -070086VKAPI_ATTR VkResult checkedBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) {
87 if (GetData(device).hook_extensions[ProcHook::KHR_bind_memory2]) {
88 return BindImageMemory2KHR(device, bindInfoCount, pBindInfos);
89 } else {
90 Logger(device).Err(device, "VK_KHR_bind_memory2 not enabled. vkBindImageMemory2KHR not executed.");
91 return VK_SUCCESS;
92 }
93}
94
Daniel Kochf25f5bb2017-10-05 00:26:58 -040095VKAPI_ATTR VkResult checkedGetDeviceGroupPresentCapabilitiesKHR(VkDevice device, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
96 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
97 return GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
98 } else {
99 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupPresentCapabilitiesKHR not executed.");
100 return VK_SUCCESS;
101 }
102}
103
104VKAPI_ATTR VkResult checkedGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR* pModes) {
105 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
106 return GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
107 } else {
108 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupSurfacePresentModesKHR not executed.");
109 return VK_SUCCESS;
110 }
111}
112
113VKAPI_ATTR VkResult checkedAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex) {
114 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
115 return AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
116 } else {
117 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImage2KHR not executed.");
118 return VK_SUCCESS;
119 }
120}
121
Jesse Hall889cd9a2017-02-25 22:12:23 -0800122VKAPI_ATTR void checkedSetHdrMetadataEXT(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata) {
123 if (GetData(device).hook_extensions[ProcHook::EXT_hdr_metadata]) {
124 SetHdrMetadataEXT(device, swapchainCount, pSwapchains, pMetadata);
125 } else {
126 Logger(device).Err(device, "VK_EXT_hdr_metadata not enabled. vkSetHdrMetadataEXT not executed.");
127 }
128}
129
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300130VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapchain) {
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300131 if (GetData(device).hook_extensions[ProcHook::KHR_shared_presentable_image]) {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300132 return GetSwapchainStatusKHR(device, swapchain);
133 } else {
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300134 Logger(device).Err(device, "VK_KHR_shared_presentable_image not enabled. vkGetSwapchainStatusKHR not executed.");
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300135 return VK_SUCCESS;
136 }
137}
138
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700139VKAPI_ATTR VkResult checkedGetRefreshCycleDurationGOOGLE(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) {
140 if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
141 return GetRefreshCycleDurationGOOGLE(device, swapchain, pDisplayTimingProperties);
Yiwei Zhang23143102019-04-10 18:24:05 -0700142 } else {
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700143 Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetRefreshCycleDurationGOOGLE not executed.");
144 return VK_SUCCESS;
145 }
146}
147
148VKAPI_ATTR VkResult checkedGetPastPresentationTimingGOOGLE(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings) {
149 if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
150 return GetPastPresentationTimingGOOGLE(device, swapchain, pPresentationTimingCount, pPresentationTimings);
151 } else {
152 Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetPastPresentationTimingGOOGLE not executed.");
Yiwei Zhang23143102019-04-10 18:24:05 -0700153 return VK_SUCCESS;
154 }
155}
156
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700157VKAPI_ATTR void checkedGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) {
158 if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) {
159 GetDeviceQueue2(device, pQueueInfo, pQueue);
160 } else {
161 Logger(device).Err(device, "VK_VERSION_1_1 not enabled. vkGetDeviceQueue2 not executed.");
162 }
163}
164
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000165VKAPI_ATTR VkResult checkedReleaseSwapchainImagesEXT(VkDevice device, const VkReleaseSwapchainImagesInfoEXT* pReleaseInfo) {
166 if (GetData(device).hook_extensions[ProcHook::EXT_swapchain_maintenance1]) {
167 return ReleaseSwapchainImagesEXT(device, pReleaseInfo);
168 } else {
169 Logger(device).Err(device, "VK_EXT_swapchain_maintenance1 not enabled. vkReleaseSwapchainImagesEXT not executed.");
170 return VK_SUCCESS;
171 }
172}
173
Chia-I Wueb7db122016-03-24 09:11:06 +0800174// clang-format on
175
176const ProcHook g_proc_hooks[] = {
177 // clang-format off
178 {
179 "vkAcquireImageANDROID",
180 ProcHook::DEVICE,
181 ProcHook::ANDROID_native_buffer,
182 nullptr,
183 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800184 },
185 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400186 "vkAcquireNextImage2KHR",
187 ProcHook::DEVICE,
188 ProcHook::KHR_swapchain,
189 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImage2KHR),
190 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImage2KHR),
191 },
192 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800193 "vkAcquireNextImageKHR",
194 ProcHook::DEVICE,
195 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800196 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800197 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImageKHR),
198 },
199 {
200 "vkAllocateCommandBuffers",
201 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700202 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu6a58a8a2016-03-24 16:29:51 +0800203 reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers),
Chia-I Wueb7db122016-03-24 09:11:06 +0800204 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800205 },
206 {
Yiwei Zhang23143102019-04-10 18:24:05 -0700207 "vkBindImageMemory2",
208 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700209 ProcHook::EXTENSION_CORE_1_1,
Yiwei Zhang23143102019-04-10 18:24:05 -0700210 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700211 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2),
Yiwei Zhang23143102019-04-10 18:24:05 -0700212 },
213 {
214 "vkBindImageMemory2KHR",
215 ProcHook::DEVICE,
216 ProcHook::KHR_bind_memory2,
217 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2KHR),
218 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2KHR),
219 },
220 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800221 "vkCreateAndroidSurfaceKHR",
222 ProcHook::INSTANCE,
223 ProcHook::KHR_android_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800224 reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800225 nullptr,
226 },
227 {
228 "vkCreateDebugReportCallbackEXT",
229 ProcHook::INSTANCE,
230 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800231 reinterpret_cast<PFN_vkVoidFunction>(CreateDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800232 nullptr,
233 },
234 {
235 "vkCreateDevice",
236 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700237 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800238 reinterpret_cast<PFN_vkVoidFunction>(CreateDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800239 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800240 },
241 {
242 "vkCreateInstance",
243 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700244 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800245 reinterpret_cast<PFN_vkVoidFunction>(CreateInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800246 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800247 },
248 {
249 "vkCreateSwapchainKHR",
250 ProcHook::DEVICE,
251 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800252 reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800253 reinterpret_cast<PFN_vkVoidFunction>(checkedCreateSwapchainKHR),
254 },
255 {
256 "vkDebugReportMessageEXT",
257 ProcHook::INSTANCE,
258 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800259 reinterpret_cast<PFN_vkVoidFunction>(DebugReportMessageEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800260 nullptr,
261 },
262 {
263 "vkDestroyDebugReportCallbackEXT",
264 ProcHook::INSTANCE,
265 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800266 reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800267 nullptr,
268 },
269 {
270 "vkDestroyDevice",
271 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700272 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800273 reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800274 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800275 },
276 {
277 "vkDestroyInstance",
278 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700279 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800280 reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800281 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800282 },
283 {
284 "vkDestroySurfaceKHR",
285 ProcHook::INSTANCE,
286 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800287 reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800288 nullptr,
289 },
290 {
291 "vkDestroySwapchainKHR",
292 ProcHook::DEVICE,
293 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800294 reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800295 reinterpret_cast<PFN_vkVoidFunction>(checkedDestroySwapchainKHR),
296 },
297 {
298 "vkEnumerateDeviceExtensionProperties",
299 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700300 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu01cf3052016-03-24 16:16:21 +0800301 reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties),
Chia-I Wueb7db122016-03-24 09:11:06 +0800302 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800303 },
304 {
305 "vkEnumerateInstanceExtensionProperties",
306 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700307 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800308 reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties),
309 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800310 },
311 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400312 "vkEnumeratePhysicalDeviceGroups",
313 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700314 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400315 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDeviceGroups),
316 nullptr,
317 },
318 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800319 "vkEnumeratePhysicalDevices",
320 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700321 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800322 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices),
Chia-I Wueb7db122016-03-24 09:11:06 +0800323 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800324 },
325 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400326 "vkGetDeviceGroupPresentCapabilitiesKHR",
327 ProcHook::DEVICE,
328 ProcHook::KHR_swapchain,
329 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupPresentCapabilitiesKHR),
330 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupPresentCapabilitiesKHR),
331 },
332 {
333 "vkGetDeviceGroupSurfacePresentModesKHR",
334 ProcHook::DEVICE,
335 ProcHook::KHR_swapchain,
336 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupSurfacePresentModesKHR),
337 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupSurfacePresentModesKHR),
338 },
339 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800340 "vkGetDeviceProcAddr",
341 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700342 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800343 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr),
344 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800345 },
346 {
347 "vkGetDeviceQueue",
348 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700349 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuba0be412016-03-24 16:24:40 +0800350 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue),
Chia-I Wueb7db122016-03-24 09:11:06 +0800351 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800352 },
353 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400354 "vkGetDeviceQueue2",
355 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700356 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400357 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700358 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceQueue2),
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400359 },
360 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800361 "vkGetInstanceProcAddr",
362 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700363 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800364 reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr),
365 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800366 },
367 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700368 "vkGetPastPresentationTimingGOOGLE",
369 ProcHook::DEVICE,
370 ProcHook::GOOGLE_display_timing,
371 reinterpret_cast<PFN_vkVoidFunction>(GetPastPresentationTimingGOOGLE),
372 reinterpret_cast<PFN_vkVoidFunction>(checkedGetPastPresentationTimingGOOGLE),
373 },
374 {
Yiwei Zhange1f35012020-07-05 22:52:04 -0700375 "vkGetPhysicalDeviceExternalBufferProperties",
376 ProcHook::INSTANCE,
377 ProcHook::EXTENSION_CORE_1_1,
378 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalBufferProperties),
379 nullptr,
380 },
381 {
382 "vkGetPhysicalDeviceExternalFenceProperties",
383 ProcHook::INSTANCE,
384 ProcHook::EXTENSION_CORE_1_1,
385 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalFenceProperties),
386 nullptr,
387 },
388 {
389 "vkGetPhysicalDeviceExternalSemaphoreProperties",
390 ProcHook::INSTANCE,
391 ProcHook::EXTENSION_CORE_1_1,
392 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalSemaphoreProperties),
393 nullptr,
394 },
395 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700396 "vkGetPhysicalDeviceFeatures2",
397 ProcHook::INSTANCE,
398 ProcHook::EXTENSION_CORE_1_1,
399 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures2),
400 nullptr,
401 },
402 {
403 "vkGetPhysicalDeviceFormatProperties2",
404 ProcHook::INSTANCE,
405 ProcHook::EXTENSION_CORE_1_1,
406 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties2),
407 nullptr,
408 },
409 {
410 "vkGetPhysicalDeviceImageFormatProperties2",
411 ProcHook::INSTANCE,
412 ProcHook::EXTENSION_CORE_1_1,
413 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties2),
414 nullptr,
415 },
416 {
417 "vkGetPhysicalDeviceMemoryProperties2",
418 ProcHook::INSTANCE,
419 ProcHook::EXTENSION_CORE_1_1,
420 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties2),
421 nullptr,
422 },
423 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400424 "vkGetPhysicalDevicePresentRectanglesKHR",
425 ProcHook::INSTANCE,
426 ProcHook::KHR_swapchain,
427 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
428 nullptr,
429 },
430 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700431 "vkGetPhysicalDeviceProperties2",
432 ProcHook::INSTANCE,
433 ProcHook::EXTENSION_CORE_1_1,
434 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties2),
435 nullptr,
436 },
437 {
438 "vkGetPhysicalDeviceQueueFamilyProperties2",
439 ProcHook::INSTANCE,
440 ProcHook::EXTENSION_CORE_1_1,
441 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties2),
442 nullptr,
443 },
444 {
445 "vkGetPhysicalDeviceSparseImageFormatProperties2",
446 ProcHook::INSTANCE,
447 ProcHook::EXTENSION_CORE_1_1,
448 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties2),
449 nullptr,
450 },
451 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300452 "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
453 ProcHook::INSTANCE,
454 ProcHook::KHR_get_surface_capabilities2,
455 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
456 nullptr,
457 },
458 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800459 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
460 ProcHook::INSTANCE,
461 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800462 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800463 nullptr,
464 },
465 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300466 "vkGetPhysicalDeviceSurfaceFormats2KHR",
467 ProcHook::INSTANCE,
468 ProcHook::KHR_get_surface_capabilities2,
469 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
470 nullptr,
471 },
472 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800473 "vkGetPhysicalDeviceSurfaceFormatsKHR",
474 ProcHook::INSTANCE,
475 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800476 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800477 nullptr,
478 },
479 {
480 "vkGetPhysicalDeviceSurfacePresentModesKHR",
481 ProcHook::INSTANCE,
482 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800483 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800484 nullptr,
485 },
486 {
487 "vkGetPhysicalDeviceSurfaceSupportKHR",
488 ProcHook::INSTANCE,
489 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800490 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800491 nullptr,
492 },
493 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700494 "vkGetRefreshCycleDurationGOOGLE",
495 ProcHook::DEVICE,
496 ProcHook::GOOGLE_display_timing,
497 reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
498 reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
499 },
500 {
Chris Forbes8e4438b2016-12-07 16:26:49 +1300501 "vkGetSwapchainGrallocUsage2ANDROID",
502 ProcHook::DEVICE,
503 ProcHook::ANDROID_native_buffer,
504 nullptr,
505 nullptr,
506 },
507 {
Trevor David Black2cc44682022-03-09 00:31:38 +0000508 "vkGetSwapchainGrallocUsage3ANDROID",
509 ProcHook::DEVICE,
510 ProcHook::ANDROID_native_buffer,
511 nullptr,
512 nullptr,
513 },
514 {
Trevor David Blackb6ca8422023-07-26 20:00:04 +0000515 "vkGetSwapchainGrallocUsage4ANDROID",
516 ProcHook::DEVICE,
517 ProcHook::ANDROID_native_buffer,
518 nullptr,
519 nullptr,
520 },
521 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800522 "vkGetSwapchainGrallocUsageANDROID",
523 ProcHook::DEVICE,
524 ProcHook::ANDROID_native_buffer,
525 nullptr,
526 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800527 },
528 {
529 "vkGetSwapchainImagesKHR",
530 ProcHook::DEVICE,
531 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800532 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800533 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
534 },
535 {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300536 "vkGetSwapchainStatusKHR",
537 ProcHook::DEVICE,
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300538 ProcHook::KHR_shared_presentable_image,
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300539 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
540 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
541 },
542 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800543 "vkQueuePresentKHR",
544 ProcHook::DEVICE,
545 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800546 reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800547 reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
548 },
549 {
550 "vkQueueSignalReleaseImageANDROID",
551 ProcHook::DEVICE,
552 ProcHook::ANDROID_native_buffer,
553 nullptr,
554 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800555 },
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700556 {
Yiwei Zhang899d1752019-09-23 16:05:35 -0700557 "vkQueueSubmit",
558 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700559 ProcHook::EXTENSION_CORE_1_0,
Yiwei Zhang899d1752019-09-23 16:05:35 -0700560 reinterpret_cast<PFN_vkVoidFunction>(QueueSubmit),
561 nullptr,
562 },
563 {
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000564 "vkReleaseSwapchainImagesEXT",
565 ProcHook::DEVICE,
566 ProcHook::EXT_swapchain_maintenance1,
567 reinterpret_cast<PFN_vkVoidFunction>(ReleaseSwapchainImagesEXT),
568 reinterpret_cast<PFN_vkVoidFunction>(checkedReleaseSwapchainImagesEXT),
569 },
570 {
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700571 "vkSetHdrMetadataEXT",
572 ProcHook::DEVICE,
573 ProcHook::EXT_hdr_metadata,
574 reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
575 reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
576 },
Chia-I Wueb7db122016-03-24 09:11:06 +0800577 // clang-format on
578};
579
Chris Forbese2d3ee12017-03-16 16:10:15 +1300580} // namespace
Chia-I Wueb7db122016-03-24 09:11:06 +0800581
582const ProcHook* GetProcHook(const char* name) {
Yiwei Zhang93b521c2020-07-11 16:32:09 -0700583 auto begin = std::cbegin(g_proc_hooks);
584 auto end = std::cend(g_proc_hooks);
585 auto hook = std::lower_bound(
Chia-I Wueb7db122016-03-24 09:11:06 +0800586 begin, end, name,
587 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
588 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
589}
590
591ProcHook::Extension GetProcHookExtension(const char* name) {
592 // clang-format off
593 if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
594 if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700595 if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700596 if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700597 if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
Ian Elliott2f7f0ff2022-02-18 16:44:58 -0700598 if (strcmp(name, "VK_GOOGLE_surfaceless_query") == 0) return ProcHook::GOOGLE_surfaceless_query;
Chia-I Wueb7db122016-03-24 09:11:06 +0800599 if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700600 if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
Chris Forbes48853712017-01-12 14:09:33 +1300601 if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700602 if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
Chia-I Wueb7db122016-03-24 09:11:06 +0800603 if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
Ian Elliott6fcbd072022-02-28 16:47:43 -0700604 if (strcmp(name, "VK_KHR_surface_protected_capabilities") == 0) return ProcHook::KHR_surface_protected_capabilities;
Chia-I Wueb7db122016-03-24 09:11:06 +0800605 if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000606 if (strcmp(name, "VK_EXT_swapchain_maintenance1") == 0) return ProcHook::EXT_swapchain_maintenance1;
607 if (strcmp(name, "VK_EXT_surface_maintenance1") == 0) return ProcHook::EXT_surface_maintenance1;
Jesse Halla8d367a2018-01-18 15:40:46 -0800608 if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer;
Yiwei Zhang23143102019-04-10 18:24:05 -0700609 if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700610 if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
Yiwei Zhange4f64172020-07-05 15:17:32 -0700611 if (strcmp(name, "VK_KHR_device_group_creation") == 0) return ProcHook::KHR_device_group_creation;
Yiwei Zhange1f35012020-07-05 22:52:04 -0700612 if (strcmp(name, "VK_KHR_external_memory_capabilities") == 0) return ProcHook::KHR_external_memory_capabilities;
613 if (strcmp(name, "VK_KHR_external_semaphore_capabilities") == 0) return ProcHook::KHR_external_semaphore_capabilities;
614 if (strcmp(name, "VK_KHR_external_fence_capabilities") == 0) return ProcHook::KHR_external_fence_capabilities;
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000615 if (strcmp(name, "VK_KHR_external_fence_fd") == 0) return ProcHook::KHR_external_fence_fd;
Chia-I Wueb7db122016-03-24 09:11:06 +0800616 // clang-format on
617 return ProcHook::EXTENSION_UNKNOWN;
618}
619
Chia-I Wucc5e2762016-03-24 13:01:16 +0800620#define UNLIKELY(expr) __builtin_expect((expr), 0)
621
Chris Forbes5948b3e2016-12-23 13:49:53 +1300622#define INIT_PROC(required, obj, proc) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800623 do { \
624 data.driver.proc = \
625 reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300626 if (UNLIKELY(required && !data.driver.proc)) { \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800627 ALOGE("missing " #obj " proc: vk" #proc); \
628 success = false; \
629 } \
630 } while (0)
631
Chris Forbes5948b3e2016-12-23 13:49:53 +1300632#define INIT_PROC_EXT(ext, required, obj, proc) \
633 do { \
634 if (extensions[ProcHook::ext]) \
635 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800636 } while (0)
637
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800638bool InitDriverTable(VkInstance instance,
639 PFN_vkGetInstanceProcAddr get_proc,
640 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800641 auto& data = GetData(instance);
642 bool success = true;
643
644 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300645 INIT_PROC(true, instance, DestroyInstance);
646 INIT_PROC(true, instance, EnumeratePhysicalDevices);
647 INIT_PROC(true, instance, GetInstanceProcAddr);
Jesse Hall85bb0c52017-02-09 22:13:02 -0800648 INIT_PROC(true, instance, GetPhysicalDeviceProperties);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300649 INIT_PROC(true, instance, CreateDevice);
650 INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
651 INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
652 INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
653 INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700654 INIT_PROC(false, instance, GetPhysicalDeviceFeatures2);
655 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFeatures2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700656 INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
Chris Forbes6aa30db2017-02-20 17:12:53 +1300657 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700658 INIT_PROC(false, instance, GetPhysicalDeviceFormatProperties2);
659 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFormatProperties2KHR);
660 INIT_PROC(false, instance, GetPhysicalDeviceImageFormatProperties2);
661 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceImageFormatProperties2KHR);
662 INIT_PROC(false, instance, GetPhysicalDeviceQueueFamilyProperties2);
663 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceQueueFamilyProperties2KHR);
664 INIT_PROC(false, instance, GetPhysicalDeviceMemoryProperties2);
665 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceMemoryProperties2KHR);
666 INIT_PROC(false, instance, GetPhysicalDeviceSparseImageFormatProperties2);
667 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceSparseImageFormatProperties2KHR);
Yiwei Zhange1f35012020-07-05 22:52:04 -0700668 INIT_PROC(false, instance, GetPhysicalDeviceExternalBufferProperties);
669 INIT_PROC_EXT(KHR_external_memory_capabilities, true, instance, GetPhysicalDeviceExternalBufferPropertiesKHR);
670 INIT_PROC(false, instance, GetPhysicalDeviceExternalSemaphoreProperties);
671 INIT_PROC_EXT(KHR_external_semaphore_capabilities, true, instance, GetPhysicalDeviceExternalSemaphorePropertiesKHR);
672 INIT_PROC(false, instance, GetPhysicalDeviceExternalFenceProperties);
673 INIT_PROC_EXT(KHR_external_fence_capabilities, true, instance, GetPhysicalDeviceExternalFencePropertiesKHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700674 INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
Yiwei Zhange4f64172020-07-05 15:17:32 -0700675 INIT_PROC_EXT(KHR_device_group_creation, true, instance, EnumeratePhysicalDeviceGroupsKHR);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800676 // clang-format on
677
678 return success;
679}
680
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800681bool InitDriverTable(VkDevice dev,
682 PFN_vkGetDeviceProcAddr get_proc,
683 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800684 auto& data = GetData(dev);
685 bool success = true;
686
687 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300688 INIT_PROC(true, dev, GetDeviceProcAddr);
689 INIT_PROC(true, dev, DestroyDevice);
690 INIT_PROC(true, dev, GetDeviceQueue);
Yiwei Zhang899d1752019-09-23 16:05:35 -0700691 INIT_PROC(true, dev, QueueSubmit);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300692 INIT_PROC(true, dev, CreateImage);
693 INIT_PROC(true, dev, DestroyImage);
694 INIT_PROC(true, dev, AllocateCommandBuffers);
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000695 INIT_PROC_EXT(KHR_external_fence_fd, true, dev, ImportFenceFdKHR);
Yiwei Zhang23143102019-04-10 18:24:05 -0700696 INIT_PROC(false, dev, BindImageMemory2);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700697 INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR);
Ian Elliottcd8ad332017-10-13 09:21:12 -0600698 INIT_PROC(false, dev, GetDeviceQueue2);
Chris Forbesd8277912017-02-10 14:59:59 +1300699 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
Yiwei Zhang4bc489b2019-09-23 15:17:22 -0700700 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
Trevor David Black2cc44682022-03-09 00:31:38 +0000701 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage3ANDROID);
Trevor David Blackb6ca8422023-07-26 20:00:04 +0000702 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage4ANDROID);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300703 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
704 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800705 // clang-format on
706
707 return success;
708}
709
Yiwei Zhang7c0c07c2020-07-04 23:49:47 -0700710const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = {
711 // clang-format off
712 std::make_pair("VK_KHR_device_group_creation", VK_API_VERSION_1_1),
713 std::make_pair("VK_KHR_external_fence_capabilities", VK_API_VERSION_1_1),
714 std::make_pair("VK_KHR_external_memory_capabilities", VK_API_VERSION_1_1),
715 std::make_pair("VK_KHR_external_semaphore_capabilities", VK_API_VERSION_1_1),
716 std::make_pair("VK_KHR_get_physical_device_properties2", VK_API_VERSION_1_1),
717 // clang-format on
718};
719
720std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) {
721 auto begin = std::cbegin(g_promoted_instance_extensions);
722 auto end = std::cend(g_promoted_instance_extensions);
723 auto iter =
724 std::lower_bound(begin, end, name,
725 [](const std::pair<const char*, uint32_t>& e,
726 const char* n) { return strcmp(e.first, n) < 0; });
727 return (iter < end && strcmp(iter->first, name) == 0)
728 ? std::optional<uint32_t>(iter->second)
729 : std::nullopt;
730}
731
732uint32_t CountPromotedInstanceExtensions(uint32_t begin_version,
733 uint32_t end_version) {
734 auto begin = std::cbegin(g_promoted_instance_extensions);
735 auto end = std::cend(g_promoted_instance_extensions);
736 uint32_t count = 0;
737
738 for (auto iter = begin; iter != end; iter++)
739 if (iter->second > begin_version && iter->second <= end_version)
740 count++;
741
742 return count;
743}
744
745std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version,
746 uint32_t end_version) {
747 auto begin = std::cbegin(g_promoted_instance_extensions);
748 auto end = std::cend(g_promoted_instance_extensions);
749 std::vector<const char*> extensions;
750
751 for (auto iter = begin; iter != end; iter++)
752 if (iter->second > begin_version && iter->second <= end_version)
753 extensions.emplace_back(iter->first);
754
755 return extensions;
756}
757
Chia-I Wueb7db122016-03-24 09:11:06 +0800758} // namespace driver
759} // namespace vulkan