gallium/u_threaded: optimize set_constant_buffer
authorMarek Olšák <marek.olsak@amd.com>
Sun, 29 Nov 2020 06:25:01 +0000 (01:25 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 8 Dec 2020 17:47:56 +0000 (17:47 +0000)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7719>

src/gallium/auxiliary/util/u_threaded_context.c

index 9d6dfa77206f13be05453a47bea7ba8a9beca45a..1c23aae60d3c09aade764427b14e816c9a517e7f 100644 (file)
@@ -783,17 +783,29 @@ tc_set_constant_buffer(struct pipe_context *_pipe,
                        const struct pipe_constant_buffer *cb)
 {
    struct threaded_context *tc = threaded_context(_pipe);
-   struct pipe_resource *buffer = NULL;
-   unsigned offset;
 
-   /* This must be done before adding set_constant_buffer, because it could
-    * generate e.g. transfer_unmap and flush partially-uninitialized
-    * set_constant_buffer to the driver if it was done afterwards.
-    */
    if (cb && cb->user_buffer) {
+      struct pipe_resource *buffer = NULL;
+      unsigned offset;
+
+      /* This must be done before adding set_constant_buffer, because it could
+       * generate e.g. transfer_unmap and flush partially-uninitialized
+       * set_constant_buffer to the driver if it was done afterwards.
+       */
       u_upload_data(tc->base.const_uploader, 0, cb->buffer_size, tc->ubo_alignment,
                     cb->user_buffer, &offset, &buffer);
       u_upload_unmap(tc->base.const_uploader);
+
+      struct tc_constant_buffer *p =
+         tc_add_struct_typed_call(tc, TC_CALL_set_constant_buffer,
+                                  tc_constant_buffer);
+      p->shader = shader;
+      p->index = index;
+      p->cb.buffer_size = cb->buffer_size;
+      p->cb.user_buffer = NULL;
+      p->cb.buffer_offset = offset;
+      p->cb.buffer = buffer;
+      return;
    }
 
    struct tc_constant_buffer *p =
@@ -803,18 +815,10 @@ tc_set_constant_buffer(struct pipe_context *_pipe,
    p->index = index;
 
    if (cb) {
-      if (cb->user_buffer) {
-         p->cb.buffer_size = cb->buffer_size;
-         p->cb.user_buffer = NULL;
-         p->cb.buffer_offset = offset;
-         p->cb.buffer = buffer;
-      } else {
-         tc_set_resource_reference(&p->cb.buffer,
-                                   cb->buffer);
-         p->cb.user_buffer = NULL;
-         p->cb.buffer_offset = cb->buffer_offset;
-         p->cb.buffer_size = cb->buffer_size;
-      }
+      tc_set_resource_reference(&p->cb.buffer, cb->buffer);
+      p->cb.user_buffer = NULL;
+      p->cb.buffer_offset = cb->buffer_offset;
+      p->cb.buffer_size = cb->buffer_size;
    } else {
       memset(&p->cb, 0, sizeof(*cb));
    }