gallium: add usage parameter to pipe_buffer_create
authorMarek Olšák <maraeo@gmail.com>
Sun, 13 Feb 2011 08:13:14 +0000 (09:13 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 15 Feb 2011 21:44:21 +0000 (22:44 +0100)
And set a reasonable buffer usage flag everywhere instead of
just PIPE_USAGE_DEFAULT.

19 files changed:
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_gen_mipmap.c
src/gallium/auxiliary/util/u_index_modify.c
src/gallium/auxiliary/util/u_inlines.h
src/gallium/auxiliary/util/u_upload_mgr.c
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/svga/svga_draw_arrays.c
src/gallium/drivers/svga/svga_draw_elements.c
src/gallium/drivers/svga/svga_swtnl_backend.c
src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
src/gallium/state_trackers/vega/renderer.c
src/gallium/state_trackers/xorg/xorg_renderer.c
src/gallium/tests/trivial/quad-tex.c
src/gallium/tests/trivial/tri.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_drawtex.c

index f07ae2a84d596414107ed4a12419b60c1bc242c6..76bd7ace52618dd5038ce17c263a91eb9cd03735 100644 (file)
@@ -199,6 +199,7 @@ get_next_slot( struct blit_state *ctx )
    if (!ctx->vbuf) {
       ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
                                      PIPE_BIND_VERTEX_BUFFER,
+                                     PIPE_USAGE_STREAM,
                                      max_slots * sizeof ctx->vertices);
    }
    
index d6f1f52085920e004fcc878c1ab2367387caaedd..3b6342ad8d19cc8c5705511fb0b7f8f6e91d8b7f 100644 (file)
@@ -1350,6 +1350,7 @@ get_next_slot(struct gen_mipmap_state *ctx)
    if (!ctx->vbuf) {
       ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
                                      PIPE_BIND_VERTEX_BUFFER,
+                                     PIPE_USAGE_STREAM,
                                      max_slots * sizeof ctx->vertices);
    }
    
index fda396ba0945dc7b7378260b03a4d6f7c17fab9a..d0a28b5fdfadd5fdac6d5d35c978131db1b51ea3 100644 (file)
@@ -65,6 +65,7 @@ void util_shorten_ubyte_elts(struct pipe_context *context,
 
     new_elts = pipe_buffer_create(context->screen,
                                   PIPE_BIND_INDEX_BUFFER,
+                                  PIPE_USAGE_STATIC,
                                   2 * count);
 
     out_map = pipe_buffer_map(context, new_elts, PIPE_TRANSFER_WRITE,
@@ -116,6 +117,7 @@ void util_rebuild_ushort_elts(struct pipe_context *context,
 
     new_elts = pipe_buffer_create(context->screen,
                                   PIPE_BIND_INDEX_BUFFER,
+                                  PIPE_USAGE_STATIC,
                                   2 * count);
 
     out_map = pipe_buffer_map(context, new_elts,
@@ -167,6 +169,7 @@ void util_rebuild_uint_elts(struct pipe_context *context,
 
     new_elts = pipe_buffer_create(context->screen,
                                   PIPE_BIND_INDEX_BUFFER,
+                                  PIPE_USAGE_STATIC,
                                   2 * count);
 
     out_map = pipe_buffer_map(context, new_elts,
index 01883271d6ab03820d7bcb23cb155784adecc23b..98889fb70ac16d1fa03817b17a1de9dd912310fb 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;
index 69b11f9bb774b4113fad034c3cfff37300f2efb7..dcf800a1e8e9e5733c361a42884b3324d7ab5a8b 100644 (file)
@@ -121,6 +121,7 @@ u_upload_alloc_buffer( struct u_upload_mgr *upload,
 
    upload->buffer = pipe_buffer_create( upload->pipe->screen,
                                         upload->bind,
+                                        PIPE_USAGE_STREAM,
                                         size );
    if (upload->buffer == NULL) 
       goto fail;
index cdca74e660d416470080e41db858bc3e31dd870c..7dc8ff08fa44d43dd061f70094a835dfc714a98f 100644 (file)
@@ -931,6 +931,7 @@ static boolean r300_render_allocate_vertices(struct vbuf_render* render,
        pipe_resource_reference(&r300->vbo, NULL);
         r300->vbo = pipe_buffer_create(screen,
                                       PIPE_BIND_VERTEX_BUFFER,
+                                      PIPE_USAGE_STREAM,
                                       R300_MAX_DRAW_VBO_SIZE);
         r300->draw_vbo_offset = 0;
         r300->draw_vbo_size = R300_MAX_DRAW_VBO_SIZE;
index be0e7abe21b4187f5a94499cfcb6b3ecbc8f7ce5..a6518042eb9d76e5487e910440f34e101059d2d5 100644 (file)
@@ -53,6 +53,7 @@ static enum pipe_error generate_indices( struct svga_hwtnl *hwtnl,
 
    dst = pipe_buffer_create( pipe->screen, 
                             PIPE_BIND_INDEX_BUFFER, 
+                            PIPE_USAGE_STATIC,
                             size );
    if (dst == NULL)
       goto fail;
index 83527c6ef496ce4d04084adf8ce7f50152251a3a..7d420c6b2954bbf1b9a7e4e1ed969901fcbf4b71 100644 (file)
@@ -56,6 +56,7 @@ translate_indices( struct svga_hwtnl *hwtnl,
 
    dst = pipe_buffer_create( pipe->screen, 
                             PIPE_BIND_INDEX_BUFFER, 
+                            PIPE_USAGE_STATIC,
                             size );
    if (dst == NULL)
       goto fail;
index 087f2d08540f5db0d396ba2798807deda855ae38..ac9d637f8cb88720eb5f90dc6798b2757aebe9de 100644 (file)
@@ -87,12 +87,14 @@ svga_vbuf_render_allocate_vertices( struct vbuf_render *render,
       svga_render->vbuf_size = MAX2(size, svga_render->vbuf_alloc_size);
       svga_render->vbuf = pipe_buffer_create(screen,
                                              PIPE_BIND_VERTEX_BUFFER,
+                                             PIPE_USAGE_STREAM,
                                              svga_render->vbuf_size);
       if(!svga_render->vbuf) {
          svga_context_flush(svga, NULL);
          assert(!svga_render->vbuf);
          svga_render->vbuf = pipe_buffer_create(screen,
                                                 PIPE_BIND_VERTEX_BUFFER,
+                                                PIPE_USAGE_STREAM,
                                                 svga_render->vbuf_size);
          assert(svga_render->vbuf);
       }
@@ -262,6 +264,7 @@ svga_vbuf_render_draw_elements( struct vbuf_render *render,
       svga_render->ibuf_size = MAX2(size, svga_render->ibuf_alloc_size);
       svga_render->ibuf = pipe_buffer_create(screen,
                                              PIPE_BIND_INDEX_BUFFER,
+                                             PIPE_USAGE_STREAM,
                                              svga_render->ibuf_size);
       svga_render->ibuf_offset = 0;
    }
index 61cf2ddd9df1bf9c77ae6510fcaa456cdda3a699..2e45f3f43e97be64ae08a34cc4309bbd416209d4 100644 (file)
@@ -794,7 +794,8 @@ struct dxgi_blitter
                const unsigned semantic_indices[] = { 0, 0 };
                vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices);
 
-               vbuf.buffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(quad_data));
+               vbuf.buffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
+                                                PIPE_USAGE_STREAM, sizeof(quad_data));
                vbuf.buffer_offset = 0;
                vbuf.stride = 4 * sizeof(float);
                pipe_buffer_write(pipe, vbuf.buffer, 0, sizeof(quad_data), quad_data);
index 952b12356a4c610548ea11481a57e2e85ba4607b..9de2cb1014dde3fcb47d7edda98283b1ac79bd5e 100644 (file)
@@ -174,6 +174,7 @@ static void renderer_set_mvp(struct renderer *renderer,
    pipe_resource_reference(&cbuf, NULL);
    cbuf = pipe_buffer_create(renderer->pipe->screen,
                              PIPE_BIND_CONSTANT_BUFFER,
+                             PIPE_USAGE_STATIC,
                              sizeof(consts));
    if (cbuf) {
       pipe_buffer_write(renderer->pipe, cbuf,
@@ -474,7 +475,8 @@ static void renderer_set_custom_fs(struct renderer *renderer,
          pipe_resource_reference(&cbuf, NULL);
 
          cbuf = pipe_buffer_create(renderer->pipe->screen,
-               PIPE_BIND_CONSTANT_BUFFER, const_buffer_len);
+               PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STATIC,
+               const_buffer_len);
          pipe_buffer_write(renderer->pipe, cbuf, 0,
                const_buffer_len, const_buffer);
          renderer->pipe->set_constant_buffer(renderer->pipe,
index 7c6b6c05daeb420e97ab107d733c8748ceda3c00..3b3ae455c0b6648cad00c000483d8cb2ad378e64 100644 (file)
@@ -429,6 +429,7 @@ void renderer_set_constants(struct xorg_renderer *r,
    pipe_resource_reference(cbuf, NULL);
    *cbuf = pipe_buffer_create(r->pipe->screen,
                               PIPE_BIND_CONSTANT_BUFFER,
+                              PIPE_USAGE_STATIC,
                               param_bytes);
 
    if (*cbuf) {
index 92c5b4dbb183f3ac5111ae6b9551d98a1d8b7511..af93e09d8d4ecd8a45b0130de3e3ecec6f821db5 100644 (file)
@@ -129,7 +129,8 @@ static void init_prog(struct program *p)
                        }
                };
 
-               p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(vertices));
+               p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER,
+                                            PIPE_USAGE_STATIC, sizeof(vertices));
                pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices);
        }
 
index 37c1573051f1da16ee2b18dc612d1539008acda9..b89cfe0d98920ef2a79d5fd19b6b5542abc7e7a2 100644 (file)
@@ -120,7 +120,8 @@ static void init_prog(struct program *p)
                        }
                };
 
-               p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(vertices));
+               p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER,
+                                            PIPE_USAGE_STATIC, sizeof(vertices));
                pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices);
        }
 
index c40a510c35159241141c153da88944fefaf798e5..0ea5671557c5f3de0e133b3f6694f0c8f44500bc 100644 (file)
@@ -349,6 +349,7 @@ setup_bitmap_vertex_data(struct st_context *st, bool normalized,
    if (!st->bitmap.vbuf) {
       st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 
                                            PIPE_BIND_VERTEX_BUFFER,
+                                           PIPE_USAGE_STREAM,
                                            max_slots *
                                            sizeof(st->bitmap.vertices));
    }
index d4d9af4ada385fb15e2c759e42307f4e97293e58..12528f49ff7ea8c13cf0c16cec14eb147ae67af0 100644 (file)
@@ -171,7 +171,7 @@ st_bufferobj_data(struct gl_context *ctx,
    struct st_context *st = st_context(ctx);
    struct pipe_context *pipe = st->pipe;
    struct st_buffer_object *st_obj = st_buffer_object(obj);
-   unsigned buffer_usage;
+   unsigned bind, pipe_usage;
 
    st_obj->Base.Size = size;
    st_obj->Base.Usage = usage;
@@ -179,22 +179,43 @@ st_bufferobj_data(struct gl_context *ctx,
    switch(target) {
    case GL_PIXEL_PACK_BUFFER_ARB:
    case GL_PIXEL_UNPACK_BUFFER_ARB:
-      buffer_usage = PIPE_BIND_RENDER_TARGET;
+      bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
       break;
    case GL_ARRAY_BUFFER_ARB:
-      buffer_usage = PIPE_BIND_VERTEX_BUFFER;
+      bind = PIPE_BIND_VERTEX_BUFFER;
       break;
    case GL_ELEMENT_ARRAY_BUFFER_ARB:
-      buffer_usage = PIPE_BIND_INDEX_BUFFER;
+      bind = PIPE_BIND_INDEX_BUFFER;
       break;
    default:
-      buffer_usage = 0;
+      bind = 0;
+   }
+
+   switch (usage) {
+   case GL_STATIC_DRAW:
+   case GL_STATIC_READ:
+   case GL_STATIC_COPY:
+      pipe_usage = PIPE_USAGE_STATIC;
+      break;
+   case GL_DYNAMIC_DRAW:
+   case GL_DYNAMIC_READ:
+   case GL_DYNAMIC_COPY:
+      pipe_usage = PIPE_USAGE_DYNAMIC;
+      break;
+   case GL_STREAM_DRAW:
+   case GL_STREAM_READ:
+   case GL_STREAM_COPY:
+      pipe_usage = PIPE_USAGE_STREAM;
+      break;
+   default:
+      pipe_usage = PIPE_USAGE_DEFAULT;
    }
 
    pipe_resource_reference( &st_obj->buffer, NULL );
 
    if (size != 0) {
-      st_obj->buffer = pipe_buffer_create(pipe->screen, buffer_usage, size);
+      st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
+                                          pipe_usage, size);
 
       if (!st_obj->buffer) {
          return GL_FALSE;
index 69e034305075dee9c0a860bfd382a0f3564fee55..d2e0cd73c760c18c4fa7b3e71db443a3c138a202 100644 (file)
@@ -138,6 +138,7 @@ draw_quad(struct st_context *st,
    if (!st->clear.vbuf) {
       st->clear.vbuf = pipe_buffer_create(pipe->screen,
                                           PIPE_BIND_VERTEX_BUFFER,
+                                          PIPE_USAGE_STREAM,
                                           max_slots * sizeof(st->clear.vertices));
    }
 
index 03fc903c92e574eab10c4f52befe3f2e041270b4..07527002b4a0ed1e248a10898782a784432299ba 100644 (file)
@@ -522,6 +522,7 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
       /* allocate/load buffer object with vertex data */
       buf = pipe_buffer_create(pipe->screen,
                               PIPE_BIND_VERTEX_BUFFER,
+                              PIPE_USAGE_STATIC,
                                sizeof(verts));
       pipe_buffer_write(st->pipe, buf, 0, sizeof(verts), verts);
 
index 81a2479b95a49fb94f408a66e50385a02d81e959..86ceb9d78b32abc294efb7203db3c95abfa8cab6 100644 (file)
@@ -139,6 +139,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
 
    /* create the vertex buffer */
    vbuffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
+                                PIPE_USAGE_STREAM,
                                 numAttribs * 4 * 4 * sizeof(GLfloat));
 
    /* load vertex buffer */