blob: 52205e9e79849018bfdfbe31bfefae5fed04c794 [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 {
Daniel Kochf25f5bb2017-10-05 00:26:58 -0400366 "vkGetPhysicalDevicePresentRectanglesKHR",
367 ProcHook::INSTANCE,
368 ProcHook::KHR_swapchain,
369 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
370 nullptr,
371 },
372 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300373 "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
374 ProcHook::INSTANCE,
375 ProcHook::KHR_get_surface_capabilities2,
376 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
377 nullptr,
378 },
379 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800380 "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
381 ProcHook::INSTANCE,
382 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800383 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800384 nullptr,
385 },
386 {
Chris Forbes2452cf72017-03-16 16:30:17 +1300387 "vkGetPhysicalDeviceSurfaceFormats2KHR",
388 ProcHook::INSTANCE,
389 ProcHook::KHR_get_surface_capabilities2,
390 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
391 nullptr,
392 },
393 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800394 "vkGetPhysicalDeviceSurfaceFormatsKHR",
395 ProcHook::INSTANCE,
396 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800397 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800398 nullptr,
399 },
400 {
401 "vkGetPhysicalDeviceSurfacePresentModesKHR",
402 ProcHook::INSTANCE,
403 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800404 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800405 nullptr,
406 },
407 {
408 "vkGetPhysicalDeviceSurfaceSupportKHR",
409 ProcHook::INSTANCE,
410 ProcHook::KHR_surface,
Chia-I Wu62262232016-03-26 07:06:44 +0800411 reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800412 nullptr,
413 },
414 {
Ian Elliott4c8bb2a2016-12-29 11:07:26 -0700415 "vkGetRefreshCycleDurationGOOGLE",
416 ProcHook::DEVICE,
417 ProcHook::GOOGLE_display_timing,
418 reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
419 reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
420 },
421 {
Chris Forbes8e4438b2016-12-07 16:26:49 +1300422 "vkGetSwapchainGrallocUsage2ANDROID",
423 ProcHook::DEVICE,
424 ProcHook::ANDROID_native_buffer,
425 nullptr,
426 nullptr,
427 },
428 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800429 "vkGetSwapchainGrallocUsageANDROID",
430 ProcHook::DEVICE,
431 ProcHook::ANDROID_native_buffer,
432 nullptr,
433 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800434 },
435 {
436 "vkGetSwapchainImagesKHR",
437 ProcHook::DEVICE,
438 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800439 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800440 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
441 },
442 {
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300443 "vkGetSwapchainStatusKHR",
444 ProcHook::DEVICE,
Chris Forbes1d5f68c2017-01-31 10:17:01 +1300445 ProcHook::KHR_shared_presentable_image,
Chris Forbes0f2ac2e2017-01-18 13:33:53 +1300446 reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
447 reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
448 },
449 {
Chia-I Wueb7db122016-03-24 09:11:06 +0800450 "vkQueuePresentKHR",
451 ProcHook::DEVICE,
452 ProcHook::KHR_swapchain,
Chia-I Wu62262232016-03-26 07:06:44 +0800453 reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
Chia-I Wueb7db122016-03-24 09:11:06 +0800454 reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
455 },
456 {
457 "vkQueueSignalReleaseImageANDROID",
458 ProcHook::DEVICE,
459 ProcHook::ANDROID_native_buffer,
460 nullptr,
461 nullptr,
Chia-I Wueb7db122016-03-24 09:11:06 +0800462 },
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700463 {
Yiwei Zhang899d1752019-09-23 16:05:35 -0700464 "vkQueueSubmit",
465 ProcHook::DEVICE,
Yiwei Zhang7cc36a52019-10-11 19:02:09 -0700466 ProcHook::EXTENSION_CORE_1_0,
Yiwei Zhang899d1752019-09-23 16:05:35 -0700467 reinterpret_cast<PFN_vkVoidFunction>(QueueSubmit),
468 nullptr,
469 },
470 {
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700471 "vkSetHdrMetadataEXT",
472 ProcHook::DEVICE,
473 ProcHook::EXT_hdr_metadata,
474 reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
475 reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
476 },
Chia-I Wueb7db122016-03-24 09:11:06 +0800477 // clang-format on
478};
479
Chris Forbese2d3ee12017-03-16 16:10:15 +1300480} // namespace
Chia-I Wueb7db122016-03-24 09:11:06 +0800481
482const ProcHook* GetProcHook(const char* name) {
483 const auto& begin = g_proc_hooks;
484 const auto& end =
485 g_proc_hooks + sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
486 const auto hook = std::lower_bound(
487 begin, end, name,
488 [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
489 return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
490}
491
492ProcHook::Extension GetProcHookExtension(const char* name) {
493 // clang-format off
494 if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
495 if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700496 if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700497 if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
Courtney Goeltzenleuchterd634c482017-01-05 15:55:31 -0700498 if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
Chia-I Wueb7db122016-03-24 09:11:06 +0800499 if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700500 if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
Chris Forbes48853712017-01-12 14:09:33 +1300501 if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
Courtney Goeltzenleuchtere278daf2017-02-02 16:54:57 -0700502 if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
Chia-I Wueb7db122016-03-24 09:11:06 +0800503 if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
504 if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
Jesse Halla8d367a2018-01-18 15:40:46 -0800505 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 -0700506 if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2;
Yiwei Zhangdc792f52019-10-10 16:29:42 -0700507 if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
Chia-I Wueb7db122016-03-24 09:11:06 +0800508 // clang-format on
509 return ProcHook::EXTENSION_UNKNOWN;
510}
511
Chia-I Wucc5e2762016-03-24 13:01:16 +0800512#define UNLIKELY(expr) __builtin_expect((expr), 0)
513
Chris Forbes5948b3e2016-12-23 13:49:53 +1300514#define INIT_PROC(required, obj, proc) \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800515 do { \
516 data.driver.proc = \
517 reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
Chris Forbes5948b3e2016-12-23 13:49:53 +1300518 if (UNLIKELY(required && !data.driver.proc)) { \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800519 ALOGE("missing " #obj " proc: vk" #proc); \
520 success = false; \
521 } \
522 } while (0)
523
Chris Forbes5948b3e2016-12-23 13:49:53 +1300524#define INIT_PROC_EXT(ext, required, obj, proc) \
525 do { \
526 if (extensions[ProcHook::ext]) \
527 INIT_PROC(required, obj, proc); \
Chia-I Wucc5e2762016-03-24 13:01:16 +0800528 } while (0)
529
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800530bool InitDriverTable(VkInstance instance,
531 PFN_vkGetInstanceProcAddr get_proc,
532 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800533 auto& data = GetData(instance);
534 bool success = true;
535
536 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300537 INIT_PROC(true, instance, DestroyInstance);
538 INIT_PROC(true, instance, EnumeratePhysicalDevices);
539 INIT_PROC(true, instance, GetInstanceProcAddr);
Jesse Hall85bb0c52017-02-09 22:13:02 -0800540 INIT_PROC(true, instance, GetPhysicalDeviceProperties);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300541 INIT_PROC(true, instance, CreateDevice);
542 INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
543 INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
544 INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
545 INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700546 INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
Chris Forbes6aa30db2017-02-20 17:12:53 +1300547 INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700548 INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800549 // clang-format on
550
551 return success;
552}
553
Chia-I Wucbe07ef2016-04-13 15:01:00 +0800554bool InitDriverTable(VkDevice dev,
555 PFN_vkGetDeviceProcAddr get_proc,
556 const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
Chia-I Wucc5e2762016-03-24 13:01:16 +0800557 auto& data = GetData(dev);
558 bool success = true;
559
560 // clang-format off
Chris Forbes5948b3e2016-12-23 13:49:53 +1300561 INIT_PROC(true, dev, GetDeviceProcAddr);
562 INIT_PROC(true, dev, DestroyDevice);
563 INIT_PROC(true, dev, GetDeviceQueue);
Yiwei Zhang899d1752019-09-23 16:05:35 -0700564 INIT_PROC(true, dev, QueueSubmit);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300565 INIT_PROC(true, dev, CreateImage);
566 INIT_PROC(true, dev, DestroyImage);
567 INIT_PROC(true, dev, AllocateCommandBuffers);
Yiwei Zhang23143102019-04-10 18:24:05 -0700568 INIT_PROC(false, dev, BindImageMemory2);
Adithya Srinivasan8dce9d72019-07-11 14:26:04 -0700569 INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR);
Ian Elliottcd8ad332017-10-13 09:21:12 -0600570 INIT_PROC(false, dev, GetDeviceQueue2);
Chris Forbesd8277912017-02-10 14:59:59 +1300571 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
Yiwei Zhang4bc489b2019-09-23 15:17:22 -0700572 INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
Chris Forbes5948b3e2016-12-23 13:49:53 +1300573 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
574 INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
Chia-I Wucc5e2762016-03-24 13:01:16 +0800575 // clang-format on
576
577 return success;
578}
579
Chia-I Wueb7db122016-03-24 09:11:06 +0800580} // namespace driver
581} // namespace vulkan