gallium/u_suballoc: use clear_buffer if available
authorMarek Olšák <marek.olsak@amd.com>
Wed, 15 Feb 2017 00:47:25 +0000 (01:47 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 18 Feb 2017 00:22:08 +0000 (01:22 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_suballoc.c

index 5aaddbc..8c463c9 100644 (file)
@@ -105,13 +105,20 @@ u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
 
       /* Clear the memory if needed. */
       if (allocator->zero_buffer_memory) {
-         struct pipe_transfer *transfer = NULL;
-         void *ptr;
-
-         ptr = pipe_buffer_map(allocator->pipe, allocator->buffer,
-                              PIPE_TRANSFER_WRITE, &transfer);
-         memset(ptr, 0, allocator->size);
-         pipe_buffer_unmap(allocator->pipe, transfer);
+         struct pipe_context *pipe = allocator->pipe;
+
+         if (pipe->clear_buffer) {
+            unsigned clear_value = 0;
+
+            pipe->clear_buffer(pipe, allocator->buffer, 0, allocator->size,
+                               &clear_value, 4);
+         } else {
+            struct pipe_transfer *transfer = NULL;
+            void *ptr = pipe_buffer_map(pipe, allocator->buffer,
+                                        PIPE_TRANSFER_WRITE, &transfer);
+            memset(ptr, 0, allocator->size);
+            pipe_buffer_unmap(pipe, transfer);
+         }
       }
    }