From fa1a66d7fc4fd7854de7958a48e4992edd154489 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 5 Nov 2007 18:04:35 +0000 Subject: [PATCH] Supply buffer usage hints to winsys. Winsys driver needs some hints in order to allocate the appropriate kind of memory for the buffer. --- .../dri/intel_winsys/intel_winsys_pipe.c | 6 ++++-- src/mesa/drivers/x11/xm_winsys.c | 5 +++-- src/mesa/pipe/i915simple/i915_prim_vbuf.c | 4 +++- src/mesa/pipe/p_defines.h | 14 ++++++++----- src/mesa/pipe/p_winsys.h | 11 ++++++++-- src/mesa/pipe/xlib/xm_winsys.c | 5 +++-- src/mesa/state_tracker/st_atom_constbuf.c | 3 ++- src/mesa/state_tracker/st_cb_bufferobjects.c | 20 ++++++++++++++++++- src/mesa/state_tracker/st_cb_rasterpos.c | 7 +++++-- src/mesa/state_tracker/st_draw.c | 4 +++- 10 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index af05a3398c8..cc76a40a5a8 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -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; } diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c index 36805437f01..f863cdbc151 100644 --- a/src/mesa/drivers/x11/xm_winsys.c +++ b/src/mesa/drivers/x11/xm_winsys.c @@ -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; } diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index 3632adce790..75ca6d6e5ef 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -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 ); diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index ef79716ed91..119ea1bd775 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -168,15 +168,19 @@ /** - * 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 /** diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 2d4432dbca4..298b5556515 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -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, diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 5de811a66fa..45ece8ef554 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -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; } diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 7da71366761..446250c226c 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -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; diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a593bd74d15..99e1eb3c7a6 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -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 ); } diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 40807fc05a3..5b97c1ee342 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -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); } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index c3f33a447e9..3e2ed6cada8 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -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; -- 2.30.2