blob: f741977d5013df2093e58287d1b6b465d9f7b172 [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
Tom Murphyea321842024-06-14 18:26:58 +000029/*
30 * This file is autogenerated by driver_generator.py. Do not edit directly.
31 */
Chia-I Wueb7db122016-03-24 09:11:06 +080032namespace {
33
34// clang-format off
35
Chia-I Wueb7db122016-03-24 09:11:06 +080036VKAPI_ATTR VkResult checkedCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080037 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
38 return CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
39 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080040 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080041 return VK_SUCCESS;
42 }
Chia-I Wueb7db122016-03-24 09:11:06 +080043}
44
45VKAPI_ATTR void checkedDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080046 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
47 DestroySwapchainKHR(device, swapchain, pAllocator);
48 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080049 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080050 }
Chia-I Wueb7db122016-03-24 09:11:06 +080051}
52
53VKAPI_ATTR VkResult checkedGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080054 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
55 return GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
56 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080057 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080058 return VK_SUCCESS;
59 }
Chia-I Wueb7db122016-03-24 09:11:06 +080060}
61
62VKAPI_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 +080063 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
64 return AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
65 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080066 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080067 return VK_SUCCESS;
68 }
Chia-I Wueb7db122016-03-24 09:11:06 +080069}
70
71VKAPI_ATTR VkResult checkedQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
Chia-I Wu36cc00a2016-04-13 16:52:06 +080072 if (GetData(queue).hook_extensions[ProcHook::KHR_swapchain]) {
73 return QueuePresentKHR(queue, pPresentInfo);
74 } else {
Chia-I Wu5beb2ac2016-05-04 16:37:23 +080075 Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
Chia-I Wu36cc00a2016-04-13 16:52:06 +080076 return VK_SUCCESS;
77 }
Chia-I Wueb7db122016-03-24 09:11:06 +080078}
79
Yiwei Zhang7cc36a52019-10-11 19:02:09 -070080VKAPI_ATTR VkResult checkedBindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) {
81 if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) {
82 return BindImageMemory2(device, bindInfoCount, pBindInfos);
83 } else {
84 Logger(device).Err(device, "VK_VERSION_1_1 not enabled. vkBindImageMemory2 not executed.");
85 return VK_SUCCESS;
86 }
87}
88
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -070089VKAPI_ATTR VkResult checkedBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) {
90 if (GetData(device).hook_extensions[ProcHook::KHR_bind_memory2]) {
91 return BindImageMemory2KHR(device, bindInfoCount, pBindInfos);
92 } else {
93 Logger(device).Err(device, "VK_KHR_bind_memory2 not enabled. vkBindImageMemory2KHR not executed.");
94 return VK_SUCCESS;
95 }
96}
97
Daniel Kochf25f5bb2017-10-05 00:26:58 -040098VKAPI_ATTR VkResult checkedGetDeviceGroupPresentCapabilitiesKHR(VkDevice device, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
99 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
100 return GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
101 } else {
102 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupPresentCapabilitiesKHR not executed.");
103 return VK_SUCCESS;
104 }
105}
106
107VKAPI_ATTR VkResult checkedGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR* pModes) {
108 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
109 return GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
110 } else {
111 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupSurfacePresentModesKHR not executed.");
112 return VK_SUCCESS;
113 }
114}
115
116VKAPI_ATTR VkResult checkedAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex) {
117 if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
118 return AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
119 } else {
120 Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImage2KHR not executed.");
121 return VK_SUCCESS;
122 }
123}
124
Jesse Hall889cd9a2017-02-25 22:12:23 -0800125VKAPI_ATTR void checkedSetHdrMetadataEXT(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata) {
126 if (GetData(device).hook_extensions[ProcHook::EXT_hdr_metadata]) {
127 SetHdrMetadataEXT(device, swapchainCount, pSwapchains, pMetadata);
128 } else {
129 Logger(device).Err(device, "VK_EXT_hdr_metadata not enabled. vkSetHdrMetadataEXT not executed.");
130 }
131}
132
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300133VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapchain) {
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300134 if (GetData(device).hook_extensions[ProcHook::KHR_shared_presentable_image]) {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300135 return GetSwapchainStatusKHR(device, swapchain);
136 } else {
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300137 Logger(device).Err(device, "VK_KHR_shared_presentable_image not enabled. vkGetSwapchainStatusKHR not executed.");
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300138 return VK_SUCCESS;
139 }
140}
141
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700142VKAPI_ATTR VkResult checkedGetRefreshCycleDurationGOOGLE(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) {
143 if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
144 return GetRefreshCycleDurationGOOGLE(device, swapchain, pDisplayTimingProperties);
Yiwei Zhang23143102019-04-10 18:24:05 -0700145 } else {
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700146 Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetRefreshCycleDurationGOOGLE not executed.");
147 return VK_SUCCESS;
148 }
149}
150
151VKAPI_ATTR VkResult checkedGetPastPresentationTimingGOOGLE(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings) {
152 if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
153 return GetPastPresentationTimingGOOGLE(device, swapchain, pPresentationTimingCount, pPresentationTimings);
154 } else {
155 Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetPastPresentationTimingGOOGLE not executed.");
Yiwei Zhang23143102019-04-10 18:24:05 -0700156 return VK_SUCCESS;
157 }
158}
159
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700160VKAPI_ATTR void checkedGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) {
161 if (GetData(device).hook_extensions[ProcHook::EXTENSION_CORE_1_1]) {
162 GetDeviceQueue2(device, pQueueInfo, pQueue);
163 } else {
164 Logger(device).Err(device, "VK_VERSION_1_1 not enabled. vkGetDeviceQueue2 not executed.");
165 }
166}
167
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000168VKAPI_ATTR VkResult checkedReleaseSwapchainImagesEXT(VkDevice device, const VkReleaseSwapchainImagesInfoEXT* pReleaseInfo) {
169 if (GetData(device).hook_extensions[ProcHook::EXT_swapchain_maintenance1]) {
170 return ReleaseSwapchainImagesEXT(device, pReleaseInfo);
171 } else {
172 Logger(device).Err(device, "VK_EXT_swapchain_maintenance1 not enabled. vkReleaseSwapchainImagesEXT not executed.");
173 return VK_SUCCESS;
174 }
175}
176
Chia-I Wueb7db122016-03-24 09:11:06 +0800177// clang-format on
178
179const ProcHook g_proc_hooks[] = {
180 // clang-format off
181 {
182 "vkAcquireImageANDROID",
183 ProcHook::DEVICE,
184 ProcHook::ANDROID_native_buffer,
185 nullptr,
186 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800187 },
188 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400189 "vkAcquireNextImage2KHR",
190 ProcHook::DEVICE,
191 ProcHook::KHR_swapchain,
192 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImage2KHR),
193 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImage2KHR),
194 },
195 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800196 "vkAcquireNextImageKHR",
197 ProcHook::DEVICE,
198 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800199 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800200 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImageKHR),
201 },
202 {
203 "vkAllocateCommandBuffers",
204 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700205 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu6a58a8a2016-03-24 16:29:51 +0800206 reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers),
Chia-I Wueb7db122016-03-24 09:11:06 +0800207 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800208 },
209 {
Yiwei Zhang23143102019-04-10 18:24:05 -0700210 "vkBindImageMemory2",
211 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700212 ProcHook::EXTENSION_CORE_1_1,
Yiwei Zhang23143102019-04-10 18:24:05 -0700213 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700214 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2),
Yiwei Zhang23143102019-04-10 18:24:05 -0700215 },
216 {
217 "vkBindImageMemory2KHR",
218 ProcHook::DEVICE,
219 ProcHook::KHR_bind_memory2,
220 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2KHR),
221 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2KHR),
222 },
223 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800224 "vkCreateAndroidSurfaceKHR",
225 ProcHook::INSTANCE,
226 ProcHook::KHR_android_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800227 reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800228 nullptr,
229 },
230 {
231 "vkCreateDebugReportCallbackEXT",
232 ProcHook::INSTANCE,
233 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800234 reinterpret_cast<PFN_vkVoidFunction>(CreateDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800235 nullptr,
236 },
237 {
238 "vkCreateDevice",
239 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700240 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800241 reinterpret_cast<PFN_vkVoidFunction>(CreateDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800242 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800243 },
244 {
245 "vkCreateInstance",
246 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700247 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800248 reinterpret_cast<PFN_vkVoidFunction>(CreateInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800249 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800250 },
251 {
252 "vkCreateSwapchainKHR",
253 ProcHook::DEVICE,
254 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800255 reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800256 reinterpret_cast<PFN_vkVoidFunction>(checkedCreateSwapchainKHR),
257 },
258 {
259 "vkDebugReportMessageEXT",
260 ProcHook::INSTANCE,
261 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800262 reinterpret_cast<PFN_vkVoidFunction>(DebugReportMessageEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800263 nullptr,
264 },
265 {
266 "vkDestroyDebugReportCallbackEXT",
267 ProcHook::INSTANCE,
268 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800269 reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800270 nullptr,
271 },
272 {
273 "vkDestroyDevice",
274 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700275 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800276 reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800277 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800278 },
279 {
280 "vkDestroyInstance",
281 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700282 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800283 reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800284 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800285 },
286 {
287 "vkDestroySurfaceKHR",
288 ProcHook::INSTANCE,
289 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800290 reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800291 nullptr,
292 },
293 {
294 "vkDestroySwapchainKHR",
295 ProcHook::DEVICE,
296 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800297 reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800298 reinterpret_cast<PFN_vkVoidFunction>(checkedDestroySwapchainKHR),
299 },
300 {
301 "vkEnumerateDeviceExtensionProperties",
302 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700303 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu01cf3052016-03-24 16:16:21 +0800304 reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties),
Chia-I Wueb7db122016-03-24 09:11:06 +0800305 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800306 },
307 {
308 "vkEnumerateInstanceExtensionProperties",
309 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700310 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800311 reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties),
312 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800313 },
314 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400315 "vkEnumeratePhysicalDeviceGroups",
316 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700317 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400318 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDeviceGroups),
319 nullptr,
320 },
321 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800322 "vkEnumeratePhysicalDevices",
323 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700324 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800325 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices),
Chia-I Wueb7db122016-03-24 09:11:06 +0800326 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800327 },
328 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400329 "vkGetDeviceGroupPresentCapabilitiesKHR",
330 ProcHook::DEVICE,
331 ProcHook::KHR_swapchain,
332 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupPresentCapabilitiesKHR),
333 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupPresentCapabilitiesKHR),
334 },
335 {
336 "vkGetDeviceGroupSurfacePresentModesKHR",
337 ProcHook::DEVICE,
338 ProcHook::KHR_swapchain,
339 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupSurfacePresentModesKHR),
340 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupSurfacePresentModesKHR),
341 },
342 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800343 "vkGetDeviceProcAddr",
344 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700345 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800346 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr),
347 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800348 },
349 {
350 "vkGetDeviceQueue",
351 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700352 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuba0be412016-03-24 16:24:40 +0800353 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue),
Chia-I Wueb7db122016-03-24 09:11:06 +0800354 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800355 },
356 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400357 "vkGetDeviceQueue2",
358 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700359 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400360 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700361 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceQueue2),
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400362 },
363 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800364 "vkGetInstanceProcAddr",
365 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700366 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800367 reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr),
368 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800369 },
370 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700371 "vkGetPastPresentationTimingGOOGLE",
372 ProcHook::DEVICE,
373 ProcHook::GOOGLE_display_timing,
374 reinterpret_cast<PFN_vkVoidFunction>(GetPastPresentationTimingGOOGLE),
375 reinterpret_cast<PFN_vkVoidFunction>(checkedGetPastPresentationTimingGOOGLE),
376 },
377 {
Yiwei Zhange1f35012020-07-05 22:52:04 -0700378 "vkGetPhysicalDeviceExternalBufferProperties",
379 ProcHook::INSTANCE,
380 ProcHook::EXTENSION_CORE_1_1,
381 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalBufferProperties),
382 nullptr,
383 },
384 {
385 "vkGetPhysicalDeviceExternalFenceProperties",
386 ProcHook::INSTANCE,
387 ProcHook::EXTENSION_CORE_1_1,
388 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalFenceProperties),
389 nullptr,
390 },
391 {
392 "vkGetPhysicalDeviceExternalSemaphoreProperties",
393 ProcHook::INSTANCE,
394 ProcHook::EXTENSION_CORE_1_1,
395 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalSemaphoreProperties),
396 nullptr,
397 },
398 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700399 "vkGetPhysicalDeviceFeatures2",
400 ProcHook::INSTANCE,
401 ProcHook::EXTENSION_CORE_1_1,
402 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures2),
403 nullptr,
404 },
405 {
406 "vkGetPhysicalDeviceFormatProperties2",
407 ProcHook::INSTANCE,
408 ProcHook::EXTENSION_CORE_1_1,
409 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties2),
410 nullptr,
411 },
412 {
413 "vkGetPhysicalDeviceImageFormatProperties2",
414 ProcHook::INSTANCE,
415 ProcHook::EXTENSION_CORE_1_1,
416 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties2),
417 nullptr,
418 },
419 {
420 "vkGetPhysicalDeviceMemoryProperties2",
421 ProcHook::INSTANCE,
422 ProcHook::EXTENSION_CORE_1_1,
423 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties2),
424 nullptr,
425 },
426 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400427 "vkGetPhysicalDevicePresentRectanglesKHR",
428 ProcHook::INSTANCE,
429 ProcHook::KHR_swapchain,
430 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
431 nullptr,
432 },
433 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700434 "vkGetPhysicalDeviceProperties2",
435 ProcHook::INSTANCE,
436 ProcHook::EXTENSION_CORE_1_1,
437 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties2),
438 nullptr,
439 },
440 {
441 "vkGetPhysicalDeviceQueueFamilyProperties2",
442 ProcHook::INSTANCE,
443 ProcHook::EXTENSION_CORE_1_1,
444 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties2),
445 nullptr,
446 },
447 {
448 "vkGetPhysicalDeviceSparseImageFormatProperties2",
449 ProcHook::INSTANCE,
450 ProcHook::EXTENSION_CORE_1_1,
451 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties2),
452 nullptr,
453 },
454 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300455 "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
456 ProcHook::INSTANCE,
457 ProcHook::KHR_get_surface_capabilities2,
458 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
459 nullptr,
460 },
461 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800462 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
463 ProcHook::INSTANCE,
464 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800465 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800466 nullptr,
467 },
468 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300469 "vkGetPhysicalDeviceSurfaceFormats2KHR",
470 ProcHook::INSTANCE,
471 ProcHook::KHR_get_surface_capabilities2,
472 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
473 nullptr,
474 },
475 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800476 "vkGetPhysicalDeviceSurfaceFormatsKHR",
477 ProcHook::INSTANCE,
478 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800479 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800480 nullptr,
481 },
482 {
483 "vkGetPhysicalDeviceSurfacePresentModesKHR",
484 ProcHook::INSTANCE,
485 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800486 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800487 nullptr,
488 },
489 {
490 "vkGetPhysicalDeviceSurfaceSupportKHR",
491 ProcHook::INSTANCE,
492 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800493 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800494 nullptr,
495 },
496 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700497 "vkGetRefreshCycleDurationGOOGLE",
498 ProcHook::DEVICE,
499 ProcHook::GOOGLE_display_timing,
500 reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
501 reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
502 },
503 {
Chris Forbes8e4438b2016-12-07 16:26:49 +1300504 "vkGetSwapchainGrallocUsage2ANDROID",
505 ProcHook::DEVICE,
506 ProcHook::ANDROID_native_buffer,
507 nullptr,
508 nullptr,
509 },
510 {
Trevor David Black2cc44682022-03-09 00:31:38 +0000511 "vkGetSwapchainGrallocUsage3ANDROID",
512 ProcHook::DEVICE,
513 ProcHook::ANDROID_native_buffer,
514 nullptr,
515 nullptr,
516 },
517 {
Trevor David Blackb6ca8422023-07-26 20:00:04 +0000518 "vkGetSwapchainGrallocUsage4ANDROID",
519 ProcHook::DEVICE,
520 ProcHook::ANDROID_native_buffer,
521 nullptr,
522 nullptr,
523 },
524 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800525 "vkGetSwapchainGrallocUsageANDROID",
526 ProcHook::DEVICE,
527 ProcHook::ANDROID_native_buffer,
528 nullptr,
529 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800530 },
531 {
532 "vkGetSwapchainImagesKHR",
533 ProcHook::DEVICE,
534 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800535 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800536 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
537 },
538 {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300539 "vkGetSwapchainStatusKHR",
540 ProcHook::DEVICE,
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300541 ProcHook::KHR_shared_presentable_image,
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300542 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
543 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
544 },
545 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800546 "vkQueuePresentKHR",
547 ProcHook::DEVICE,
548 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800549 reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800550 reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
551 },
552 {
553 "vkQueueSignalReleaseImageANDROID",
554 ProcHook::DEVICE,
555 ProcHook::ANDROID_native_buffer,
556 nullptr,
557 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800558 },
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700559 {
Yiwei Zhang899d1752019-09-23 16:05:35 -0700560 "vkQueueSubmit",
561 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700562 ProcHook::EXTENSION_CORE_1_0,
Yiwei Zhang899d1752019-09-23 16:05:35 -0700563 reinterpret_cast<PFN_vkVoidFunction>(QueueSubmit),
564 nullptr,
565 },
566 {
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000567 "vkReleaseSwapchainImagesEXT",
568 ProcHook::DEVICE,
569 ProcHook::EXT_swapchain_maintenance1,
570 reinterpret_cast<PFN_vkVoidFunction>(ReleaseSwapchainImagesEXT),
571 reinterpret_cast<PFN_vkVoidFunction>(checkedReleaseSwapchainImagesEXT),
572 },
573 {
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700574 "vkSetHdrMetadataEXT",
575 ProcHook::DEVICE,
576 ProcHook::EXT_hdr_metadata,
577 reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
578 reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
579 },
Chia-I Wueb7db122016-03-24 09:11:06 +0800580 // clang-format on
581};
582
Chris Forbese2d3ee12017-03-16 16:10:15 +1300583} // namespace
Chia-I Wueb7db122016-03-24 09:11:06 +0800584
585const ProcHook* GetProcHook(const char* name) {
Yiwei Zhang93b521c2020-07-11 16:32:09 -0700586 auto begin = std::cbegin(g_proc_hooks);
587 auto end = std::cend(g_proc_hooks);
588 auto hook = std::lower_bound(
Chia-I Wueb7db122016-03-24 09:11:06 +0800589 begin, end, name,
590 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
591 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
592}
593
594ProcHook::Extension GetProcHookExtension(const char* name) {
595 // clang-format off
596 if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
597 if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700598 if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700599 if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700600 if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
Ian Elliott2f7f0ff2022-02-18 16:44:58 -0700601 if (strcmp(name, "VK_GOOGLE_surfaceless_query") == 0) return ProcHook::GOOGLE_surfaceless_query;
Chia-I Wueb7db122016-03-24 09:11:06 +0800602 if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700603 if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
Chris Forbes48853712017-01-12 14:09:33 +1300604 if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700605 if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
Chia-I Wueb7db122016-03-24 09:11:06 +0800606 if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
Ian Elliott6fcbd072022-02-28 16:47:43 -0700607 if (strcmp(name, "VK_KHR_surface_protected_capabilities") == 0) return ProcHook::KHR_surface_protected_capabilities;
Chia-I Wueb7db122016-03-24 09:11:06 +0800608 if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000609 if (strcmp(name, "VK_EXT_swapchain_maintenance1") == 0) return ProcHook::EXT_swapchain_maintenance1;
610 if (strcmp(name, "VK_EXT_surface_maintenance1") == 0) return ProcHook::EXT_surface_maintenance1;
Jesse Halla8d367a2018-01-18 15:40:46 -0800611 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 -0700612 if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700613 if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
Yiwei Zhange4f64172020-07-05 15:17:32 -0700614 if (strcmp(name, "VK_KHR_device_group_creation") == 0) return ProcHook::KHR_device_group_creation;
Yiwei Zhange1f35012020-07-05 22:52:04 -0700615 if (strcmp(name, "VK_KHR_external_memory_capabilities") == 0) return ProcHook::KHR_external_memory_capabilities;
616 if (strcmp(name, "VK_KHR_external_semaphore_capabilities") == 0) return ProcHook::KHR_external_semaphore_capabilities;
617 if (strcmp(name, "VK_KHR_external_fence_capabilities") == 0) return ProcHook::KHR_external_fence_capabilities;
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000618 if (strcmp(name, "VK_KHR_external_fence_fd") == 0) return ProcHook::KHR_external_fence_fd;
Tom Murphyea321842024-06-14 18:26:58 +0000619 if (strcmp(name, "VK_KHR_swapchain_mutable_format") == 0) return ProcHook::KHR_swapchain_mutable_format;
Chia-I Wueb7db122016-03-24 09:11:06 +0800620 // clang-format on
621 return ProcHook::EXTENSION_UNKNOWN;
622}
623
Chia-I Wucc5e2762016-03-24 13:01:16 +0800624#define UNLIKELY(expr) __builtin_expect((expr), 0)
625
Chris Forbes5948b3e2016-12-23 13:49:53 +1300626#define INIT_PROC(required, obj, proc) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800627 do { \
628 data.driver.proc = \
629 reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300630 if (UNLIKELY(required && !data.driver.proc)) { \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800631 ALOGE("missing " #obj " proc: vk" #proc); \
632 success = false; \
633 } \
634 } while (0)
635
Chris Forbes5948b3e2016-12-23 13:49:53 +1300636#define INIT_PROC_EXT(ext, required, obj, proc) \
637 do { \
638 if (extensions[ProcHook::ext]) \
639 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800640 } while (0)
641
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800642bool InitDriverTable(VkInstance instance,
643 PFN_vkGetInstanceProcAddr get_proc,
644 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800645 auto& data = GetData(instance);
646 bool success = true;
647
648 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300649 INIT_PROC(true, instance, DestroyInstance);
650 INIT_PROC(true, instance, EnumeratePhysicalDevices);
651 INIT_PROC(true, instance, GetInstanceProcAddr);
Jesse Hall85bb0c52017-02-09 22:13:02 -0800652 INIT_PROC(true, instance, GetPhysicalDeviceProperties);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300653 INIT_PROC(true, instance, CreateDevice);
654 INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
655 INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
656 INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
657 INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700658 INIT_PROC(false, instance, GetPhysicalDeviceFeatures2);
659 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFeatures2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700660 INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
Chris Forbes6aa30db2017-02-20 17:12:53 +1300661 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700662 INIT_PROC(false, instance, GetPhysicalDeviceFormatProperties2);
663 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFormatProperties2KHR);
664 INIT_PROC(false, instance, GetPhysicalDeviceImageFormatProperties2);
665 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceImageFormatProperties2KHR);
666 INIT_PROC(false, instance, GetPhysicalDeviceQueueFamilyProperties2);
667 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceQueueFamilyProperties2KHR);
668 INIT_PROC(false, instance, GetPhysicalDeviceMemoryProperties2);
669 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceMemoryProperties2KHR);
670 INIT_PROC(false, instance, GetPhysicalDeviceSparseImageFormatProperties2);
671 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceSparseImageFormatProperties2KHR);
Yiwei Zhange1f35012020-07-05 22:52:04 -0700672 INIT_PROC(false, instance, GetPhysicalDeviceExternalBufferProperties);
673 INIT_PROC_EXT(KHR_external_memory_capabilities, true, instance, GetPhysicalDeviceExternalBufferPropertiesKHR);
674 INIT_PROC(false, instance, GetPhysicalDeviceExternalSemaphoreProperties);
675 INIT_PROC_EXT(KHR_external_semaphore_capabilities, true, instance, GetPhysicalDeviceExternalSemaphorePropertiesKHR);
676 INIT_PROC(false, instance, GetPhysicalDeviceExternalFenceProperties);
677 INIT_PROC_EXT(KHR_external_fence_capabilities, true, instance, GetPhysicalDeviceExternalFencePropertiesKHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700678 INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
Yiwei Zhange4f64172020-07-05 15:17:32 -0700679 INIT_PROC_EXT(KHR_device_group_creation, true, instance, EnumeratePhysicalDeviceGroupsKHR);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800680 // clang-format on
681
682 return success;
683}
684
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800685bool InitDriverTable(VkDevice dev,
686 PFN_vkGetDeviceProcAddr get_proc,
687 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800688 auto& data = GetData(dev);
689 bool success = true;
690
691 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300692 INIT_PROC(true, dev, GetDeviceProcAddr);
693 INIT_PROC(true, dev, DestroyDevice);
694 INIT_PROC(true, dev, GetDeviceQueue);
Yiwei Zhang899d1752019-09-23 16:05:35 -0700695 INIT_PROC(true, dev, QueueSubmit);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300696 INIT_PROC(true, dev, CreateImage);
697 INIT_PROC(true, dev, DestroyImage);
698 INIT_PROC(true, dev, AllocateCommandBuffers);
Chris Forbes9d0d9ff2022-12-28 01:58:31 +0000699 INIT_PROC_EXT(KHR_external_fence_fd, true, dev, ImportFenceFdKHR);
Yiwei Zhang23143102019-04-10 18:24:05 -0700700 INIT_PROC(false, dev, BindImageMemory2);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700701 INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR);
Ian Elliottcd8ad332017-10-13 09:21:12 -0600702 INIT_PROC(false, dev, GetDeviceQueue2);
Chris Forbesd8277912017-02-10 14:59:59 +1300703 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
Yiwei Zhang4bc489b2019-09-23 15:17:22 -0700704 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
Trevor David Black2cc44682022-03-09 00:31:38 +0000705 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage3ANDROID);
Trevor David Blackb6ca8422023-07-26 20:00:04 +0000706 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage4ANDROID);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300707 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
708 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800709 // clang-format on
710
711 return success;
712}
713
Yiwei Zhang7c0c07c2020-07-04 23:49:47 -0700714const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = {
715 // clang-format off
716 std::make_pair("VK_KHR_device_group_creation", VK_API_VERSION_1_1),
717 std::make_pair("VK_KHR_external_fence_capabilities", VK_API_VERSION_1_1),
718 std::make_pair("VK_KHR_external_memory_capabilities", VK_API_VERSION_1_1),
719 std::make_pair("VK_KHR_external_semaphore_capabilities", VK_API_VERSION_1_1),
720 std::make_pair("VK_KHR_get_physical_device_properties2", VK_API_VERSION_1_1),
721 // clang-format on
722};
723
724std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) {
725 auto begin = std::cbegin(g_promoted_instance_extensions);
726 auto end = std::cend(g_promoted_instance_extensions);
727 auto iter =
728 std::lower_bound(begin, end, name,
729 [](const std::pair<const char*, uint32_t>& e,
730 const char* n) { return strcmp(e.first, n) < 0; });
731 return (iter < end && strcmp(iter->first, name) == 0)
732 ? std::optional<uint32_t>(iter->second)
733 : std::nullopt;
734}
735
736uint32_t CountPromotedInstanceExtensions(uint32_t begin_version,
737 uint32_t end_version) {
738 auto begin = std::cbegin(g_promoted_instance_extensions);
739 auto end = std::cend(g_promoted_instance_extensions);
740 uint32_t count = 0;
741
742 for (auto iter = begin; iter != end; iter++)
743 if (iter->second > begin_version && iter->second <= end_version)
744 count++;
745
746 return count;
747}
748
749std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version,
750 uint32_t end_version) {
751 auto begin = std::cbegin(g_promoted_instance_extensions);
752 auto end = std::cend(g_promoted_instance_extensions);
753 std::vector<const char*> extensions;
754
755 for (auto iter = begin; iter != end; iter++)
756 if (iter->second > begin_version && iter->second <= end_version)
757 extensions.emplace_back(iter->first);
758
759 return extensions;
760}
761
Chia-I Wueb7db122016-03-24 09:11:06 +0800762} // namespace driver
763} // namespace vulkan