gallium/u_upload_mgr: don't do align twice in the u_upload_alloc fast path
authorMarek Olšák <marek.olsak@amd.com>
Fri, 24 Jan 2020 01:40:35 +0000 (20:40 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 14 Feb 2020 23:16:27 +0000 (18:16 -0500)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>

src/gallium/auxiliary/util/u_upload_mgr.c

index c199ad0edf12050d996b9254e5483bec6d61e6c4..375fad005b4401f23a0f66b71d62f4134d8ff2f8 100644 (file)
@@ -244,18 +244,17 @@ u_upload_alloc(struct u_upload_mgr *upload,
                void **ptr)
 {
    unsigned buffer_size = upload->buffer_size;
-   unsigned offset;
+   unsigned offset = MAX2(min_out_offset, upload->offset);
 
-   min_out_offset = align(min_out_offset, alignment);
-
-   offset = align(upload->offset, alignment);
-   offset = MAX2(offset, min_out_offset);
+   offset = align(offset, alignment);
 
    /* Make sure we have enough space in the upload buffer
     * for the sub-allocation.
     */
    if (unlikely(offset + size > buffer_size)) {
-      buffer_size = u_upload_alloc_buffer(upload, min_out_offset + size);
+      /* Allocate a new buffer and set the offset to the smallest one. */
+      offset = align(min_out_offset, alignment);
+      buffer_size = u_upload_alloc_buffer(upload, offset + size);
 
       if (unlikely(!buffer_size)) {
          *out_offset = ~0;
@@ -263,8 +262,6 @@ u_upload_alloc(struct u_upload_mgr *upload,
          *ptr = NULL;
          return;
       }
-
-      offset = min_out_offset;
    }
 
    if (unlikely(!upload->map)) {