st/mesa: add a simple path to BufferData if it only discards buffer contents
authorMarek Olšák <maraeo@gmail.com>
Sun, 14 Apr 2013 21:28:36 +0000 (23:28 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 24 Apr 2013 01:23:23 +0000 (03:23 +0200)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/state_tracker/st_cb_bufferobjects.c

index 8ff32c8429186dd250866ea0a7b3691236bf6deb..1b3991c3f6d3dc31a103e7c3d6e3d5bb2e71aecd 100644 (file)
@@ -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;