mesa/st: Accelerate ARB_clear_buffer_object with clear_buffer
authorIlia Mirkin <imirkin@alum.mit.edu>
Tue, 25 Mar 2014 21:02:48 +0000 (17:02 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Tue, 1 Apr 2014 01:21:11 +0000 (21:21 -0400)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/bufferobj.c
src/mesa/main/bufferobj.h
src/mesa/state_tracker/st_cb_bufferobjects.c

index 2e9e05918bd573c4a16dfa85edc067213c6ea44b..36acd64ce7076f02cf1a41812b91334ebd03b329 100644 (file)
@@ -665,7 +665,7 @@ _mesa_buffer_get_subdata( struct gl_context *ctx, GLintptrARB offset,
  * \sa glClearBufferSubData, glClearBufferData and
  * dd_function_table::ClearBufferSubData.
  */
-static void
+void
 _mesa_buffer_clear_subdata(struct gl_context *ctx,
                            GLintptr offset, GLsizeiptr size,
                            const GLvoid *clearValue,
@@ -1458,7 +1458,7 @@ _mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
    if (data == NULL) {
       /* clear to zeros, per the spec */
       ctx->Driver.ClearBufferSubData(ctx, 0, bufObj->Size,
-                                     NULL, 0, bufObj);
+                                     NULL, clearValueSize, bufObj);
       return;
    }
 
@@ -1510,7 +1510,7 @@ _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
       /* clear to zeros, per the spec */
       if (size > 0) {
          ctx->Driver.ClearBufferSubData(ctx, offset, size,
-                                        NULL, 0, bufObj);
+                                        NULL, clearValueSize, bufObj);
       }
       return;
    }
index 9814552eb9642ee65aaceb032929edd68372c672..c08c4fdf2af76c9478f1736f0d6e3013ac38e932 100644 (file)
@@ -115,6 +115,13 @@ extern void
 _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,
                                 struct gl_buffer_object *bufObj);
 
+extern void
+_mesa_buffer_clear_subdata(struct gl_context *ctx,
+                           GLintptr offset, GLsizeiptr size,
+                           const GLvoid *clearValue,
+                           GLsizeiptr clearValueSize,
+                           struct gl_buffer_object *bufObj);
+
 /*
  * API functions
  */
index 49c4b903e594e692fd85d8bbdba741229d34e172..02624617ba882ea4d94713cdbb9fa5ca5b8a2679 100644 (file)
@@ -447,6 +447,33 @@ st_copy_buffer_subdata(struct gl_context *ctx,
                               srcObj->buffer, 0, &box);
 }
 
+/**
+ * Called via glClearBufferSubData().
+ */
+static void
+st_clear_buffer_subdata(struct gl_context *ctx,
+                        GLintptr offset, GLsizeiptr size,
+                        const GLvoid *clearValue,
+                        GLsizeiptr clearValueSize,
+                        struct gl_buffer_object *bufObj)
+{
+   struct pipe_context *pipe = st_context(ctx)->pipe;
+   struct st_buffer_object *buf = st_buffer_object(bufObj);
+   static const char zeros[16] = {0};
+
+   if (!pipe->clear_buffer) {
+      _mesa_buffer_clear_subdata(ctx, offset, size,
+                                 clearValue, clearValueSize, bufObj);
+      return;
+   }
+
+   if (!clearValue)
+      clearValue = zeros;
+
+   pipe->clear_buffer(pipe, buf->buffer, offset, size,
+                      clearValue, clearValueSize);
+}
+
 
 /* TODO: if buffer wasn't created with appropriate usage flags, need
  * to recreate it now and copy contents -- or possibly create a
@@ -476,6 +503,7 @@ st_init_bufferobject_functions(struct dd_function_table *functions)
    functions->FlushMappedBufferRange = st_bufferobj_flush_mapped_range;
    functions->UnmapBuffer = st_bufferobj_unmap;
    functions->CopyBufferSubData = st_copy_buffer_subdata;
+   functions->ClearBufferSubData = st_clear_buffer_subdata;
 
    /* For GL_APPLE_vertex_array_object */
    functions->NewArrayObject = _mesa_new_vao;