[Mesa-dev] [PATCH 1/2] vulkan/wsi: move image count to shared structure.

Edward O'Callaghan funfunctor at folklore1984.net
Tue Feb 21 13:06:55 UTC 2017


wait, why is this needed at all Dave?

The application should be querying and picking the correct GPU as you
well know. This seems unwise to tamper with the mechanism defined by the
specification.

Kindly,
Edward.

On 02/21/2017 01:47 PM, Jason Ekstrand wrote:
> Fine by me
> 
> Reviewed-by: Jason Ekstrand <jason at jlekstrand.net
> <mailto:jason at jlekstrand.net>>
> 
> On Mon, Feb 20, 2017 at 6:26 PM, Dave Airlie <airlied at gmail.com
> <mailto:airlied at gmail.com>> wrote:
> 
>     From: Dave Airlie <airlied at redhat.com <mailto:airlied at redhat.com>>
> 
>     For prime support I need to access this, so move it in advance.
> 
>     Signed-off-by: Dave Airlie <airlied at redhat.com
>     <mailto:airlied at redhat.com>>
>     ---
>      src/vulkan/wsi/wsi_common.h         |  1 +
>      src/vulkan/wsi/wsi_common_wayland.c | 20 +++++++++-----------
>      src/vulkan/wsi/wsi_common_x11.c     | 29 ++++++++++++++---------------
>      3 files changed, 24 insertions(+), 26 deletions(-)
> 
>     diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
>     index ae9e587..1a22935 100644
>     --- a/src/vulkan/wsi/wsi_common.h
>     +++ b/src/vulkan/wsi/wsi_common.h
>     @@ -54,6 +54,7 @@ struct wsi_swapchain {
>         const struct wsi_image_fns *image_fns;
>         VkFence fences[3];
>         VkPresentModeKHR present_mode;
>     +   int image_count;
> 
>         VkResult (*destroy)(struct wsi_swapchain *swapchain,
>                             const VkAllocationCallbacks *pAllocator);
>     diff --git a/src/vulkan/wsi/wsi_common_wayland.c
>     b/src/vulkan/wsi/wsi_common_wayland.c
>     index 4489736..e6490ee 100644
>     --- a/src/vulkan/wsi/wsi_common_wayland.c
>     +++ b/src/vulkan/wsi/wsi_common_wayland.c
>     @@ -495,7 +495,6 @@ struct wsi_wl_swapchain {
>         VkPresentModeKHR                             present_mode;
>         bool                                         fifo_ready;
> 
>     -   uint32_t                                     image_count;
>         struct wsi_wl_image                          images[0];
>      };
> 
>     @@ -508,13 +507,13 @@ wsi_wl_swapchain_get_images(struct
>     wsi_swapchain *wsi_chain,
>         VkResult result;
> 
>         if (pSwapchainImages == NULL) {
>     -      *pCount = chain->image_count;
>     +      *pCount = chain->base.image_count;
>            return VK_SUCCESS;
>         }
> 
>         result = VK_SUCCESS;
>     -   ret_count = chain->image_count;
>     -   if (chain->image_count > *pCount) {
>     +   ret_count = chain->base.image_count;
>     +   if (chain->base.image_count > *pCount) {
>           ret_count = *pCount;
>           result = VK_INCOMPLETE;
>         }
>     @@ -543,7 +542,7 @@ wsi_wl_swapchain_acquire_next_image(struct
>     wsi_swapchain *wsi_chain,
>            return VK_ERROR_OUT_OF_DATE_KHR;
> 
>         while (1) {
>     -      for (uint32_t i = 0; i < chain->image_count; i++) {
>     +      for (uint32_t i = 0; i < chain->base.image_count; i++) {
>               if (!chain->images[i].busy) {
>                  /* We found a non-busy image */
>                  *image_index = i;
>     @@ -591,7 +590,7 @@ wsi_wl_swapchain_queue_present(struct
>     wsi_swapchain *wsi_chain,
>            }
>         }
> 
>     -   assert(image_index < chain->image_count);
>     +   assert(image_index < chain->base.image_count);
>         wl_surface_attach(chain->surface,
>     chain->images[image_index].buffer, 0, 0);
>         wl_surface_damage(chain->surface, 0, 0, INT32_MAX, INT32_MAX);
> 
>     @@ -679,7 +678,7 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain
>     *wsi_chain,
>      {
>         struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain
>     *)wsi_chain;
> 
>     -   for (uint32_t i = 0; i < chain->image_count; i++) {
>     +   for (uint32_t i = 0; i < chain->base.image_count; i++) {
>            if (chain->images[i].buffer)
>               chain->base.image_fns->free_wsi_image(chain->base.device,
>     pAllocator,
>                                                     chain->images[i].image,
>     @@ -724,6 +723,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase
>     *icd_surface,
>         chain->base.queue_present = wsi_wl_swapchain_queue_present;
>         chain->base.image_fns = image_fns;
>         chain->base.present_mode = pCreateInfo->presentMode;
>     +   chain->base.image_count = num_images;
>         chain->surface = surface->surface;
>         chain->extent = pCreateInfo->imageExtent;
>         chain->vk_format = pCreateInfo->imageFormat;
>     @@ -731,12 +731,10 @@
>     wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
> 
>         chain->fifo_ready = true;
> 
>     -   chain->image_count = num_images;
>     -
>         /* Mark a bunch of stuff as NULL.  This way we can just call
>          * destroy_swapchain for cleanup.
>          */
>     -   for (uint32_t i = 0; i < chain->image_count; i++)
>     +   for (uint32_t i = 0; i < chain->base.image_count; i++)
>            chain->images[i].buffer = NULL;
>         chain->queue = NULL;
> 
>     @@ -753,7 +751,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase
>     *icd_surface,
>            goto fail;
>         }
> 
>     -   for (uint32_t i = 0; i < chain->image_count; i++) {
>     +   for (uint32_t i = 0; i < chain->base.image_count; i++) {
>            result = wsi_wl_image_init(chain, &chain->images[i],
>                                       pCreateInfo, pAllocator);
>            if (result != VK_SUCCESS)
>     diff --git a/src/vulkan/wsi/wsi_common_x11.c
>     b/src/vulkan/wsi/wsi_common_x11.c
>     index bec4907..9e19b10 100644
>     --- a/src/vulkan/wsi/wsi_common_x11.c
>     +++ b/src/vulkan/wsi/wsi_common_x11.c
>     @@ -565,7 +565,6 @@ struct x11_swapchain {
>         xcb_gc_t                                     gc;
>         uint32_t                                     depth;
>         VkExtent2D                                   extent;
>     -   uint32_t                                     image_count;
> 
>         xcb_present_event_t                          event_id;
>         xcb_special_event_t *                        special_event;
>     @@ -591,13 +590,13 @@ x11_get_images(struct wsi_swapchain *anv_chain,
>         VkResult result;
> 
>         if (pSwapchainImages == NULL) {
>     -      *pCount = chain->image_count;
>     +      *pCount = chain->base.image_count;
>            return VK_SUCCESS;
>         }
> 
>         result = VK_SUCCESS;
>     -   ret_count = chain->image_count;
>     -   if (chain->image_count > *pCount) {
>     +   ret_count = chain->base.image_count;
>     +   if (chain->base.image_count > *pCount) {
>           ret_count = *pCount;
>           result = VK_INCOMPLETE;
>         }
>     @@ -626,7 +625,7 @@ x11_handle_dri3_present_event(struct
>     x11_swapchain *chain,
>         case XCB_PRESENT_EVENT_IDLE_NOTIFY: {
>            xcb_present_idle_notify_event_t *idle = (void *) event;
> 
>     -      for (unsigned i = 0; i < chain->image_count; i++) {
>     +      for (unsigned i = 0; i < chain->base.image_count; i++) {
>               if (chain->images[i].pixmap == idle->pixmap) {
>                  chain->images[i].busy = false;
>                  if (chain->threaded)
>     @@ -680,7 +679,7 @@ x11_acquire_next_image_poll_x11(struct
>     x11_swapchain *chain,
>         struct pollfd pfds;
>         uint64_t atimeout;
>         while (1) {
>     -      for (uint32_t i = 0; i < chain->image_count; i++) {
>     +      for (uint32_t i = 0; i < chain->base.image_count; i++) {
>               if (!chain->images[i].busy) {
>                  /* We found a non-busy image */
>                  xshmfence_await(chain->images[i].shm_fence);
>     @@ -747,7 +746,7 @@ x11_acquire_next_image_from_queue(struct
>     x11_swapchain *chain,
>            return chain->status;
>         }
> 
>     -   assert(image_index < chain->image_count);
>     +   assert(image_index < chain->base.image_count);
>         xshmfence_await(chain->images[image_index].shm_fence);
> 
>         *image_index_out = image_index;
>     @@ -761,7 +760,7 @@ x11_present_to_x11(struct x11_swapchain *chain,
>     uint32_t image_index,
>      {
>         struct x11_image *image = &chain->images[image_index];
> 
>     -   assert(image_index < chain->image_count);
>     +   assert(image_index < chain->base.image_count);
> 
>         uint32_t options = XCB_PRESENT_OPTION_NONE;
> 
>     @@ -971,7 +970,7 @@ x11_swapchain_destroy(struct wsi_swapchain
>     *anv_chain,
>         struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
>         xcb_void_cookie_t cookie;
> 
>     -   for (uint32_t i = 0; i < chain->image_count; i++)
>     +   for (uint32_t i = 0; i < chain->base.image_count; i++)
>            x11_image_finish(chain, pAllocator, &chain->images[i]);
> 
>         if (chain->threaded) {
>     @@ -1032,11 +1031,11 @@
>     x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
>         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;
>         chain->window = window;
>         chain->depth = geometry->depth;
>         chain->extent = pCreateInfo->imageExtent;
>     -   chain->image_count = num_images;
>         chain->send_sbc = 0;
>         chain->last_present_msc = 0;
>         chain->threaded = false;
>     @@ -1072,7 +1071,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase
>     *icd_surface,
>         xcb_discard_reply(chain->conn, cookie.sequence);
> 
>         uint32_t image = 0;
>     -   for (; image < chain->image_count; image++) {
>     +   for (; image < chain->base.image_count; image++) {
>            result = x11_image_init(device, chain, pCreateInfo, pAllocator,
>                                    &chain->images[image]);
>            if (result != VK_SUCCESS)
>     @@ -1082,23 +1081,23 @@
>     x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
>         if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR) {
>            chain->threaded = true;
> 
>     -      /* Initialize our queues.  We make them image_count + 1
>     because we will
>     +      /* Initialize our queues.  We make them base.image_count + 1
>     because we will
>             * occasionally use UINT32_MAX to signal the other thread
>     that an error
>             * has occurred and we don't want an overflow.
>             */
>            int ret;
>     -      ret = wsi_queue_init(&chain->acquire_queue,
>     chain->image_count + 1);
>     +      ret = wsi_queue_init(&chain->acquire_queue,
>     chain->base.image_count + 1);
>            if (ret) {
>               goto fail_init_images;
>            }
> 
>     -      ret = wsi_queue_init(&chain->present_queue,
>     chain->image_count + 1);
>     +      ret = wsi_queue_init(&chain->present_queue,
>     chain->base.image_count + 1);
>            if (ret) {
>               wsi_queue_destroy(&chain->acquire_queue);
>               goto fail_init_images;
>            }
> 
>     -      for (unsigned i = 0; i < chain->image_count; i++)
>     +      for (unsigned i = 0; i < chain->base.image_count; i++)
>               wsi_queue_push(&chain->acquire_queue, i);
> 
>            ret = pthread_create(&chain->queue_manager, NULL,
>     --
>     2.9.3
> 
>     _______________________________________________
>     mesa-dev mailing list
>     mesa-dev at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
>     https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>     <https://lists.freedesktop.org/mailman/listinfo/mesa-dev>
> 
> 
> 
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170222/5f418e8e/attachment-0001.sig>


More information about the mesa-dev mailing list