iris: Use persistent mappings for pinned memory (userptr)
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 29 Sep 2022 23:12:07 +0000 (16:12 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 9 Dec 2022 21:46:03 +0000 (21:46 +0000)
This is a port of Nicolai's b52721e3b693e113aa537d163c8a855169e7b75d
from radeonsi.  Because GL_AMD_pinned_memory guarantees that mappings
will refer to the same underlying page, we need to avoid using staging
maps.  Using a persistent map is a reasonable way to accomplish this.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19209>

src/gallium/drivers/iris/iris_resource.c

index d33a8e7..5546edf 100644 (file)
@@ -2369,6 +2369,20 @@ iris_transfer_map(struct pipe_context *ctx,
    struct iris_resource *res = (struct iris_resource *)resource;
    struct isl_surf *surf = &res->surf;
 
+   /* From GL_AMD_pinned_memory issues:
+    *
+    *     4) Is glMapBuffer on a shared buffer guaranteed to return the
+    *        same system address which was specified at creation time?
+    *
+    *        RESOLVED: NO. The GL implementation might return a different
+    *        virtual mapping of that memory, although the same physical
+    *        page will be used.
+    *
+    * So don't ever use staging buffers.
+    */
+   if (res->base.is_user_ptr)
+      usage |= PIPE_MAP_PERSISTENT;
+
    if (usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE) {
       /* Replace the backing storage with a fresh buffer for non-async maps */
       if (!(usage & (PIPE_MAP_UNSYNCHRONIZED |