[Mesa-dev] [PATCH 2/3] mesa/st: Accelerate ARB_clear_buffer_object with clear_buffer
Ilia Mirkin
imirkin at alum.mit.edu
Tue Mar 25 14:36:35 PDT 2014
Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
Note that this also ensures that the clear size is passed through even when
the data is null. This preserves the validation done to make sure that size %
clear size == 0.
src/mesa/main/bufferobj.c | 6 +++---
src/mesa/main/bufferobj.h | 7 +++++++
src/mesa/state_tracker/st_cb_bufferobjects.c | 28 ++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 2e9e059..36acd64 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -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;
}
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index 9814552..c08c4fd 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -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
*/
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 49c4b90..2706903 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -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);
+ 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;
--
1.8.3.2
More information about the mesa-dev
mailing list