Module: Mesa
Branch: master
Commit: a1d6c03e2f343b0c959e1b96dc8a77c2439a1b40
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=a1d6c03e2f343b0c959e1b96dc8a77c2439a1b40

Author: Lucas Stach <[email protected]>
Date:   Tue Jul  7 20:38:33 2020 +0200

etnaviv: don't import allocated scanout resources via from_handle

etna_resource_from_handle() recomputes (or second guesses) a lot of
properties we already have available in the allocation call. To make
things a bit more easier to follow, just import the BO without going
through the full handle import.

Signed-off-by: Lucas Stach <[email protected]>
Reviewed-by: Christian Gmeiner <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7367>

---

 src/gallium/drivers/etnaviv/etnaviv_resource.c | 70 +++++++++++---------------
 1 file changed, 30 insertions(+), 40 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 78c4e493e6d..ae4f24b9b44 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -256,39 +256,6 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
    if (!screen->specs.use_blt && templat->target != PIPE_BUFFER && layout == 
ETNA_LAYOUT_LINEAR)
       paddingY = align(paddingY, ETNA_RS_HEIGHT_MASK + 1);
 
-   if (templat->bind & PIPE_BIND_SCANOUT && screen->ro->kms_fd >= 0) {
-      struct pipe_resource scanout_templat = *templat;
-      struct renderonly_scanout *scanout;
-      struct winsys_handle handle;
-
-      /* pad scanout buffer size to be compatible with the RS */
-      if (!screen->specs.use_blt && modifier == DRM_FORMAT_MOD_LINEAR) {
-         paddingX = align(paddingX, ETNA_RS_WIDTH_MASK + 1);
-         paddingY = align(paddingY, ETNA_RS_HEIGHT_MASK + 1);
-      }
-
-      scanout_templat.width0 = align(scanout_templat.width0, paddingX);
-      scanout_templat.height0 = align(scanout_templat.height0, paddingY);
-
-      scanout = renderonly_scanout_for_resource(&scanout_templat,
-                                                screen->ro, &handle);
-      if (!scanout)
-         return NULL;
-
-      assert(handle.type == WINSYS_HANDLE_TYPE_FD);
-      handle.modifier = modifier;
-      rsc = etna_resource(pscreen->resource_from_handle(pscreen, templat,
-                                                        &handle,
-                                                        
PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE));
-      close(handle.handle);
-      if (!rsc)
-         return NULL;
-
-      rsc->scanout = scanout;
-
-      return &rsc->base;
-   }
-
    rsc = CALLOC_STRUCT(etna_resource);
    if (!rsc)
       return NULL;
@@ -304,14 +271,37 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
layout,
 
    size = setup_miptree(rsc, paddingX, paddingY, msaa_xscale, msaa_yscale);
 
-   uint32_t flags = DRM_ETNA_GEM_CACHE_WC;
-   if (templat->bind & PIPE_BIND_VERTEX_BUFFER)
-      flags |= DRM_ETNA_GEM_FORCE_MMU;
+   if (unlikely(templat->bind & PIPE_BIND_SCANOUT) && screen->ro->kms_fd >= 0) 
{
+      struct pipe_resource scanout_templat = *templat;
+      struct winsys_handle handle;
 
-   rsc->bo = etna_bo_new(screen->dev, size, flags);
-   if (unlikely(!rsc->bo)) {
-      BUG("Problem allocating video memory for resource");
-      goto free_rsc;
+      scanout_templat.width0 = align(scanout_templat.width0, paddingX);
+      scanout_templat.height0 = align(scanout_templat.height0, paddingY);
+
+      rsc->scanout = renderonly_scanout_for_resource(&scanout_templat,
+                                                     screen->ro, &handle);
+      if (!rsc->scanout) {
+         BUG("Problem allocating kms memory for resource");
+         goto free_rsc;
+      }
+
+      assert(handle.type == WINSYS_HANDLE_TYPE_FD);
+      rsc->levels[0].stride = handle.stride;
+      rsc->bo = etna_screen_bo_from_handle(pscreen, &handle);
+      close(handle.handle);
+      if (unlikely(!rsc->bo))
+         goto free_rsc;
+   } else {
+      uint32_t flags = DRM_ETNA_GEM_CACHE_WC;
+
+      if (templat->bind & PIPE_BIND_VERTEX_BUFFER)
+         flags |= DRM_ETNA_GEM_FORCE_MMU;
+
+      rsc->bo = etna_bo_new(screen->dev, size, flags);
+      if (unlikely(!rsc->bo)) {
+         BUG("Problem allocating video memory for resource");
+         goto free_rsc;
+      }
    }
 
    if (DBG_ENABLED(ETNA_DBG_ZERO)) {

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to