Mesa (main): iris: Allow userptr on 1D and 2D images

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 6 23:41:20 UTC 2022


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

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Wed Apr  6 14:22:43 2022 -0500

iris: Allow userptr on 1D and 2D images

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15779>

---

 src/gallium/drivers/iris/iris_resource.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c
index ca93b82025e..bd39845a3e7 100644
--- a/src/gallium/drivers/iris/iris_resource.c
+++ b/src/gallium/drivers/iris/iris_resource.c
@@ -1175,7 +1175,24 @@ iris_resource_from_user_memory(struct pipe_screen *pscreen,
    if (!res)
       return NULL;
 
-   assert(templ->target == PIPE_BUFFER);
+   assert(templ->target == PIPE_BUFFER ||
+          templ->target == PIPE_TEXTURE_1D ||
+          templ->target == PIPE_TEXTURE_2D);
+
+   size_t res_size = templ->width0;
+   if (templ->target != PIPE_BUFFER) {
+      const uint32_t row_pitch_B =
+         templ->width0 * util_format_get_blocksize(templ->format);
+      res_size = templ->height0 * row_pitch_B;
+
+      if (!iris_resource_configure_main(screen, res, templ,
+                                        DRM_FORMAT_MOD_LINEAR,
+                                        row_pitch_B)) {
+         iris_resource_destroy(pscreen, &res->base.b);
+         return NULL;
+      }
+      assert(res->surf.size_B <= res_size);
+   }
 
    /* The userptr ioctl only works on whole pages.  Because we know that
     * things will exist in memory at a page granularity, we can expand the
@@ -1187,7 +1204,7 @@ iris_resource_from_user_memory(struct pipe_screen *pscreen,
    assert(util_is_power_of_two_nonzero(page_size));
    size_t offset = (uintptr_t)user_memory & (page_size - 1);
    void *mem_start = (char *)user_memory - offset;
-   size_t mem_size = offset + templ->width0;
+   size_t mem_size = offset + res_size;
    mem_size = ALIGN_NPOT(mem_size, page_size);
 
    res->internal_format = templ->format;



More information about the mesa-commit mailing list