vulkan/wsi: provide api for drivers to setup syncobj fd

Drivers that import sync_fd to the wsi fences can use this to set file
descriptor for syncobj related calls. This fixes permission errors when
registering display/device events and importing sync_fd from driver
side.

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12305>
This commit is contained in:
Tapani Pälli 2021-10-14 14:43:00 +03:00 committed by Marge Bot
parent 92215d8da8
commit 73f21ea2e1
4 changed files with 37 additions and 4 deletions

View File

@ -203,6 +203,15 @@ wsi_DestroySurfaceKHR(VkInstance _instance,
vk_free2(&instance->alloc, pAllocator, surface);
}
void
wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
int fd)
{
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
wsi_display_setup_syncobj_fd(wsi_device, fd);
#endif
}
VkResult
wsi_swapchain_init(const struct wsi_device *wsi,
struct wsi_swapchain *chain,

View File

@ -226,6 +226,11 @@ void
wsi_device_finish(struct wsi_device *wsi,
const VkAllocationCallbacks *alloc);
/* Setup file descriptor to be used with imported sync_fd's in wsi fences. */
void
wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
int fd);
#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
\
static inline __VkIcdType * \

View File

@ -96,6 +96,9 @@ struct wsi_display {
int fd;
/* Used with syncobj imported from driver side. */
int syncobj_fd;
pthread_mutex_t wait_mutex;
pthread_cond_t wait_cond;
pthread_t wait_thread;
@ -1542,8 +1545,8 @@ static void wsi_display_fence_event_handler(struct wsi_display_fence *fence)
(struct wsi_display *) fence->base.wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
if (fence->syncobj) {
(void) drmSyncobjSignal(wsi->fd, &fence->syncobj, 1);
(void) drmSyncobjDestroy(wsi->fd, fence->syncobj);
(void) drmSyncobjSignal(wsi->syncobj_fd, &fence->syncobj, 1);
(void) drmSyncobjDestroy(wsi->syncobj_fd, fence->syncobj);
}
fence->event_received = true;
@ -1577,7 +1580,8 @@ wsi_display_fence_alloc(VkDevice device,
return NULL;
if (sync_fd >= 0) {
int ret = drmSyncobjFDToHandle(wsi->fd, sync_fd, &fence->syncobj);
int ret = drmSyncobjFDToHandle(wsi->syncobj_fd, sync_fd, &fence->syncobj);
if (ret) {
vk_free2(wsi->alloc, allocator, fence);
return NULL;
@ -1926,6 +1930,8 @@ wsi_display_init_wsi(struct wsi_device *wsi_device,
if (wsi->fd != -1 && !local_drmIsMaster(wsi->fd))
wsi->fd = -1;
wsi->syncobj_fd = wsi->fd;
wsi->alloc = alloc;
list_inithead(&wsi->connectors);
@ -2579,7 +2585,7 @@ wsi_register_display_event(VkDevice device,
fence->base.destroy(&fence->base);
} else if (fence != NULL) {
if (fence->syncobj)
drmSyncobjDestroy(wsi->fd, fence->syncobj);
drmSyncobjDestroy(wsi->syncobj_fd, fence->syncobj);
vk_free2(wsi->alloc, allocator, fence);
}
@ -2602,6 +2608,15 @@ wsi_RegisterDisplayEventEXT(VkDevice device,
unreachable("Not enough common infrastructure to implement this yet");
}
void
wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
int fd)
{
struct wsi_display *wsi =
(struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
wsi->syncobj_fd = fd;
}
VKAPI_ATTR VkResult VKAPI_CALL
wsi_GetSwapchainCounterEXT(VkDevice _device,
VkSwapchainKHR _swapchain,

View File

@ -167,6 +167,10 @@ void
wsi_display_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
void
wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
int fd);
VK_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, base, VkSwapchainKHR,
VK_OBJECT_TYPE_SWAPCHAIN_KHR)