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 <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22353>
This commit is contained in:
Asahi Lina 2023-04-05 21:41:27 +09:00 committed by Marge Bot
parent 9db36376a6
commit 534a04d557
2 changed files with 11 additions and 53 deletions

View file

@ -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;

View file

@ -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