• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2022 The Khronos Group Inc.
3  * Copyright (c) 2015-2022 Valve Corporation
4  * Copyright (c) 2015-2022 LunarG, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Mark Young <marky@lunarg.com>
19  * Author: Lenny Komow <lenny@lunarg.com>
20  * Author: Charles Giessen <charles@lunarg.com>
21  */
22 
23 #include "extension_manual.h"
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "allocation.h"
30 #include "debug_utils.h"
31 #include "loader.h"
32 #include "log.h"
33 #include "wsi.h"
34 
35 // ---- Manually added trampoline/terminator functions
36 
37 // These functions, for whatever reason, require more complex changes than
38 // can easily be automatically generated.
39 
40 // ---- VK_NV_external_memory_capabilities extension trampoline/terminators
41 
GetPhysicalDeviceExternalImageFormatPropertiesNV(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkExternalMemoryHandleTypeFlagsNV externalHandleType,VkExternalImageFormatPropertiesNV * pExternalImageFormatProperties)42 VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceExternalImageFormatPropertiesNV(
43     VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage,
44     VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType,
45     VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
46     const VkLayerInstanceDispatchTable *disp;
47     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
48     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
49         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
50                    "vkGetPhysicalDeviceExternalImageFormatPropertiesNV: Invalid physicalDevice "
51                    "[VUID-vkGetPhysicalDeviceExternalImageFormatPropertiesNV-physicalDevice-parameter]");
52         abort(); /* Intentionally fail so user can correct issue. */
53     }
54     disp = loader_get_instance_layer_dispatch(physicalDevice);
55 
56     return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(unwrapped_phys_dev, format, type, tiling, usage, flags,
57                                                                   externalHandleType, pExternalImageFormatProperties);
58 }
59 
terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkExternalMemoryHandleTypeFlagsNV externalHandleType,VkExternalImageFormatPropertiesNV * pExternalImageFormatProperties)60 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV(
61     VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage,
62     VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType,
63     VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
64     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
65     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
66 
67     if (!icd_term->dispatch.GetPhysicalDeviceExternalImageFormatPropertiesNV) {
68         if (externalHandleType) {
69             return VK_ERROR_FORMAT_NOT_SUPPORTED;
70         }
71 
72         if (!icd_term->dispatch.GetPhysicalDeviceImageFormatProperties) {
73             return VK_ERROR_INITIALIZATION_FAILED;
74         }
75 
76         pExternalImageFormatProperties->externalMemoryFeatures = 0;
77         pExternalImageFormatProperties->exportFromImportedHandleTypes = 0;
78         pExternalImageFormatProperties->compatibleHandleTypes = 0;
79 
80         return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties(
81             phys_dev_term->phys_dev, format, type, tiling, usage, flags, &pExternalImageFormatProperties->imageFormatProperties);
82     }
83 
84     return icd_term->dispatch.GetPhysicalDeviceExternalImageFormatPropertiesNV(
85         phys_dev_term->phys_dev, format, type, tiling, usage, flags, externalHandleType, pExternalImageFormatProperties);
86 }
87 
88 // ---- VK_EXT_display_surface_counter extension trampoline/terminators
89 
GetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilities2EXT * pSurfaceCapabilities)90 VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
91                                                                         VkSurfaceCapabilities2EXT *pSurfaceCapabilities) {
92     const VkLayerInstanceDispatchTable *disp;
93     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
94     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
95         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
96                    "vkGetPhysicalDeviceExternalImageFormatPropertiesNV: Invalid physicalDevice "
97                    "[VUID-vkGetPhysicalDeviceSurfaceCapabilities2EXT-physicalDevice-parameter]");
98         abort(); /* Intentionally fail so user can correct issue. */
99     }
100     disp = loader_get_instance_layer_dispatch(physicalDevice);
101     return disp->GetPhysicalDeviceSurfaceCapabilities2EXT(unwrapped_phys_dev, surface, pSurfaceCapabilities);
102 }
103 
terminator_GetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilities2EXT * pSurfaceCapabilities)104 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfaceCapabilities2EXT(
105     VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilities2EXT *pSurfaceCapabilities) {
106     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
107     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
108 
109     VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)(surface);
110     uint8_t icd_index = phys_dev_term->icd_index;
111 
112     // Unwrap the surface if needed
113     VkSurfaceKHR unwrapped_surface = surface;
114     if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)(uintptr_t)(icd_surface->real_icd_surfaces[icd_index])) {
115         unwrapped_surface = icd_surface->real_icd_surfaces[icd_index];
116     }
117 
118     if (NULL != icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2EXT) {
119         // Pass the call to the driver
120         return icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilities2EXT(phys_dev_term->phys_dev, unwrapped_surface,
121                                                                            pSurfaceCapabilities);
122     } else {
123         // Emulate the call
124         loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
125                    "vkGetPhysicalDeviceSurfaceCapabilities2EXT: Emulating call in ICD \"%s\" using "
126                    "vkGetPhysicalDeviceSurfaceCapabilitiesKHR",
127                    icd_term->scanned_icd->lib_name);
128 
129         VkSurfaceCapabilitiesKHR surface_caps;
130         VkResult res =
131             icd_term->dispatch.GetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev_term->phys_dev, unwrapped_surface, &surface_caps);
132         pSurfaceCapabilities->minImageCount = surface_caps.minImageCount;
133         pSurfaceCapabilities->maxImageCount = surface_caps.maxImageCount;
134         pSurfaceCapabilities->currentExtent = surface_caps.currentExtent;
135         pSurfaceCapabilities->minImageExtent = surface_caps.minImageExtent;
136         pSurfaceCapabilities->maxImageExtent = surface_caps.maxImageExtent;
137         pSurfaceCapabilities->maxImageArrayLayers = surface_caps.maxImageArrayLayers;
138         pSurfaceCapabilities->supportedTransforms = surface_caps.supportedTransforms;
139         pSurfaceCapabilities->currentTransform = surface_caps.currentTransform;
140         pSurfaceCapabilities->supportedCompositeAlpha = surface_caps.supportedCompositeAlpha;
141         pSurfaceCapabilities->supportedUsageFlags = surface_caps.supportedUsageFlags;
142         pSurfaceCapabilities->supportedSurfaceCounters = 0;
143 
144         if (pSurfaceCapabilities->pNext != NULL) {
145             loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
146                        "vkGetPhysicalDeviceSurfaceCapabilities2EXT: Emulation found unrecognized structure type in "
147                        "pSurfaceCapabilities->pNext - this struct will be ignored");
148         }
149 
150         return res;
151     }
152 }
153 
154 // ---- VK_EXT_direct_mode_display extension trampoline/terminators
155 
ReleaseDisplayEXT(VkPhysicalDevice physicalDevice,VkDisplayKHR display)156 VKAPI_ATTR VkResult VKAPI_CALL ReleaseDisplayEXT(VkPhysicalDevice physicalDevice, VkDisplayKHR display) {
157     const VkLayerInstanceDispatchTable *disp;
158     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
159     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
160         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
161                    "vkReleaseDisplayEXT: Invalid physicalDevice [VUID-vkReleaseDisplayEXT-physicalDevice-parameter]");
162         abort(); /* Intentionally fail so user can correct issue. */
163     }
164     disp = loader_get_instance_layer_dispatch(physicalDevice);
165     return disp->ReleaseDisplayEXT(unwrapped_phys_dev, display);
166 }
167 
terminator_ReleaseDisplayEXT(VkPhysicalDevice physicalDevice,VkDisplayKHR display)168 VKAPI_ATTR VkResult VKAPI_CALL terminator_ReleaseDisplayEXT(VkPhysicalDevice physicalDevice, VkDisplayKHR display) {
169     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
170     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
171 
172     if (icd_term->dispatch.ReleaseDisplayEXT == NULL) {
173         loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
174                    "ICD \"%s\" associated with VkPhysicalDevice does not support vkReleaseDisplayEXT - Consequently, the call is "
175                    "invalid because it should not be possible to acquire a display on this device",
176                    icd_term->scanned_icd->lib_name);
177         abort();
178     }
179     return icd_term->dispatch.ReleaseDisplayEXT(phys_dev_term->phys_dev, display);
180 }
181 
182 // ---- VK_EXT_acquire_xlib_display extension trampoline/terminators
183 
184 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
AcquireXlibDisplayEXT(VkPhysicalDevice physicalDevice,Display * dpy,VkDisplayKHR display)185 VKAPI_ATTR VkResult VKAPI_CALL AcquireXlibDisplayEXT(VkPhysicalDevice physicalDevice, Display *dpy, VkDisplayKHR display) {
186     const VkLayerInstanceDispatchTable *disp;
187     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
188     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
189         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
190                    "vkAcquireXlibDisplayEXT: Invalid physicalDevice [VUID-vkAcquireXlibDisplayEXT-physicalDevice-parameter]");
191         abort(); /* Intentionally fail so user can correct issue. */
192     }
193     disp = loader_get_instance_layer_dispatch(physicalDevice);
194     return disp->AcquireXlibDisplayEXT(unwrapped_phys_dev, dpy, display);
195 }
196 
terminator_AcquireXlibDisplayEXT(VkPhysicalDevice physicalDevice,Display * dpy,VkDisplayKHR display)197 VKAPI_ATTR VkResult VKAPI_CALL terminator_AcquireXlibDisplayEXT(VkPhysicalDevice physicalDevice, Display *dpy,
198                                                                 VkDisplayKHR display) {
199     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
200     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
201 
202     if (icd_term->dispatch.AcquireXlibDisplayEXT != NULL) {
203         // Pass the call to the driver
204         return icd_term->dispatch.AcquireXlibDisplayEXT(phys_dev_term->phys_dev, dpy, display);
205     } else {
206         // Emulate the call
207         loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
208                    "vkAcquireXLibDisplayEXT: Emulating call in ICD \"%s\" by returning error", icd_term->scanned_icd->lib_name);
209 
210         // Fail for the unsupported command
211         return VK_ERROR_INITIALIZATION_FAILED;
212     }
213 }
214 
GetRandROutputDisplayEXT(VkPhysicalDevice physicalDevice,Display * dpy,RROutput rrOutput,VkDisplayKHR * pDisplay)215 VKAPI_ATTR VkResult VKAPI_CALL GetRandROutputDisplayEXT(VkPhysicalDevice physicalDevice, Display *dpy, RROutput rrOutput,
216                                                         VkDisplayKHR *pDisplay) {
217     const VkLayerInstanceDispatchTable *disp;
218     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
219     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
220         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
221                    "vkGetRandROutputDisplayEXT: Invalid physicalDevice [VUID-vkGetRandROutputDisplayEXT-physicalDevice-parameter]");
222         abort(); /* Intentionally fail so user can correct issue. */
223     }
224     disp = loader_get_instance_layer_dispatch(physicalDevice);
225     return disp->GetRandROutputDisplayEXT(unwrapped_phys_dev, dpy, rrOutput, pDisplay);
226 }
227 
terminator_GetRandROutputDisplayEXT(VkPhysicalDevice physicalDevice,Display * dpy,RROutput rrOutput,VkDisplayKHR * pDisplay)228 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetRandROutputDisplayEXT(VkPhysicalDevice physicalDevice, Display *dpy, RROutput rrOutput,
229                                                                    VkDisplayKHR *pDisplay) {
230     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
231     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
232 
233     if (icd_term->dispatch.GetRandROutputDisplayEXT != NULL) {
234         // Pass the call to the driver
235         return icd_term->dispatch.GetRandROutputDisplayEXT(phys_dev_term->phys_dev, dpy, rrOutput, pDisplay);
236     } else {
237         // Emulate the call
238         loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
239                    "vkGetRandROutputDisplayEXT: Emulating call in ICD \"%s\" by returning null display",
240                    icd_term->scanned_icd->lib_name);
241 
242         // Return a null handle to indicate this can't be done
243         *pDisplay = VK_NULL_HANDLE;
244         return VK_SUCCESS;
245     }
246 }
247 
248 #endif  // VK_USE_PLATFORM_XLIB_XRANDR_EXT
249 
250 #ifdef VK_USE_PLATFORM_WIN32_KHR
GetPhysicalDeviceSurfacePresentModes2EXT(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)251 VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceSurfacePresentModes2EXT(VkPhysicalDevice physicalDevice,
252                                                                         const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
253                                                                         uint32_t *pPresentModeCount,
254                                                                         VkPresentModeKHR *pPresentModes) {
255     const VkLayerInstanceDispatchTable *disp;
256     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
257     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
258         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
259                    "vkGetPhysicalDeviceSurfacePresentModes2EXT: Invalid physicalDevice "
260                    "[VUID-vkGetPhysicalDeviceSurfacePresentModes2EXT-physicalDevice-parameter]");
261         abort(); /* Intentionally fail so user can correct issue. */
262     }
263     disp = loader_get_instance_layer_dispatch(physicalDevice);
264     return disp->GetPhysicalDeviceSurfacePresentModes2EXT(unwrapped_phys_dev, pSurfaceInfo, pPresentModeCount, pPresentModes);
265 }
266 
terminator_GetPhysicalDeviceSurfacePresentModes2EXT(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)267 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModes2EXT(
268     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo, uint32_t *pPresentModeCount,
269     VkPresentModeKHR *pPresentModes) {
270     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
271     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
272     if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfacePresentModes2EXT) {
273         loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
274                    "ICD associated with VkPhysicalDevice does not support GetPhysicalDeviceSurfacePresentModes2EXT");
275         abort();
276     }
277     VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)(pSurfaceInfo->surface);
278     uint8_t icd_index = phys_dev_term->icd_index;
279     if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)(uintptr_t)icd_surface->real_icd_surfaces[icd_index]) {
280         VkPhysicalDeviceSurfaceInfo2KHR surface_info_copy;
281         surface_info_copy.sType = pSurfaceInfo->sType;
282         surface_info_copy.pNext = pSurfaceInfo->pNext;
283         surface_info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
284         return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModes2EXT(phys_dev_term->phys_dev, &surface_info_copy,
285                                                                            pPresentModeCount, pPresentModes);
286     }
287     return icd_term->dispatch.GetPhysicalDeviceSurfacePresentModes2EXT(phys_dev_term->phys_dev, pSurfaceInfo, pPresentModeCount,
288                                                                        pPresentModes);
289 }
290 
GetDeviceGroupSurfacePresentModes2EXT(VkDevice device,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkDeviceGroupPresentModeFlagsKHR * pModes)291 VKAPI_ATTR VkResult VKAPI_CALL GetDeviceGroupSurfacePresentModes2EXT(VkDevice device,
292                                                                      const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
293                                                                      VkDeviceGroupPresentModeFlagsKHR *pModes) {
294     const VkLayerDispatchTable *disp = loader_get_dispatch(device);
295     if (NULL == disp) {
296         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
297                    "vkGetDeviceGroupSurfacePresentModes2EXT: Invalid device "
298                    "[VUID-vkGetDeviceGroupSurfacePresentModes2EXT-device-parameter]");
299         abort(); /* Intentionally fail so user can correct issue. */
300     }
301     return disp->GetDeviceGroupSurfacePresentModes2EXT(device, pSurfaceInfo, pModes);
302 }
303 
terminator_GetDeviceGroupSurfacePresentModes2EXT(VkDevice device,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkDeviceGroupPresentModeFlagsKHR * pModes)304 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetDeviceGroupSurfacePresentModes2EXT(VkDevice device,
305                                                                                 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
306                                                                                 VkDeviceGroupPresentModeFlagsKHR *pModes) {
307     uint32_t icd_index = 0;
308     struct loader_device *dev;
309     struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, &icd_index);
310     if (NULL != icd_term && NULL != icd_term->dispatch.GetDeviceGroupSurfacePresentModes2EXT) {
311         VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)pSurfaceInfo->surface;
312         if (NULL != icd_surface->real_icd_surfaces && (VkSurfaceKHR)NULL != icd_surface->real_icd_surfaces[icd_index]) {
313             VkPhysicalDeviceSurfaceInfo2KHR surface_info_copy;
314             surface_info_copy.sType = pSurfaceInfo->sType;
315             surface_info_copy.pNext = pSurfaceInfo->pNext;
316             surface_info_copy.surface = icd_surface->real_icd_surfaces[icd_index];
317             return icd_term->dispatch.GetDeviceGroupSurfacePresentModes2EXT(device, &surface_info_copy, pModes);
318         }
319         return icd_term->dispatch.GetDeviceGroupSurfacePresentModes2EXT(device, pSurfaceInfo, pModes);
320     }
321     return VK_SUCCESS;
322 }
323 
324 #endif  // VK_USE_PLATFORM_WIN32_KHR
325 
326 // ---- VK_EXT_tooling_info extension trampoline/terminators
327 
GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice,uint32_t * pToolCount,VkPhysicalDeviceToolPropertiesEXT * pToolProperties)328 VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t *pToolCount,
329                                                                   VkPhysicalDeviceToolPropertiesEXT *pToolProperties) {
330     const VkLayerInstanceDispatchTable *disp;
331     VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(physicalDevice);
332     if (VK_NULL_HANDLE == unwrapped_phys_dev) {
333         loader_log(NULL, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
334                    "vkGetPhysicalDeviceToolPropertiesEXT: Invalid physicalDevice "
335                    "[VUID-vkGetPhysicalDeviceToolPropertiesEXT-physicalDevice-parameter]");
336         abort(); /* Intentionally fail so user can correct issue. */
337     }
338     disp = loader_get_instance_layer_dispatch(physicalDevice);
339     return disp->GetPhysicalDeviceToolPropertiesEXT(unwrapped_phys_dev, pToolCount, pToolProperties);
340 }
341 
terminator_GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice,uint32_t * pToolCount,VkPhysicalDeviceToolPropertiesEXT * pToolProperties)342 VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t *pToolCount,
343                                                                              VkPhysicalDeviceToolPropertiesEXT *pToolProperties) {
344     struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
345     struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
346 
347     bool tooling_info_supported = false;
348     uint32_t ext_count = 0;
349     VkExtensionProperties *ext_props = NULL;
350     VkResult res = VK_SUCCESS;
351     VkResult enumerate_res = VK_SUCCESS;
352 
353     enumerate_res = icd_term->dispatch.EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &ext_count, NULL);
354     if (enumerate_res != VK_SUCCESS) {
355         goto out;
356     }
357 
358     ext_props = loader_instance_heap_alloc(icd_term->this_instance, sizeof(VkExtensionProperties) * ext_count,
359                                            VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
360     if (!ext_props) {
361         res = VK_ERROR_OUT_OF_HOST_MEMORY;
362         goto out;
363     }
364 
365     enumerate_res = icd_term->dispatch.EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &ext_count, ext_props);
366     if (enumerate_res != VK_SUCCESS) {
367         goto out;
368     }
369 
370     for (uint32_t i = 0; i < ext_count; i++) {
371         if (strncmp(ext_props[i].extensionName, VK_EXT_TOOLING_INFO_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE) == 0) {
372             tooling_info_supported = true;
373             break;
374         }
375     }
376 
377     if (tooling_info_supported && icd_term->dispatch.GetPhysicalDeviceToolPropertiesEXT) {
378         res = icd_term->dispatch.GetPhysicalDeviceToolPropertiesEXT(phys_dev_term->phys_dev, pToolCount, pToolProperties);
379     }
380 
381 out:
382     // In the case the driver didn't support the extension, make sure that the first layer doesn't find the count uninitialized
383     if (!tooling_info_supported || !icd_term->dispatch.GetPhysicalDeviceToolPropertiesEXT) {
384         *pToolCount = 0;
385     }
386 
387     loader_instance_heap_free(icd_term->this_instance, ext_props);
388 
389     return res;
390 }
391