From 0a2c318d9c48bce0d5865be69c008631a5f98e87 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 9 Nov 2016 10:20:31 -0800 Subject: vulkan/wsi/wayland: Include pthread.h We use pthreads and, for some reason, it wasn't getting included Signed-off-by: Jason Ekstrand Cc: "13.0" (cherry picked from commit 3b6abfc69ac485006cbedba7bcad234888cad44f) --- src/vulkan/wsi/wsi_common_wayland.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/vulkan/wsi/wsi_common_wayland.c') diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 196ee28..79f7e96 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "wsi_common_wayland.h" -- cgit v1.1 From a4b67f664e6a52898e681b35ca769e1fd206a4d1 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 9 Nov 2016 10:21:03 -0800 Subject: vulkan/wsi/wayland: Clean up some error handling paths This gets rid of all the memory leaks reported by the WSI CTS tests. Signed-off-by: Jason Ekstrand Reviewed-by: Dave Airlie Cc: "13.0" (cherry picked from commit 302f641d14f5c4d1560b6a0170803e21bd4bb976) --- src/vulkan/wsi/wsi_common_wayland.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/vulkan/wsi/wsi_common_wayland.c') diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 79f7e96..a61b74d 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -322,6 +322,8 @@ wsi_wl_get_display(struct wsi_device *wsi_device, pthread_mutex_unlock(&wsi->mutex); struct wsi_wl_display *display = wsi_wl_display_create(wsi, wl_display); + if (!display) + return NULL; pthread_mutex_lock(&wsi->mutex); @@ -398,6 +400,8 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface, VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)icd_surface; struct wsi_wl_display *display = wsi_wl_get_display(wsi_device, surface->display); + if (!display) + return VK_ERROR_OUT_OF_HOST_MEMORY; uint32_t count = u_vector_length(&display->formats); @@ -827,6 +831,10 @@ wsi_wl_finish_wsi(struct wsi_device *wsi_device, (struct wsi_wayland *)wsi_device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND]; if (wsi) { + struct hash_entry *entry; + hash_table_foreach(wsi->displays, entry) + wsi_wl_display_destroy(wsi, entry->data); + _mesa_hash_table_destroy(wsi->displays, NULL); pthread_mutex_destroy(&wsi->mutex); -- cgit v1.1 From cf8b11fc6ce5618117bb48aca108ea448438a926 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 4 Nov 2016 15:42:48 -0700 Subject: vulkan/wsi: Report the correct min/maxImageCount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the Vulkan spec 1.0.32 section 29.6 docs for vkAcquireNextImageKHR: "Let n be the total number of images in the swapchain, m be the value of VkSurfaceCapabilitiesKHR::minImageCount, and a be the number of presentable images that the application has currently acquired (i.e. images acquired with vkAcquireNextImageKHR, but not yet presented with vkQueuePresentKHR). vkAcquireNextImageKHR can always succeed if a ≤ n - m at the time vkAcquireNextImageKHR is called. vkAcquireNextImageKHR should not be called if a > n - m with a timeout of UINT64_MAX; in such a case, vkAcquireNextImageKHR may block indefinitely." With minImageCount == 2 (as it was previously, the client is allowed to acquire all but one image withoutblocking. If we really need 4 images for mailbox mode + pageflipping, then we need to request a minimum of 4 images up-front. This is a bit unfortunate because it means we will always consume 4 images. In the future, we may be able to optimize this a bit by waiting until the server starts to flip and returning OUT_OF_DATE to get the client to re-allocate with more images or something like that. Signed-off-by: Jason Ekstrand Reviewed-by: Dave Airlie Cc: "13.0" (cherry picked from commit 4fa0ca80eeeac813affcbb0129ed61f1534d8df0) --- src/vulkan/wsi/wsi_common_wayland.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/vulkan/wsi/wsi_common_wayland.c') diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index a61b74d..d28c430 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -42,8 +42,6 @@ memcpy((dest), (src), (count) * sizeof(*(src))); \ }) -#define MIN_NUM_IMAGES 2 - struct wsi_wayland; struct wsi_wl_display { @@ -369,8 +367,16 @@ static VkResult wsi_wl_surface_get_capabilities(VkIcdSurfaceBase *surface, VkSurfaceCapabilitiesKHR* caps) { - caps->minImageCount = MIN_NUM_IMAGES; - caps->maxImageCount = 4; + /* For true mailbox mode, we need at least 4 images: + * 1) One to scan out from + * 2) One to have queued for scan-out + * 3) One to be currently held by the Wayland compositor + * 4) One to render to + */ + caps->minImageCount = 4; + /* There is no real maximum */ + caps->maxImageCount = 0; + caps->currentExtent = (VkExtent2D) { -1, -1 }; caps->minImageExtent = (VkExtent2D) { 1, 1 }; caps->maxImageExtent = (VkExtent2D) { INT16_MAX, INT16_MAX }; @@ -690,17 +696,6 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, int num_images = pCreateInfo->minImageCount; - assert(num_images >= MIN_NUM_IMAGES); - - /* For true mailbox mode, we need at least 4 images: - * 1) One to scan out from - * 2) One to have queued for scan-out - * 3) One to be currently held by the Wayland compositor - * 4) One to render to - */ - if (pCreateInfo->presentMode == VK_PRESENT_MODE_MAILBOX_KHR) - num_images = MAX2(num_images, 4); - size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]); chain = vk_alloc(pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); -- cgit v1.1 From a3f628ca25fc64022a27287f18e8c7fbe20c7e56 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 15 Nov 2016 21:18:50 +0000 Subject: wsi: fix VK_INCOMPLETE for vkGetSwapchainImagesKHR This fixes the x11 and wayland backends to not assert: dEQP-VK.wsi.xcb.swapchain.get_images.incomplete Reviewed-by: Jason Ekstrand Cc: "13.0" Signed-off-by: Dave Airlie (cherry picked from commit 253fa25d09b77e18f736b97da07d57be0e6c4200) --- src/vulkan/wsi/wsi_common_wayland.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/vulkan/wsi/wsi_common_wayland.c') diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index d28c430..a8130ce 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -498,19 +498,25 @@ wsi_wl_swapchain_get_images(struct wsi_swapchain *wsi_chain, uint32_t *pCount, VkImage *pSwapchainImages) { struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain; + uint32_t ret_count; + VkResult result; if (pSwapchainImages == NULL) { *pCount = chain->image_count; return VK_SUCCESS; } - assert(chain->image_count <= *pCount); - for (uint32_t i = 0; i < chain->image_count; i++) - pSwapchainImages[i] = chain->images[i].image; + result = VK_SUCCESS; + ret_count = chain->image_count; + if (chain->image_count > *pCount) { + ret_count = *pCount; + result = VK_INCOMPLETE; + } - *pCount = chain->image_count; + for (uint32_t i = 0; i < ret_count; i++) + pSwapchainImages[i] = chain->images[i].image; - return VK_SUCCESS; + return result; } static VkResult -- cgit v1.1