wsi: Better integration interface between WSI and ICD 89/72789/1
authorTaekyun Kim <tkq.kim@samsung.com>
Fri, 27 May 2016 05:49:19 +0000 (14:49 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Thu, 2 Jun 2016 11:02:53 +0000 (20:02 +0900)
Now, ICD provides functions required by WSI as vulkan extensions.
Those extensions might be exposed user if required in the future.
ICD should return the extension functions for all possible query
functions (vk_icdGetInstanceProcAddr and vkGetXXXProcAddress)

Change-Id: I776790598d8d5f3056e5b42c8defb388b8d30e3d

include/vulkan/vk_tizen.h [new file with mode: 0644]
src/null-driver/null-driver.c
src/wsi/Makefile.am
src/wsi/icd.c
src/wsi/swapchain.c
src/wsi/vulkan-wsi-tizen.h [deleted file]
src/wsi/wsi.h

diff --git a/include/vulkan/vk_tizen.h b/include/vulkan/vk_tizen.h
new file mode 100644 (file)
index 0000000..1c25b63
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef VK_TIZEN_H
+#define VK_TIZEN_H
+
+#include <vulkan/vulkan.h>
+#include <tbm_surface.h>
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateImageFromNativeBufferTIZEN)(VkDevice device, tbm_surface_h
+                                                                                                                                        surface, const
+                                                                                                                                        VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkImage *pImage);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageFromNativeBufferTIZEN(
+       VkDevice                                                                        device,
+       tbm_surface_h                                                           surface,
+       const VkImageCreateInfo *                                       pCreateInfo,
+       const VkAllocationCallbacks *                           pAllocator,
+       VkImage *                                                                       pImage);
+#endif
+
+#endif /* VK_TIZEN_H */
index e0648d5..15711e9 100644 (file)
@@ -34,7 +34,7 @@
 #include <string.h>
 #include <vulkan/vk_icd.h>
 #include <utils.h>
-#include <vulkan-wsi-tizen.h>
+#include <vulkan/vk_tizen.h>
 
 #if 0
 #include <stdio.h>
@@ -2284,9 +2284,22 @@ get_physical_device_image_format_properties(VkPhysicalDevice dev,
        return VK_SUCCESS;
 }
 
+static VKAPI_ATTR VkResult VKAPI_CALL
+create_image_from_native_buffer_TIZEN(VkDevice                                         device,
+                                                                         tbm_surface_h                                 surface,
+                                                                         const VkImageCreateInfo *             info,
+                                                                         const VkAllocationCallbacks * allocator,
+                                                                         VkImage *                                             image)
+{
+       NULLDRV_LOG_FUNC;
+       struct nulldrv_dev *dev = nulldrv_dev(device);
+
+       return nulldrv_img_create(dev, surface, info, false,
+                                                         (struct nulldrv_img **) image);
+}
 struct nulldrv_entry
 {
-       const char      *name;
+       const char      *name;
        void            *func;
 };
 
@@ -2337,6 +2350,7 @@ static const struct nulldrv_entry device_funcs[] =
        { "vkCreateBufferView", create_buffer_view },
        { "vkDestroyBufferView", destroy_buffer_view },
        { "vkCreateImage", create_image },
+       { "vkCreateImageFromNativeBufferTIZEN", create_image_from_native_buffer_TIZEN },
        { "vkDestroyImage", destroy_image },
        { "vkGetImageSubresourceLayout", get_image_subresource_layout },
        { "vkCreateImageView", create_image_view },
@@ -2511,34 +2525,3 @@ vk_icdGetInstanceProcAddr(VkInstance instance, const char *name)
 
        return NULL;
 }
-
-VK_EXPORT VkImage
-vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h surface)
-{
-       NULLDRV_LOG_FUNC;
-       struct nulldrv_dev *dev = nulldrv_dev(device);
-       struct nulldrv_img *img;
-
-       if (nulldrv_img_create(dev, surface, info, false, &img) == VK_SUCCESS)
-               return (VkImage)(uintptr_t)img;
-
-       return (VkImage)(uintptr_t)NULL;
-}
-
-VK_EXPORT VkBool32
-vk_signal_semaphore(VkSemaphore semaphore)
-{
-       return VK_TRUE;
-}
-
-VK_EXPORT VkBool32
-vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores)
-{
-       return VK_TRUE;
-}
-
-VK_EXPORT VkBool32
-vk_signal_fence(VkFence fence)
-{
-       return VK_TRUE;
-}
index bd8d241..7c894b8 100644 (file)
@@ -4,7 +4,7 @@ moduledir = $(libdir)/vulkan
 AM_CFLAGS = $(GCC_CFLAGS)
 
 vulkan_wsi_tizen_includedir = $(includedir)/vulkan
-vulkan_wsi_tizen_include_HEADERS = vulkan-wsi-tizen.h
+vulkan_wsi_tizen_include_HEADERS = $(top_srcdir)/include/vulkan/vk_tizen.h
 
 vulkan_wsi_tizen_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/include      \
                                                         -I$(top_srcdir)/src/utils                              \
index 7f02a04..d9e85cc 100644 (file)
@@ -67,10 +67,8 @@ module_init(void)
        VK_CHECK(icd.enum_dev_exts, return, "vkEnumerateDeviceExtensionProperties() not present.\n");
 
        /* Retrieve WSI-ICD interface functions. */
-       icd.create_presentable_image    = dlsym(icd.lib, "vk_create_presentable_image");
-       icd.signal_semaphore                    = dlsym(icd.lib, "vk_signal_semaphore");
-       icd.wait_for_semaphores                 = dlsym(icd.lib, "vk_wait_for_semaphores");
-       icd.signal_fence                                = dlsym(icd.lib, "vk_signal_fence");
+       icd.create_presentable_image =
+               (void *)icd.get_proc_addr(NULL, "vkCreateImageFromNativeBufferTIZEN");
 
        /* Initialize instance extensions. */
        enum_inst_exts = (void *)icd.get_proc_addr(NULL, "vkEnumerateInstanceExtensionProperties");
index 48734b8..d488595 100644 (file)
@@ -104,7 +104,8 @@ vk_CreateSwapchainKHR(VkDevice                                                       device,
                };
 
                chain->buffers[i].tbm = buffers[i];
-               chain->buffers[i].image = icd->create_presentable_image(device, &image_info, buffers[i]);
+               icd->create_presentable_image(device, buffers[i], &image_info, allocator,
+                                                                         &chain->buffers[i].image);
        }
 
        chain->buffer_count = buffer_count;
@@ -207,12 +208,6 @@ vk_AcquireNextImageKHR(VkDevice                     device,
                         * buffer is not released yet. The fence or semaphore will be signaled when
                         * wl_buffer.release actually arrives. */
 
-                       if (fence != VK_NULL_HANDLE)
-                               icd->signal_fence(fence);
-
-                       if (semaphore != VK_NULL_HANDLE)
-                               icd->signal_semaphore(semaphore);
-
                        return VK_SUCCESS;
                }
        }
@@ -227,8 +222,6 @@ vk_QueuePresentKHR(VkQueue                                   queue,
        vk_icd_t        *icd = vk_get_icd();
        uint32_t         i;
 
-       icd->wait_for_semaphores(info->waitSemaphoreCount, info->pWaitSemaphores);
-
        for (i = 0; i < info->swapchainCount; i++) {
                tpl_result_t res;
                vk_swapchain_t  *chain = (vk_swapchain_t *)(uintptr_t)info->pSwapchains[i];
diff --git a/src/wsi/vulkan-wsi-tizen.h b/src/wsi/vulkan-wsi-tizen.h
deleted file mode 100644 (file)
index df3041e..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * This header file defines interface between tizen vulkan WSI implementation and vendor vulkan ICD.
- * Following is a brief diagram how vulkan is provided on tizen platform.
- *
- *      -------------------------------------------------
- *      |             Vulkan Application                |
- *      -------------------------------------------------
- *      -------------------------------------------------
- *      |            Khronos Vulkan Loader              |
- *      -------------------------------------------------
- *      -------------------------------------------------
- *      |              Tizen Vulkan WSI                 |
- *      -------------------------------------------------
- *      -------------------------------------------------
- *      |                Vendor ICD                     |
- *      -------------------------------------------------
- *
- * Khronos vulkan loader provides libvulkan.so so that applications can link against it to use
- * vulkan symbols. Application can choose layers to activate and ICD to load by configuring khronos
- * vulkan loader settings.
- *
- * On tizen, tizen vulkan WSI wraps a vendor ICD and behaves as if it is a complete vulkan ICD. As
- * we all know, loader will dispatch vulkan functions using vk_icdGetInstanceProcAddr(). WSI
- * provides the function to the loader and the function dispatches WSI functions and vendor ICD
- * functions.
- *
- * Vendor ICD does not need to concern the above loading mechanism. They can implement their ICD
- * like a normal khronos-loader-loadable ICD. However, in order to implement WSI functions, vendor
- * ICD should provides some functions to WSI. The functions are defined in this header file and
- * they should be exposed in the vendor ICD .so file so that it can be retrieved via dlsym.
- */
-#ifndef VULKAN_WSI_TIZEN_H
-#define VULKAN_WSI_TIZEN_H
-
-#include <vulkan/vulkan.h>
-#include <tpl.h>
-
-/**
- * Create a VkImage which is used for presentation from the given tbm_surface_h.
- *
- * @param device       VkDevice where the image belongs to.
- * @param info         Pointer to the structure VkImageCreateInfo, see below descriptions.
- * @param buffer       tbm_surface_h which is the actual pixel storage of the image.
- *
- * After an application creates a swapchain, swapchain images can be queried via
- * vkGetSwapchainImagesKHR(). However, VkImage is vendor ICD defined object, so vendor ICDs should
- * provide functions for creating VkImage from native buffer. On tizen, we use tbm_surface_h as
- * the native buffer type.
- *
- * Vendors can get various information about the tbm_surface_h using libtbm like dimension, format,
- * planes (multi-planar) including tbm_bo. Vendor can implement their ICD using the provided tbm
- * APIs.
- *
- * Paremeter "info" should be NULL. It is reserved for future use.
- */
-VkImage
-vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info,    tbm_surface_h buffer);
-
-/**
- * Turn the given semaphore into signaled state.
- *
- * @param      semaphore       VkSemaphore to signal.
- *
- * @returns    VK_TRUE if succeed, VK_FALSE otherwise.
- *
- * vkAcquireNextImageKHR() gives semaphore or fence to be signaled when the acquired image is ready
- * to be accessed. When the image will be ready is WSI implementation specific and so WSI should be
- * able to signal the given semaphore when the image is ready.
- *
- * This function should be thread-safe. WSI should be able to call this function from any thread.
- */
-VkBool32
-vk_signal_semaphore(VkSemaphore semaphore);
-
-/**
- * Wait for given semaphores to be signaled.
- *
- * @param count                        the number of semaphores to wait for.
- * @param semaphores   pointer to the array of semaphores.
- *
- * @returns    VK_TRUE if succeed, VK_FALSE otherwise.
- *
- * WSI should wait for semaphores before issueing present request to the presentation engine in
- * vkQueuepresentKHR(). This function returns when all of the given semaphores are signaled.
- */
-VkBool32
-vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores);
-
-/**
- * Turn the given fence into signaled state.
- *
- * @param      fence   VkFence to signal.
- *
- * @returns    VK_TRUE if succeed, VK_FALSE otherwise.
- *
- * @see vk_signal_semaphore()
- */
-VkBool32
-vk_signal_fence(VkFence fence);
-
-#endif /* VULKAN_WSI_TIZEN_H */
index d342b25..24bfdbc 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <config.h>
 #include <vulkan/vulkan.h>
-#include "vulkan-wsi-tizen.h"
+#include <vulkan/vk_tizen.h>
 #include <stdbool.h>
 #include <vulkan/vk_icd.h>
 #include <utils.h>
@@ -48,11 +48,7 @@ struct vk_icd {
        VkExtensionProperties   *instance_extensions;
 
        /* WSI-ICD interface. */
-       VkImage (*create_presentable_image)(VkDevice device, const VkImageCreateInfo *info,
-                                                                               tbm_surface_h buffer);
-       VkBool32 (*signal_semaphore)(VkSemaphore semaphore);
-       VkBool32 (*wait_for_semaphores)(uint32_t count, const VkSemaphore *semaphores);
-       VkBool32 (*signal_fence)(VkFence fence);
+       PFN_vkCreateImageFromNativeBufferTIZEN  create_presentable_image;
 };
 
 vk_icd_t *