From: Marek Olšák <marek.ol...@amd.com>

---
 src/gallium/auxiliary/util/u_suballoc.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_suballoc.c 
b/src/gallium/auxiliary/util/u_suballoc.c
index 5aaddbc..8c463c9 100644
--- a/src/gallium/auxiliary/util/u_suballoc.c
+++ b/src/gallium/auxiliary/util/u_suballoc.c
@@ -98,27 +98,34 @@ u_suballocator_alloc(struct u_suballocator *allocator, 
unsigned size,
       pipe_resource_reference(&allocator->buffer, NULL);
       allocator->offset = 0;
       allocator->buffer =
          pipe_buffer_create(allocator->pipe->screen, allocator->bind,
                             allocator->usage, allocator->size);
       if (!allocator->buffer)
          goto fail;
 
       /* 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);
+         }
       }
    }
 
    assert(allocator->offset % alignment == 0);
    assert(allocator->offset < allocator->buffer->width0);
    assert(allocator->offset + size <= allocator->buffer->width0);
 
    /* Return the buffer. */
    *out_offset = allocator->offset;
    pipe_resource_reference(outbuf, allocator->buffer);
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to