vulkan/wsi/x11: Set OUT_OF_DATE if wait_for_special_event fails
[mesa.git] / src / vulkan / wsi / wsi_common_x11.c
index fd60cfa95b05f22bf9376d5769ad86cfb33bc283..15d291463e9012b637792d854971d4dc0088b153 100644 (file)
@@ -405,7 +405,6 @@ x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
                         const VkAllocationCallbacks *alloc,
                         uint32_t queueFamilyIndex,
                         int local_fd,
-                        bool can_handle_different_gpu,
                         VkBool32* pSupported)
 {
    xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
@@ -421,10 +420,6 @@ x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
       return VK_SUCCESS;
    }
 
-   if (!can_handle_different_gpu)
-      if (!wsi_x11_check_dri3_compatible(conn, local_fd))
-         return false;
-
    unsigned visual_depth;
    if (!get_visualtype_for_window(conn, window, &visual_depth)) {
       *pSupported = false;
@@ -625,8 +620,6 @@ struct x11_image {
 struct x11_swapchain {
    struct wsi_swapchain                        base;
 
-   bool                                         use_prime_blit;
-
    xcb_connection_t *                           conn;
    xcb_window_t                                 window;
    xcb_gc_t                                     gc;
@@ -648,30 +641,11 @@ struct x11_swapchain {
    struct x11_image                             images[0];
 };
 
-static VkResult
-x11_get_images(struct wsi_swapchain *anv_chain,
-               uint32_t* pCount, VkImage *pSwapchainImages)
+static struct wsi_image *
+x11_get_wsi_image(struct wsi_swapchain *wsi_chain, uint32_t image_index)
 {
-   struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
-   uint32_t ret_count;
-   VkResult result;
-
-   if (pSwapchainImages == NULL) {
-      *pCount = chain->base.image_count;
-      return VK_SUCCESS;
-   }
-
-   result = VK_SUCCESS;
-   ret_count = chain->base.image_count;
-   if (chain->base.image_count > *pCount) {
-     ret_count = *pCount;
-     result = VK_INCOMPLETE;
-   }
-
-   for (uint32_t i = 0; i < ret_count; i++)
-      pSwapchainImages[i] = chain->images[i].base.image;
-
-   return result;
+   struct x11_swapchain *chain = (struct x11_swapchain *)wsi_chain;
+   return &chain->images[image_index].base;
 }
 
 static VkResult
@@ -881,24 +855,10 @@ x11_acquire_next_image(struct wsi_swapchain *anv_chain,
 
 static VkResult
 x11_queue_present(struct wsi_swapchain *anv_chain,
-                  VkQueue queue,
-                  uint32_t waitSemaphoreCount,
-                  const VkSemaphore *pWaitSemaphores,
                   uint32_t image_index,
                   const VkPresentRegionKHR *damage)
 {
    struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
-   VkResult result;
-
-   if (chain->use_prime_blit) {
-      result = wsi_prime_image_blit_to_linear(&chain->base,
-                                              &chain->images[image_index].base,
-                                              queue,
-                                              waitSemaphoreCount,
-                                              pWaitSemaphores);
-      if (result != VK_SUCCESS)
-         return result;
-   }
 
    if (chain->threaded) {
       wsi_queue_push(&chain->present_queue, image_index);
@@ -939,8 +899,10 @@ x11_manage_fifo_queues(void *state)
       while (chain->last_present_msc < target_msc) {
          xcb_generic_event_t *event =
             xcb_wait_for_special_event(chain->conn, chain->special_event);
-         if (!event)
+         if (!event) {
+            result = VK_ERROR_OUT_OF_DATE_KHR;
             goto fail;
+         }
 
          result = x11_handle_dri3_present_event(chain, (void *)event);
          free(event);
@@ -966,31 +928,32 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain,
    VkResult result;
    uint32_t bpp = 32;
 
-   if (chain->use_prime_blit) {
+   if (chain->base.use_prime_blit) {
       result = wsi_create_prime_image(&chain->base, pCreateInfo, &image->base);
    } else {
-      result = chain->base.image_fns->create_wsi_image(device_h,
-                                                       pCreateInfo,
-                                                       pAllocator,
-                                                       &image->base);
+      result = wsi_create_native_image(&chain->base, pCreateInfo,
+                                       0, NULL, NULL, &image->base);
    }
    if (result != VK_SUCCESS)
       return result;
 
    image->pixmap = xcb_generate_id(chain->conn);
 
+   /* Without passing modifiers, we can't have multi-plane RGB images. */
+   assert(image->base.num_planes == 1);
+
    cookie =
       xcb_dri3_pixmap_from_buffer_checked(chain->conn,
                                           image->pixmap,
                                           chain->window,
-                                          image->base.size,
+                                          image->base.sizes[0],
                                           pCreateInfo->imageExtent.width,
                                           pCreateInfo->imageExtent.height,
-                                          image->base.row_pitch,
+                                          image->base.row_pitches[0],
                                           chain->depth, bpp,
-                                          image->base.fd);
+                                          image->base.fds[0]);
    xcb_discard_reply(chain->conn, cookie.sequence);
-   image->base.fd = -1; /* XCB has now taken ownership of the FD */
+   image->base.fds[0] = -1; /* XCB has now taken ownership of the FD */
 
    int fence_fd = xshmfence_alloc_shm();
    if (fence_fd < 0)
@@ -1019,11 +982,7 @@ fail_pixmap:
    cookie = xcb_free_pixmap(chain->conn, image->pixmap);
    xcb_discard_reply(chain->conn, cookie.sequence);
 
-   if (chain->use_prime_blit) {
-      wsi_destroy_prime_image(&chain->base, &image->base);
-   } else {
-      chain->base.image_fns->free_wsi_image(device_h, pAllocator, &image->base);
-   }
+   wsi_destroy_image(&chain->base, &image->base);
 
    return result;
 }
@@ -1042,12 +1001,7 @@ x11_image_finish(struct x11_swapchain *chain,
    cookie = xcb_free_pixmap(chain->conn, image->pixmap);
    xcb_discard_reply(chain->conn, cookie.sequence);
 
-   if (chain->use_prime_blit) {
-      wsi_destroy_prime_image(&chain->base, &image->base);
-   } else {
-      chain->base.image_fns->free_wsi_image(chain->base.device,
-                                            pAllocator, &image->base);
-   }
+   wsi_destroy_image(&chain->base, &image->base);
 }
 
 static VkResult
@@ -1089,7 +1043,6 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
                              int local_fd,
                              const VkSwapchainCreateInfoKHR *pCreateInfo,
                              const VkAllocationCallbacks* pAllocator,
-                             const struct wsi_image_fns *image_fns,
                              struct wsi_swapchain **swapchain_out)
 {
    struct x11_swapchain *chain;
@@ -1122,10 +1075,9 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
       goto fail_alloc;
 
    chain->base.destroy = x11_swapchain_destroy;
-   chain->base.get_images = x11_get_images;
+   chain->base.get_wsi_image = x11_get_wsi_image;
    chain->base.acquire_next_image = x11_acquire_next_image;
    chain->base.queue_present = x11_queue_present;
-   chain->base.image_fns = image_fns;
    chain->base.present_mode = pCreateInfo->presentMode;
    chain->base.image_count = num_images;
    chain->conn = conn;
@@ -1137,11 +1089,8 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
    chain->threaded = false;
    chain->status = VK_SUCCESS;
 
-
-   chain->use_prime_blit = false;
-   if (!wsi_x11_check_dri3_compatible(conn, local_fd)) {
-       chain->use_prime_blit = true;
-   }
+   if (!wsi_x11_check_dri3_compatible(conn, local_fd))
+       chain->base.use_prime_blit = true;
 
    chain->event_id = xcb_generate_id(chain->conn);
    xcb_present_select_input(chain->conn, chain->event_id, chain->window,