Mesa (main): vc4: implement resource_get_param

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 19 13:33:26 UTC 2021


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

Author: Simon Ser <contact at emersion.fr>
Date:   Sat Aug 14 14:07:28 2021 +0200

vc4: implement resource_get_param

Prior to this commit, the stride, offset and modifier were fetched
via WINSYS_HANDLE_TYPE_KMS. However we can't make such a query
succeed if the buffer couldn't be imported to the KMS device.

Instead, implement the resource_get_param hook to allow users to
fetch this information without WINSYS_HANDLE_TYPE_KMS.

A tiny helper function is introduced to compute the modifier of a
resource.

Signed-off-by: Simon Ser <contact at emersion.fr>
Fixes: 7bcb22363935 ("v3d, vc4: Fix dmabuf import for non-scanout buffers")
Reported-by: Roman Stratiienko <r.stratiienko at gmail.com>
Reviewed-by: Daniel Stone <daniels at collabora.com>
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12370>

---

 src/gallium/drivers/vc4/vc4_resource.c | 40 +++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c
index af61c4860b8..052588e49f6 100644
--- a/src/gallium/drivers/vc4/vc4_resource.c
+++ b/src/gallium/drivers/vc4/vc4_resource.c
@@ -283,6 +283,15 @@ vc4_resource_destroy(struct pipe_screen *pscreen,
         free(rsc);
 }
 
+static uint64_t
+vc4_resource_modifier(struct vc4_resource *rsc)
+{
+        if (rsc->tiled)
+                return DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED;
+        else
+                return DRM_FORMAT_MOD_LINEAR;
+}
+
 static bool
 vc4_resource_get_handle(struct pipe_screen *pscreen,
                         struct pipe_context *pctx,
@@ -295,6 +304,7 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
 
         whandle->stride = rsc->slices[0].stride;
         whandle->offset = 0;
+        whandle->modifier = vc4_resource_modifier(rsc);
 
         /* If we're passing some reference to our BO out to some other part of
          * the system, then we can't do any optimizations about only us being
@@ -302,11 +312,6 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
          */
         rsc->bo->private = false;
 
-        if (rsc->tiled)
-                whandle->modifier = DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED;
-        else
-                whandle->modifier = DRM_FORMAT_MOD_LINEAR;
-
         switch (whandle->type) {
         case WINSYS_HANDLE_TYPE_SHARED:
                 if (screen->ro) {
@@ -334,6 +339,30 @@ vc4_resource_get_handle(struct pipe_screen *pscreen,
         return false;
 }
 
+static bool
+vc4_resource_get_param(struct pipe_screen *pscreen,
+                       struct pipe_context *pctx, struct pipe_resource *prsc,
+                       unsigned plane, unsigned layer, unsigned level,
+                       enum pipe_resource_param param,
+                       unsigned usage, uint64_t *value)
+{
+        struct vc4_resource *rsc = vc4_resource(prsc);
+
+        switch (param) {
+        case PIPE_RESOURCE_PARAM_STRIDE:
+                *value = rsc->slices[level].stride;
+                return true;
+        case PIPE_RESOURCE_PARAM_OFFSET:
+                *value = 0;
+                return true;
+        case PIPE_RESOURCE_PARAM_MODIFIER:
+                *value = vc4_resource_modifier(rsc);
+                return true;
+        default:
+                return false;
+        }
+}
+
 static void
 vc4_setup_slices(struct vc4_resource *rsc, const char *caller)
 {
@@ -1119,6 +1148,7 @@ vc4_resource_screen_init(struct pipe_screen *pscreen)
                 vc4_resource_create_with_modifiers;
         pscreen->resource_from_handle = vc4_resource_from_handle;
         pscreen->resource_get_handle = vc4_resource_get_handle;
+        pscreen->resource_get_param = vc4_resource_get_param;
         pscreen->resource_destroy = vc4_resource_destroy;
         pscreen->transfer_helper = u_transfer_helper_create(&transfer_vtbl,
                                                             false, false,



More information about the mesa-commit mailing list