Mesa (master): v3dv: move authenticated display fd acquisition to swapchain creation time

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 12 09:12:39 UTC 2020


Module: Mesa
Branch: master
Commit: 87fb1ec35279470f692bdda03c6868186db96e07
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=87fb1ec35279470f692bdda03c6868186db96e07

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Wed Nov 11 09:45:33 2020 +0100

v3dv: move authenticated display fd acquisition to swapchain creation time

So far, we have only been supporting X11, so we assumed that we were running
inside X11 and would always try to get an authenticated fd from Xorg during
device initialization. While this works for desktop Raspbian, it is not
really correct and it is not what we want to do when we start considering
other WSIs.

Initially, one could think we can still do this by guarding the WSI code
under the proper instance extension check. This, however, doesn't work
reliably, as the Vulkan loader can call vkEnumerateDevices without enabling
surface extensions on the instance, which then can lead to us not
initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED,
which is not correct, so while we can try to acquire the display_fd here,
it might not always work, and we should definitely not fail initialization
of the physical device for that.

Instead, with this change we move acquisition of display_fd to swapchain
creation time where required extensions need to be enabled in the instance.
This was also suggested by Daniel Stone during review of a work-in-progress
implementation for the Wayland WSI.

There is a special case to consider though: applications like Zink that
don't use Vulkan's swapchains at all but still allocate images that they
intend to use for WSI. We need to handle these by checking that we have
indeed acquired a display_fd before doing any memory allocation for WSI,
and acquiring one at that time if that's not the case.

This change also removes the render_fd and display_fd fields from the
logical device (which we were copying from the physical device), because
now there is no guarantee that we have acquired a display_fd at the
time we create a logical device. Instead, we now put a reference to the
physical device on the logical device from which we can access these.

Finally, this also fixes a regression introduced with VK_KHR_display, where
if that extension is enabled but we are running inside a compositor, we would
acquire a display_fd that is not authenticated and try to use that instead
of acquiring an authenticated display_fd from the display server.

Fixes: b1188c9451 (v3dv: VK_KHR_display extension support)

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>

---

 src/broadcom/vulkan/v3dv_bo.c      |  13 +--
 src/broadcom/vulkan/v3dv_device.c  | 162 ++++++++++++++++++++++++++-----------
 src/broadcom/vulkan/v3dv_private.h |   9 ++-
 src/broadcom/vulkan/v3dv_queue.c   |  37 +++++----
 src/broadcom/vulkan/v3dv_wsi.c     |  16 ++--
 5 files changed, 162 insertions(+), 75 deletions(-)

diff --git a/src/broadcom/vulkan/v3dv_bo.c b/src/broadcom/vulkan/v3dv_bo.c
index 86d9f366498..e6049baa1df 100644
--- a/src/broadcom/vulkan/v3dv_bo.c
+++ b/src/broadcom/vulkan/v3dv_bo.c
@@ -137,7 +137,7 @@ bo_free(struct v3dv_device *device,
    struct drm_gem_close c;
    memset(&c, 0, sizeof(c));
    c.handle = bo->handle;
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_GEM_CLOSE, &c);
+   int ret = v3dv_ioctl(device->pdevice->render_fd, DRM_IOCTL_GEM_CLOSE, &c);
    if (ret != 0)
       fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno));
 
@@ -233,7 +233,8 @@ v3dv_bo_alloc(struct v3dv_device *device,
       .size = size
    };
 
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_CREATE_BO, &create);
+   int ret = v3dv_ioctl(device->pdevice->render_fd,
+                        DRM_IOCTL_V3D_CREATE_BO, &create);
    if (ret != 0) {
       if (!list_is_empty(&device->bo_cache.time_list) &&
           !cleared_and_retried) {
@@ -275,14 +276,15 @@ v3dv_bo_map_unsynchronized(struct v3dv_device *device,
    struct drm_v3d_mmap_bo map;
    memset(&map, 0, sizeof(map));
    map.handle = bo->handle;
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_MMAP_BO, &map);
+   int ret = v3dv_ioctl(device->pdevice->render_fd,
+                        DRM_IOCTL_V3D_MMAP_BO, &map);
    if (ret != 0) {
       fprintf(stderr, "map ioctl failure\n");
       return false;
    }
 
    bo->map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
-                  device->render_fd, map.offset);
+                  device->pdevice->render_fd, map.offset);
    if (bo->map == MAP_FAILED) {
       fprintf(stderr, "mmap of bo %d (offset 0x%016llx, size %d) failed\n",
               bo->handle, (long long)map.offset, (uint32_t)bo->size);
@@ -304,7 +306,8 @@ v3dv_bo_wait(struct v3dv_device *device,
       .handle = bo->handle,
       .timeout_ns = timeout_ns,
    };
-   return v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_WAIT_BO, &wait) == 0;
+   return v3dv_ioctl(device->pdevice->render_fd,
+                     DRM_IOCTL_V3D_WAIT_BO, &wait) == 0;
 }
 
 bool
diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c
index 36031caee18..ceba9bca193 100644
--- a/src/broadcom/vulkan/v3dv_device.c
+++ b/src/broadcom/vulkan/v3dv_device.c
@@ -268,12 +268,16 @@ physical_device_finish(struct v3dv_physical_device *device)
    close(device->render_fd);
    if (device->display_fd >= 0)
       close(device->display_fd);
+   if (device->master_fd >= 0)
+      close(device->master_fd);
 
    free(device->name);
 
 #if using_v3d_simulator
    v3d_simulator_destroy(device->sim_file);
 #endif
+
+   mtx_destroy(&device->mutex);
 }
 
 void
@@ -369,6 +373,69 @@ finish:
 #endif
 #endif
 
+/* Attempts to get an authenticated display fd from the display server that
+ * we can use to allocate BOs for presentable images.
+ */
+VkResult
+v3dv_physical_device_acquire_display(struct v3dv_instance *instance,
+                                     struct v3dv_physical_device *pdevice)
+{
+   VkResult result = VK_SUCCESS;
+   mtx_lock(&pdevice->mutex);
+
+   if (pdevice->display_fd != -1)
+      goto done;
+
+   /* When running on the simulator we do everything on a single render node so
+    * we don't need to get an authenticated display fd from the display server.
+    */
+
+#if !using_v3d_simulator
+   /* Mesa will set both of VK_USE_PLATFORM_{XCB,XLIB} when building with
+    * platform X11, so only check for XCB and rely on XCB to get an
+    * authenticated device also for Xlib.
+    */
+#ifdef VK_USE_PLATFORM_XCB_KHR
+   if (instance->enabled_extensions.KHR_xcb_surface ||
+       instance->enabled_extensions.KHR_xlib_surface) {
+      pdevice->display_fd = create_display_fd_xcb();
+   }
+#endif
+
+   /* If we are not running under a compositor and we are doing
+    * direct display we want to make our display_fd be the
+    * master_fd, which shoud be authenticated.
+    */
+   if (pdevice->display_fd == -1 &&
+       instance->enabled_extensions.KHR_display) {
+      assert(pdevice->master_fd >= 0);
+      pdevice->display_fd = dup(pdevice->master_fd);
+   }
+
+   /* Fallback cases.
+    *
+    * Some applications seem to try and create a swapchain without
+    * the instance extension enables, so if we have not managed to
+    * create a display_fd above, try again without the extension checks
+    * as a last resort.
+    */
+#ifdef VK_USE_PLATFORM_XCB_KHR
+   if (pdevice->display_fd == -1)
+      pdevice->display_fd = create_display_fd_xcb();
+#endif
+
+   if (pdevice->display_fd == -1 && pdevice->master_fd >= 0)
+      pdevice->display_fd = dup(pdevice->master_fd);
+
+   if (pdevice->display_fd == -1)
+      result = VK_ERROR_INITIALIZATION_FAILED;
+#endif
+
+done:
+   mtx_unlock(&pdevice->mutex);
+   return result;
+}
+
 static bool
 v3d_has_feature(struct v3dv_physical_device *device, enum drm_v3d_param feature)
 {
@@ -450,50 +517,44 @@ physical_device_init(struct v3dv_physical_device *device,
                      drmDevicePtr drm_primary_device)
 {
    VkResult result = VK_SUCCESS;
-   int32_t display_fd = -1;
+   int32_t master_fd = -1;
 
    device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    device->instance = instance;
 
+   assert(drm_render_device);
    const char *path = drm_render_device->nodes[DRM_NODE_RENDER];
    int32_t render_fd = open(path, O_RDWR | O_CLOEXEC);
    if (render_fd < 0)
       return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
 
-   /* If we are running on real hardware we need to open the vc4 display
-    * device so we can allocate winsys BOs for the v3d core to render into.
+   /* If we are running on VK_KHR_display we need to acquire the master
+    * display device now for the v3dv_wsi_init() call below. For anything else
+    * we postpone that until a swapchain is created.
     */
-#if !using_v3d_simulator
+
    if (instance->enabled_extensions.KHR_display) {
+#if !using_v3d_simulator
       /* Open the primary node on the vc4 display device */
       assert(drm_primary_device);
       const char *primary_path = drm_primary_device->nodes[DRM_NODE_PRIMARY];
-      display_fd = open(primary_path, O_RDWR | O_CLOEXEC);
-   }
-
-#ifdef VK_USE_PLATFORM_XCB_KHR
-   if (display_fd == -1)
-      display_fd = create_display_fd_xcb();
-#endif
-
-   if (display_fd == -1) {
-      result = VK_ERROR_INCOMPATIBLE_DRIVER;
-      goto fail;
-   }
+      master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
 #else
-   /* using_v3d_simulator */
-   if (instance->enabled_extensions.KHR_display) {
       /* There is only one device with primary and render nodes.
        * Open its primary node.
        */
       const char *primary_path = drm_render_device->nodes[DRM_NODE_PRIMARY];
-      display_fd = open(primary_path, O_RDWR | O_CLOEXEC);
+      master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
+#endif
    }
+
+#if using_v3d_simulator
    device->sim_file = v3d_simulator_init(render_fd);
 #endif
 
-   device->render_fd = render_fd;       /* The v3d render node  */
-   device->display_fd = display_fd;    /* The vc4 primary node */
+   device->render_fd = render_fd;    /* The v3d render node  */
+   device->display_fd = -1;          /* Authenticated vc4 primary node */
+   device->master_fd = master_fd;    /* Master vc4 primary node */
 
    if (!v3d_get_device_info(device->render_fd, &device->devinfo, &v3dv_ioctl)) {
       result = VK_ERROR_INCOMPATIBLE_DRIVER;
@@ -545,6 +606,8 @@ physical_device_init(struct v3dv_physical_device *device,
    v3dv_physical_device_get_supported_extensions(device,
                                                  &device->supported_extensions);
 
+   pthread_mutex_init(&device->mutex, NULL);
+
    fprintf(stderr, "WARNING: v3dv is neither a complete nor a conformant "
                    "Vulkan implementation. Testing use only.\n");
 
@@ -553,8 +616,8 @@ physical_device_init(struct v3dv_physical_device *device,
 fail:
    if (render_fd >= 0)
       close(render_fd);
-   if (display_fd >= 0)
-      close(display_fd);
+   if (master_fd >= 0)
+      close(master_fd);
 
    return result;
 }
@@ -1336,28 +1399,13 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
 
    device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
    device->instance = instance;
+   device->pdevice = physical_device;
 
    if (pAllocator)
       device->alloc = *pAllocator;
    else
       device->alloc = physical_device->instance->alloc;
 
-   device->render_fd = physical_device->render_fd;
-   if (device->render_fd == -1) {
-      result = VK_ERROR_INITIALIZATION_FAILED;
-      goto fail;
-   }
-
-   if (physical_device->display_fd != -1) {
-      device->display_fd = physical_device->display_fd;
-      if (device->display_fd == -1) {
-         result = VK_ERROR_INITIALIZATION_FAILED;
-         goto fail;
-      }
-   } else {
-      device->display_fd = -1;
-   }
-
    pthread_mutex_init(&device->mutex, NULL);
 
    result = queue_init(device, &device->queue);
@@ -1372,7 +1420,7 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
              sizeof(device->features));
    }
 
-   int ret = drmSyncobjCreate(device->render_fd,
+   int ret = drmSyncobjCreate(physical_device->render_fd,
                               DRM_SYNCOBJ_CREATE_SIGNALED,
                               &device->last_job_sync);
    if (ret) {
@@ -1405,7 +1453,7 @@ v3dv_DestroyDevice(VkDevice _device,
    v3dv_DeviceWaitIdle(_device);
    queue_finish(&device->queue);
    pthread_mutex_destroy(&device->mutex);
-   drmSyncobjDestroy(device->render_fd, device->last_job_sync);
+   drmSyncobjDestroy(device->pdevice->render_fd, device->last_job_sync);
    destroy_device_meta(device);
    v3dv_pipeline_cache_finish(&device->default_pipeline_cache);
 
@@ -1565,9 +1613,12 @@ device_import_bo(struct v3dv_device *device,
       goto fail;
    }
 
+   int render_fd = device->pdevice->render_fd;
+   assert(render_fd >= 0);
+
    int ret;
    uint32_t handle;
-   ret = drmPrimeFDToHandle(device->render_fd, fd, &handle);
+   ret = drmPrimeFDToHandle(render_fd, fd, &handle);
    if (ret) {
       result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
       goto fail;
@@ -1576,7 +1627,7 @@ device_import_bo(struct v3dv_device *device,
    struct drm_v3d_get_bo_offset get_offset = {
       .handle = handle,
    };
-   ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get_offset);
+   ret = v3dv_ioctl(render_fd, DRM_IOCTL_V3D_GET_BO_OFFSET, &get_offset);
    if (ret) {
       result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
       goto fail;
@@ -1609,10 +1660,24 @@ device_alloc_for_wsi(struct v3dv_device *device,
 #if using_v3d_simulator
       return device_alloc(device, mem, size);
 #else
+   /* If we are allocating for WSI we should have a swapchain and thus,
+    * we should've initialized the display device. However, Zink doesn't
+    * use swapchains, so in that case we can get here without acquiring the
+    * display device and we need to do it now.
+    */
+   VkResult result;
+   struct v3dv_instance *instance = device->instance;
+   struct v3dv_physical_device *pdevice = &device->instance->physicalDevice;
+   if (unlikely(pdevice->display_fd < 0)) {
+      result = v3dv_physical_device_acquire_display(instance, pdevice);
+      if (result != VK_SUCCESS)
+         return result;
+   }
+   assert(pdevice->display_fd != -1);
+
    mem->is_for_wsi = true;
 
-   assert(device->display_fd != -1);
-   int display_fd = device->instance->physicalDevice.display_fd;
+   int display_fd = pdevice->display_fd;
    struct drm_mode_create_dumb create_dumb = {
       .width = 1024, /* one page */
       .height = align(size, 4096) / 4096,
@@ -1630,7 +1695,7 @@ device_alloc_for_wsi(struct v3dv_device *device,
    if (err < 0)
       goto fail_export;
 
-   VkResult result = device_import_bo(device, pAllocator, fd, size, &mem->bo);
+   result = device_import_bo(device, pAllocator, fd, size, &mem->bo);
    close(fd);
    if (result != VK_SUCCESS)
       goto fail_import;
@@ -2059,8 +2124,9 @@ v3dv_GetMemoryFdKHR(VkDevice _device,
           pGetFdInfo->handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
 
    int fd, ret;
-   ret =
-      drmPrimeHandleToFD(device->render_fd, mem->bo->handle, DRM_CLOEXEC, &fd);
+   ret = drmPrimeHandleToFD(device->pdevice->render_fd,
+                            mem->bo->handle,
+                            DRM_CLOEXEC, &fd);
    if (ret)
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 9b93517e7bc..90a5b286781 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -138,11 +138,14 @@ struct v3dv_physical_device {
    char *name;
    int32_t render_fd;
    int32_t display_fd;
+   int32_t master_fd;
 
    uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
    uint8_t device_uuid[VK_UUID_SIZE];
    uint8_t driver_uuid[VK_UUID_SIZE];
 
+   mtx_t mutex;
+
    struct wsi_device wsi_device;
 
    VkPhysicalDeviceMemoryProperties memory;
@@ -159,6 +162,9 @@ struct v3dv_physical_device {
    } options;
 };
 
+VkResult v3dv_physical_device_acquire_display(struct v3dv_instance *instance,
+                                              struct v3dv_physical_device *pdevice);
+
 VkResult v3dv_wsi_init(struct v3dv_physical_device *physical_device);
 void v3dv_wsi_finish(struct v3dv_physical_device *physical_device);
 
@@ -286,12 +292,11 @@ struct v3dv_device {
    VkAllocationCallbacks alloc;
 
    struct v3dv_instance *instance;
+   struct v3dv_physical_device *pdevice;
 
    struct v3dv_device_extension_table enabled_extensions;
    struct v3dv_device_dispatch_table dispatch;
 
-   int32_t render_fd;
-   int32_t display_fd;
    struct v3d_device_info devinfo;
    struct v3dv_queue queue;
 
diff --git a/src/broadcom/vulkan/v3dv_queue.c b/src/broadcom/vulkan/v3dv_queue.c
index 722e6b4b42e..069b6140709 100644
--- a/src/broadcom/vulkan/v3dv_queue.c
+++ b/src/broadcom/vulkan/v3dv_queue.c
@@ -128,7 +128,7 @@ gpu_queue_wait_idle(struct v3dv_queue *queue)
    uint32_t last_job_sync = device->last_job_sync;
    mtx_unlock(&device->mutex);
 
-   int ret = drmSyncobjWait(device->render_fd,
+   int ret = drmSyncobjWait(device->pdevice->render_fd,
                             &last_job_sync, 1, INT64_MAX, 0, NULL);
    if (ret)
       return VK_ERROR_DEVICE_LOST;
@@ -502,9 +502,11 @@ process_semaphores_to_signal(struct v3dv_device *device,
    if (count == 0)
       return VK_SUCCESS;
 
+   int render_fd = device->pdevice->render_fd;
+
    int fd;
    mtx_lock(&device->mutex);
-   drmSyncobjExportSyncFile(device->render_fd, device->last_job_sync, &fd);
+   drmSyncobjExportSyncFile(render_fd, device->last_job_sync, &fd);
    mtx_unlock(&device->mutex);
    if (fd == -1)
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -516,7 +518,7 @@ process_semaphores_to_signal(struct v3dv_device *device,
          close(sem->fd);
       sem->fd = -1;
 
-      int ret = drmSyncobjImportSyncFile(device->render_fd, sem->sync, fd);
+      int ret = drmSyncobjImportSyncFile(render_fd, sem->sync, fd);
       if (ret)
          return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -538,14 +540,16 @@ process_fence_to_signal(struct v3dv_device *device, VkFence _fence)
       close(fence->fd);
    fence->fd = -1;
 
+   int render_fd = device->pdevice->render_fd;
+
    int fd;
    mtx_lock(&device->mutex);
-   drmSyncobjExportSyncFile(device->render_fd, device->last_job_sync, &fd);
+   drmSyncobjExportSyncFile(render_fd, device->last_job_sync, &fd);
    mtx_unlock(&device->mutex);
    if (fd == -1)
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   int ret = drmSyncobjImportSyncFile(device->render_fd, fence->sync, fd);
+   int ret = drmSyncobjImportSyncFile(render_fd, fence->sync, fd);
    if (ret)
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -627,7 +631,8 @@ handle_cl_job(struct v3dv_queue *queue,
    submit.in_sync_rcl = needs_rcl_sync ? device->last_job_sync : 0;
    submit.out_sync = device->last_job_sync;
    v3dv_clif_dump(device, job, &submit);
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_SUBMIT_CL, &submit);
+   int ret = v3dv_ioctl(device->pdevice->render_fd,
+                        DRM_IOCTL_V3D_SUBMIT_CL, &submit);
    mtx_unlock(&queue->device->mutex);
 
    static bool warned = false;
@@ -657,7 +662,8 @@ handle_tfu_job(struct v3dv_queue *queue,
    mtx_lock(&device->mutex);
    job->tfu.in_sync = needs_sync ? device->last_job_sync : 0;
    job->tfu.out_sync = device->last_job_sync;
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_SUBMIT_TFU, &job->tfu);
+   int ret = v3dv_ioctl(device->pdevice->render_fd,
+                        DRM_IOCTL_V3D_SUBMIT_TFU, &job->tfu);
    mtx_unlock(&device->mutex);
 
    if (ret != 0) {
@@ -693,7 +699,8 @@ handle_csd_job(struct v3dv_queue *queue,
    mtx_lock(&queue->device->mutex);
    submit->in_sync = needs_sync ? device->last_job_sync : 0;
    submit->out_sync = device->last_job_sync;
-   int ret = v3dv_ioctl(device->render_fd, DRM_IOCTL_V3D_SUBMIT_CSD, submit);
+   int ret = v3dv_ioctl(device->pdevice->render_fd,
+                        DRM_IOCTL_V3D_SUBMIT_CSD, submit);
    mtx_unlock(&queue->device->mutex);
 
    static bool warned = false;
@@ -1126,7 +1133,7 @@ v3dv_CreateSemaphore(VkDevice _device,
 
    sem->fd = -1;
 
-   int ret = drmSyncobjCreate(device->render_fd, 0, &sem->sync);
+   int ret = drmSyncobjCreate(device->pdevice->render_fd, 0, &sem->sync);
    if (ret) {
       vk_free2(&device->alloc, pAllocator, sem);
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1148,7 +1155,7 @@ v3dv_DestroySemaphore(VkDevice _device,
    if (sem == NULL)
       return;
 
-   drmSyncobjDestroy(device->render_fd, sem->sync);
+   drmSyncobjDestroy(device->pdevice->render_fd, sem->sync);
 
    if (sem->fd != -1)
       close(sem->fd);
@@ -1175,7 +1182,7 @@ v3dv_CreateFence(VkDevice _device,
    unsigned flags = 0;
    if (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT)
       flags |= DRM_SYNCOBJ_CREATE_SIGNALED;
-   int ret = drmSyncobjCreate(device->render_fd, flags, &fence->sync);
+   int ret = drmSyncobjCreate(device->pdevice->render_fd, flags, &fence->sync);
    if (ret) {
       vk_free2(&device->alloc, pAllocator, fence);
       return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -1199,7 +1206,7 @@ v3dv_DestroyFence(VkDevice _device,
    if (fence == NULL)
       return;
 
-   drmSyncobjDestroy(device->render_fd, fence->sync);
+   drmSyncobjDestroy(device->pdevice->render_fd, fence->sync);
 
    if (fence->fd != -1)
       close(fence->fd);
@@ -1213,7 +1220,7 @@ v3dv_GetFenceStatus(VkDevice _device, VkFence _fence)
    V3DV_FROM_HANDLE(v3dv_device, device, _device);
    V3DV_FROM_HANDLE(v3dv_fence, fence, _fence);
 
-   int ret = drmSyncobjWait(device->render_fd, &fence->sync, 1,
+   int ret = drmSyncobjWait(device->pdevice->render_fd, &fence->sync, 1,
                             0, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT, NULL);
    if (ret == -ETIME)
       return VK_NOT_READY;
@@ -1238,7 +1245,7 @@ v3dv_ResetFences(VkDevice _device, uint32_t fenceCount, const VkFence *pFences)
       syncobjs[i] = fence->sync;
    }
 
-   int ret = drmSyncobjReset(device->render_fd, syncobjs, fenceCount);
+   int ret = drmSyncobjReset(device->pdevice->render_fd, syncobjs, fenceCount);
 
    vk_free(&device->alloc, syncobjs);
 
@@ -1275,7 +1282,7 @@ v3dv_WaitForFences(VkDevice _device,
 
    int ret;
    do {
-      ret = drmSyncobjWait(device->render_fd, syncobjs, fenceCount,
+      ret = drmSyncobjWait(device->pdevice->render_fd, syncobjs, fenceCount,
                            timeout, flags, NULL);
    } while (ret == -ETIME && gettime_ns() < abs_timeout);
 
diff --git a/src/broadcom/vulkan/v3dv_wsi.c b/src/broadcom/vulkan/v3dv_wsi.c
index c903ce1d91d..01af8a200af 100644
--- a/src/broadcom/vulkan/v3dv_wsi.c
+++ b/src/broadcom/vulkan/v3dv_wsi.c
@@ -45,7 +45,7 @@ v3dv_wsi_init(struct v3dv_physical_device *physical_device)
                             v3dv_physical_device_to_handle(physical_device),
                             v3dv_wsi_proc_addr,
                             &physical_device->instance->alloc,
-                            physical_device->display_fd, NULL, false);
+                            physical_device->master_fd, NULL, false);
 
    if (result != VK_SUCCESS)
       return result;
@@ -178,9 +178,15 @@ VkResult v3dv_CreateSwapchainKHR(
     VkSwapchainKHR*                              pSwapchain)
 {
    V3DV_FROM_HANDLE(v3dv_device, device, _device);
-   struct wsi_device *wsi_device = &device->instance->physicalDevice.wsi_device;
-   const VkAllocationCallbacks *alloc;
+   struct v3dv_instance *instance = device->instance;
+   struct v3dv_physical_device *pdevice = &instance->physicalDevice;
+   struct wsi_device *wsi_device = &pdevice->wsi_device;
 
+   VkResult result = v3dv_physical_device_acquire_display(instance, pdevice);
+   if (result != VK_SUCCESS)
+      return result;
+
+   const VkAllocationCallbacks *alloc;
    if (pAllocator)
      alloc = pAllocator;
    else
@@ -254,9 +260,9 @@ VkResult v3dv_AcquireNextImage2KHR(
 
    if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
       if (fence)
-         drmSyncobjSignal(device->render_fd, &fence->sync, 1);
+         drmSyncobjSignal(pdevice->render_fd, &fence->sync, 1);
       if (semaphore)
-         drmSyncobjSignal(device->render_fd, &semaphore->sync, 1);
+         drmSyncobjSignal(pdevice->render_fd, &semaphore->sync, 1);
    }
 
    return result;



More information about the mesa-commit mailing list