From e9ddb9abcd903fb3632854aa793a2955e30e9aa2 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Mon, 18 Apr 2016 12:46:52 +0900 Subject: [PATCH 01/16] entry-points: Fix func type of vkEnumerateInstanceExtensionProperties() Change-Id: I308b64051edfabe41ebc7967d8aee5080d324779 --- src/wsi/entry-points.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wsi/entry-points.c b/src/wsi/entry-points.c index e053463..581fe79 100644 --- a/src/wsi/entry-points.c +++ b/src/wsi/entry-points.c @@ -43,7 +43,7 @@ struct vk_entry { }; static const vk_entry_t entry_points[] = { - VK_ENTRY_POINT(EnumerateInstanceExtensionProperties, INSTANCE), + VK_ENTRY_POINT(EnumerateInstanceExtensionProperties, GLOBAL), VK_ENTRY_POINT(EnumerateDeviceExtensionProperties, INSTANCE), VK_ENTRY_POINT(GetPhysicalDeviceSurfaceSupportKHR, INSTANCE), VK_ENTRY_POINT(GetPhysicalDeviceSurfaceCapabilitiesKHR, INSTANCE), -- 2.7.4 From 8baf86d923fb0cdd0e53bdff9d966d9d382d2e2a Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Tue, 10 May 2016 14:50:04 +0900 Subject: [PATCH 02/16] wsi: Add devel package Vendors should use devel package for their drivers to work correctly with tizen vulkan WSI. Change-Id: Ie4bcfc6ef6d771b8a286857fd423c4f1c1238c6c --- packaging/vulkan-wsi-tizen.spec | 12 ++++++++++++ src/wsi/Makefile.am | 3 +++ src/wsi/vulkan-wsi-tizen.h | 11 +++++++++++ src/wsi/wsi.h | 5 +++-- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/wsi/vulkan-wsi-tizen.h diff --git a/packaging/vulkan-wsi-tizen.spec b/packaging/vulkan-wsi-tizen.spec index 4a71811..13b924b 100644 --- a/packaging/vulkan-wsi-tizen.spec +++ b/packaging/vulkan-wsi-tizen.spec @@ -26,9 +26,17 @@ Summary: Vulkan sample Group: Graphics & UI Framework/Hardware Adaptation Requires: %{name} = %{version}-%{release} +%package devel +Summary: Development package for tizen vulkan driver +Group: Graphics & UI Framework/Hardware Adaptation +Requires: %{name} = %{version}-%{release} + %description samples Vulkan WSI (Window System Integration) sample with null-driver for Test +%description devel +Development packages for tizen vulkan driver + %prep %setup -q @@ -55,3 +63,7 @@ cp %{_builddir}/%{buildsubdir}/samples/vulkaninfo %{buildroot}/%{_bindir} %{_libdir}/vulkan/null-driver.so %{_bindir}/tri %{_bindir}/vulkaninfo + +%files devel +%defattr(-,root,root,-) +%{_includedir}/vulkan/vulkan-wsi-tizen.h diff --git a/src/wsi/Makefile.am b/src/wsi/Makefile.am index a7325a7..4646ae1 100644 --- a/src/wsi/Makefile.am +++ b/src/wsi/Makefile.am @@ -3,6 +3,9 @@ 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_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/include \ -I$(top_srcdir)/src/utils \ -fvisibility=hidden \ diff --git a/src/wsi/vulkan-wsi-tizen.h b/src/wsi/vulkan-wsi-tizen.h new file mode 100644 index 0000000..6553053 --- /dev/null +++ b/src/wsi/vulkan-wsi-tizen.h @@ -0,0 +1,11 @@ +#ifndef VULKAN_WSI_TIZEN_H +#define VULKAN_WSI_TIZEN_H + +#include +#include +#include + +VkImage +vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h buffer); + +#endif /* VULKAN_WSI_TIZEN_H */ diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index b1dd0f3..3d67fe7 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -27,8 +27,8 @@ #include #include +#include "vulkan-wsi-tizen.h" #include -#include #include #include @@ -81,7 +81,8 @@ PFN_vkVoidFunction vk_icd_get_proc_addr(VkInstance instance, const char *name); VkImage -vk_icd_create_presentable_image(VkDevice, const VkImageCreateInfo *, tbm_surface_h); +vk_icd_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, + tbm_surface_h buffer); /* Entry point proto types. */ VKAPI_ATTR VkResult VKAPI_CALL -- 2.7.4 From b24ab47c9cd281a4bac18c51948a48ec2327a432 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:13:39 +0900 Subject: [PATCH 03/16] null-driver: Fix type cast warning Change-Id: I707d2552af61c4aa0778230d96e5cb3adfbbdd2c --- src/null-driver/null-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/null-driver/null-driver.c b/src/null-driver/null-driver.c index 1766edb..5cdcc67 100644 --- a/src/null-driver/null-driver.c +++ b/src/null-driver/null-driver.c @@ -2521,5 +2521,5 @@ vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_ if (nulldrv_img_create(dev, surface, info, false, &img) == VK_SUCCESS) return (VkImage)(uintptr_t)img; - return (uintptr_t)NULL; + return (VkImage)(uintptr_t)NULL; } -- 2.7.4 From 59782cb21c7c60426caa98e3ed499c9333bba352 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:17:44 +0900 Subject: [PATCH 04/16] wsi: Add function prototypes that vendors should provide Change-Id: Ie19a4dd9924cf9273f58f490d56f2d71b11aaeae --- src/wsi/vulkan-wsi-tizen.h | 12 ++++++++++-- src/wsi/wsi.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wsi/vulkan-wsi-tizen.h b/src/wsi/vulkan-wsi-tizen.h index 6553053..fede261 100644 --- a/src/wsi/vulkan-wsi-tizen.h +++ b/src/wsi/vulkan-wsi-tizen.h @@ -1,11 +1,19 @@ #ifndef VULKAN_WSI_TIZEN_H #define VULKAN_WSI_TIZEN_H -#include -#include +#include #include VkImage vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h buffer); +VkBool32 +vk_signal_semaphore(VkSemaphore semaphore); + +VkBool32 +vk_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores); + +VkBool32 +vk_signal_fence(VkFence fence); + #endif /* VULKAN_WSI_TIZEN_H */ diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index 3d67fe7..279a4b3 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -29,6 +29,7 @@ #include #include "vulkan-wsi-tizen.h" #include +#include #include #include -- 2.7.4 From 0350a9d909b24c4588a61b3cd9e2f523cf8a3644 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:29:19 +0900 Subject: [PATCH 05/16] null-driver: Implement functions required by vulkan-wsi-tizen.h Change-Id: I134d19221eb73b609be1e25a34ffe9dcc5cb1097 --- src/null-driver/Makefile.am | 1 + src/null-driver/null-driver.c | 19 +++++++++++++++++++ src/null-driver/null-driver.h | 3 --- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/null-driver/Makefile.am b/src/null-driver/Makefile.am index 872358e..c91e49e 100644 --- a/src/null-driver/Makefile.am +++ b/src/null-driver/Makefile.am @@ -5,6 +5,7 @@ AM_CFLAGS = $(GCC_CFLAGS) null_driver_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/include \ -I$(top_srcdir)/src/utils \ + -I$(top_srcdir)/src/wsi \ -fvisibility=hidden null_driver_la_LDFLAGS = -module -avoid-version diff --git a/src/null-driver/null-driver.c b/src/null-driver/null-driver.c index 5cdcc67..a309e31 100644 --- a/src/null-driver/null-driver.c +++ b/src/null-driver/null-driver.c @@ -34,6 +34,7 @@ #include #include #include +#include #if 0 #include @@ -2523,3 +2524,21 @@ vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_ return (VkImage)(uintptr_t)NULL; } + +VkBool32 +vk_signal_semaphore(VkSemaphore semaphore) +{ + return VK_TRUE; +} + +VkBool32 +vk_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores) +{ + return VK_TRUE; +} + +VkBool32 +vk_signal_fence(VkFence fence) +{ + return VK_TRUE; +} diff --git a/src/null-driver/null-driver.h b/src/null-driver/null-driver.h index 460897b..d3cb858 100644 --- a/src/null-driver/null-driver.h +++ b/src/null-driver/null-driver.h @@ -36,7 +36,4 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char *name); -VkImage -vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h surface); - #endif /* NULL_DRIVER_H */ -- 2.7.4 From 6b0a3f2d94d302779364590bb3c1d9d62bba9e2a Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:33:22 +0900 Subject: [PATCH 06/16] icd: Retreive semaphore and fence functions from ICD Change-Id: I5ebcf66738c6f58f0b589d89dbdc0a52539e0056 --- src/wsi/icd.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wsi/icd.c b/src/wsi/icd.c index b9eda4e..b356376 100644 --- a/src/wsi/icd.c +++ b/src/wsi/icd.c @@ -40,7 +40,12 @@ struct vk_icd { VkExtensionProperties *global_extensions; /* WSI-ICD interface. */ - VkImage (*create_presentable_image)(VkDevice, const VkImageCreateInfo *, tbm_surface_h); + 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, VkSemaphore *semaphores); + VkBool32 (*signal_fence)(VkFence fence); + }; static vk_icd_t icd; @@ -96,7 +101,10 @@ icd_init(void) icd.global_extension_count = count + ARRAY_LENGTH(global_extensions); - icd.create_presentable_image = dlsym(icd.lib, "vk_create_presentable_image"); + 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"); } static void __attribute__((destructor)) -- 2.7.4 From d0521091879afc6880b7a49390e4e3222e44982f Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:35:46 +0900 Subject: [PATCH 07/16] icd: Functions for calling vendor ICD semaphore and fence functions Change-Id: Idd757bae2504cb5ba94808f12e9191270fb8b088 --- src/wsi/icd.c | 18 ++++++++++++++++++ src/wsi/wsi.h | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/src/wsi/icd.c b/src/wsi/icd.c index b356376..b5678a0 100644 --- a/src/wsi/icd.c +++ b/src/wsi/icd.c @@ -128,6 +128,24 @@ vk_icd_create_presentable_image(VkDevice device, return icd.create_presentable_image(device, info, surface); } +VkBool32 +vk_icd_signal_semaphore(VkSemaphore semaphore) +{ + return icd.signal_semaphore(semaphore); +} + +VkBool32 +vk_icd_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores) +{ + return icd.wait_for_semaphores(count, semaphores); +} + +VkBool32 +vk_icd_signal_fence(VkFence fence) +{ + return icd.signal_fence(fence); +} + VKAPI_ATTR VkResult VKAPI_CALL vk_EnumerateInstanceExtensionProperties(const char *layer_name, uint32_t *count, diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index 279a4b3..00d1c0e 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -85,6 +85,15 @@ VkImage vk_icd_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h buffer); +VkBool32 +vk_icd_signal_semaphore(VkSemaphore semaphore); + +VkBool32 +vk_icd_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores); + +VkBool32 +vk_icd_signal_fence(VkFence fence); + /* Entry point proto types. */ VKAPI_ATTR VkResult VKAPI_CALL vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index, -- 2.7.4 From 96e417924fc371a5c74ff21de668a1997e8d3af2 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:44:29 +0900 Subject: [PATCH 08/16] swapchain: Signal fence and semaphore in vkAcquireNextImageKHR() Users should wait for fence or semaphore to be signaled in order to use the acquired VkImage. We signal them immediately because the dequeued buffer is already ready to be used. Later, we can do some kinda lazy signaling by returning buffer index immediately and signal fence or semaphore when wl_buffer.release actually arrives. Change-Id: I59c555f939834448ce4251552452c4a1bc54f26f --- src/wsi/swapchain.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wsi/swapchain.c b/src/wsi/swapchain.c index 961e649..40b1433 100644 --- a/src/wsi/swapchain.c +++ b/src/wsi/swapchain.c @@ -200,6 +200,17 @@ vk_AcquireNextImageKHR(VkDevice device, if (next == chain->buffers[i].tbm) { VK_DEBUG("%s, tbm_surface: %p, index: %d\n", __func__, next, i); *image_index = i; + + /* TODO: We can do optimization here by returning buffer index immediatly despite the + * buffer is not released yet. The fence or semaphore will be signaled when + * wl_buffer.release actually arrives. */ + + if (fence != VK_NULL_HANDLE) + vk_icd_signal_fence(fence); + + if (semaphore != VK_NULL_HANDLE) + vk_icd_signal_semaphore(semaphore); + return VK_SUCCESS; } } -- 2.7.4 From 6a09d1e71d49f75589fd40cd3998c174185dff42 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:48:45 +0900 Subject: [PATCH 09/16] wsi: Use const qualifier for semaphores in vk_wait_for_semaphores() Change-Id: I99c42eddee86aecf58b2fa315208299638682f24 --- src/null-driver/null-driver.c | 2 +- src/wsi/icd.c | 4 ++-- src/wsi/vulkan-wsi-tizen.h | 2 +- src/wsi/wsi.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/null-driver/null-driver.c b/src/null-driver/null-driver.c index a309e31..2835ef9 100644 --- a/src/null-driver/null-driver.c +++ b/src/null-driver/null-driver.c @@ -2532,7 +2532,7 @@ vk_signal_semaphore(VkSemaphore semaphore) } VkBool32 -vk_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores) +vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores) { return VK_TRUE; } diff --git a/src/wsi/icd.c b/src/wsi/icd.c index b5678a0..146c2ce 100644 --- a/src/wsi/icd.c +++ b/src/wsi/icd.c @@ -43,7 +43,7 @@ struct vk_icd { 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, VkSemaphore *semaphores); + VkBool32 (*wait_for_semaphores)(uint32_t count, const VkSemaphore *semaphores); VkBool32 (*signal_fence)(VkFence fence); }; @@ -135,7 +135,7 @@ vk_icd_signal_semaphore(VkSemaphore semaphore) } VkBool32 -vk_icd_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores) +vk_icd_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores) { return icd.wait_for_semaphores(count, semaphores); } diff --git a/src/wsi/vulkan-wsi-tizen.h b/src/wsi/vulkan-wsi-tizen.h index fede261..27e97f7 100644 --- a/src/wsi/vulkan-wsi-tizen.h +++ b/src/wsi/vulkan-wsi-tizen.h @@ -11,7 +11,7 @@ VkBool32 vk_signal_semaphore(VkSemaphore semaphore); VkBool32 -vk_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores); +vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores); VkBool32 vk_signal_fence(VkFence fence); diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index 00d1c0e..35761c7 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -89,7 +89,7 @@ VkBool32 vk_icd_signal_semaphore(VkSemaphore semaphore); VkBool32 -vk_icd_wait_for_semaphores(uint32_t count, VkSemaphore *semaphores); +vk_icd_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores); VkBool32 vk_icd_signal_fence(VkFence fence); -- 2.7.4 From 24f8ebbe5bbf2c351f2a552dc9ae5e688946966b Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 12 May 2016 18:49:57 +0900 Subject: [PATCH 10/16] swapchain: Wait semaphores before issueing present request Change-Id: I5425a825df875365c399d34a12bd57c154a7c000 --- src/wsi/swapchain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wsi/swapchain.c b/src/wsi/swapchain.c index 40b1433..763d06a 100644 --- a/src/wsi/swapchain.c +++ b/src/wsi/swapchain.c @@ -224,6 +224,8 @@ vk_QueuePresentKHR(VkQueue queue, { uint32_t i; + vk_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]; -- 2.7.4 From 78d5996595f0f13185727de342366e406d93a6a3 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Wed, 18 May 2016 13:54:58 +0900 Subject: [PATCH 11/16] wsi: Tizen vulkan WSI development header file documentation Change-Id: Ie93558c3b0cc65a3e25d702347f1e5c0c8961207 --- src/wsi/vulkan-wsi-tizen.h | 106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/wsi/vulkan-wsi-tizen.h b/src/wsi/vulkan-wsi-tizen.h index 27e97f7..df3041e 100644 --- a/src/wsi/vulkan-wsi-tizen.h +++ b/src/wsi/vulkan-wsi-tizen.h @@ -1,18 +1,124 @@ +/* + * 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 #include +/** + * 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); -- 2.7.4 From c108047b3d630e92278f7ef21193faa28c1c299a Mon Sep 17 00:00:00 2001 From: "deasung.kim" Date: Thu, 19 May 2016 14:00:03 +0900 Subject: [PATCH 12/16] null-driver: added missing VK_EXPORT keyword vk_signal_semaphore vk_wait_for_semaphores vk_signal_fence Change-Id: Iefe018d26d3a2bfb23f334be487883d8e28a261f --- src/null-driver/null-driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/null-driver/null-driver.c b/src/null-driver/null-driver.c index 2835ef9..e0648d5 100644 --- a/src/null-driver/null-driver.c +++ b/src/null-driver/null-driver.c @@ -2525,19 +2525,19 @@ vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_ return (VkImage)(uintptr_t)NULL; } -VkBool32 +VK_EXPORT VkBool32 vk_signal_semaphore(VkSemaphore semaphore) { return VK_TRUE; } -VkBool32 +VK_EXPORT VkBool32 vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores) { return VK_TRUE; } -VkBool32 +VK_EXPORT VkBool32 vk_signal_fence(VkFence fence) { return VK_TRUE; -- 2.7.4 From d4085d931deedc55f6d29c5cb366f014282269c3 Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 19 May 2016 14:06:25 +0900 Subject: [PATCH 13/16] utils: Add missing vk_container_of macro Change-Id: I5dc389412a8a22098f994b29e281d8dde659f2bf --- src/utils/utils.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/utils.h b/src/utils/utils.h index f92a2c8..4750d90 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -68,6 +68,9 @@ #define VK_ASSERT(exp) assert(exp) +#define vk_container_of(ptr, sample, member) \ + (__typeof__(sample))((char *)(ptr) - offsetof(__typeof__(*sample), member)) + typedef VkBool32 vk_bool_t; void -- 2.7.4 From 6b404d82a01a188add855650cc728eb68e8d869e Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Thu, 19 May 2016 17:18:44 +0900 Subject: [PATCH 14/16] wsi: Refactoring to support display surface Change-Id: I7be92c8251838995f618f961c9d595cbd77d19d9 --- src/wsi/Makefile.am | 3 +- src/wsi/entry-points.c | 11 ++- src/wsi/extensions.c | 97 +++++++++++++++++++++++++ src/wsi/icd.c | 193 ++++++++++--------------------------------------- src/wsi/swapchain.c | 17 +++-- src/wsi/wsi.h | 43 ++++++----- 6 files changed, 177 insertions(+), 187 deletions(-) create mode 100644 src/wsi/extensions.c diff --git a/src/wsi/Makefile.am b/src/wsi/Makefile.am index 4646ae1..bd8d241 100644 --- a/src/wsi/Makefile.am +++ b/src/wsi/Makefile.am @@ -21,7 +21,8 @@ vulkan_wsi_tizen_la_SOURCES = wsi.h \ swapchain.c \ display.c \ allocator.c \ - icd.c + icd.c \ + extensions.c manifestdir = /etc/vulkan/icd.d manifest_DATA = vulkan-wsi-tizen.json diff --git a/src/wsi/entry-points.c b/src/wsi/entry-points.c index 581fe79..143f2d3 100644 --- a/src/wsi/entry-points.c +++ b/src/wsi/entry-points.c @@ -84,6 +84,7 @@ get_entry_point(const char *name) VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_GetInstanceProcAddr(VkInstance instance, const char *name) { + vk_icd_t *icd = vk_get_icd(); const vk_entry_t *entry = get_entry_point(name); PFN_vkGetInstanceProcAddr gipa; @@ -106,7 +107,7 @@ vk_GetInstanceProcAddr(VkInstance instance, const char *name) } /* TODO: Avoid getting GIPA on the fly. */ - gipa = (PFN_vkGetInstanceProcAddr)vk_icd_get_proc_addr(instance, "vkGetInstanceProcAddr"); + gipa = (PFN_vkGetInstanceProcAddr)icd->get_proc_addr(instance, "vkGetInstanceProcAddr"); return gipa(instance, name); } @@ -114,6 +115,7 @@ vk_GetInstanceProcAddr(VkInstance instance, const char *name) VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_GetDeviceProcAddr(VkDevice device, const char *name) { + vk_icd_t *icd = vk_get_icd(); const vk_entry_t *entry = get_entry_point(name); PFN_vkGetDeviceProcAddr gdpa; @@ -128,7 +130,7 @@ vk_GetDeviceProcAddr(VkDevice device, const char *name) } /* TODO: We are trying to get the most specific device functions here. */ - gdpa = (PFN_vkGetDeviceProcAddr)vk_icd_get_proc_addr(NULL, "vkGetDeviceProcAddr"); + gdpa = (PFN_vkGetDeviceProcAddr)icd->get_proc_addr(NULL, "vkGetDeviceProcAddr"); gdpa = (PFN_vkGetDeviceProcAddr)gdpa(device, "vkGetDeviceProcAddr"); return gdpa(device, name); @@ -138,10 +140,11 @@ vk_GetDeviceProcAddr(VkDevice device, const char *name) VK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char *name) { - const vk_entry_t *entry = get_entry_point(name); + vk_icd_t *icd = vk_get_icd(); + const vk_entry_t *entry = get_entry_point(name); if (entry) return entry->func; - return vk_icd_get_proc_addr(instance, name); + return icd->get_proc_addr(instance, name); } diff --git a/src/wsi/extensions.c b/src/wsi/extensions.c new file mode 100644 index 0000000..e93ad78 --- /dev/null +++ b/src/wsi/extensions.c @@ -0,0 +1,97 @@ +/* + * 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 + +VKAPI_ATTR VkResult VKAPI_CALL +vk_EnumerateInstanceExtensionProperties(const char *layer_name, + uint32_t *count, + VkExtensionProperties *extensions) +{ + vk_icd_t *icd = vk_get_icd(); + + if (!extensions) { + *count = icd->instance_extension_count; + return VK_SUCCESS; + } + + *count = MIN(*count, icd->instance_extension_count); + memcpy(extensions, icd->instance_extensions, *count * sizeof(VkExtensionProperties)); + + if (*count < icd->instance_extension_count) + return VK_INCOMPLETE; + + return VK_SUCCESS; +} + +static const VkExtensionProperties wsi_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) +{ + vk_icd_t *icd = vk_get_icd(); + uint32_t max_ext_count, remaining, copied = 0; + VkResult result; + + result = icd->enum_dev_exts(pdev, layer_name, &max_ext_count, NULL); + VK_CHECK(result == VK_SUCCESS, return VK_ERROR_OUT_OF_HOST_MEMORY, + "vkEnumerateDeviceExtensionProperties() failed.\n"); + + max_ext_count += ARRAY_LENGTH(wsi_device_extensions); + + if (!extensions) { + *count = max_ext_count; + return VK_SUCCESS; + } + + /* Copy ICD extensions and WSI extensions together into the given pointer. */ + + /* Calculate the number of extensions we have to copy. */ + remaining = MIN(*count, max_ext_count); + + /* Copy ICD extensions first. */ + copied = remaining; + result = icd->enum_dev_exts(pdev, layer_name, &copied, extensions); + VK_CHECK(result == VK_SUCCESS || result == VK_INCOMPLETE, return VK_ERROR_OUT_OF_HOST_MEMORY, + "vkEnumerateDeviceExtensionProperties() failed.\n"); + + /* Calculate remaining extensions to copy. */ + remaining = MIN(remaining - copied, ARRAY_LENGTH(wsi_device_extensions)); + memcpy(extensions + copied, wsi_device_extensions, remaining * sizeof(VkExtensionProperties)); + copied += remaining; + + /* Return the number of extensions copied. */ + *count = copied; + + if (*count < max_ext_count) + return VK_INCOMPLETE; + + return VK_SUCCESS; +} diff --git a/src/wsi/icd.c b/src/wsi/icd.c index 146c2ce..7f02a04 100644 --- a/src/wsi/icd.c +++ b/src/wsi/icd.c @@ -27,194 +27,75 @@ #include #include -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; - - /* 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); - -}; - static vk_icd_t icd; -static const VkExtensionProperties global_extensions[] = { +vk_icd_t * +vk_get_icd(void) +{ + return &icd; +} + +static const VkExtensionProperties wsi_instance_extensions[] = { { VK_KHR_SURFACE_EXTENSION_NAME, 25 }, { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, 4 }, }; static void __attribute__((constructor)) -icd_init(void) +module_init(void) { - const char *filename; - VkResult res; + const char *filename; uint32_t count; + VkResult res; + PFN_vkEnumerateInstanceExtensionProperties enum_inst_exts; + /* Get env var for ICD path. */ filename = getenv("VK_TIZEN_ICD"); VK_CHECK(filename, return, "No ICD library given.\n"); dlerror(); + /* Open ICD file. */ 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 our first entry point for vulkan symbols. */ + icd.get_proc_addr = dlsym(icd.lib, "vk_icdGetInstanceProcAddr"); + VK_CHECK(icd.get_proc_addr, 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); + /* Dispatch device extension enumeration function. */ + icd.enum_dev_exts = (void *)icd.get_proc_addr(NULL, "vkEnumerateDeviceExtensionProperties"); + 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"); -} - -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); -} - -VkImage -vk_icd_create_presentable_image(VkDevice device, - const VkImageCreateInfo *info, - tbm_surface_h surface) -{ - return icd.create_presentable_image(device, info, surface); -} -VkBool32 -vk_icd_signal_semaphore(VkSemaphore semaphore) -{ - return icd.signal_semaphore(semaphore); -} + /* Initialize instance extensions. */ + enum_inst_exts = (void *)icd.get_proc_addr(NULL, "vkEnumerateInstanceExtensionProperties"); + VK_CHECK(enum_inst_exts, return, "vkEnumerateInstanceExtensionProperties() not present.\n"); -VkBool32 -vk_icd_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores) -{ - return icd.wait_for_semaphores(count, semaphores); -} + res = enum_inst_exts(NULL, &count, NULL); + VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n"); -VkBool32 -vk_icd_signal_fence(VkFence fence) -{ - return icd.signal_fence(fence); -} + count += ARRAY_LENGTH(wsi_instance_extensions); -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; - } + icd.instance_extensions = malloc(count * sizeof(VkExtensionProperties)); + VK_CHECK(icd.instance_extensions, return, "malloc() failed.\n"); - *count = MIN(*count, icd.global_extension_count); - memcpy(extensions, icd.global_extensions, *count * sizeof(VkExtensionProperties)); + res = enum_inst_exts(NULL, &count, icd.instance_extensions); + VK_CHECK(res == VK_SUCCESS, return, "vkEnumerateInstanceExtensionProperties() failed.\n"); - if (*count < icd.global_extension_count) - return VK_INCOMPLETE; + memcpy(icd.instance_extensions + count, wsi_instance_extensions, + ARRAY_LENGTH(wsi_instance_extensions) * sizeof(VkExtensionProperties)); - return VK_SUCCESS; + icd.instance_extension_count = count + ARRAY_LENGTH(wsi_instance_extensions); } -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) +static void __attribute__((destructor)) +module_fini(void) { - 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; + if (icd.lib) + dlclose(icd.lib); } diff --git a/src/wsi/swapchain.c b/src/wsi/swapchain.c index 763d06a..48734b8 100644 --- a/src/wsi/swapchain.c +++ b/src/wsi/swapchain.c @@ -31,6 +31,7 @@ vk_CreateSwapchainKHR(VkDevice device, const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchain) { + vk_icd_t *icd = vk_get_icd(); vk_swapchain_t *chain; tbm_format format; tpl_result_t res; @@ -103,7 +104,7 @@ vk_CreateSwapchainKHR(VkDevice device, }; chain->buffers[i].tbm = buffers[i]; - chain->buffers[i].image = vk_icd_create_presentable_image(device, &image_info, buffers[i]); + chain->buffers[i].image = icd->create_presentable_image(device, &image_info, buffers[i]); } chain->buffer_count = buffer_count; @@ -187,12 +188,13 @@ vk_AcquireNextImageKHR(VkDevice device, VkFence fence, uint32_t *image_index) { - /* TODO: apply timeout, semaphore, fence */ - + vk_icd_t *icd = vk_get_icd(); uint32_t i; tbm_surface_h next; vk_swapchain_t *chain = (vk_swapchain_t *)(uintptr_t)swapchain; + /* TODO: timeout */ + next = tpl_surface_dequeue_buffer(chain->tpl_surface); VK_CHECK(next, return VK_ERROR_SURFACE_LOST_KHR, "tpl_surface_dequeue_buffers() failed\n."); @@ -206,10 +208,10 @@ vk_AcquireNextImageKHR(VkDevice device, * wl_buffer.release actually arrives. */ if (fence != VK_NULL_HANDLE) - vk_icd_signal_fence(fence); + icd->signal_fence(fence); if (semaphore != VK_NULL_HANDLE) - vk_icd_signal_semaphore(semaphore); + icd->signal_semaphore(semaphore); return VK_SUCCESS; } @@ -222,9 +224,10 @@ VKAPI_ATTR VkResult VKAPI_CALL vk_QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *info) { - uint32_t i; + vk_icd_t *icd = vk_get_icd(); + uint32_t i; - vk_icd_wait_for_semaphores(info->waitSemaphoreCount, info->pWaitSemaphores); + icd->wait_for_semaphores(info->waitSemaphoreCount, info->pWaitSemaphores); for (i = 0; i < info->swapchainCount; i++) { tpl_result_t res; diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index 35761c7..d342b25 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -36,6 +36,27 @@ typedef struct vk_surface vk_surface_t; typedef struct vk_swapchain vk_swapchain_t; typedef struct vk_buffer vk_buffer_t; +typedef struct vk_icd vk_icd_t; + +struct vk_icd { + void *lib; + + PFN_vkGetInstanceProcAddr get_proc_addr; + PFN_vkEnumerateDeviceExtensionProperties enum_dev_exts; + + uint32_t instance_extension_count; + 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); +}; + +vk_icd_t * +vk_get_icd(void); struct vk_buffer { tbm_surface_h tbm; @@ -53,9 +74,6 @@ struct vk_swapchain { vk_buffer_t *buffers; }; -VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL -vk_icdGetInstanceProcAddr(VkInstance instance, const char *name); - const VkAllocationCallbacks * vk_get_allocator(void *parent, const VkAllocationCallbacks *allocator); @@ -78,23 +96,10 @@ vk_get_tpl_display(tpl_handle_t native_dpy) return display; }; -PFN_vkVoidFunction -vk_icd_get_proc_addr(VkInstance instance, const char *name); - -VkImage -vk_icd_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, - tbm_surface_h buffer); - -VkBool32 -vk_icd_signal_semaphore(VkSemaphore semaphore); - -VkBool32 -vk_icd_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores); - -VkBool32 -vk_icd_signal_fence(VkFence fence); - /* Entry point proto types. */ +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL +vk_icdGetInstanceProcAddr(VkInstance instance, const char *name); + VKAPI_ATTR VkResult VKAPI_CALL vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index, VkSurfaceKHR surface, VkBool32 *supported); -- 2.7.4 From f8dad796cae4348f8ef7de2519573cf656fe6b0e Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Fri, 27 May 2016 14:49:19 +0900 Subject: [PATCH 15/16] wsi: Better integration interface between WSI and ICD 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 | 20 +++++++ src/null-driver/null-driver.c | 49 ++++++----------- src/wsi/Makefile.am | 2 +- src/wsi/icd.c | 6 +- src/wsi/swapchain.c | 11 +--- src/wsi/vulkan-wsi-tizen.h | 125 ------------------------------------------ src/wsi/wsi.h | 8 +-- 7 files changed, 43 insertions(+), 178 deletions(-) create mode 100644 include/vulkan/vk_tizen.h delete mode 100644 src/wsi/vulkan-wsi-tizen.h diff --git a/include/vulkan/vk_tizen.h b/include/vulkan/vk_tizen.h new file mode 100644 index 0000000..1c25b63 --- /dev/null +++ b/include/vulkan/vk_tizen.h @@ -0,0 +1,20 @@ +#ifndef VK_TIZEN_H +#define VK_TIZEN_H + +#include +#include + +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 */ diff --git a/src/null-driver/null-driver.c b/src/null-driver/null-driver.c index e0648d5..15711e9 100644 --- a/src/null-driver/null-driver.c +++ b/src/null-driver/null-driver.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #if 0 #include @@ -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; -} diff --git a/src/wsi/Makefile.am b/src/wsi/Makefile.am index bd8d241..7c894b8 100644 --- a/src/wsi/Makefile.am +++ b/src/wsi/Makefile.am @@ -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 \ diff --git a/src/wsi/icd.c b/src/wsi/icd.c index 7f02a04..d9e85cc 100644 --- a/src/wsi/icd.c +++ b/src/wsi/icd.c @@ -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"); diff --git a/src/wsi/swapchain.c b/src/wsi/swapchain.c index 48734b8..d488595 100644 --- a/src/wsi/swapchain.c +++ b/src/wsi/swapchain.c @@ -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 index df3041e..0000000 --- a/src/wsi/vulkan-wsi-tizen.h +++ /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 -#include - -/** - * 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 */ diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index d342b25..24bfdbc 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -27,7 +27,7 @@ #include #include -#include "vulkan-wsi-tizen.h" +#include #include #include #include @@ -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 * -- 2.7.4 From af25734349f8f43d91b4ae51a741b2f7052cae2b Mon Sep 17 00:00:00 2001 From: Taekyun Kim Date: Tue, 7 Jun 2016 13:26:55 +0900 Subject: [PATCH 16/16] build: Fix incorrect include header file for devel package Change-Id: I72acefd6e300f8c124a5aaf429f0a23096d02f91 --- packaging/vulkan-wsi-tizen.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/vulkan-wsi-tizen.spec b/packaging/vulkan-wsi-tizen.spec index 13b924b..48fd3af 100644 --- a/packaging/vulkan-wsi-tizen.spec +++ b/packaging/vulkan-wsi-tizen.spec @@ -66,4 +66,4 @@ cp %{_builddir}/%{buildsubdir}/samples/vulkaninfo %{buildroot}/%{_bindir} %files devel %defattr(-,root,root,-) -%{_includedir}/vulkan/vulkan-wsi-tizen.h +%{_includedir}/vulkan/vk_tizen.h -- 2.7.4