blob: de0ed60673be97e51d231b2f384e808a43527f45 [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 Zhanga55624b2020-07-05 16:05:26 -0700366 "vkGetPhysicalDeviceFeatures2",
367 ProcHook::INSTANCE,
368 ProcHook::EXTENSION_CORE_1_1,
369 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures2),
370 nullptr,
371 },
372 {
373 "vkGetPhysicalDeviceFormatProperties2",
374 ProcHook::INSTANCE,
375 ProcHook::EXTENSION_CORE_1_1,
376 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties2),
377 nullptr,
378 },
379 {
380 "vkGetPhysicalDeviceImageFormatProperties2",
381 ProcHook::INSTANCE,
382 ProcHook::EXTENSION_CORE_1_1,
383 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties2),
384 nullptr,
385 },
386 {
387 "vkGetPhysicalDeviceMemoryProperties2",
388 ProcHook::INSTANCE,
389 ProcHook::EXTENSION_CORE_1_1,
390 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties2),
391 nullptr,
392 },
393 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400394 "vkGetPhysicalDevicePresentRectanglesKHR",
395 ProcHook::INSTANCE,
396 ProcHook::KHR_swapchain,
397 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
398 nullptr,
399 },
400 {
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700401 "vkGetPhysicalDeviceProperties2",
402 ProcHook::INSTANCE,
403 ProcHook::EXTENSION_CORE_1_1,
404 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties2),
405 nullptr,
406 },
407 {
408 "vkGetPhysicalDeviceQueueFamilyProperties2",
409 ProcHook::INSTANCE,
410 ProcHook::EXTENSION_CORE_1_1,
411 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties2),
412 nullptr,
413 },
414 {
415 "vkGetPhysicalDeviceSparseImageFormatProperties2",
416 ProcHook::INSTANCE,
417 ProcHook::EXTENSION_CORE_1_1,
418 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties2),
419 nullptr,
420 },
421 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300422 "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
423 ProcHook::INSTANCE,
424 ProcHook::KHR_get_surface_capabilities2,
425 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
426 nullptr,
427 },
428 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800429 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
430 ProcHook::INSTANCE,
431 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800432 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800433 nullptr,
434 },
435 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300436 "vkGetPhysicalDeviceSurfaceFormats2KHR",
437 ProcHook::INSTANCE,
438 ProcHook::KHR_get_surface_capabilities2,
439 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
440 nullptr,
441 },
442 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800443 "vkGetPhysicalDeviceSurfaceFormatsKHR",
444 ProcHook::INSTANCE,
445 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800446 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800447 nullptr,
448 },
449 {
450 "vkGetPhysicalDeviceSurfacePresentModesKHR",
451 ProcHook::INSTANCE,
452 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800453 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800454 nullptr,
455 },
456 {
457 "vkGetPhysicalDeviceSurfaceSupportKHR",
458 ProcHook::INSTANCE,
459 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800460 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800461 nullptr,
462 },
463 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700464 "vkGetRefreshCycleDurationGOOGLE",
465 ProcHook::DEVICE,
466 ProcHook::GOOGLE_display_timing,
467 reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
468 reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
469 },
470 {
Chris Forbes8e4438b2016-12-07 16:26:49 +1300471 "vkGetSwapchainGrallocUsage2ANDROID",
472 ProcHook::DEVICE,
473 ProcHook::ANDROID_native_buffer,
474 nullptr,
475 nullptr,
476 },
477 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800478 "vkGetSwapchainGrallocUsageANDROID",
479 ProcHook::DEVICE,
480 ProcHook::ANDROID_native_buffer,
481 nullptr,
482 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800483 },
484 {
485 "vkGetSwapchainImagesKHR",
486 ProcHook::DEVICE,
487 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800488 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800489 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
490 },
491 {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300492 "vkGetSwapchainStatusKHR",
493 ProcHook::DEVICE,
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300494 ProcHook::KHR_shared_presentable_image,
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300495 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
496 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
497 },
498 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800499 "vkQueuePresentKHR",
500 ProcHook::DEVICE,
501 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800502 reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800503 reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
504 },
505 {
506 "vkQueueSignalReleaseImageANDROID",
507 ProcHook::DEVICE,
508 ProcHook::ANDROID_native_buffer,
509 nullptr,
510 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800511 },
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700512 {
Yiwei Zhang899d1752019-09-23 16:05:35 -0700513 "vkQueueSubmit",
514 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700515 ProcHook::EXTENSION_CORE_1_0,
Yiwei Zhang899d1752019-09-23 16:05:35 -0700516 reinterpret_cast<PFN_vkVoidFunction>(QueueSubmit),
517 nullptr,
518 },
519 {
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700520 "vkSetHdrMetadataEXT",
521 ProcHook::DEVICE,
522 ProcHook::EXT_hdr_metadata,
523 reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
524 reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
525 },
Chia-I Wueb7db122016-03-24 09:11:06 +0800526 // clang-format on
527};
528
Chris Forbese2d3ee12017-03-16 16:10:15 +1300529} // namespace
Chia-I Wueb7db122016-03-24 09:11:06 +0800530
531const ProcHook* GetProcHook(const char* name) {
532 const auto& begin = g_proc_hooks;
533 const auto& end =
534 g_proc_hooks + sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
535 const auto hook = std::lower_bound(
536 begin, end, name,
537 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
538 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
539}
540
541ProcHook::Extension GetProcHookExtension(const char* name) {
542 // clang-format off
543 if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
544 if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700545 if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700546 if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700547 if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
Chia-I Wueb7db122016-03-24 09:11:06 +0800548 if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700549 if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
Chris Forbes48853712017-01-12 14:09:33 +1300550 if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700551 if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
Chia-I Wueb7db122016-03-24 09:11:06 +0800552 if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
553 if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
Jesse Halla8d367a2018-01-18 15:40:46 -0800554 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 -0700555 if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700556 if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
Yiwei Zhange4f64172020-07-05 15:17:32 -0700557 if (strcmp(name, "VK_KHR_device_group_creation") == 0) return ProcHook::KHR_device_group_creation;
Chia-I Wueb7db122016-03-24 09:11:06 +0800558 // clang-format on
559 return ProcHook::EXTENSION_UNKNOWN;
560}
561
Chia-I Wucc5e2762016-03-24 13:01:16 +0800562#define UNLIKELY(expr) __builtin_expect((expr), 0)
563
Chris Forbes5948b3e2016-12-23 13:49:53 +1300564#define INIT_PROC(required, obj, proc) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800565 do { \
566 data.driver.proc = \
567 reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300568 if (UNLIKELY(required && !data.driver.proc)) { \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800569 ALOGE("missing " #obj " proc: vk" #proc); \
570 success = false; \
571 } \
572 } while (0)
573
Chris Forbes5948b3e2016-12-23 13:49:53 +1300574#define INIT_PROC_EXT(ext, required, obj, proc) \
575 do { \
576 if (extensions[ProcHook::ext]) \
577 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800578 } while (0)
579
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800580bool InitDriverTable(VkInstance instance,
581 PFN_vkGetInstanceProcAddr get_proc,
582 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800583 auto& data = GetData(instance);
584 bool success = true;
585
586 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300587 INIT_PROC(true, instance, DestroyInstance);
588 INIT_PROC(true, instance, EnumeratePhysicalDevices);
589 INIT_PROC(true, instance, GetInstanceProcAddr);
Jesse Hall85bb0c52017-02-09 22:13:02 -0800590 INIT_PROC(true, instance, GetPhysicalDeviceProperties);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300591 INIT_PROC(true, instance, CreateDevice);
592 INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
593 INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
594 INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
595 INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700596 INIT_PROC(false, instance, GetPhysicalDeviceFeatures2);
597 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFeatures2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700598 INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
Chris Forbes6aa30db2017-02-20 17:12:53 +1300599 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
Yiwei Zhanga55624b2020-07-05 16:05:26 -0700600 INIT_PROC(false, instance, GetPhysicalDeviceFormatProperties2);
601 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceFormatProperties2KHR);
602 INIT_PROC(false, instance, GetPhysicalDeviceImageFormatProperties2);
603 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceImageFormatProperties2KHR);
604 INIT_PROC(false, instance, GetPhysicalDeviceQueueFamilyProperties2);
605 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceQueueFamilyProperties2KHR);
606 INIT_PROC(false, instance, GetPhysicalDeviceMemoryProperties2);
607 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceMemoryProperties2KHR);
608 INIT_PROC(false, instance, GetPhysicalDeviceSparseImageFormatProperties2);
609 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceSparseImageFormatProperties2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700610 INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
Yiwei Zhange4f64172020-07-05 15:17:32 -0700611 INIT_PROC_EXT(KHR_device_group_creation, true, instance, EnumeratePhysicalDeviceGroupsKHR);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800612 // clang-format on
613
614 return success;
615}
616
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800617bool InitDriverTable(VkDevice dev,
618 PFN_vkGetDeviceProcAddr get_proc,
619 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800620 auto& data = GetData(dev);
621 bool success = true;
622
623 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300624 INIT_PROC(true, dev, GetDeviceProcAddr);
625 INIT_PROC(true, dev, DestroyDevice);
626 INIT_PROC(true, dev, GetDeviceQueue);
Yiwei Zhang899d1752019-09-23 16:05:35 -0700627 INIT_PROC(true, dev, QueueSubmit);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300628 INIT_PROC(true, dev, CreateImage);
629 INIT_PROC(true, dev, DestroyImage);
630 INIT_PROC(true, dev, AllocateCommandBuffers);
Yiwei Zhang23143102019-04-10 18:24:05 -0700631 INIT_PROC(false, dev, BindImageMemory2);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700632 INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR);
Ian Elliottcd8ad332017-10-13 09:21:12 -0600633 INIT_PROC(false, dev, GetDeviceQueue2);
Chris Forbesd8277912017-02-10 14:59:59 +1300634 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
Yiwei Zhang4bc489b2019-09-23 15:17:22 -0700635 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300636 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
637 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800638 // clang-format on
639
640 return success;
641}
642
Yiwei Zhang7c0c07c2020-07-04 23:49:47 -0700643const std::pair<const char*, uint32_t> g_promoted_instance_extensions[] = {
644 // clang-format off
645 std::make_pair("VK_KHR_device_group_creation", VK_API_VERSION_1_1),
646 std::make_pair("VK_KHR_external_fence_capabilities", VK_API_VERSION_1_1),
647 std::make_pair("VK_KHR_external_memory_capabilities", VK_API_VERSION_1_1),
648 std::make_pair("VK_KHR_external_semaphore_capabilities", VK_API_VERSION_1_1),
649 std::make_pair("VK_KHR_get_physical_device_properties2", VK_API_VERSION_1_1),
650 // clang-format on
651};
652
653std::optional<uint32_t> GetInstanceExtensionPromotedVersion(const char* name) {
654 auto begin = std::cbegin(g_promoted_instance_extensions);
655 auto end = std::cend(g_promoted_instance_extensions);
656 auto iter =
657 std::lower_bound(begin, end, name,
658 [](const std::pair<const char*, uint32_t>& e,
659 const char* n) { return strcmp(e.first, n) < 0; });
660 return (iter < end && strcmp(iter->first, name) == 0)
661 ? std::optional<uint32_t>(iter->second)
662 : std::nullopt;
663}
664
665uint32_t CountPromotedInstanceExtensions(uint32_t begin_version,
666 uint32_t end_version) {
667 auto begin = std::cbegin(g_promoted_instance_extensions);
668 auto end = std::cend(g_promoted_instance_extensions);
669 uint32_t count = 0;
670
671 for (auto iter = begin; iter != end; iter++)
672 if (iter->second > begin_version && iter->second <= end_version)
673 count++;
674
675 return count;
676}
677
678std::vector<const char*> GetPromotedInstanceExtensions(uint32_t begin_version,
679 uint32_t end_version) {
680 auto begin = std::cbegin(g_promoted_instance_extensions);
681 auto end = std::cend(g_promoted_instance_extensions);
682 std::vector<const char*> extensions;
683
684 for (auto iter = begin; iter != end; iter++)
685 if (iter->second > begin_version && iter->second <= end_version)
686 extensions.emplace_back(iter->first);
687
688 return extensions;
689}
690
Chia-I Wueb7db122016-03-24 09:11:06 +0800691} // namespace driver
692} // namespace vulkan