[Mesa-dev] [PATCH 02/14] st/mesa: add a simple path to BufferData if it only discards buffer contents

Marek Olšák maraeo at gmail.com
Mon Apr 15 06:17:27 PDT 2013


The next patch makes sure _NEW_BUFFER_OBJECT is not needlessly set
for this code.
---
 src/mesa/state_tracker/st_cb_bufferobjects.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 8ff32c8..1b3991c 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -182,6 +182,20 @@ st_bufferobj_data(struct gl_context *ctx,
    struct st_buffer_object *st_obj = st_buffer_object(obj);
    unsigned bind, pipe_usage;
 
+   if (st_obj->Base.Size == size && st_obj->Base.Usage == usage && data) {
+      /* Just discard the old contents and write new data.
+       * This should be the same as creating a new buffer, but we avoid
+       * a lot of validation in Mesa.
+       */
+      struct pipe_box box;
+
+      u_box_1d(0, size, &box);
+      pipe->transfer_inline_write(pipe, st_obj->buffer, 0,
+                                  PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
+                                  &box, data, 0, 0);
+      return GL_TRUE;
+   }
+
    st_obj->Base.Size = size;
    st_obj->Base.Usage = usage;
    
-- 
1.7.10.4



More information about the mesa-dev mailing list