svga: Avoid bouncing buffer data in malloced buffers
authorThomas Hellstrom <thellstrom@vmware.com>
Tue, 2 Apr 2019 10:36:34 +0000 (12:36 +0200)
committerThomas Hellstrom <thellstrom@vmware.com>
Thu, 2 May 2019 07:51:00 +0000 (09:51 +0200)
Some constant- and texture upload buffer data may bounce in malloced
buffers before being transferred to hardware buffers. In the case of
texture upload buffers this seems to be an oversight. In the case of
constant buffers, code comments indicate that we want to avoid mapping
hardware buffers for reading when copying out of buffers that need
modification before being passed to hardware. In this case we avoid
data bouncing for upload manager buffers but make sure buffers that
we read out from stay in malloced memory.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/svga/svga_context.c
src/gallium/drivers/svga/svga_resource_buffer.c
src/gallium/drivers/svga/svga_resource_texture.c

index 7b3e9e81f4cd00ba86480e024b73d9681f886aac..57c0dc49957db5422ab738173f50b736fceb8c11 100644 (file)
@@ -230,7 +230,8 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
 
    svga->const0_upload = u_upload_create(&svga->pipe,
                                          CONST0_UPLOAD_DEFAULT_SIZE,
-                                         PIPE_BIND_CONSTANT_BUFFER,
+                                         PIPE_BIND_CONSTANT_BUFFER |
+                                         PIPE_BIND_CUSTOM,
                                          PIPE_USAGE_STREAM, 0);
    if (!svga->const0_upload)
       goto cleanup;
index a3e11adfac64f17c9d5e2f8c12d9d2abcbcf889c..3f37ef692faf8bec05b0a2442544ced0253054ec 100644 (file)
 
 
 /**
- * Vertex and index buffers need hardware backing.  Constant buffers
- * do not.  No other types of buffers currently supported.
+ * Determine what buffers eventually need hardware backing.
+ *
+ * Vertex- and index buffers need hardware backing.  Constant buffers
+ * do on vgpu10. Staging texture-upload buffers do when they are
+ * supported.
  */
 static inline boolean
-svga_buffer_needs_hw_storage(unsigned usage)
+svga_buffer_needs_hw_storage(const struct svga_screen *ss,
+                             const struct pipe_resource *template)
 {
-   return (usage & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
-                    PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT)) != 0;
-}
+   unsigned bind_mask = (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
+                         PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT);
 
+   if (ss->sws->have_vgpu10) {
+      /*
+       * Driver-created upload const0- and staging texture upload buffers
+       * tagged with PIPE_BIND_CUSTOM
+       */
+      bind_mask |= PIPE_BIND_CUSTOM;
+      /* Uniform buffer objects.
+       * Make sure we don't create hardware storage for state-tracker
+       * const0 buffers, because we frequently map them for reading.
+       * They are distinguished by having PIPE_USAGE_STREAM, but not
+       * PIPE_BIND_CUSTOM.
+       */
+      if (template->usage != PIPE_USAGE_STREAM)
+         bind_mask |= PIPE_BIND_CONSTANT_BUFFER;
+   }
+
+   return !!(template->bind & bind_mask);
+}
 
 /**
  * Create a buffer transfer.
@@ -411,7 +432,7 @@ svga_buffer_create(struct pipe_screen *screen,
    sbuf->b.vtbl = &svga_buffer_vtbl;
    pipe_reference_init(&sbuf->b.b.reference, 1);
    sbuf->b.b.screen = screen;
-   bind_flags = template->bind;
+   bind_flags = template->bind & ~PIPE_BIND_CUSTOM;
 
    LIST_INITHEAD(&sbuf->surfaces);
 
@@ -430,7 +451,7 @@ svga_buffer_create(struct pipe_screen *screen,
     */
    sbuf->b.b.width0 = align(sbuf->b.b.width0, 16);
 
-   if (svga_buffer_needs_hw_storage(bind_flags)) {
+   if (svga_buffer_needs_hw_storage(ss, template)) {
 
       /* If the buffer is not used for constant buffer, set
        * the vertex/index bind flags as well so that the buffer will be
@@ -442,9 +463,10 @@ svga_buffer_create(struct pipe_screen *screen,
        * bind flag since streamout buffer is an output buffer and
        * might have performance implication.
        */
-      if (!(template->bind & PIPE_BIND_CONSTANT_BUFFER)) {
-         /* Not a constant buffer.  The buffer may be used for vertex data
-          * or indexes.
+      if (!(template->bind & PIPE_BIND_CONSTANT_BUFFER) &&
+          !(template->bind & PIPE_BIND_CUSTOM)) {
+         /* Not a constant- or staging buffer.
+          * The buffer may be used for vertex data or indexes.
           */
          bind_flags |= (PIPE_BIND_VERTEX_BUFFER |
                         PIPE_BIND_INDEX_BUFFER);
index c716b66e89f9ece0d984ec7c04c1c7ddbc2b2d99..e9449e8a1ffbc5193a71c8605e38966bb8fd6937 100644 (file)
@@ -1335,7 +1335,7 @@ boolean
 svga_texture_transfer_map_upload_create(struct svga_context *svga)
 {
    svga->tex_upload = u_upload_create(&svga->pipe, TEX_UPLOAD_DEFAULT_SIZE,
-                                      0, PIPE_USAGE_STAGING, 0);
+                                      PIPE_BIND_CUSTOM, PIPE_USAGE_STAGING, 0);
    return svga->tex_upload != NULL;
 }