summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorMichel Dänzer <[email protected]>2008-01-25 17:01:01 +0100
committerMichel Dänzer <[email protected]>2008-01-25 17:01:01 +0100
commit756d52ec12c41ee90ee9598dc9028cc134806bd2 (patch)
treea112f0b2a933faccb8e759c3b039f8b492daa8ed /src/mesa/state_tracker
parent7a207682aafc05c62cbc5851cc6c98c43aa3d9bd (diff)
gallium: Simplify winsys buffer interface.
The properties of a buffer represented by struct pipe_buffer_handle are now basically constant over its lifetime. The state tracker gets to deal with any more complex buffer semantics it may need to provide.
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom_constbuf.c16
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.c106
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.h1
-rw-r--r--src/mesa/state_tracker/st_context.h7
-rw-r--r--src/mesa/state_tracker/st_draw.c45
5 files changed, 86 insertions, 89 deletions
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
index 57f5ec68d20..c9d63136b5f 100644
--- a/src/mesa/state_tracker/st_atom_constbuf.c
+++ b/src/mesa/state_tracker/st_atom_constbuf.c
@@ -69,8 +69,13 @@ void st_upload_constants( struct st_context *st,
_mesa_load_state_parameters(st->ctx, params);
- if (!cbuf->buffer)
- cbuf->buffer = ws->buffer_create(ws, 1, 0, 0);
+ if (cbuf->buffer && cbuf->size != paramBytes)
+ ws->buffer_reference( ws, &cbuf->buffer, NULL );
+
+ if (!cbuf->buffer) {
+ cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT,
+ paramBytes);
+ }
if (0)
{
@@ -80,8 +85,11 @@ void st_upload_constants( struct st_context *st,
}
/* load Mesa constants into the constant buffer */
- ws->buffer_data(ws, cbuf->buffer, paramBytes, params->ParameterValues,
- PIPE_BUFFER_USAGE_CONSTANT);
+ if (cbuf->buffer) {
+ memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
+ params->ParameterValues, paramBytes);
+ ws->buffer_unmap(ws, cbuf->buffer);
+ }
cbuf->size = paramBytes;
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 872248cdb5b..60bd1d5f0d2 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -55,7 +55,6 @@
static struct gl_buffer_object *
st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target)
{
- struct st_context *st = st_context(ctx);
struct st_buffer_object *st_obj = CALLOC_STRUCT(st_buffer_object);
if (!st_obj)
@@ -63,8 +62,6 @@ st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target)
_mesa_initialize_buffer_object(&st_obj->Base, name, target);
- st_obj->buffer = st->pipe->winsys->buffer_create( st->pipe->winsys, 32, 0, 0 );
-
return &st_obj->Base;
}
@@ -89,6 +86,57 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj)
/**
+ * Replace data in a subrange of buffer object. If the data range
+ * specified by size + offset extends beyond the end of the buffer or
+ * if data is NULL, no copy is performed.
+ * Called via glBufferSubDataARB().
+ */
+static void
+st_bufferobj_subdata(GLcontext *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ const GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ char *map;
+
+ if (offset >= st_obj->size || size > (st_obj->size - offset))
+ return;
+
+ map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer,
+ PIPE_BUFFER_USAGE_CPU_WRITE);
+ memcpy(map + offset, data, size);
+ pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer);
+}
+
+
+/**
+ * Called via glGetBufferSubDataARB().
+ */
+static void
+st_bufferobj_get_subdata(GLcontext *ctx,
+ GLenum target,
+ GLintptrARB offset,
+ GLsizeiptrARB size,
+ GLvoid * data, struct gl_buffer_object *obj)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_buffer_object *st_obj = st_buffer_object(obj);
+ char *map;
+
+ if (offset >= st_obj->size || size > (st_obj->size - offset))
+ return;
+
+ map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer,
+ PIPE_BUFFER_USAGE_CPU_READ);
+ memcpy(data, map + offset, size);
+ pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer);
+}
+
+
+/**
* Allocate space for and store data in a buffer object. Any data that was
* previously stored in the buffer object is lost. If data is NULL,
* memory will be allocated, but no copy will occur.
@@ -102,7 +150,8 @@ st_bufferobj_data(GLcontext *ctx,
GLenum usage,
struct gl_buffer_object *obj)
{
- struct pipe_context *pipe = st_context(ctx)->pipe;
+ 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;
@@ -124,46 +173,15 @@ st_bufferobj_data(GLcontext *ctx,
buffer_usage = 0;
}
- pipe->winsys->buffer_data( pipe->winsys, st_obj->buffer,
- size, data,
- buffer_usage );
-}
+ pipe->winsys->buffer_reference( pipe->winsys, &st_obj->buffer, NULL );
+ st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage,
+ size );
-/**
- * Replace data in a subrange of buffer object. If the data range
- * specified by size + offset extends beyond the end of the buffer or
- * if data is NULL, no copy is performed.
- * Called via glBufferSubDataARB().
- */
-static void
-st_bufferobj_subdata(GLcontext *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- const GLvoid * data, struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
-
- pipe->winsys->buffer_subdata(pipe->winsys, st_obj->buffer, offset, size, data);
-}
-
-
-/**
- * Called via glGetBufferSubDataARB().
- */
-static void
-st_bufferobj_get_subdata(GLcontext *ctx,
- GLenum target,
- GLintptrARB offset,
- GLsizeiptrARB size,
- GLvoid * data, struct gl_buffer_object *obj)
-{
- struct pipe_context *pipe = st_context(ctx)->pipe;
- struct st_buffer_object *st_obj = st_buffer_object(obj);
+ st_obj->size = size;
- pipe->winsys->buffer_get_subdata(pipe->winsys, st_obj->buffer, offset, size, data);
+ if (data)
+ st_bufferobj_subdata(ctx, target, 0, size, data, obj);
}
@@ -180,15 +198,15 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access,
switch (access) {
case GL_WRITE_ONLY:
- flags = PIPE_BUFFER_FLAG_WRITE;
+ flags = PIPE_BUFFER_USAGE_CPU_WRITE;
break;
case GL_READ_ONLY:
- flags = PIPE_BUFFER_FLAG_READ;
+ flags = PIPE_BUFFER_USAGE_CPU_READ;
break;
case GL_READ_WRITE:
/* fall-through */
default:
- flags = PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE;
+ flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
break;
}
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h
index 2090a743e0a..15003ae15d6 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.h
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.h
@@ -40,6 +40,7 @@ struct st_buffer_object
{
struct gl_buffer_object Base;
struct pipe_buffer_handle *buffer;
+ GLsizeiptrARB size;
};
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 5ae21c93f93..2b6f8743f38 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -164,13 +164,6 @@ struct st_context
struct st_fragment_program *combined_prog;
} bitmap;
- /**
- * Buffer object which stores the ctx->Current.Attrib[] values.
- * Used for vertex array drawing when we we need an attribute for
- * which there's no enabled array.
- */
- struct pipe_buffer_handle *default_attrib_buffer;
-
struct cso_cache *cache;
};
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 71acf6e862f..371d4e7966b 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -191,29 +191,6 @@ pipe_vertex_format(GLenum type, GLuint size, GLboolean normalized)
/**
- * The default attribute buffer is basically a copy of the
- * ctx->Current.Attrib[] array. It's used when the vertex program
- * references an attribute for which we don't have a VBO/array.
- */
-static void
-create_default_attribs_buffer(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- /* XXX don't hardcode magic 32 here */
- st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32, 0, 0 );
-}
-
-
-static void
-destroy_default_attribs_buffer(struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- pipe->winsys->buffer_reference(pipe->winsys,
- &st->default_attrib_buffer, NULL);
-}
-
-
-/**
* This function gets plugged into the VBO module and is called when
* we have something to render.
* Basically, translate the information into the format expected by pipe.
@@ -399,10 +376,14 @@ st_draw_vertices(GLcontext *ctx, unsigned prim,
}
/* XXX create one-time */
- vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0);
- pipe->winsys->buffer_data(pipe->winsys, vbuf,
- vertex_bytes, verts,
- PIPE_BUFFER_USAGE_VERTEX);
+ vbuf = pipe->winsys->buffer_create(pipe->winsys, 32,
+ PIPE_BUFFER_USAGE_VERTEX, vertex_bytes);
+ assert(vbuf);
+
+ memcpy(pipe->winsys->buffer_map(pipe->winsys, vbuf,
+ PIPE_BUFFER_USAGE_CPU_WRITE),
+ verts, vertex_bytes);
+ pipe->winsys->buffer_unmap(pipe->winsys, vbuf);
/* tell pipe about the vertex buffer */
vbuffer.buffer = vbuf;
@@ -568,7 +549,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
/* map the attrib buffer */
map = pipe->winsys->buffer_map(pipe->winsys,
vbuffer[attr].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_vertex_buffer(draw, attr, map);
}
@@ -592,7 +573,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
map = pipe->winsys->buffer_map(pipe->winsys,
index_buffer_handle,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_element_buffer(draw, indexSize, map);
}
else {
@@ -604,7 +585,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
/* map constant buffers */
mapped_constants = winsys->buffer_map(winsys,
st->state.constants[PIPE_SHADER_VERTEX].buffer,
- PIPE_BUFFER_FLAG_READ);
+ PIPE_BUFFER_USAGE_CPU_READ);
draw_set_mapped_constant_buffer(st->draw, mapped_constants);
@@ -640,16 +621,12 @@ void st_init_draw( struct st_context *st )
{
GLcontext *ctx = st->ctx;
- /* actually, not used here, but elsewhere */
- create_default_attribs_buffer(st);
-
vbo_set_draw_func(ctx, st_draw_vbo);
}
void st_destroy_draw( struct st_context *st )
{
- destroy_default_attribs_buffer(st);
}