blob: 5f37a50a0346e456e4b5e820c271801ecc7dbfc1 [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
Chia-I Wueb7db122016-03-24 09:11:06 +0800165// clang-format on
166
167const ProcHook g_proc_hooks[] = {
168 // clang-format off
169 {
170 "vkAcquireImageANDROID",
171 ProcHook::DEVICE,
172 ProcHook::ANDROID_native_buffer,
173 nullptr,
174 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800175 },
176 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400177 "vkAcquireNextImage2KHR",
178 ProcHook::DEVICE,
179 ProcHook::KHR_swapchain,
180 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImage2KHR),
181 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImage2KHR),
182 },
183 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800184 "vkAcquireNextImageKHR",
185 ProcHook::DEVICE,
186 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800187 reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800188 reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImageKHR),
189 },
190 {
191 "vkAllocateCommandBuffers",
192 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700193 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu6a58a8a2016-03-24 16:29:51 +0800194 reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers),
Chia-I Wueb7db122016-03-24 09:11:06 +0800195 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800196 },
197 {
Yiwei Zhang23143102019-04-10 18:24:05 -0700198 "vkBindImageMemory2",
199 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700200 ProcHook::EXTENSION_CORE_1_1,
Yiwei Zhang23143102019-04-10 18:24:05 -0700201 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700202 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2),
Yiwei Zhang23143102019-04-10 18:24:05 -0700203 },
204 {
205 "vkBindImageMemory2KHR",
206 ProcHook::DEVICE,
207 ProcHook::KHR_bind_memory2,
208 reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2KHR),
209 reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2KHR),
210 },
211 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800212 "vkCreateAndroidSurfaceKHR",
213 ProcHook::INSTANCE,
214 ProcHook::KHR_android_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800215 reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800216 nullptr,
217 },
218 {
219 "vkCreateDebugReportCallbackEXT",
220 ProcHook::INSTANCE,
221 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800222 reinterpret_cast<PFN_vkVoidFunction>(CreateDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800223 nullptr,
224 },
225 {
226 "vkCreateDevice",
227 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700228 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800229 reinterpret_cast<PFN_vkVoidFunction>(CreateDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800230 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800231 },
232 {
233 "vkCreateInstance",
234 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700235 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800236 reinterpret_cast<PFN_vkVoidFunction>(CreateInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800237 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800238 },
239 {
240 "vkCreateSwapchainKHR",
241 ProcHook::DEVICE,
242 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800243 reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800244 reinterpret_cast<PFN_vkVoidFunction>(checkedCreateSwapchainKHR),
245 },
246 {
247 "vkDebugReportMessageEXT",
248 ProcHook::INSTANCE,
249 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800250 reinterpret_cast<PFN_vkVoidFunction>(DebugReportMessageEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800251 nullptr,
252 },
253 {
254 "vkDestroyDebugReportCallbackEXT",
255 ProcHook::INSTANCE,
256 ProcHook::EXT_debug_report,
Chia-I Wu62262232016-03-26 07:06:44 +0800257 reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugReportCallbackEXT),
Chia-I Wueb7db122016-03-24 09:11:06 +0800258 nullptr,
259 },
260 {
261 "vkDestroyDevice",
262 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700263 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu4901db72016-03-24 16:38:58 +0800264 reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice),
Chia-I Wueb7db122016-03-24 09:11:06 +0800265 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800266 },
267 {
268 "vkDestroyInstance",
269 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700270 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800271 reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance),
Chia-I Wueb7db122016-03-24 09:11:06 +0800272 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800273 },
274 {
275 "vkDestroySurfaceKHR",
276 ProcHook::INSTANCE,
277 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800278 reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800279 nullptr,
280 },
281 {
282 "vkDestroySwapchainKHR",
283 ProcHook::DEVICE,
284 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800285 reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800286 reinterpret_cast<PFN_vkVoidFunction>(checkedDestroySwapchainKHR),
287 },
288 {
289 "vkEnumerateDeviceExtensionProperties",
290 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700291 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wu01cf3052016-03-24 16:16:21 +0800292 reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties),
Chia-I Wueb7db122016-03-24 09:11:06 +0800293 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800294 },
295 {
296 "vkEnumerateInstanceExtensionProperties",
297 ProcHook::GLOBAL,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700298 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800299 reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties),
300 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800301 },
302 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400303 "vkEnumeratePhysicalDeviceGroups",
304 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700305 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400306 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDeviceGroups),
307 nullptr,
308 },
309 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800310 "vkEnumeratePhysicalDevices",
311 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700312 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuff4a6c72016-03-24 16:05:56 +0800313 reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices),
Chia-I Wueb7db122016-03-24 09:11:06 +0800314 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800315 },
316 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400317 "vkGetDeviceGroupPresentCapabilitiesKHR",
318 ProcHook::DEVICE,
319 ProcHook::KHR_swapchain,
320 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupPresentCapabilitiesKHR),
321 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupPresentCapabilitiesKHR),
322 },
323 {
324 "vkGetDeviceGroupSurfacePresentModesKHR",
325 ProcHook::DEVICE,
326 ProcHook::KHR_swapchain,
327 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupSurfacePresentModesKHR),
328 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupSurfacePresentModesKHR),
329 },
330 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800331 "vkGetDeviceProcAddr",
332 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700333 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800334 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr),
335 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800336 },
337 {
338 "vkGetDeviceQueue",
339 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700340 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wuba0be412016-03-24 16:24:40 +0800341 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue),
Chia-I Wueb7db122016-03-24 09:11:06 +0800342 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800343 },
344 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400345 "vkGetDeviceQueue2",
346 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700347 ProcHook::EXTENSION_CORE_1_1,
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400348 reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue2),
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700349 reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceQueue2),
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400350 },
351 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800352 "vkGetInstanceProcAddr",
353 ProcHook::INSTANCE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700354 ProcHook::EXTENSION_CORE_1_0,
Chia-I Wueb7db122016-03-24 09:11:06 +0800355 reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr),
356 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800357 },
358 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700359 "vkGetPastPresentationTimingGOOGLE",
360 ProcHook::DEVICE,
361 ProcHook::GOOGLE_display_timing,
362 reinterpret_cast<PFN_vkVoidFunction>(GetPastPresentationTimingGOOGLE),
363 reinterpret_cast<PFN_vkVoidFunction>(checkedGetPastPresentationTimingGOOGLE),
364 },
365 {
Yiwei Zhange1f35012020-07-05 22:52:04 -0700366 "vkGetPhysicalDeviceExternalBufferProperties",
367 ProcHook::INSTANCE,
368 ProcHook::EXTENSION_CORE_1_1,
369 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalBufferProperties),
370 nullptr,
371 },
372 {
373 "vkGetPhysicalDeviceExternalFenceProperties",
374 ProcHook::INSTANCE,
375 ProcHook::EXTENSION_CORE_1_1,
376 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalFenceProperties),
377 nullptr,
378 },
379 {
380 "vkGetPhysicalDeviceExternalSemaphoreProperties",
381 ProcHook::INSTANCE,
382 ProcHook::EXTENSION_CORE_1_1,
383 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceExternalSemaphoreProperties),
384 nullptr,
385 },
386 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700387 "vkGetPhysicalDeviceFeatures2",
388 ProcHook::INSTANCE,
389 ProcHook::EXTENSION_CORE_1_1,
390 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures2),
391 nullptr,
392 },
393 {
394 "vkGetPhysicalDeviceFormatProperties2",
395 ProcHook::INSTANCE,
396 ProcHook::EXTENSION_CORE_1_1,
397 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties2),
398 nullptr,
399 },
400 {
401 "vkGetPhysicalDeviceImageFormatProperties2",
402 ProcHook::INSTANCE,
403 ProcHook::EXTENSION_CORE_1_1,
404 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties2),
405 nullptr,
406 },
407 {
408 "vkGetPhysicalDeviceMemoryProperties2",
409 ProcHook::INSTANCE,
410 ProcHook::EXTENSION_CORE_1_1,
411 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties2),
412 nullptr,
413 },
414 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400415 "vkGetPhysicalDevicePresentRectanglesKHR",
416 ProcHook::INSTANCE,
417 ProcHook::KHR_swapchain,
418 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
419 nullptr,
420 },
421 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700422 "vkGetPhysicalDeviceProperties2",
423 ProcHook::INSTANCE,
424 ProcHook::EXTENSION_CORE_1_1,
425 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties2),
426 nullptr,
427 },
428 {
429 "vkGetPhysicalDeviceQueueFamilyProperties2",
430 ProcHook::INSTANCE,
431 ProcHook::EXTENSION_CORE_1_1,
432 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties2),
433 nullptr,
434 },
435 {
436 "vkGetPhysicalDeviceSparseImageFormatProperties2",
437 ProcHook::INSTANCE,
438 ProcHook::EXTENSION_CORE_1_1,
439 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties2),
440 nullptr,
441 },
442 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300443 "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
444 ProcHook::INSTANCE,
445 ProcHook::KHR_get_surface_capabilities2,
446 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
447 nullptr,
448 },
449 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800450 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
451 ProcHook::INSTANCE,
452 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800453 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800454 nullptr,
455 },
456 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300457 "vkGetPhysicalDeviceSurfaceFormats2KHR",
458 ProcHook::INSTANCE,
459 ProcHook::KHR_get_surface_capabilities2,
460 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
461 nullptr,
462 },
463 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800464 "vkGetPhysicalDeviceSurfaceFormatsKHR",
465 ProcHook::INSTANCE,
466 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800467 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800468 nullptr,
469 },
470 {
471 "vkGetPhysicalDeviceSurfacePresentModesKHR",
472 ProcHook::INSTANCE,
473 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800474 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800475 nullptr,
476 },
477 {
478 "vkGetPhysicalDeviceSurfaceSupportKHR",
479 ProcHook::INSTANCE,
480 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800481 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800482 nullptr,
483 },
484 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700485 "vkGetRefreshCycleDurationGOOGLE",
486 ProcHook::DEVICE,
487 ProcHook::GOOGLE_display_timing,
488 reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
489 reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
490 },
491 {
Chris Forbes8e4438b2016-12-07 16:26:49 +1300492 "vkGetSwapchainGrallocUsage2ANDROID",
493 ProcHook::DEVICE,
494 ProcHook::ANDROID_native_buffer,
495 nullptr,
496 nullptr,
497 },
498 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800499 "vkGetSwapchainGrallocUsageANDROID",
500 ProcHook::DEVICE,
501 ProcHook::ANDROID_native_buffer,
502 nullptr,
503 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800504 },
505 {
506 "vkGetSwapchainImagesKHR",
507 ProcHook::DEVICE,
508 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800509 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800510 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
511 },
512 {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300513 "vkGetSwapchainStatusKHR",
514 ProcHook::DEVICE,
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300515 ProcHook::KHR_shared_presentable_image,
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300516 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
517 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
518 },
519 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800520 "vkQueuePresentKHR",
521 ProcHook::DEVICE,
522 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800523 reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800524 reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
525 },
526 {
527 "vkQueueSignalReleaseImageANDROID",
528 ProcHook::DEVICE,
529 ProcHook::ANDROID_native_buffer,
530 nullptr,
531 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800532 },
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700533 {
Yiwei Zhang899d1752019-09-23 16:05:35 -0700534 "vkQueueSubmit",
535 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700536 ProcHook::EXTENSION_CORE_1_0,
Yiwei Zhang899d1752019-09-23 16:05:35 -0700537 reinterpret_cast<PFN_vkVoidFunction>(QueueSubmit),
538 nullptr,
539 },
540 {
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700541 "vkSetHdrMetadataEXT",
542 ProcHook::DEVICE,
543 ProcHook::EXT_hdr_metadata,
544 reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
545 reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
546 },
Chia-I Wueb7db122016-03-24 09:11:06 +0800547 // clang-format on
548};
549
Chris Forbese2d3ee12017-03-16 16:10:15 +1300550} // namespace
Chia-I Wueb7db122016-03-24 09:11:06 +0800551
552const ProcHook* GetProcHook(const char* name) {
Yiwei Zhang93b521c2020-07-11 16:32:09 -0700553 auto begin = std::cbegin(g_proc_hooks);
554 auto end = std::cend(g_proc_hooks);
555 auto hook = std::lower_bound(
Chia-I Wueb7db122016-03-24 09:11:06 +0800556 begin, end, name,
557 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
558 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
559}
560
561ProcHook::Extension GetProcHookExtension(const char* name) {
562 // clang-format off
563 if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
564 if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700565 if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700566 if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700567 if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
Chia-I Wueb7db122016-03-24 09:11:06 +0800568 if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700569 if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
Chris Forbes48853712017-01-12 14:09:33 +1300570 if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700571 if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
Chia-I Wueb7db122016-03-24 09:11:06 +0800572 if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
573 if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
Jesse Halla8d367a2018-01-18 15:40:46 -0800574 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 -0700575 if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700576 if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
Yiwei Zhange4f64172020-07-05 15:17:32 -0700577 if (strcmp(name, "VK_KHR_device_group_creation") == 0) return ProcHook::KHR_device_group_creation;
Yiwei Zhange1f35012020-07-05 22:52:04 -0700578 if (strcmp(name, "VK_KHR_external_memory_capabilities") == 0) return ProcHook::KHR_external_memory_capabilities;
579 if (strcmp(name, "VK_KHR_external_semaphore_capabilities") == 0) return ProcHook::KHR_external_semaphore_capabilities;
580 if (strcmp(name, "VK_KHR_external_fence_capabilities") == 0) return ProcHook::KHR_external_fence_capabilities;
Chia-I Wueb7db122016-03-24 09:11:06 +0800581 // clang-format on
582 return ProcHook::EXTENSION_UNKNOWN;
583}
584
Chia-I Wucc5e2762016-03-24 13:01:16 +0800585#define UNLIKELY(expr) __builtin_expect((expr), 0)
586
Chris Forbes5948b3e2016-12-23 13:49:53 +1300587#define INIT_PROC(required, obj, proc) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800588 do { \
589 data.driver.proc = \
590 reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300591 if (UNLIKELY(required && !data.driver.proc)) { \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800592 ALOGE("missing " #obj " proc: vk" #proc); \
593 success = false; \
594 } \
595 } while (0)
596
Chris Forbes5948b3e2016-12-23 13:49:53 +1300597#define INIT_PROC_EXT(ext, required, obj, proc) \
598 do { \
599 if (extensions[ProcHook::ext]) \
600 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800601 } while (0)
602
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800603bool InitDriverTable(VkInstance instance,
604 PFN_vkGetInstanceProcAddr get_proc,
605 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800606 auto& data = GetData(instance);
607 bool success = true;
608
609 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300610 INIT_PROC(true, instance, DestroyInstance);
611 INIT_PROC(true, instance, EnumeratePhysicalDevices);
612 INIT_PROC(true, instance, GetInstanceProcAddr);
Jesse Hall85bb0c52017-02-09 22:13:02 -0800613 INIT_PROC(true, instance, GetPhysicalDeviceProperties);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300614 INIT_PROC(true, instance, CreateDevice);
615 INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
616 INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
617 INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
618 INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700619 INIT_PROC(false, instance, GetPhysicalDeviceFeatures2);
620 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFeatures2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700621 INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
Chris Forbes6aa30db2017-02-20 17:12:53 +1300622 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700623 INIT_PROC(false, instance, GetPhysicalDeviceFormatProperties2);
624 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFormatProperties2KHR);
625 INIT_PROC(false, instance, GetPhysicalDeviceImageFormatProperties2);
626 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceImageFormatProperties2KHR);
627 INIT_PROC(false, instance, GetPhysicalDeviceQueueFamilyProperties2);
628 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceQueueFamilyProperties2KHR);
629 INIT_PROC(false, instance, GetPhysicalDeviceMemoryProperties2);
630 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceMemoryProperties2KHR);
631 INIT_PROC(false, instance, GetPhysicalDeviceSparseImageFormatProperties2);
632 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceSparseImageFormatProperties2KHR);
Yiwei Zhange1f35012020-07-05 22:52:04 -0700633 INIT_PROC(false, instance, GetPhysicalDeviceExternalBufferProperties);
634 INIT_PROC_EXT(KHR_external_memory_capabilities, true, instance, GetPhysicalDeviceExternalBufferPropertiesKHR);
635 INIT_PROC(false, instance, GetPhysicalDeviceExternalSemaphoreProperties);
636 INIT_PROC_EXT(KHR_external_semaphore_capabilities, true, instance, GetPhysicalDeviceExternalSemaphorePropertiesKHR);
637 INIT_PROC(false, instance, GetPhysicalDeviceExternalFenceProperties);
638 INIT_PROC_EXT(KHR_external_fence_capabilities, true, instance, GetPhysicalDeviceExternalFencePropertiesKHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700639 INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
Yiwei Zhange4f64172020-07-05 15:17:32 -0700640 INIT_PROC_EXT(KHR_device_group_creation, true, instance, EnumeratePhysicalDeviceGroupsKHR);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800641 // clang-format on
642
643 return success;
644}
645
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800646bool InitDriverTable(VkDevice dev,
647 PFN_vkGetDeviceProcAddr get_proc,
648 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800649 auto& data = GetData(dev);
650 bool success = true;
651
652 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300653 INIT_PROC(true, dev, GetDeviceProcAddr);
654 INIT_PROC(true, dev, DestroyDevice);
655 INIT_PROC(true, dev, GetDeviceQueue);
Yiwei Zhang899d1752019-09-23 16:05:35 -0700656 INIT_PROC(true, dev, QueueSubmit);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300657 INIT_PROC(true, dev, CreateImage);
658 INIT_PROC(true, dev, DestroyImage);
659 INIT_PROC(true, dev, AllocateCommandBuffers);
Yiwei Zhang23143102019-04-10 18:24:05 -0700660 INIT_PROC(false, dev, BindImageMemory2);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700661 INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR);
Ian Elliottcd8ad332017-10-13 09:21:12 -0600662 INIT_PROC(false, dev, GetDeviceQueue2);
Chris Forbesd8277912017-02-10 14:59:59 +1300663 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
Yiwei Zhang4bc489b2019-09-23 15:17:22 -0700664 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300665 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
666 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800667 // clang-format on
668
669 return success;
670}
671
Yiwei Zhang7c0c07c2020-07-04 23:49:47 -0700672const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = {
673 // clang-format off
674 std::make_pair("VK_KHR_device_group_creation", VK_API_VERSION_1_1),
675 std::make_pair("VK_KHR_external_fence_capabilities", VK_API_VERSION_1_1),
676 std::make_pair("VK_KHR_external_memory_capabilities", VK_API_VERSION_1_1),
677 std::make_pair("VK_KHR_external_semaphore_capabilities", VK_API_VERSION_1_1),
678 std::make_pair("VK_KHR_get_physical_device_properties2", VK_API_VERSION_1_1),
679 // clang-format on
680};
681
682std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) {
683 auto begin = std::cbegin(g_promoted_instance_extensions);
684 auto end = std::cend(g_promoted_instance_extensions);
685 auto iter =
686 std::lower_bound(begin, end, name,
687 [](const std::pair<const char*, uint32_t>& e,
688 const char* n) { return strcmp(e.first, n) < 0; });
689 return (iter < end && strcmp(iter->first, name) == 0)
690 ? std::optional<uint32_t>(iter->second)
691 : std::nullopt;
692}
693
694uint32_t CountPromotedInstanceExtensions(uint32_t begin_version,
695 uint32_t end_version) {
696 auto begin = std::cbegin(g_promoted_instance_extensions);
697 auto end = std::cend(g_promoted_instance_extensions);
698 uint32_t count = 0;
699
700 for (auto iter = begin; iter != end; iter++)
701 if (iter->second > begin_version && iter->second <= end_version)
702 count++;
703
704 return count;
705}
706
707std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version,
708 uint32_t end_version) {
709 auto begin = std::cbegin(g_promoted_instance_extensions);
710 auto end = std::cend(g_promoted_instance_extensions);
711 std::vector<const char*> extensions;
712
713 for (auto iter = begin; iter != end; iter++)
714 if (iter->second > begin_version && iter->second <= end_version)
715 extensions.emplace_back(iter->first);
716
717 return extensions;
718}
719
Chia-I Wueb7db122016-03-24 09:11:06 +0800720} // namespace driver
721} // namespace vulkan