st/mesa: restore the transfer_inline_write path for BufferData
authorMarek Olšák <maraeo@gmail.com>
Thu, 25 Apr 2013 20:12:47 +0000 (22:12 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sat, 11 May 2013 21:45:02 +0000 (23:45 +0200)
Version 2 that shouldn't crash.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/state_tracker/st_cb_bufferobjects.c

index d166fe644148d7af8996216b3e73f80c24f8e467..c868d5e163e46ee5f0d11643fd33262658453781 100644 (file)
@@ -182,6 +182,21 @@ st_bufferobj_data(struct gl_context *ctx,
    struct st_buffer_object *st_obj = st_buffer_object(obj);
    unsigned bind, pipe_usage;
 
+   if (size && data && st_obj->buffer &&
+       st_obj->Base.Size == size && st_obj->Base.Usage == usage) {
+      /* 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;