amdgpu: Add new function to get fd.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 16 Nov 2021 00:41:49 +0000 (01:41 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 23 Nov 2021 16:02:05 +0000 (16:02 +0000)
Dual purpose:
 - The drm fd dedupe functionality confuses the radeonsi
   amdgpu winsys if radeonsi isn't the first thing opening
   the device. By exposing the fd we can detect this case.
 - For a common mesa Vulkan sync objects implementation
   with syncobj. (notable: no buffer allocation)

Both shouldn't interferece with libdrm_amdgpu functionality
though it does somewhat piece the abstraction of the library.

Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3424
Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5630
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
amdgpu/amdgpu-symbols.txt
amdgpu/amdgpu.h
amdgpu/amdgpu_device.c

index a2ed652..af2b643 100644 (file)
@@ -53,6 +53,7 @@ amdgpu_cs_syncobj_wait
 amdgpu_cs_wait_fences
 amdgpu_cs_wait_semaphore
 amdgpu_device_deinitialize
+amdgpu_device_get_fd
 amdgpu_device_initialize
 amdgpu_find_bo_by_cpu_mapping
 amdgpu_get_marketing_name
index b118dd4..cde8585 100644 (file)
@@ -546,6 +546,19 @@ int amdgpu_device_initialize(int fd,
 */
 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
 
+/**
+ *
+ * /param device_handle - \c [in] Device handle.
+ *                           See #amdgpu_device_initialize()
+ *
+ * \return Returns the drm fd used for operations on this
+ *         device. This is still owned by the library and hence
+ *         should not be closed. Guaranteed to be valid until
+ *         #amdgpu_device_deinitialize gets called.
+ *
+*/
+int amdgpu_device_get_fd(amdgpu_device_handle device_handle);
+
 /*
  * Memory Management
  *
index 76b4e5e..73fd27f 100644 (file)
@@ -285,6 +285,11 @@ drm_public int amdgpu_device_deinitialize(amdgpu_device_handle dev)
        return 0;
 }
 
+drm_public int amdgpu_device_get_fd(amdgpu_device_handle device_handle)
+{
+       return device_handle->fd;
+}
+
 drm_public const char *amdgpu_get_marketing_name(amdgpu_device_handle dev)
 {
        return dev->marketing_name;