asahi: Implement agx_resource_get_handle
authorAsahi Lina <lina@asahilina.net>
Tue, 8 Nov 2022 15:31:26 +0000 (10:31 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 17 Nov 2022 02:47:10 +0000 (02:47 +0000)
Only useful on Linux.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19606>

src/gallium/drivers/asahi/agx_pipe.c

index 961b771..8f15c1f 100644 (file)
@@ -217,7 +217,46 @@ agx_resource_get_handle(struct pipe_screen *pscreen,
                         struct winsys_handle *handle,
                         unsigned usage)
 {
-   unreachable("Handles todo");
+   struct agx_device *dev = agx_device(pscreen);
+   struct renderonly_scanout *scanout;
+   struct pipe_resource *cur = pt;
+
+   /* Even though asahi doesn't support multi-planar formats, we
+    * can get here through GBM, which does. Walk the list of planes
+    * to find the right one.
+    */
+   for (int i = 0; i < handle->plane; i++) {
+      cur = cur->next;
+      if (!cur)
+         return false;
+   }
+
+   struct agx_resource *rsrc = (struct agx_resource *)cur;
+   scanout = rsrc->scanout;
+
+   if (handle->type == WINSYS_HANDLE_TYPE_KMS && dev->ro) {
+      return renderonly_get_handle(scanout, handle);
+   } else if (handle->type == WINSYS_HANDLE_TYPE_KMS) {
+      handle->handle = rsrc->bo->handle;
+   } else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
+      int fd = agx_bo_export(rsrc->bo);
+
+      if (fd < 0)
+         return false;
+
+      handle->handle = fd;
+   } else {
+      /* Other handle types not supported */
+      return false;
+   }
+
+   handle->stride = ail_get_wsi_stride_B(&rsrc->layout, 0);
+   handle->size = rsrc->layout.size_B;
+   handle->offset = rsrc->layout.level_offsets_B[0];
+   handle->format = rsrc->layout.format;
+   handle->modifier = rsrc->modifier;
+
+   return true;
 }
 
 /* Linear textures require specifying their strides explicitly, which only