gallium: add B10G10R10A2_UINT format
[mesa.git] / src / gallium / auxiliary / util / u_inlines.h
index fc4eb8fdd2ec1cf0941bd45f457f05148b2b8ce9..ddb81b5b95700df0f9c768507524b83d996886e4 100644 (file)
@@ -182,6 +182,7 @@ pipe_surface_equal(struct pipe_surface *s1, struct pipe_surface *s2)
 static INLINE struct pipe_resource *
 pipe_buffer_create( struct pipe_screen *screen,
                    unsigned bind,
+                   unsigned usage,
                    unsigned size )
 {
    struct pipe_resource buffer;
@@ -189,7 +190,7 @@ pipe_buffer_create( struct pipe_screen *screen,
    buffer.target = PIPE_BUFFER;
    buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */
    buffer.bind = bind;
-   buffer.usage = PIPE_USAGE_DEFAULT;
+   buffer.usage = usage;
    buffer.flags = 0;
    buffer.width0 = size;
    buffer.height0 = 1;
@@ -235,6 +236,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
    map = pipe->transfer_map( pipe, *transfer );
    if (map == NULL) {
       pipe->transfer_destroy( pipe, *transfer );
+      *transfer = NULL;
       return NULL;
    }
 
@@ -297,13 +299,20 @@ pipe_buffer_write(struct pipe_context *pipe,
                   const void *data)
 {
    struct pipe_box box;
+   unsigned usage = PIPE_TRANSFER_WRITE;
+
+   if (offset == 0 && size == buf->width0) {
+      usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
+   } else {
+      usage |= PIPE_TRANSFER_DISCARD_RANGE;
+   }
 
    u_box_1d(offset, size, &box);
 
    pipe->transfer_inline_write( pipe,
                                 buf,
                                 0,
-                                PIPE_TRANSFER_WRITE,
+                                usage,
                                 &box,
                                 data,
                                 size,