Supply buffer usage hints to winsys.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 5 Nov 2007 18:04:35 +0000 (18:04 +0000)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Tue, 6 Nov 2007 14:49:38 +0000 (14:49 +0000)
Winsys driver needs some hints in order to allocate the appropriate kind of
memory for the buffer.

src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c
src/mesa/drivers/x11/xm_winsys.c
src/mesa/pipe/i915simple/i915_prim_vbuf.c
src/mesa/pipe/p_defines.h
src/mesa/pipe/p_winsys.h
src/mesa/pipe/xlib/xm_winsys.c
src/mesa/state_tracker/st_atom_constbuf.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_draw.c

index af05a3398c8e4911d0f043a64a1c9da9de4cbce0..cc76a40a5a8119a846a55350d053495c646103d5 100644 (file)
@@ -107,7 +107,8 @@ intel_buffer_reference(struct pipe_winsys *sws,
  */
 static void intel_buffer_data(struct pipe_winsys *sws, 
                              struct pipe_buffer_handle *buf,
-                             unsigned size, const void *data )
+                             unsigned size, const void *data,
+                             unsigned usage )
 {
    struct intel_context *intel = intel_pipe_winsys(sws)->intel;
 
@@ -229,7 +230,8 @@ intel_i915_region_alloc(struct pipe_winsys *winsys,
    winsys->buffer_data( winsys,
                         region->buffer, 
                         pitch * cpp * height, 
-                        NULL );
+                        NULL,
+                        PIPE_BUFFER_USAGE_PIXEL );
 
    return region;
 }
index 36805437f0156b62e2c5230cec6246e6542046b0..f863cdbc15126ed70c04daaf69d553b78525e9e7 100644 (file)
@@ -140,7 +140,7 @@ xm_buffer_reference(struct pipe_winsys *pws,
 
 static void
 xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
-               unsigned size, const void *data )
+               unsigned size, const void *data, unsigned usage)
 {
    struct xm_buffer *xm_buf = xm_bo(buf);
    assert(!xm_buf->userBuffer);
@@ -265,7 +265,8 @@ xm_region_alloc(struct pipe_winsys *winsys,
    winsys->buffer_data( winsys,
                         region->buffer, 
                         region->pitch * cpp * height, 
-                        NULL );
+                        NULL,
+                        PIPE_BUFFER_USAGE_PIXEL );
    return region;
 }
 
index 3632adce7906b94ca5e70394bb143bbaa06049ee..75ca6d6e5ef51bb7105ed9e7128d348b15bbe033 100644 (file)
@@ -376,7 +376,9 @@ static void vbuf_flush_elements( struct draw_stage *stage )
    /* FIXME: handle failure */
    if(!vbuf->buf)
       vbuf->buf = winsys->buffer_create(winsys, 64);
-   winsys->buffer_data(winsys, vbuf->buf, VBUF_SIZE, NULL);
+   winsys->buffer_data( winsys, vbuf->buf, 
+                        VBUF_SIZE, NULL, 
+                        PIPE_BUFFER_USAGE_VERTEX );
    vbuf->vertex_map = winsys->buffer_map(winsys, 
                                          vbuf->buf, 
                                          PIPE_BUFFER_FLAG_WRITE );
index ef79716ed918a226bc44acf6225729a811dd6445..119ea1bd775a0214686d35c769cf823be05189bb 100644 (file)
 
 
 /**
- * Buffer flags
+ * Buffer access flags
  */
 #define PIPE_BUFFER_FLAG_READ    0x1
 #define PIPE_BUFFER_FLAG_WRITE   0x2
 
-#define PIPE_BUFFER_USE_TEXTURE         0x1
-#define PIPE_BUFFER_USE_VERTEX_BUFFER   0x2
-#define PIPE_BUFFER_USE_INDEX_BUFFER    0x4
-#define PIPE_BUFFER_USE_RENDER_TARGET   0x8
+
+/**
+ * Buffer usage flags
+ */
+#define PIPE_BUFFER_USAGE_PIXEL    0x1
+#define PIPE_BUFFER_USAGE_VERTEX   0x2
+#define PIPE_BUFFER_USAGE_INDEX    0x4
+#define PIPE_BUFFER_USAGE_CONSTANT 0x8
 
 
 /** 
index 2d4432dbca424af79d2e753b5008db10ffb7f8a3..298b55565152d95e1e30c688492055ae4dfe4559 100644 (file)
@@ -116,10 +116,17 @@ struct pipe_winsys
                              struct pipe_buffer_handle **ptr,
                              struct pipe_buffer_handle *buf );
 
-   /** Create the data store of a buffer and optionally initialize it */
+   /** 
+    * Create the data store of a buffer and optionally initialize it.
+    * 
+    * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
+    * usage argument is only an optimization hint, not a guarantee, therefore 
+    * proper behavior must be observed in all circumstances.
+    */
    void (*buffer_data)(struct pipe_winsys *sws, 
                       struct pipe_buffer_handle *buf,
-                      unsigned size, const void *data );
+                      unsigned size, const void *data,
+                      unsigned usage);
 
    /** Modify some or all of the data contained in a buffer's data store */
    void (*buffer_subdata)(struct pipe_winsys *sws, 
index 5de811a66fa886595a19767354fc9e9c0bcec92f..45ece8ef5547089d710cb016d3dd9edeac4f5c29 100644 (file)
@@ -120,7 +120,7 @@ xm_buffer_reference(struct pipe_winsys *pws,
 
 static void
 xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
-               unsigned size, const void *data )
+               unsigned size, const void *data, unsigned usage )
 {
    struct xm_buffer *xm_buf = xm_bo(buf);
    assert(!xm_buf->userBuffer);
@@ -245,7 +245,8 @@ xm_region_alloc(struct pipe_winsys *winsys,
    winsys->buffer_data( winsys,
                         region->buffer, 
                         region->pitch * cpp * height, 
-                        NULL );
+                        NULL,
+                        PIPE_BUFFER_USAGE_PIXEL );
    return region;
 }
 
index 7da71366761533f666827509b7ecc2e8426e21f4..446250c226c237698a7f8135c50b3c8fb1c82fb5 100644 (file)
@@ -80,7 +80,8 @@ void st_upload_constants( struct st_context *st,
       }
 
       /* load Mesa constants into the constant buffer */
-      ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues);
+      ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues,
+                      PIPE_BUFFER_USAGE_CONSTANT);
 
       cbuf->size = paramBytes;
 
index a593bd74d15ab9a44b62d1634f104246b453a62c..99e1eb3c7a64515ed0e810b6e0985d528ea87454 100644 (file)
@@ -104,11 +104,29 @@ st_bufferobj_data(GLcontext *ctx,
 {
    struct pipe_context *pipe = st_context(ctx)->pipe;
    struct st_buffer_object *st_obj = st_buffer_object(obj);
+   unsigned buffer_usage;
 
    st_obj->Base.Size = size;
    st_obj->Base.Usage = usage;
+   
+   switch(target) {
+   case GL_PIXEL_PACK_BUFFER_ARB:
+   case GL_PIXEL_UNPACK_BUFFER_ARB:
+      buffer_usage = PIPE_BUFFER_USAGE_PIXEL;
+      break;
+   case GL_ARRAY_BUFFER_ARB:
+      buffer_usage = PIPE_BUFFER_USAGE_VERTEX;
+      break;
+   case GL_ELEMENT_ARRAY_BUFFER_ARB:
+      buffer_usage = PIPE_BUFFER_USAGE_INDEX;
+      break;
+   default:
+      buffer_usage = 0;
+   }
 
-   pipe->winsys->buffer_data( pipe->winsys, st_obj->buffer, size, data );
+   pipe->winsys->buffer_data( pipe->winsys, st_obj->buffer, 
+                              size, data, 
+                              buffer_usage );
 }
 
 
index 40807fc05a39a68982af63c59a0757ab4d424bb2..5b97c1ee342f5b976fbba656876a3e6530a7756f 100644 (file)
@@ -282,7 +282,9 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
       const unsigned size = sizeof(ctx->Current.Attrib);
       const void *data = ctx->Current.Attrib;
       /* colors, texcoords, etc */
-      pipe->winsys->buffer_data(pipe->winsys, buf, size, data);
+      pipe->winsys->buffer_data(pipe->winsys, buf, 
+                                size, data, 
+                                PIPE_BUFFER_USAGE_VERTEX);
       /* position */
       pipe->winsys->buffer_subdata(pipe->winsys, buf,
                                    0, /* offset */
@@ -301,7 +303,8 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
       fb_buf.start_offset = 0;
       pipe->winsys->buffer_data(pipe->winsys, fb_buf.buffer,
                                 fb_buf.size,
-                                NULL); /* data */
+                                NULL, /* data */
+                                PIPE_BUFFER_USAGE_VERTEX);
       if (pipe->set_feedback_buffer)
          pipe->set_feedback_buffer(pipe, 0, &fb_buf);
    }
index c3f33a447e94b7588742c838022f0b727394726c..3e2ed6cada8a65f538705d217be2a80efc3b875c 100644 (file)
@@ -289,7 +289,9 @@ st_draw_vertices(GLcontext *ctx, unsigned prim,
 
    /* XXX create one-time */
    vbuf = pipe->winsys->buffer_create(pipe->winsys, 32);
-   pipe->winsys->buffer_data(pipe->winsys, vbuf, vertex_bytes, verts);
+   pipe->winsys->buffer_data(pipe->winsys, vbuf, 
+                             vertex_bytes, verts,
+                             PIPE_BUFFER_USAGE_VERTEX);
 
    /* tell pipe about the vertex buffer */
    vbuffer.buffer = vbuf;