From: Taekyun Kim Date: Thu, 14 Apr 2016 06:54:02 +0000 (+0900) Subject: surface: swapchain: WSI do not need to implement surface create/destroy X-Git-Tag: submit/submit/tizen/20170906.070327/20170906.070422~64 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0fd3265f62df747f14ba3baf7d3d285284939b2e;p=platform%2Fcore%2Fuifw%2Fvulkan-wsi-tizen.git surface: swapchain: WSI do not need to implement surface create/destroy vkCreate*SurfaceKHR/vkDestroySurfaceKHR are implemented in the vulkan loader. Implementing swapchain functions would be enough. Change-Id: Ic27ed8d513ebb45c106794e3db2c4f243a058151 --- diff --git a/src/wsi/entry-points.c b/src/wsi/entry-points.c index cbce212..96cf20c 100644 --- a/src/wsi/entry-points.c +++ b/src/wsi/entry-points.c @@ -57,7 +57,6 @@ struct vk_icd_loader { }; static const vk_entry_t entry_points[] = { - VK_ENTRY_POINT(DestroySurfaceKHR, INSTANCE), VK_ENTRY_POINT(EnumerateInstanceExtensionProperties, INSTANCE), VK_ENTRY_POINT(EnumerateDeviceExtensionProperties, INSTANCE), VK_ENTRY_POINT(GetPhysicalDeviceSurfaceSupportKHR, INSTANCE), @@ -75,9 +74,7 @@ static const vk_entry_t entry_points[] = { VK_ENTRY_POINT(GetDisplayModePropertiesKHR, INSTANCE), VK_ENTRY_POINT(CreateDisplayModeKHR, INSTANCE), VK_ENTRY_POINT(GetDisplayPlaneCapabilitiesKHR, INSTANCE), - VK_ENTRY_POINT(CreateDisplayPlaneSurfaceKHR, INSTANCE), VK_ENTRY_POINT(CreateSharedSwapchainsKHR, DEVICE), - VK_ENTRY_POINT(CreateWaylandSurfaceKHR,INSTANCE), VK_ENTRY_POINT(GetPhysicalDeviceWaylandPresentationSupportKHR,INSTANCE), VK_ENTRY_POINT(GetInstanceProcAddr, INSTANCE), VK_ENTRY_POINT(GetDeviceProcAddr, DEVICE), diff --git a/src/wsi/surface.c b/src/wsi/surface.c index d5cb631..b3dff9d 100644 --- a/src/wsi/surface.c +++ b/src/wsi/surface.c @@ -25,56 +25,6 @@ #include "wsi.h" #include -VKAPI_ATTR void VKAPI_CALL -vk_DestroySurfaceKHR(VkInstance instance, - VkSurfaceKHR surface, - const VkAllocationCallbacks *allocator) -{ - vk_surface_t *sfc = (vk_surface_t *)surface; - - if (sfc->tpl.surface) - tpl_object_unreference((tpl_object_t *)sfc->tpl.surface); - if (sfc->tpl.display) - tpl_object_unreference((tpl_object_t *)sfc->tpl.display); - - vk_free(&sfc->allocator, sfc); -} - -VKAPI_ATTR VkResult VKAPI_CALL -vk_CreateWaylandSurfaceKHR(VkInstance instance, - const VkWaylandSurfaceCreateInfoKHR *info, - const VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface) -{ - vk_surface_t *sfc; - - allocator = vk_get_allocator(instance, allocator); - - sfc = vk_alloc(allocator, sizeof(vk_surface_t), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - VK_CHECK(sfc, return VK_ERROR_OUT_OF_HOST_MEMORY, "vk_alloc() failed.\n"); - - memset(sfc, 0x00, sizeof(vk_surface_t)); - - sfc->allocator = *allocator; - sfc->platform.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND; - sfc->platform.wayland.display = info->display; - sfc->platform.wayland.surface = info->surface; - - sfc->tpl.display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI, info->display); - VK_CHECK(sfc->tpl.display, goto error, "tpl_display_create() failed.\n"); - - sfc->tpl.surface = tpl_surface_create(sfc->tpl.display, info->surface, TPL_SURFACE_TYPE_WINDOW, - TBM_FORMAT_ARGB8888); - VK_CHECK(sfc->tpl.surface, goto error, "tpl_surface_create() failed.\n"); - - *surface = (VkSurfaceKHR)sfc; - return VK_SUCCESS; - -error: - vk_DestroySurfaceKHR(instance, (VkSurfaceKHR)sfc, allocator); - return VK_ERROR_INITIALIZATION_FAILED; -} - VKAPI_ATTR VkBool32 VKAPI_CALL vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index, @@ -85,36 +35,6 @@ vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev, } VKAPI_ATTR VkResult VKAPI_CALL -vk_CreateDisplayPlaneSurfaceKHR(VkInstance instance, - const VkDisplaySurfaceCreateInfoKHR *info, - const VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface) -{ - vk_surface_t *sfc; - - allocator = vk_get_allocator(instance, allocator); - - sfc = vk_alloc(allocator, sizeof(vk_surface_t), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); - VK_CHECK(sfc, return VK_ERROR_OUT_OF_HOST_MEMORY, "vk_alloc() failed.\n"); - - sfc->allocator = *allocator; - sfc->platform.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY; - sfc->platform.display.displayMode = info->displayMode; - sfc->platform.display.planeIndex = info->planeIndex; - sfc->platform.display.planeStackIndex = info->planeStackIndex; - sfc->platform.display.transform = info->transform; - sfc->platform.display.globalAlpha = info->globalAlpha; - sfc->platform.display.alphaMode = info->alphaMode; - sfc->platform.display.imageExtent = info->imageExtent; - - *surface = (VkSurfaceKHR)sfc; - - /* TODO: */ - - return VK_SUCCESS; -} - -VKAPI_ATTR VkResult VKAPI_CALL vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index, VkSurfaceKHR surface, @@ -129,31 +49,48 @@ vk_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice pdev, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *caps) { - int min, max; - tpl_result_t res; - vk_surface_t *sfc = (vk_surface_t *)surface; + VkIcdSurfaceWayland *sfc = (VkIcdSurfaceWayland *)surface; + tpl_display_t *display; + VK_CHECK(sfc->base.platform == VK_ICD_WSI_PLATFORM_WAYLAND, return VK_ERROR_DEVICE_LOST, + "Not supported platform surface.\n"); + + display = tpl_display_get(sfc->display); + VK_CHECK(display, return VK_ERROR_DEVICE_LOST, "tpl_display_get() failed.\n"); + +#if 0 res = tpl_surface_query_supported_buffer_count(sfc->tpl.surface, &min, &max); VK_CHECK(res == TPL_ERROR_NONE, return VK_ERROR_DEVICE_LOST, "tpl_surface_query_supported_buffer_count() failed.\n"); +#endif + + /* TODO: Hard-coded. */ + caps->minImageCount = 3; + caps->maxImageCount = 3; - caps->minImageCount = min; - caps->maxImageCount = max; caps->currentExtent.width = -1; caps->currentExtent.height = -1; + caps->minImageExtent.width = 1; caps->minImageExtent.height = 1; + caps->maxImageExtent.width = INT16_MAX; caps->maxImageExtent.height = INT16_MAX; + caps->maxImageArrayLayers = 1; + caps->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; caps->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; caps->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR | VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR; + caps->supportedUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + if (display) + tpl_object_unreference((tpl_object_t *)display); + return VK_SUCCESS; } diff --git a/src/wsi/swapchain.c b/src/wsi/swapchain.c index f15c90c..373c34d 100644 --- a/src/wsi/swapchain.c +++ b/src/wsi/swapchain.c @@ -31,10 +31,12 @@ vk_CreateSwapchainKHR(VkDevice device, const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchain) { - vk_swapchain_t *chain; - vk_surface_t *sfc = (vk_surface_t *)info->surface; - tbm_format format; - tpl_result_t res; + vk_swapchain_t *chain; + tbm_format format; + tpl_result_t res; + VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)info->surface; + + VK_ASSERT(surface->base.platform == VK_ICD_WSI_PLATFORM_WAYLAND); switch (info->imageFormat) { case VK_FORMAT_R8G8B8_SRGB: @@ -44,7 +46,7 @@ vk_CreateSwapchainKHR(VkDevice device, format = TBM_FORMAT_ARGB8888; break; default: - format = TBM_FORMAT_ARGB8888; + return VK_ERROR_SURFACE_LOST_KHR; } allocator = vk_get_allocator(device, allocator); @@ -54,17 +56,33 @@ vk_CreateSwapchainKHR(VkDevice device, memset(chain, 0x00, sizeof(vk_swapchain_t)); - res = tpl_surface_create_swapchain(sfc->tpl.surface, format, info->imageExtent.width, - info->imageExtent.height, info->minImageCount); - VK_CHECK(res == TPL_ERROR_NONE, goto error, "tpl_surface_create_swapchain() failed.\n"); - chain->allocator = *allocator; - chain->surface = sfc; + chain->surface = info->surface; + + /* Don't check NULL for display and window. There might be default ones for some systems. */ + + chain->tpl_display = tpl_display_get(surface->display); + VK_CHECK(chain->tpl_display, goto error, "tpl_display_get() failed.\n"); + + chain->tpl_surface = tpl_surface_create(chain->tpl_display, surface->surface, + TPL_SURFACE_TYPE_WINDOW, format); + VK_CHECK(chain->tpl_surface, goto error, "tpl_surface_create() failed.\n"); + + res = tpl_surface_create_swapchain(chain->tpl_surface, format, + info->imageExtent.width, info->imageExtent.height, + info->minImageCount); + VK_CHECK(res == TPL_ERROR_NONE, goto error, "tpl_surface_create_swapchain() failed.\n"); *swapchain = (VkSwapchainKHR)chain; return VK_SUCCESS; error: + if (chain->tpl_display) + tpl_object_unreference((tpl_object_t *)chain->tpl_display); + + if (chain->tpl_surface) + tpl_object_unreference((tpl_object_t *)chain->tpl_surface); + vk_free(allocator, chain); return VK_ERROR_DEVICE_LOST; } @@ -87,9 +105,15 @@ vk_DestroySwapchainKHR(VkDevice device, { vk_swapchain_t *chain = (vk_swapchain_t *)swapchain; - tpl_surface_destroy_swapchain(chain->surface->tpl.surface); + tpl_surface_destroy_swapchain(chain->tpl_surface); free(chain->buffers); + if (chain->tpl_display) + tpl_object_unreference((tpl_object_t *)chain->tpl_display); + + if (chain->tpl_surface) + tpl_object_unreference((tpl_object_t *)chain->tpl_surface); + vk_free(&chain->allocator, chain); } @@ -105,8 +129,7 @@ vk_GetSwapchainImagesKHR(VkDevice device, tpl_result_t res; int buffer_count; - res = tpl_surface_get_swapchain_buffers(chain->surface->tpl.surface, - &chain->buffers, &buffer_count); + res = tpl_surface_get_swapchain_buffers(chain->tpl_surface, &chain->buffers, &buffer_count); VK_CHECK(res == TPL_ERROR_NONE, return VK_ERROR_SURFACE_LOST_KHR, "tpl_surface_get_swapchain_buffers() failed\n."); chain->buffer_count = buffer_count; @@ -145,7 +168,7 @@ vk_AcquireNextImageKHR(VkDevice device, tbm_surface_h next; vk_swapchain_t *chain = (vk_swapchain_t *)swapchain; - next = tpl_surface_dequeue_buffer(chain->surface->tpl.surface); + next = tpl_surface_dequeue_buffer(chain->tpl_surface); VK_CHECK(next, return VK_ERROR_SURFACE_LOST_KHR, "tpl_surface_dequeue_buffers() failed\n."); for (i = 0; i < chain->buffer_count; i++) { @@ -168,7 +191,7 @@ vk_QueuePresentKHR(VkQueue queue, tpl_result_t res; vk_swapchain_t *chain = (vk_swapchain_t *)info->pSwapchains[i]; - res = tpl_surface_enqueue_buffer(chain->surface->tpl.surface, + res = tpl_surface_enqueue_buffer(chain->tpl_surface, chain->buffers[info->pImageIndices[i]]); if (info->pResults != NULL) diff --git a/src/wsi/wsi.h b/src/wsi/wsi.h index a50f65f..9b16c46 100644 --- a/src/wsi/wsi.h +++ b/src/wsi/wsi.h @@ -35,27 +35,15 @@ typedef struct vk_surface vk_surface_t; typedef struct vk_swapchain vk_swapchain_t; -struct vk_surface { - union { - VkIcdSurfaceBase base; - VkIcdSurfaceDisplay display; - VkIcdSurfaceWayland wayland; - } platform; - - VkAllocationCallbacks allocator; - - struct { - tpl_display_t *display; - tpl_surface_t *surface; - } tpl; -}; - struct vk_swapchain { - VkAllocationCallbacks allocator; - vk_surface_t *surface; + VkAllocationCallbacks allocator; + VkSurfaceKHR surface; + + tpl_display_t *tpl_display; + tpl_surface_t *tpl_surface; - tbm_surface_h *buffers; - uint32_t buffer_count; + uint32_t buffer_count; + tbm_surface_h *buffers; }; VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL @@ -75,10 +63,6 @@ void vk_free(const VkAllocationCallbacks *allocator, void *mem); /* Entry point proto types. */ -VKAPI_ATTR void VKAPI_CALL -vk_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, - const VkAllocationCallbacks *allocator); - VKAPI_ATTR VkResult VKAPI_CALL vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index, VkSurfaceKHR surface, VkBool32 *supported); @@ -140,18 +124,10 @@ vk_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice pdev, VkDisplayModeKHR mode, uint32_t plane_index, VkDisplayPlaneCapabilitiesKHR *caps); VKAPI_ATTR VkResult VKAPI_CALL -vk_CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *info, - const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); - -VKAPI_ATTR VkResult VKAPI_CALL vk_CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchain_count, const VkSwapchainCreateInfoKHR *infos, const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchains); -VKAPI_ATTR VkResult VKAPI_CALL -vk_CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *info, - const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); - VKAPI_ATTR VkBool32 VKAPI_CALL vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index,