entry-points: Hook GetInstanceProcAddr()/GetDeviceProcAddr() 88/65688/1
authorTaekyun Kim <tkq.kim@samsung.com>
Mon, 11 Apr 2016 10:08:51 +0000 (19:08 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Tue, 12 Apr 2016 05:56:02 +0000 (14:56 +0900)
Any vulkan function that WSI has its implementation should not be called
directly by the vulkan loader or application. WSI implementation shoud call
ICD functions in that case.

Change-Id: Ibd4e43fafe3db20467abcd93dc883d0afcc89637

src/wsi/entry-points.c
src/wsi/wsi.h

index 46ce175..8dc5dfe 100644 (file)
@@ -84,6 +84,9 @@ static const vk_entry_t       entry_points[] = {
        VK_ENTRY_POINT(CreateWaylandSurfaceKHR,INSTANCE),
        VK_ENTRY_POINT(GetPhysicalDeviceWaylandPresentationSupportKHR,INSTANCE),
 #endif
+
+       VK_ENTRY_POINT(GetInstanceProcAddr, INSTANCE),
+       VK_ENTRY_POINT(GetDeviceProcAddr, DEVICE),
 };
 
 static const vk_entry_t *
@@ -127,6 +130,60 @@ icd_fini(void)
                dlclose(icd.lib);
 }
 
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
+vk_GetInstanceProcAddr(VkInstance instance, const char *name)
+{
+       const vk_entry_t                        *entry = get_entry_point(name);
+       PFN_vkGetInstanceProcAddr        gipa;
+
+       /* According to vulkan specification 1.0, when instance is NULL, name must be one of global
+        * functions. When instance is not NULL, then name must be not one of global functions. */
+       if (entry) {
+               if (instance == NULL && entry->type == VK_FUNC_TYPE_GLOBAL)
+                       return entry->func;
+
+               if (instance != NULL && entry->type != VK_FUNC_TYPE_GLOBAL)
+                       return entry->func;
+
+               if (entry->func == vk_GetInstanceProcAddr)
+                       return entry->func;
+
+               if (entry->func == vk_GetDeviceProcAddr)
+                       return entry->func;
+
+               return NULL;
+       }
+
+       /* TODO: Avoid getting GIPA on the fly. */
+       gipa = (PFN_vkGetInstanceProcAddr)icd.gpa(instance, "vkGetInstanceProcAddr");
+
+       return gipa(instance, name);
+}
+
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
+vk_GetDeviceProcAddr(VkDevice device, const char *name)
+{
+       const vk_entry_t                *entry = get_entry_point(name);
+       PFN_vkGetDeviceProcAddr  gdpa;
+
+       if (device == NULL)
+               return NULL;
+
+       if (entry) {
+               if ( entry->type == VK_FUNC_TYPE_DEVICE)
+                       return entry->func;
+
+               return NULL;
+       }
+
+       /* TODO: We are trying to get the most specific device functions here. */
+       gdpa = (PFN_vkGetDeviceProcAddr)icd.gpa(NULL, "vkGetDeviceProcAddr");
+       gdpa = (PFN_vkGetDeviceProcAddr)gdpa(device, "vkGetDeviceProcAddr");
+
+       return gdpa(device, name);
+
+}
+
 VK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
 vk_icdGetInstanceProcAddr(VkInstance instance, const char *name)
 {
index a2228df..d012863 100644 (file)
@@ -176,4 +176,10 @@ vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev,
                                                                                                  struct wl_display *display);
 #endif
 
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
+vk_GetInstanceProcAddr(VkInstance instance, const char *name);
+
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
+vk_GetDeviceProcAddr(VkDevice device, const char *name);
+
 #endif /* WSI_H */