[Mesa-dev] [PATCH 7/8] panfrost: Fix BO import and export

Tomeu Vizoso tomeu.vizoso at collabora.com
Mon Mar 4 16:11:43 UTC 2019


Implement resource_get_handle for non-scanout cases.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
---
 src/gallium/drivers/panfrost/pan_resource.c | 37 +++++++++++----------
 src/gallium/drivers/panfrost/pan_screen.h   |  1 +
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index a64814902573..abef927ada55 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -68,6 +68,12 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
 
 	rsc->bo = screen->driver->import_bo(screen, whandle);
 
+	if (screen->ro) {
+		rsc->scanout =
+			renderonly_create_gpu_import_for_resource(prsc, screen->ro, NULL);
+		/* failure is expected in some cases.. */
+	}
+
         return prsc;
 }
 
@@ -87,17 +93,15 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
         handle->stride = stride;
         handle->modifier = DRM_FORMAT_MOD_INVALID;
 
-        if (handle->type == WINSYS_HANDLE_TYPE_SHARED) {
-                printf("Missed shared handle\n");
-                return FALSE;
-        } else if (handle->type == WINSYS_HANDLE_TYPE_KMS) {
-                if (renderonly_get_handle(scanout, handle)) {
-                        return TRUE;
-                } else {
-                        printf("Missed nonrenderonly KMS handle for resource %p with scanout %p\n", pt, scanout);
-                        return FALSE;
-                }
-        } else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
+	if (handle->type == WINSYS_HANDLE_TYPE_SHARED) {
+		return FALSE;
+	} else if (handle->type == WINSYS_HANDLE_TYPE_KMS) {
+		if (renderonly_get_handle(scanout, handle))
+			return TRUE;
+
+		handle->handle = rsrc->bo->gem_handle;
+		return TRUE;
+	} else if (handle->type == WINSYS_HANDLE_TYPE_FD) {
                 if (scanout) {
                         struct drm_prime_handle args = {
                                 .handle = scanout->handle,
@@ -111,14 +115,11 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
                         handle->handle = args.fd;
 
                         return TRUE;
-                } else {
-                        printf("Missed nonscanout FD handle\n");
-                        assert(0);
-                        return FALSE;
-                }
-        }
+                } else
+			return screen->driver->export_bo(screen, rsrc->bo->gem_handle, handle);
+	}
 
-        return FALSE;
+	return FALSE;
 }
 
 static void
diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h
index f109df857c7b..882611e93e3e 100644
--- a/src/gallium/drivers/panfrost/pan_screen.h
+++ b/src/gallium/drivers/panfrost/pan_screen.h
@@ -49,6 +49,7 @@ struct panfrost_screen;
 
 struct panfrost_driver {
 	struct panfrost_bo * (*import_bo) (struct panfrost_screen *screen, struct winsys_handle *whandle);
+	int (*export_bo) (struct panfrost_screen *screen, int gem_handle, struct winsys_handle *whandle);
 
 	int (*submit_vs_fs_job) (struct panfrost_context *ctx, bool has_draws, bool is_scanout);
 	void (*force_flush_fragment) (struct panfrost_context *ctx,
-- 
2.20.1



More information about the mesa-dev mailing list