From fa75b2a02748e67508a2311afe046a2d04fb4ae0 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Fri, 4 Jun 2021 19:42:08 +0300 Subject: [PATCH] vulkan/wsi: create a common function to compare drm devices Effectively moves most of v3dv_wsi_can_present_on_device to the common code to be used in other drivers. Signed-off-by: Danylo Piliaiev Reviewed-by: Emma Anholt Reviewed-by: Jason Ekstrand Part-of: --- src/broadcom/vulkan/v3dv_wsi.c | 20 ++------------------ src/vulkan/wsi/wsi_common_drm.c | 25 +++++++++++++++++++++++++ src/vulkan/wsi/wsi_common_drm.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 src/vulkan/wsi/wsi_common_drm.h diff --git a/src/broadcom/vulkan/v3dv_wsi.c b/src/broadcom/vulkan/v3dv_wsi.c index d4723c8b40b..a18e0eaf57b 100644 --- a/src/broadcom/vulkan/v3dv_wsi.c +++ b/src/broadcom/vulkan/v3dv_wsi.c @@ -28,6 +28,7 @@ #include "wsi_common_entrypoints.h" #include "vk_util.h" #include "wsi_common.h" +#include "wsi_common_drm.h" static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL v3dv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) @@ -41,24 +42,7 @@ v3dv_wsi_can_present_on_device(VkPhysicalDevice _pdevice, int fd) { V3DV_FROM_HANDLE(v3dv_physical_device, pdevice, _pdevice); - drmDevicePtr fd_devinfo, display_devinfo; - int ret; - - ret = drmGetDevice2(fd, 0, &fd_devinfo); - if (ret) - return false; - - ret = drmGetDevice2(pdevice->display_fd, 0, &display_devinfo); - if (ret) { - drmFreeDevice(&fd_devinfo); - return false; - } - - bool result = drmDevicesEqual(fd_devinfo, display_devinfo); - - drmFreeDevice(&fd_devinfo); - drmFreeDevice(&display_devinfo); - return result; + return wsi_common_drm_devices_equal(fd, pdevice->display_fd); } VkResult diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c index 7a2ad29477d..aaba3b371c4 100644 --- a/src/vulkan/wsi/wsi_common_drm.c +++ b/src/vulkan/wsi/wsi_common_drm.c @@ -22,6 +22,7 @@ */ #include "wsi_common_private.h" +#include "wsi_common_drm.h" #include "util/macros.h" #include "util/os_file.h" #include "util/xmlconfig.h" @@ -34,6 +35,30 @@ #include #include +bool +wsi_common_drm_devices_equal(int fd_a, int fd_b) +{ + drmDevicePtr device_a, device_b; + int ret; + + ret = drmGetDevice2(fd_a, 0, &device_a); + if (ret) + return false; + + ret = drmGetDevice2(fd_b, 0, &device_b); + if (ret) { + drmFreeDevice(&device_a); + return false; + } + + bool result = drmDevicesEqual(device_a, device_b); + + drmFreeDevice(&device_a); + drmFreeDevice(&device_b); + + return result; +} + bool wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd) { diff --git a/src/vulkan/wsi/wsi_common_drm.h b/src/vulkan/wsi/wsi_common_drm.h new file mode 100644 index 00000000000..2dd78a3f599 --- /dev/null +++ b/src/vulkan/wsi/wsi_common_drm.h @@ -0,0 +1,30 @@ +/* + * Copyright © 2021 Igalia S.L. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef WSI_COMMON_DRM_H +#define WSI_COMMON_DRM_H + +bool +wsi_common_drm_devices_equal(int fd_a, int fd_b); + +#endif /* WSI_COMMON_DRM_H */