gallium: New inline to write buffers which avoids synchronization.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 21 Jan 2010 17:30:22 +0000 (09:30 -0800)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 21 Jan 2010 23:18:40 +0000 (15:18 -0800)
src/gallium/include/pipe/p_inlines.h

index 11ed46c7e7260ccd6e228948cee49fb0a680a641..72f5c1dc2a261d7ba26a4cf2c19d32d915d84357 100644 (file)
@@ -129,6 +129,37 @@ pipe_buffer_write(struct pipe_screen *screen,
    }
 }
 
+/**
+ * Special case for writing non-overlapping ranges.
+ *
+ * We can avoid GPU/CPU synchronization when writing range that has never
+ * been written before.
+ */
+static INLINE void
+pipe_buffer_write_nooverlap(struct pipe_screen *screen,
+                            struct pipe_buffer *buf,
+                            unsigned offset, unsigned size,
+                            const void *data)
+{
+   void *map;
+
+   assert(offset < buf->size);
+   assert(offset + size <= buf->size);
+   assert(size);
+
+   map = pipe_buffer_map_range(screen, buf, offset, size,
+                               PIPE_BUFFER_USAGE_CPU_WRITE |
+                               PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
+                               PIPE_BUFFER_USAGE_DISCARD |
+                               PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
+   assert(map);
+   if(map) {
+      memcpy((uint8_t *)map + offset, data, size);
+      pipe_buffer_flush_mapped_range(screen, buf, offset, size);
+      pipe_buffer_unmap(screen, buf);
+   }
+}
+
 static INLINE void
 pipe_buffer_read(struct pipe_screen *screen,
                  struct pipe_buffer *buf,