gallium: add interface and state tracker support for GL_AMD_pinned_memory
authorMarek Olšák <marek.olsak@amd.com>
Tue, 10 Feb 2015 13:00:57 +0000 (14:00 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 17 Feb 2015 16:31:48 +0000 (17:31 +0100)
v2: add alignment restrictions to docs, fix indentation in headers

Reviewed-by: Christian König <christian.koenig@amd.com>
15 files changed:
src/gallium/docs/source/screen.rst
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/ilo/ilo_screen.c
src/gallium/drivers/llvmpipe/lp_screen.c
src/gallium/drivers/nouveau/nv30/nv30_screen.c
src/gallium/drivers/nouveau/nv50/nv50_screen.c
src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_screen.h
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_extensions.c

index 5d80908057cd35581ae58a75b1202a801d3708c9..373a2fe25d0a53c87239c20cfa7b6bf8b2862874 100644 (file)
@@ -246,6 +246,12 @@ The integer capabilities:
 * ``PIPE_CAP_MULTISAMPLE_Z_RESOLVE``: Whether the driver supports blitting
   a multisampled depth buffer into a single-sampled texture (or depth buffer).
   Only the first sampled should be copied.
+* ``PIPE_CAP_RESOURCE_FROM_USER_MEMORY``: Whether the driver can create
+  a pipe_resource where an already-existing piece of (malloc'd) user memory
+  is used as its backing storage. In other words, whether the driver can map
+  existing user memory into the device address space for direct device access.
+  The create function is pipe_screen::resource_from_user_memory. The address
+  and size must be page-aligned.
 
 
 .. _pipe_capf:
index 2dcb50733523741375fc7c491eeb457b8e535c82..5fbbcf5158d8915ba3fb1a6745a865e4f2f00cc6 100644 (file)
@@ -229,6 +229,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
    case PIPE_CAP_VERTEXID_NOBASE:
    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
 
    case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
index cf9f89750041e68a1fcb2f979691fe8d3a63875d..95e34d3e4de618f7c358192ee0007c3e55f1b37b 100644 (file)
@@ -471,6 +471,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
    case PIPE_CAP_SAMPLER_VIEW_TARGET:
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 31c65df022ae270f8d77ce0691aa3afde958679b..8b6e66e968cfec15d6f26c3e3939fa4523168ef2 100644 (file)
@@ -288,6 +288,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
       return 1;
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
    }
    /* should only get here on unhandled cases */
index 83cae7a173d7a80fd0227e4d57de3bb5c2294e1d..a532e5303e75fc3e4f2298ee5e12bbe4900f610f 100644 (file)
@@ -160,6 +160,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_VERTEXID_NOBASE:
    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 222fa65b31f306f2daf63a8aea181505bafb4aaa..6c1de08ddcaa793fb2a084cbd7ffc276eec7462b 100644 (file)
@@ -208,6 +208,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_DRAW_INDIRECT:
    case PIPE_CAP_VERTEXID_NOBASE:
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE: /* potentially supported on some hw */
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 63fbad7a09599148ae3a628ea3fc0bc2d935103d..edea845ecba8f279f187c22b38fb1af8ebe66dd0 100644 (file)
@@ -192,6 +192,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_FAKE_SW_MSAA:
    case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
    case PIPE_CAP_VERTEXID_NOBASE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 7794fc26cd925e5fb61fca0691a266fabc9d4376..36b299654660c4c97d75eedcd4597b6e2f8a0b5a 100644 (file)
@@ -184,6 +184,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
         case PIPE_CAP_VERTEXID_NOBASE:
         case PIPE_CAP_POLYGON_OFFSET_CLAMP:
         case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+        case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
             return 0;
 
         /* SWTCL-only features. */
index 365fc0a1db9ebd7b29a9dcc7b01bcfafefd91df3..bae136768a4abd01c1276be2483755068c204021 100644 (file)
@@ -236,6 +236,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
       return 0;
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
    }
    /* should only get here on unhandled cases */
index e3db4a8b447c03876c8cab415a9cfac19117c587..e468a2f89ce6a85b0e3b665c9558a3bdd0c9e5d0 100644 (file)
@@ -307,6 +307,7 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
       /* XXX: Query the host ? */
       return 1;
    case PIPE_CAP_UMA:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
       return 0;
    }
 
index db88eaa5bb46e1d9732bd60b10ea47b7cbc8629a..74643512b9cf8a36d06b1ef34abc35a77861f1be 100644 (file)
@@ -172,6 +172,7 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_VERTEXID_NOBASE:
         case PIPE_CAP_POLYGON_OFFSET_CLAMP:
         case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+        case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
                 return 0;
 
                 /* Stream output. */
index 7ce25af20c85b345af2db03d6a5f33a9c798ea36..17850438dc80ea1c692f93cb7f95b4382659e126 100644 (file)
@@ -575,6 +575,7 @@ enum pipe_cap {
    PIPE_CAP_VERTEXID_NOBASE = 112,
    PIPE_CAP_POLYGON_OFFSET_CLAMP = 113,
    PIPE_CAP_MULTISAMPLE_Z_RESOLVE = 114,
+   PIPE_CAP_RESOURCE_FROM_USER_MEMORY = 115,
 };
 
 #define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0)
index cf958d26a059bd881dfaaeaf725cbb540f6d4b9d..ac885068aa3c3bed858e8b838a8f0a1928158d66 100644 (file)
@@ -163,6 +163,14 @@ struct pipe_screen {
                                                  const struct pipe_resource *templat,
                                                  struct winsys_handle *handle);
 
+   /**
+    * Create a resource from user memory. This maps the user memory into
+    * the device address space.
+    */
+   struct pipe_resource * (*resource_from_user_memory)(struct pipe_screen *,
+                                                       const struct pipe_resource *t,
+                                                       void *user_memory);
+
    /**
     * Get a winsys_handle from a texture. Some platforms/winsys requires
     * that the texture is created with a special usage flag like
index 90f786cc1f2b5351af274f24145ef3686a3eba26..f24805cf5dd8d12c5ae4500ecfb9c2b32916006f 100644 (file)
@@ -186,7 +186,8 @@ st_bufferobj_data(struct gl_context *ctx,
    struct st_buffer_object *st_obj = st_buffer_object(obj);
    unsigned bind, pipe_usage, pipe_flags = 0;
 
-   if (size && data && st_obj->buffer &&
+   if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&
+       size && data && st_obj->buffer &&
        st_obj->Base.Size == size &&
        st_obj->Base.Usage == usage &&
        st_obj->Base.StorageFlags == storageFlags) {
@@ -287,6 +288,7 @@ st_bufferobj_data(struct gl_context *ctx,
    }
 
    if (size != 0) {
+      struct pipe_screen *screen = pipe->screen;
       struct pipe_resource buffer;
 
       memset(&buffer, 0, sizeof buffer);
@@ -300,16 +302,22 @@ st_bufferobj_data(struct gl_context *ctx,
       buffer.depth0 = 1;
       buffer.array_size = 1;
 
-      st_obj->buffer = pipe->screen->resource_create(pipe->screen, &buffer);
+      if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
+         st_obj->buffer =
+            screen->resource_from_user_memory(screen, &buffer, (void*)data);
+      }
+      else {
+         st_obj->buffer = screen->resource_create(screen, &buffer);
+
+         if (st_obj->buffer && data)
+            pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
+      }
 
       if (!st_obj->buffer) {
          /* out of memory */
          st_obj->Base.Size = 0;
          return GL_FALSE;
       }
-
-      if (data)
-         pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
    }
 
    /* BufferData may change an array or uniform buffer, need to update it */
index 2b5cde28041af84b7663a7357069eacbe4369b2e..036fac71a0cb56d05ea397545c574459bf8f7ab1 100644 (file)
@@ -446,6 +446,7 @@ void st_init_extensions(struct pipe_screen *screen,
       { o(EXT_texture_swizzle),              PIPE_CAP_TEXTURE_SWIZZLE                  },
       { o(EXT_transform_feedback),           PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS        },
 
+      { o(AMD_pinned_memory),                PIPE_CAP_RESOURCE_FROM_USER_MEMORY        },
       { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE    },
       { o(ATI_separate_stencil),             PIPE_CAP_TWO_SIDED_STENCIL                },
       { o(ATI_texture_mirror_once),          PIPE_CAP_TEXTURE_MIRROR_CLAMP             },