[7/8] panfrost: Fix BO import and export

Submitted by Tomeu Vizoso on March 4, 2019, 4:11 p.m.

Details

Message ID 20190304161144.52910-8-tomeu.vizoso@collabora.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Tomeu Vizoso March 4, 2019, 4:11 p.m.
Implement resource_get_handle for non-scanout cases.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@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(-)

Patch hide | download patch | download mbox

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,

Comments

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Out of curiosity, when would this code path be needed? Was this a
problem on the non-DRM driver too, or just the new kernel which makes
heavier use of real BOs?
On 3/5/19 1:25 AM, Alyssa Rosenzweig wrote:
> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> 
> Out of curiosity, when would this code path be needed? Was this a
> problem on the non-DRM driver too, or just the new kernel which makes
> heavier use of real BOs?

With non-DRM this code doesn't execute (at least on the workloads I 
tested with) because we don't support GEM handles for !scanout.

Cheers,

Tomeu
> With non-DRM this code doesn't execute (at least on the workloads I tested
> with) because we don't support GEM handles for !scanout.

Gotcha, thank you.