From 539cc909292b78ea2c9b1148464edec14ff9d8ed Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Wed, 13 Jul 2022 20:48:33 +0200 Subject: [PATCH] etnaviv: allocate TS memory from KMS when resource bind is SCANOUT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some display engines are able to resolve fast clear and/or compression on the fly and need access to the TS buffer to do so. As they might have restrictions on which memory they can access, allocate the TS buffer memory from the KMS side when the resource should be SCANOUT capable. Signed-off-by: Lucas Stach Tested-by: Guido Günther Reviewed-by: Christian Gmeiner Part-of: --- .../drivers/etnaviv/etnaviv_resource.c | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c b/src/gallium/drivers/etnaviv/etnaviv_resource.c index 22fdf1b7f76ee..5ae018c882aca 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c @@ -119,15 +119,33 @@ etna_screen_resource_alloc_ts(struct pipe_screen *pscreen, DBG_F(ETNA_DBG_RESOURCE_MSGS, "%p: Allocating tile status of size %zu", rsc, rt_ts_size); - struct etna_bo *rt_ts; - rt_ts = etna_bo_new(screen->dev, rt_ts_size, DRM_ETNA_GEM_CACHE_WC); + if ((rsc->base.bind & PIPE_BIND_SCANOUT) && screen->ro->kms_fd >= 0) { + struct pipe_resource scanout_templat; + struct winsys_handle handle; - if (unlikely(!rt_ts)) { + scanout_templat.format = PIPE_FORMAT_R8_UNORM; + scanout_templat.width0 = align(rt_ts_size, 4096); + scanout_templat.height0 = 1; + + rsc->ts_scanout = renderonly_scanout_for_resource(&scanout_templat, + screen->ro, &handle); + if (!rsc->ts_scanout) { + BUG("Problem allocating kms memory for TS resource"); + return false; + } + + assert(handle.type == WINSYS_HANDLE_TYPE_FD); + rsc->ts_bo = etna_screen_bo_from_handle(pscreen, &handle); + close(handle.handle); + } else { + rsc->ts_bo = etna_bo_new(screen->dev, ts_bo_size, DRM_ETNA_GEM_CACHE_WC); + } + + if (unlikely(!rsc->ts_bo)) { BUG("Problem allocating tile status for resource"); return false; } - rsc->ts_bo = rt_ts; rsc->levels[0].ts_offset = 0; rsc->levels[0].ts_layer_stride = ts_layer_stride; rsc->levels[0].ts_size = rt_ts_size;