From: Asahi Lina Date: Wed, 5 Apr 2023 12:41:27 +0000 (+0900) Subject: asahi: Flip kmsro around to allocate on the GPU X-Git-Tag: upstream/23.3.3~10312 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=534a04d557f3e2022b23821368ae06f2f746c9d8;p=platform%2Fupstream%2Fmesa.git asahi: Flip kmsro around to allocate on the GPU Our display controller can handle arbitrary GPU imports, so there is no reason to use dumb KMS buffers. Allocate everything on the GPU instead. This also allows us to be lazy about mapping things to the KMS side, so only clients that really want a KMS handle actually do that, which stops us from ending up with a bunch of junk mapped to DCP (e.g. X11 clients always request SCANOUT even under XWayland). Signed-off-by: Asahi Lina Part-of: --- diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 04e10bc..08360cb 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -223,12 +223,6 @@ agx_resource_from_handle(struct pipe_screen *pscreen, ail_make_miptree(&rsc->layout); - if (dev->ro) { - rsc->scanout = - renderonly_create_gpu_import_for_resource(prsc, dev->ro, NULL); - /* failure is expected in some cases.. */ - } - if (prsc->target == PIPE_BUFFER) { assert(rsc->layout.tiling == AIL_TILING_LINEAR); util_range_init(&rsc->valid_buffer_range); @@ -245,7 +239,6 @@ agx_resource_get_handle(struct pipe_screen *pscreen, struct pipe_context *ctx, unsigned usage) { 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 @@ -258,13 +251,20 @@ agx_resource_get_handle(struct pipe_screen *pscreen, struct pipe_context *ctx, return false; } - struct agx_resource *rsrc = (struct agx_resource *)cur; - scanout = rsrc->scanout; + struct agx_resource *rsrc = agx_resource(cur); if (handle->type == WINSYS_HANDLE_TYPE_KMS && dev->ro) { rsrc_debug(rsrc, "Get handle: %p (KMS RO)\n", rsrc); - return renderonly_get_handle(scanout, handle); + if (!rsrc->scanout && dev->ro && (rsrc->base.bind & PIPE_BIND_SCANOUT)) { + rsrc->scanout = + renderonly_scanout_for_resource(&rsrc->base, dev->ro, NULL); + } + + if (!rsrc->scanout) + return false; + + return renderonly_get_handle(rsrc->scanout, handle); } else if (handle->type == WINSYS_HANDLE_TYPE_KMS) { rsrc_debug(rsrc, "Get handle: %p (KMS)\n", rsrc); @@ -524,48 +524,6 @@ agx_resource_create_with_modifiers(struct pipe_screen *screen, util_range_init(&nresource->valid_buffer_range); } - if (dev->ro && (templ->bind & PIPE_BIND_SCANOUT)) { - struct winsys_handle handle; - assert(util_format_get_blockwidth(templ->format) == 1); - assert(util_format_get_blockheight(templ->format) == 1); - - unsigned width = templ->width0; - unsigned stride = - templ->width0 * util_format_get_blocksize(templ->format); - unsigned size = nresource->layout.size_B; - unsigned effective_rows = DIV_ROUND_UP(size, stride); - - struct pipe_resource scanout_tmpl = { - .target = nresource->base.target, - .format = templ->format, - .width0 = width, - .height0 = effective_rows, - .depth0 = 1, - .array_size = 1, - }; - - nresource->scanout = - renderonly_scanout_for_resource(&scanout_tmpl, dev->ro, &handle); - - if (!nresource->scanout) { - agx_msg("Failed to create scanout resource\n"); - free(nresource); - return NULL; - } - assert(handle.type == WINSYS_HANDLE_TYPE_FD); - nresource->bo = agx_bo_import(dev, handle.handle); - close(handle.handle); - - if (!nresource->bo) { - free(nresource); - return NULL; - } - - agx_resource_debug(nresource, "New[RO]: "); - - return &nresource->base; - } - if (winsys && templ->bind & PIPE_BIND_DISPLAY_TARGET) { unsigned width = templ->width0; unsigned height = templ->height0; diff --git a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c index 16a79d4..5703254 100644 --- a/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c +++ b/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c @@ -76,7 +76,7 @@ struct pipe_screen *kmsro_drm_screen_create(int fd, { .name = "asahi", .create_screen = asahi_drm_screen_create_renderonly, - .create_for_resource = renderonly_create_kms_dumb_buffer_for_resource, + .create_for_resource = renderonly_create_gpu_import_for_resource, }, #endif