icd: Dedicated files for manipulating vendor ICD 61/66061/1
authorTaekyun Kim <tkq.kim@samsung.com>
Thu, 14 Apr 2016 07:34:02 +0000 (16:34 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Fri, 15 Apr 2016 04:48:29 +0000 (13:48 +0900)
Change-Id: Icc2498e31047aeac2a67c5527b79d5b24cd9fb20

src/wsi/Makefile.am
src/wsi/entry-points.c
src/wsi/icd.c [new file with mode: 0644]
src/wsi/wsi.h

index 4a7d7a2..a7325a7 100644 (file)
@@ -17,7 +17,8 @@ vulkan_wsi_tizen_la_SOURCES = wsi.h                           \
                                                          surface.c                     \
                                                          swapchain.c           \
                                                          display.c                     \
-                                                         allocator.c
+                                                         allocator.c           \
+                                                         icd.c
 
 manifestdir = /etc/vulkan/icd.d
 manifest_DATA = vulkan-wsi-tizen.json
index 96cf20c..e053463 100644 (file)
 
 #include "wsi.h"
 #include <string.h>
-#include <stdlib.h>
-#include <dlfcn.h>
 
 #define VK_ENTRY_POINT(name, type) { "vk"#name, vk_##name, VK_FUNC_TYPE_##type }
 
 typedef enum vk_func_type              vk_func_type_t;
 typedef struct vk_entry                        vk_entry_t;
-typedef struct vk_icd_loader   vk_icd_loader_t;
 
 enum vk_func_type {
        VK_FUNC_TYPE_GLOBAL,
@@ -45,17 +42,6 @@ struct vk_entry {
        vk_func_type_t   type;
 };
 
-struct vk_icd_loader {
-       void                                            *lib;
-       PFN_vkGetInstanceProcAddr        gpa;
-
-       PFN_vkEnumerateInstanceExtensionProperties      enum_instance_extensions;
-       PFN_vkEnumerateDeviceExtensionProperties        enum_device_extensions;
-
-       uint32_t                                 global_extension_count;
-       VkExtensionProperties   *global_extensions;
-};
-
 static const vk_entry_t        entry_points[] = {
        VK_ENTRY_POINT(EnumerateInstanceExtensionProperties, INSTANCE),
        VK_ENTRY_POINT(EnumerateDeviceExtensionProperties, INSTANCE),
@@ -95,67 +81,6 @@ get_entry_point(const char *name)
        return NULL;
 }
 
-static vk_icd_loader_t icd;
-
-static const VkExtensionProperties global_extensions[] = {
-       { VK_KHR_SURFACE_EXTENSION_NAME, 25 },
-       { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, 4 },
-};
-
-static void __attribute__((constructor))
-icd_init(void)
-{
-       const char *filename;
-       VkResult        res;
-       uint32_t        count;
-
-       filename = getenv("VK_TIZEN_ICD");
-       VK_CHECK(filename, return, "No ICD library given.\n");
-
-       dlerror();
-
-       icd.lib = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
-       VK_CHECK(icd.lib, return, "dlopen() failed - %s\n", dlerror());
-
-       icd.gpa = dlsym(icd.lib, "vk_icdGetInstanceProcAddr");
-       VK_CHECK(icd.gpa, return, "vk_icdGetInstanceProcAddr() not present.\n");
-
-       /* Retrieve extension enumeration functions. */
-       icd.enum_instance_extensions = (void *)icd.gpa(NULL, "vkEnumerateInstanceExtensionProperties");
-       VK_CHECK(icd.enum_instance_extensions, return,
-                        "vkEnumerateInstanceExtensionProperties() not present.\n");
-
-       icd.enum_device_extensions = (void *)icd.gpa(NULL, "vkEnumerateDeviceExtensionProperties");
-       VK_CHECK(icd.enum_device_extensions, return,
-                        "vkEnumerateDeviceExtensionProperties() not present.\n");
-
-       /* Get ICD global extension count. */
-       res = icd.enum_instance_extensions(NULL, &count, NULL);
-       VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n");
-
-       /* Allocate memory to hold the extensions both for ICD and WSI. */
-       icd.global_extensions =
-               malloc((count + ARRAY_LENGTH(global_extensions)) * sizeof(VkExtensionProperties));
-       VK_CHECK(icd.global_extensions, return, "malloc() failed.\n");
-
-       /* Copy ICD extensions first. */
-       res = icd.enum_instance_extensions(NULL, &count, icd.global_extensions);
-       VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n");
-
-       /* Append WSI extensions. */
-       memcpy(icd.global_extensions + count, global_extensions,
-                  ARRAY_LENGTH(global_extensions) * sizeof(VkExtensionProperties));
-
-       icd.global_extension_count = count + ARRAY_LENGTH(global_extensions);
-}
-
-static void __attribute__((destructor))
-icd_fini(void)
-{
-       if (icd.lib)
-               dlclose(icd.lib);
-}
-
 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
 vk_GetInstanceProcAddr(VkInstance instance, const char *name)
 {
@@ -181,7 +106,7 @@ vk_GetInstanceProcAddr(VkInstance instance, const char *name)
        }
 
        /* TODO: Avoid getting GIPA on the fly. */
-       gipa = (PFN_vkGetInstanceProcAddr)icd.gpa(instance, "vkGetInstanceProcAddr");
+       gipa = (PFN_vkGetInstanceProcAddr)vk_icd_get_proc_addr(instance, "vkGetInstanceProcAddr");
 
        return gipa(instance, name);
 }
@@ -203,7 +128,7 @@ vk_GetDeviceProcAddr(VkDevice device, const char *name)
        }
 
        /* TODO: We are trying to get the most specific device functions here. */
-       gdpa = (PFN_vkGetDeviceProcAddr)icd.gpa(NULL, "vkGetDeviceProcAddr");
+       gdpa = (PFN_vkGetDeviceProcAddr)vk_icd_get_proc_addr(NULL, "vkGetDeviceProcAddr");
        gdpa = (PFN_vkGetDeviceProcAddr)gdpa(device, "vkGetDeviceProcAddr");
 
        return gdpa(device, name);
@@ -218,78 +143,5 @@ vk_icdGetInstanceProcAddr(VkInstance instance, const char *name)
        if (entry)
                return entry->func;
 
-       return icd.gpa(instance, name);
-}
-
-VKAPI_ATTR VkResult VKAPI_CALL
-vk_EnumerateInstanceExtensionProperties(const char                             *layer_name,
-                                                                               uint32_t                                *count,
-                                                                               VkExtensionProperties   *extensions)
-{
-       if (!extensions) {
-               *count = icd.global_extension_count;
-               return VK_SUCCESS;
-       }
-
-       *count = MIN(*count, icd.global_extension_count);
-       memcpy(extensions, icd.global_extensions, *count * sizeof(VkExtensionProperties));
-
-       if (*count < icd.global_extension_count)
-               return VK_INCOMPLETE;
-
-       return VK_SUCCESS;
-}
-
-static const VkExtensionProperties device_extensions[] = {
-       { VK_KHR_SWAPCHAIN_EXTENSION_NAME, 67 },
-};
-
-VKAPI_ATTR VkResult VKAPI_CALL
-vk_EnumerateDeviceExtensionProperties(VkPhysicalDevice          pdev,
-                                                                         const char                    *layer_name,
-                                                                         uint32_t                              *count,
-                                                                         VkExtensionProperties *extensions)
-{
-       uint32_t                                 ext_count, copied = 0;
-       uint32_t                                 icd_count, max_count;
-       VkResult                                 result;
-
-       result = icd.enum_device_extensions(pdev, layer_name, &icd_count, NULL);
-       VK_CHECK(result == VK_SUCCESS, return VK_ERROR_OUT_OF_HOST_MEMORY,
-                        "vkEnumerateDeviceExtensionProperties() failed.\n");
-
-       max_count = icd_count + ARRAY_LENGTH(device_extensions);
-
-       if (!extensions) {
-               /* Just return the number of enabled extension properties in this case. */
-               *count = max_count;
-               return VK_SUCCESS;
-       }
-
-       /* We should copy ICD extensions and WSI extensions together into the given pointer. */
-
-       ext_count = MIN(*count, icd_count);
-       result = icd.enum_device_extensions(pdev, layer_name, &ext_count, extensions);
-       VK_CHECK(result == VK_SUCCESS || result == VK_INCOMPLETE, return VK_ERROR_OUT_OF_HOST_MEMORY,
-                        "vkEnumerateDeviceExtensionProperties() failed.\n");
-
-       /* Advance the destination pointer. */
-       extensions += ext_count;
-       copied += ext_count;
-
-       /* Calculate remaining extensions to copy. */
-       ext_count = *count - ext_count;
-
-       if (ext_count > 0) {
-               ext_count = MIN(ext_count, ARRAY_LENGTH(device_extensions));
-               memcpy(extensions, device_extensions, ext_count * sizeof(VkExtensionProperties));
-               copied += ext_count;
-       }
-
-       *count = copied;
-
-       if (*count < max_count)
-               return VK_INCOMPLETE;
-
-       return VK_SUCCESS;
+       return vk_icd_get_proc_addr(instance, name);
 }
diff --git a/src/wsi/icd.c b/src/wsi/icd.c
new file mode 100644 (file)
index 0000000..cbda699
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright © 2016 S-Core Corporation
+ * Copyright © 2016-2017 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "wsi.h"
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct vk_icd  vk_icd_t;
+
+struct vk_icd {
+       void                                            *lib;
+       PFN_vkGetInstanceProcAddr        gpa;
+
+       PFN_vkEnumerateInstanceExtensionProperties      enum_instance_extensions;
+       PFN_vkEnumerateDeviceExtensionProperties        enum_device_extensions;
+
+       uint32_t                                 global_extension_count;
+       VkExtensionProperties   *global_extensions;
+};
+
+static vk_icd_t        icd;
+
+static const VkExtensionProperties global_extensions[] = {
+       { VK_KHR_SURFACE_EXTENSION_NAME, 25 },
+       { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, 4 },
+};
+
+static void __attribute__((constructor))
+icd_init(void)
+{
+       const char *filename;
+       VkResult        res;
+       uint32_t        count;
+
+       filename = getenv("VK_TIZEN_ICD");
+       VK_CHECK(filename, return, "No ICD library given.\n");
+
+       dlerror();
+
+       icd.lib = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+       VK_CHECK(icd.lib, return, "dlopen() failed - %s\n", dlerror());
+
+       icd.gpa = dlsym(icd.lib, "vk_icdGetInstanceProcAddr");
+       VK_CHECK(icd.gpa, return, "vk_icdGetInstanceProcAddr() not present.\n");
+
+       /* Retrieve extension enumeration functions. */
+       icd.enum_instance_extensions = (void *)icd.gpa(NULL, "vkEnumerateInstanceExtensionProperties");
+       VK_CHECK(icd.enum_instance_extensions, return,
+                        "vkEnumerateInstanceExtensionProperties() not present.\n");
+
+       icd.enum_device_extensions = (void *)icd.gpa(NULL, "vkEnumerateDeviceExtensionProperties");
+       VK_CHECK(icd.enum_device_extensions, return,
+                        "vkEnumerateDeviceExtensionProperties() not present.\n");
+
+       /* Get ICD global extension count. */
+       res = icd.enum_instance_extensions(NULL, &count, NULL);
+       VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n");
+
+       /* Allocate memory to hold the extensions both for ICD and WSI. */
+       icd.global_extensions =
+               malloc((count + ARRAY_LENGTH(global_extensions)) * sizeof(VkExtensionProperties));
+       VK_CHECK(icd.global_extensions, return, "malloc() failed.\n");
+
+       /* Copy ICD extensions first. */
+       res = icd.enum_instance_extensions(NULL, &count, icd.global_extensions);
+       VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n");
+
+       /* Append WSI extensions. */
+       memcpy(icd.global_extensions + count, global_extensions,
+                  ARRAY_LENGTH(global_extensions) * sizeof(VkExtensionProperties));
+
+       icd.global_extension_count = count + ARRAY_LENGTH(global_extensions);
+}
+
+static void __attribute__((destructor))
+icd_fini(void)
+{
+       if (icd.lib)
+               dlclose(icd.lib);
+}
+
+PFN_vkVoidFunction
+vk_icd_get_proc_addr(VkInstance instance, const char *name)
+{
+       return icd.gpa(instance, name);
+}
+
+VKAPI_ATTR VkResult VKAPI_CALL
+vk_EnumerateInstanceExtensionProperties(const char                             *layer_name,
+                                                                               uint32_t                                *count,
+                                                                               VkExtensionProperties   *extensions)
+{
+       if (!extensions) {
+               *count = icd.global_extension_count;
+               return VK_SUCCESS;
+       }
+
+       *count = MIN(*count, icd.global_extension_count);
+       memcpy(extensions, icd.global_extensions, *count * sizeof(VkExtensionProperties));
+
+       if (*count < icd.global_extension_count)
+               return VK_INCOMPLETE;
+
+       return VK_SUCCESS;
+}
+
+static const VkExtensionProperties device_extensions[] = {
+       { VK_KHR_SWAPCHAIN_EXTENSION_NAME, 67 },
+};
+
+VKAPI_ATTR VkResult VKAPI_CALL
+vk_EnumerateDeviceExtensionProperties(VkPhysicalDevice          pdev,
+                                                                         const char                    *layer_name,
+                                                                         uint32_t                              *count,
+                                                                         VkExtensionProperties *extensions)
+{
+       uint32_t                                 ext_count, copied = 0;
+       uint32_t                                 icd_count, max_count;
+       VkResult                                 result;
+
+       result = icd.enum_device_extensions(pdev, layer_name, &icd_count, NULL);
+       VK_CHECK(result == VK_SUCCESS, return VK_ERROR_OUT_OF_HOST_MEMORY,
+                        "vkEnumerateDeviceExtensionProperties() failed.\n");
+
+       max_count = icd_count + ARRAY_LENGTH(device_extensions);
+
+       if (!extensions) {
+               /* Just return the number of enabled extension properties in this case. */
+               *count = max_count;
+               return VK_SUCCESS;
+       }
+
+       /* We should copy ICD extensions and WSI extensions together into the given pointer. */
+
+       ext_count = MIN(*count, icd_count);
+       result = icd.enum_device_extensions(pdev, layer_name, &ext_count, extensions);
+       VK_CHECK(result == VK_SUCCESS || result == VK_INCOMPLETE, return VK_ERROR_OUT_OF_HOST_MEMORY,
+                        "vkEnumerateDeviceExtensionProperties() failed.\n");
+
+       /* Advance the destination pointer. */
+       extensions += ext_count;
+       copied += ext_count;
+
+       /* Calculate remaining extensions to copy. */
+       ext_count = *count - ext_count;
+
+       if (ext_count > 0) {
+               ext_count = MIN(ext_count, ARRAY_LENGTH(device_extensions));
+               memcpy(extensions, device_extensions, ext_count * sizeof(VkExtensionProperties));
+               copied += ext_count;
+       }
+
+       *count = copied;
+
+       if (*count < max_count)
+               return VK_INCOMPLETE;
+
+       return VK_SUCCESS;
+}
index e6be170..7d9fec0 100644 (file)
@@ -68,6 +68,9 @@ vk_realloc(const VkAllocationCallbacks *allocator, void *mem, size_t size,
 void
 vk_free(const VkAllocationCallbacks *allocator, void *mem);
 
+PFN_vkVoidFunction
+vk_icd_get_proc_addr(VkInstance instance, const char *name);
+
 /* Entry point proto types. */
 VKAPI_ATTR VkResult VKAPI_CALL
 vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index,