• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 #include <string.h>
20 
21 #include <algorithm>
22 
23 #include <log/log.h>
24 
25 #include "driver.h"
26 
27 namespace vulkan {
28 namespace driver {
29 
30 namespace {
31 
32 // clang-format off
33 
checkedCreateSwapchainKHR(VkDevice device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain)34 VKAPI_ATTR VkResult checkedCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
35     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
36         return CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
37     } else {
38         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
39         return VK_SUCCESS;
40     }
41 }
42 
checkedDestroySwapchainKHR(VkDevice device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)43 VKAPI_ATTR void checkedDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator) {
44     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
45         DestroySwapchainKHR(device, swapchain, pAllocator);
46     } else {
47         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
48     }
49 }
50 
checkedGetSwapchainImagesKHR(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pSwapchainImageCount,VkImage * pSwapchainImages)51 VKAPI_ATTR VkResult checkedGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) {
52     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
53         return GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
54     } else {
55         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
56         return VK_SUCCESS;
57     }
58 }
59 
checkedAcquireNextImageKHR(VkDevice device,VkSwapchainKHR swapchain,uint64_t timeout,VkSemaphore semaphore,VkFence fence,uint32_t * pImageIndex)60 VKAPI_ATTR VkResult checkedAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex) {
61     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
62         return AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
63     } else {
64         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
65         return VK_SUCCESS;
66     }
67 }
68 
checkedQueuePresentKHR(VkQueue queue,const VkPresentInfoKHR * pPresentInfo)69 VKAPI_ATTR VkResult checkedQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
70     if (GetData(queue).hook_extensions[ProcHook::KHR_swapchain]) {
71         return QueuePresentKHR(queue, pPresentInfo);
72     } else {
73         Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
74         return VK_SUCCESS;
75     }
76 }
77 
checkedGetDeviceGroupPresentCapabilitiesKHR(VkDevice device,VkDeviceGroupPresentCapabilitiesKHR * pDeviceGroupPresentCapabilities)78 VKAPI_ATTR VkResult checkedGetDeviceGroupPresentCapabilitiesKHR(VkDevice device, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
79     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
80         return GetDeviceGroupPresentCapabilitiesKHR(device, pDeviceGroupPresentCapabilities);
81     } else {
82         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupPresentCapabilitiesKHR not executed.");
83         return VK_SUCCESS;
84     }
85 }
86 
checkedGetDeviceGroupSurfacePresentModesKHR(VkDevice device,VkSurfaceKHR surface,VkDeviceGroupPresentModeFlagsKHR * pModes)87 VKAPI_ATTR VkResult checkedGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR* pModes) {
88     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
89         return GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
90     } else {
91         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetDeviceGroupSurfacePresentModesKHR not executed.");
92         return VK_SUCCESS;
93     }
94 }
95 
checkedAcquireNextImage2KHR(VkDevice device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex)96 VKAPI_ATTR VkResult checkedAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex) {
97     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
98         return AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
99     } else {
100         Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImage2KHR not executed.");
101         return VK_SUCCESS;
102     }
103 }
104 
checkedGetRefreshCycleDurationGOOGLE(VkDevice device,VkSwapchainKHR swapchain,VkRefreshCycleDurationGOOGLE * pDisplayTimingProperties)105 VKAPI_ATTR VkResult checkedGetRefreshCycleDurationGOOGLE(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties) {
106     if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
107         return GetRefreshCycleDurationGOOGLE(device, swapchain, pDisplayTimingProperties);
108     } else {
109         Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetRefreshCycleDurationGOOGLE not executed.");
110         return VK_SUCCESS;
111     }
112 }
113 
checkedGetPastPresentationTimingGOOGLE(VkDevice device,VkSwapchainKHR swapchain,uint32_t * pPresentationTimingCount,VkPastPresentationTimingGOOGLE * pPresentationTimings)114 VKAPI_ATTR VkResult checkedGetPastPresentationTimingGOOGLE(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings) {
115     if (GetData(device).hook_extensions[ProcHook::GOOGLE_display_timing]) {
116         return GetPastPresentationTimingGOOGLE(device, swapchain, pPresentationTimingCount, pPresentationTimings);
117     } else {
118         Logger(device).Err(device, "VK_GOOGLE_display_timing not enabled. vkGetPastPresentationTimingGOOGLE not executed.");
119         return VK_SUCCESS;
120     }
121 }
122 
checkedSetHdrMetadataEXT(VkDevice device,uint32_t swapchainCount,const VkSwapchainKHR * pSwapchains,const VkHdrMetadataEXT * pMetadata)123 VKAPI_ATTR void checkedSetHdrMetadataEXT(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata) {
124     if (GetData(device).hook_extensions[ProcHook::EXT_hdr_metadata]) {
125         SetHdrMetadataEXT(device, swapchainCount, pSwapchains, pMetadata);
126     } else {
127         Logger(device).Err(device, "VK_EXT_hdr_metadata not enabled. vkSetHdrMetadataEXT not executed.");
128     }
129 }
130 
checkedGetSwapchainStatusKHR(VkDevice device,VkSwapchainKHR swapchain)131 VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapchain) {
132     if (GetData(device).hook_extensions[ProcHook::KHR_shared_presentable_image]) {
133         return GetSwapchainStatusKHR(device, swapchain);
134     } else {
135         Logger(device).Err(device, "VK_KHR_shared_presentable_image not enabled. vkGetSwapchainStatusKHR not executed.");
136         return VK_SUCCESS;
137     }
138 }
139 
140 // clang-format on
141 
142 const ProcHook g_proc_hooks[] = {
143     // clang-format off
144     {
145         "vkAcquireImageANDROID",
146         ProcHook::DEVICE,
147         ProcHook::ANDROID_native_buffer,
148         nullptr,
149         nullptr,
150     },
151     {
152         "vkAcquireNextImage2KHR",
153         ProcHook::DEVICE,
154         ProcHook::KHR_swapchain,
155         reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImage2KHR),
156         reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImage2KHR),
157     },
158     {
159         "vkAcquireNextImageKHR",
160         ProcHook::DEVICE,
161         ProcHook::KHR_swapchain,
162         reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR),
163         reinterpret_cast<PFN_vkVoidFunction>(checkedAcquireNextImageKHR),
164     },
165     {
166         "vkAllocateCommandBuffers",
167         ProcHook::DEVICE,
168         ProcHook::EXTENSION_CORE,
169         reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers),
170         nullptr,
171     },
172     {
173         "vkCreateAndroidSurfaceKHR",
174         ProcHook::INSTANCE,
175         ProcHook::KHR_android_surface,
176         reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR),
177         nullptr,
178     },
179     {
180         "vkCreateDebugReportCallbackEXT",
181         ProcHook::INSTANCE,
182         ProcHook::EXT_debug_report,
183         reinterpret_cast<PFN_vkVoidFunction>(CreateDebugReportCallbackEXT),
184         nullptr,
185     },
186     {
187         "vkCreateDevice",
188         ProcHook::INSTANCE,
189         ProcHook::EXTENSION_CORE,
190         reinterpret_cast<PFN_vkVoidFunction>(CreateDevice),
191         nullptr,
192     },
193     {
194         "vkCreateInstance",
195         ProcHook::GLOBAL,
196         ProcHook::EXTENSION_CORE,
197         reinterpret_cast<PFN_vkVoidFunction>(CreateInstance),
198         nullptr,
199     },
200     {
201         "vkCreateSwapchainKHR",
202         ProcHook::DEVICE,
203         ProcHook::KHR_swapchain,
204         reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR),
205         reinterpret_cast<PFN_vkVoidFunction>(checkedCreateSwapchainKHR),
206     },
207     {
208         "vkDebugReportMessageEXT",
209         ProcHook::INSTANCE,
210         ProcHook::EXT_debug_report,
211         reinterpret_cast<PFN_vkVoidFunction>(DebugReportMessageEXT),
212         nullptr,
213     },
214     {
215         "vkDestroyDebugReportCallbackEXT",
216         ProcHook::INSTANCE,
217         ProcHook::EXT_debug_report,
218         reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugReportCallbackEXT),
219         nullptr,
220     },
221     {
222         "vkDestroyDevice",
223         ProcHook::DEVICE,
224         ProcHook::EXTENSION_CORE,
225         reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice),
226         nullptr,
227     },
228     {
229         "vkDestroyInstance",
230         ProcHook::INSTANCE,
231         ProcHook::EXTENSION_CORE,
232         reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance),
233         nullptr,
234     },
235     {
236         "vkDestroySurfaceKHR",
237         ProcHook::INSTANCE,
238         ProcHook::KHR_surface,
239         reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR),
240         nullptr,
241     },
242     {
243         "vkDestroySwapchainKHR",
244         ProcHook::DEVICE,
245         ProcHook::KHR_swapchain,
246         reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR),
247         reinterpret_cast<PFN_vkVoidFunction>(checkedDestroySwapchainKHR),
248     },
249     {
250         "vkEnumerateDeviceExtensionProperties",
251         ProcHook::INSTANCE,
252         ProcHook::EXTENSION_CORE,
253         reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties),
254         nullptr,
255     },
256     {
257         "vkEnumerateInstanceExtensionProperties",
258         ProcHook::GLOBAL,
259         ProcHook::EXTENSION_CORE,
260         reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties),
261         nullptr,
262     },
263     {
264         "vkEnumeratePhysicalDeviceGroups",
265         ProcHook::INSTANCE,
266         ProcHook::EXTENSION_CORE,
267         reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDeviceGroups),
268         nullptr,
269     },
270     {
271         "vkEnumeratePhysicalDevices",
272         ProcHook::INSTANCE,
273         ProcHook::EXTENSION_CORE,
274         reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices),
275         nullptr,
276     },
277     {
278         "vkGetDeviceGroupPresentCapabilitiesKHR",
279         ProcHook::DEVICE,
280         ProcHook::KHR_swapchain,
281         reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupPresentCapabilitiesKHR),
282         reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupPresentCapabilitiesKHR),
283     },
284     {
285         "vkGetDeviceGroupSurfacePresentModesKHR",
286         ProcHook::DEVICE,
287         ProcHook::KHR_swapchain,
288         reinterpret_cast<PFN_vkVoidFunction>(GetDeviceGroupSurfacePresentModesKHR),
289         reinterpret_cast<PFN_vkVoidFunction>(checkedGetDeviceGroupSurfacePresentModesKHR),
290     },
291     {
292         "vkGetDeviceProcAddr",
293         ProcHook::DEVICE,
294         ProcHook::EXTENSION_CORE,
295         reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr),
296         nullptr,
297     },
298     {
299         "vkGetDeviceQueue",
300         ProcHook::DEVICE,
301         ProcHook::EXTENSION_CORE,
302         reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue),
303         nullptr,
304     },
305     {
306         "vkGetDeviceQueue2",
307         ProcHook::DEVICE,
308         ProcHook::EXTENSION_CORE,
309         reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue2),
310         nullptr,
311     },
312     {
313         "vkGetInstanceProcAddr",
314         ProcHook::INSTANCE,
315         ProcHook::EXTENSION_CORE,
316         reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr),
317         nullptr,
318     },
319     {
320         "vkGetPastPresentationTimingGOOGLE",
321         ProcHook::DEVICE,
322         ProcHook::GOOGLE_display_timing,
323         reinterpret_cast<PFN_vkVoidFunction>(GetPastPresentationTimingGOOGLE),
324         reinterpret_cast<PFN_vkVoidFunction>(checkedGetPastPresentationTimingGOOGLE),
325     },
326     {
327         "vkGetPhysicalDevicePresentRectanglesKHR",
328         ProcHook::INSTANCE,
329         ProcHook::KHR_swapchain,
330         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDevicePresentRectanglesKHR),
331         nullptr,
332     },
333     {
334         "vkGetPhysicalDeviceSurfaceCapabilities2KHR",
335         ProcHook::INSTANCE,
336         ProcHook::KHR_get_surface_capabilities2,
337         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilities2KHR),
338         nullptr,
339     },
340     {
341         "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
342         ProcHook::INSTANCE,
343         ProcHook::KHR_surface,
344         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceCapabilitiesKHR),
345         nullptr,
346     },
347     {
348         "vkGetPhysicalDeviceSurfaceFormats2KHR",
349         ProcHook::INSTANCE,
350         ProcHook::KHR_get_surface_capabilities2,
351         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormats2KHR),
352         nullptr,
353     },
354     {
355         "vkGetPhysicalDeviceSurfaceFormatsKHR",
356         ProcHook::INSTANCE,
357         ProcHook::KHR_surface,
358         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceFormatsKHR),
359         nullptr,
360     },
361     {
362         "vkGetPhysicalDeviceSurfacePresentModesKHR",
363         ProcHook::INSTANCE,
364         ProcHook::KHR_surface,
365         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfacePresentModesKHR),
366         nullptr,
367     },
368     {
369         "vkGetPhysicalDeviceSurfaceSupportKHR",
370         ProcHook::INSTANCE,
371         ProcHook::KHR_surface,
372         reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSurfaceSupportKHR),
373         nullptr,
374     },
375     {
376         "vkGetRefreshCycleDurationGOOGLE",
377         ProcHook::DEVICE,
378         ProcHook::GOOGLE_display_timing,
379         reinterpret_cast<PFN_vkVoidFunction>(GetRefreshCycleDurationGOOGLE),
380         reinterpret_cast<PFN_vkVoidFunction>(checkedGetRefreshCycleDurationGOOGLE),
381     },
382     {
383         "vkGetSwapchainGrallocUsage2ANDROID",
384         ProcHook::DEVICE,
385         ProcHook::ANDROID_native_buffer,
386         nullptr,
387         nullptr,
388     },
389     {
390         "vkGetSwapchainGrallocUsageANDROID",
391         ProcHook::DEVICE,
392         ProcHook::ANDROID_native_buffer,
393         nullptr,
394         nullptr,
395     },
396     {
397         "vkGetSwapchainImagesKHR",
398         ProcHook::DEVICE,
399         ProcHook::KHR_swapchain,
400         reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR),
401         reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainImagesKHR),
402     },
403     {
404         "vkGetSwapchainStatusKHR",
405         ProcHook::DEVICE,
406         ProcHook::KHR_shared_presentable_image,
407         reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainStatusKHR),
408         reinterpret_cast<PFN_vkVoidFunction>(checkedGetSwapchainStatusKHR),
409     },
410     {
411         "vkQueuePresentKHR",
412         ProcHook::DEVICE,
413         ProcHook::KHR_swapchain,
414         reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR),
415         reinterpret_cast<PFN_vkVoidFunction>(checkedQueuePresentKHR),
416     },
417     {
418         "vkQueueSignalReleaseImageANDROID",
419         ProcHook::DEVICE,
420         ProcHook::ANDROID_native_buffer,
421         nullptr,
422         nullptr,
423     },
424     {
425         "vkSetHdrMetadataEXT",
426         ProcHook::DEVICE,
427         ProcHook::EXT_hdr_metadata,
428         reinterpret_cast<PFN_vkVoidFunction>(SetHdrMetadataEXT),
429         reinterpret_cast<PFN_vkVoidFunction>(checkedSetHdrMetadataEXT),
430     },
431     // clang-format on
432 };
433 
434 }  // namespace
435 
GetProcHook(const char * name)436 const ProcHook* GetProcHook(const char* name) {
437     const auto& begin = g_proc_hooks;
438     const auto& end =
439         g_proc_hooks + sizeof(g_proc_hooks) / sizeof(g_proc_hooks[0]);
440     const auto hook = std::lower_bound(
441         begin, end, name,
442         [](const ProcHook& e, const char* n) { return strcmp(e.name, n) < 0; });
443     return (hook < end && strcmp(hook->name, name) == 0) ? hook : nullptr;
444 }
445 
GetProcHookExtension(const char * name)446 ProcHook::Extension GetProcHookExtension(const char* name) {
447     // clang-format off
448     if (strcmp(name, "VK_ANDROID_native_buffer") == 0) return ProcHook::ANDROID_native_buffer;
449     if (strcmp(name, "VK_EXT_debug_report") == 0) return ProcHook::EXT_debug_report;
450     if (strcmp(name, "VK_EXT_hdr_metadata") == 0) return ProcHook::EXT_hdr_metadata;
451     if (strcmp(name, "VK_EXT_swapchain_colorspace") == 0) return ProcHook::EXT_swapchain_colorspace;
452     if (strcmp(name, "VK_GOOGLE_display_timing") == 0) return ProcHook::GOOGLE_display_timing;
453     if (strcmp(name, "VK_KHR_android_surface") == 0) return ProcHook::KHR_android_surface;
454     if (strcmp(name, "VK_KHR_incremental_present") == 0) return ProcHook::KHR_incremental_present;
455     if (strcmp(name, "VK_KHR_shared_presentable_image") == 0) return ProcHook::KHR_shared_presentable_image;
456     if (strcmp(name, "VK_KHR_surface") == 0) return ProcHook::KHR_surface;
457     if (strcmp(name, "VK_KHR_swapchain") == 0) return ProcHook::KHR_swapchain;
458     if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2;
459     if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2;
460     if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer;
461     // clang-format on
462     return ProcHook::EXTENSION_UNKNOWN;
463 }
464 
465 #define UNLIKELY(expr) __builtin_expect((expr), 0)
466 
467 #define INIT_PROC(required, obj, proc)                                 \
468     do {                                                               \
469         data.driver.proc =                                             \
470             reinterpret_cast<PFN_vk##proc>(get_proc(obj, "vk" #proc)); \
471         if (UNLIKELY(required && !data.driver.proc)) {                 \
472             ALOGE("missing " #obj " proc: vk" #proc);                  \
473             success = false;                                           \
474         }                                                              \
475     } while (0)
476 
477 #define INIT_PROC_EXT(ext, required, obj, proc) \
478     do {                                        \
479         if (extensions[ProcHook::ext])          \
480             INIT_PROC(required, obj, proc);     \
481     } while (0)
482 
InitDriverTable(VkInstance instance,PFN_vkGetInstanceProcAddr get_proc,const std::bitset<ProcHook::EXTENSION_COUNT> & extensions)483 bool InitDriverTable(VkInstance instance,
484                      PFN_vkGetInstanceProcAddr get_proc,
485                      const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
486     auto& data = GetData(instance);
487     bool success = true;
488 
489     // clang-format off
490     INIT_PROC(true, instance, DestroyInstance);
491     INIT_PROC(true, instance, EnumeratePhysicalDevices);
492     INIT_PROC(true, instance, GetInstanceProcAddr);
493     INIT_PROC(true, instance, GetPhysicalDeviceProperties);
494     INIT_PROC(true, instance, CreateDevice);
495     INIT_PROC(true, instance, EnumerateDeviceExtensionProperties);
496     INIT_PROC(false, instance, EnumeratePhysicalDeviceGroups);
497     INIT_PROC(false, instance, GetPhysicalDeviceProperties2);
498     INIT_PROC_EXT(EXT_debug_report, true, instance, CreateDebugReportCallbackEXT);
499     INIT_PROC_EXT(EXT_debug_report, true, instance, DestroyDebugReportCallbackEXT);
500     INIT_PROC_EXT(EXT_debug_report, true, instance, DebugReportMessageEXT);
501     INIT_PROC_EXT(KHR_get_physical_device_properties2, true, instance, GetPhysicalDeviceProperties2KHR);
502     // clang-format on
503 
504     return success;
505 }
506 
InitDriverTable(VkDevice dev,PFN_vkGetDeviceProcAddr get_proc,const std::bitset<ProcHook::EXTENSION_COUNT> & extensions)507 bool InitDriverTable(VkDevice dev,
508                      PFN_vkGetDeviceProcAddr get_proc,
509                      const std::bitset<ProcHook::EXTENSION_COUNT>& extensions) {
510     auto& data = GetData(dev);
511     bool success = true;
512 
513     // clang-format off
514     INIT_PROC(true, dev, GetDeviceProcAddr);
515     INIT_PROC(true, dev, DestroyDevice);
516     INIT_PROC(true, dev, GetDeviceQueue);
517     INIT_PROC(true, dev, CreateImage);
518     INIT_PROC(true, dev, DestroyImage);
519     INIT_PROC(true, dev, AllocateCommandBuffers);
520     INIT_PROC(false, dev, GetDeviceQueue2);
521     INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID);
522     INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID);
523     INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID);
524     INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID);
525     // clang-format on
526 
527     return success;
528 }
529 
530 }  // namespace driver
531 }  // namespace vulkan
532 
533 // clang-format on
534