summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-08-19 17:31:21 +0100
committerBrian <brian.paul@tungstengraphics.com>2007-08-19 17:31:21 +0100
commit14327705fd53e984b74f8e9adb053df03fba7aff (patch)
tree26ac5c3cce962b9f40bce70de3373bbb68f29d33
parent0453760a0bf139f113792d22e65ce6904f06f28b (diff)
Fix some draw_arrays issues.
We weren't mapping all the needed vertex array buffers. Move array state that was temporarily in draw_context to softpipe_context. Remove a bunch of dead code.
-rw-r--r--src/mesa/pipe/draw/draw_context.c10
-rw-r--r--src/mesa/pipe/draw/draw_context.h4
-rw-r--r--src/mesa/pipe/draw/draw_private.h5
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c4
-rw-r--r--src/mesa/pipe/softpipe/sp_context.h5
-rw-r--r--src/mesa/pipe/softpipe/sp_draw_arrays.c158
6 files changed, 38 insertions, 148 deletions
diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c
index 7e6a95127a..532c9c3682 100644
--- a/src/mesa/pipe/draw/draw_context.c
+++ b/src/mesa/pipe/draw/draw_context.c
@@ -201,13 +201,3 @@ void draw_set_viewport_state( struct draw_context *draw,
* Full pipe will have vertex shader, vertex fetch of its own.
*/
}
-
-
-void draw_set_vertex_array_info(struct draw_context *draw,
- const struct pipe_vertex_buffer *buffers,
- const struct pipe_vertex_element *elements)
-{
- draw->vertex_buffer = buffers;
- draw->vertex_element = elements;
-}
-
diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h
index afa3a04165..e1b4848ab3 100644
--- a/src/mesa/pipe/draw/draw_context.h
+++ b/src/mesa/pipe/draw/draw_context.h
@@ -82,10 +82,6 @@ void draw_set_vertex_attributes2( struct draw_context *draw,
const unsigned *attrs,
unsigned nr_attrs );
-void draw_set_vertex_array_info(struct draw_context *draw,
- const struct pipe_vertex_buffer *buffers,
- const struct pipe_vertex_element *elements);
-
/* XXX temporary */
void draw_vb(struct draw_context *draw,
struct vertex_buffer *VB );
diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h
index 278950ec48..798fa5c3a6 100644
--- a/src/mesa/pipe/draw/draw_private.h
+++ b/src/mesa/pipe/draw/draw_private.h
@@ -158,8 +158,6 @@ struct draw_context
/* pipe state that we need: */
struct pipe_setup_state setup;
struct pipe_viewport_state viewport;
- const struct pipe_vertex_buffer *vertex_buffer; /**< note: pointer */
- const struct pipe_vertex_element *vertex_element; /**< note: pointer */
/** need to know the pipe for vertex flushing/transformation: */
struct pipe_context *pipe;
@@ -230,9 +228,6 @@ struct draw_context
ubyte *verts;
boolean in_vb;
struct vertex_fetch *vf;
-
- /* Misc for sp_draw_arrays.c (temporary?) */
- void *mapped_vbuffer;
};
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index e63ce208d4..ea2f0ec04f 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -322,10 +322,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
assert(softpipe->draw);
draw_set_setup_stage(softpipe->draw, sp_draw_render_stage(softpipe));
- draw_set_vertex_array_info(softpipe->draw,
- softpipe->vertex_buffer,
- softpipe->vertex_element);
-
sp_init_region_functions(softpipe);
sp_init_surface_functions(softpipe);
diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h
index 8f184c644a..14ae9f2105 100644
--- a/src/mesa/pipe/softpipe/sp_context.h
+++ b/src/mesa/pipe/softpipe/sp_context.h
@@ -101,6 +101,11 @@ struct softpipe_context {
*/
enum interp_mode interp[PIPE_ATTRIB_MAX];
+ /*
+ * Mapped vertex buffers
+ */
+ ubyte *mapped_vbuffer[PIPE_ATTRIB_MAX];
+
/* FS + setup derived state:
*/
diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c
index e7dec31921..a7fb39ca09 100644
--- a/src/mesa/pipe/softpipe/sp_draw_arrays.c
+++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c
@@ -127,18 +127,17 @@ fetch_attrib4(const void *ptr, unsigned format, float attrib[4])
* \param vOut array of pointers to four output vertices
*/
static void
-run_vertex_program(struct draw_context *draw,
- const void *vbuffer, unsigned elts[4], unsigned count,
+run_vertex_program(struct softpipe_context *sp,
+ unsigned elts[4], unsigned count,
struct vertex_header *vOut[])
{
- struct softpipe_context *sp = softpipe_context(draw->pipe);
struct tgsi_exec_machine machine;
unsigned int j;
ALIGN16_DECL(struct tgsi_exec_vector, inputs, PIPE_ATTRIB_MAX);
ALIGN16_DECL(struct tgsi_exec_vector, outputs, PIPE_ATTRIB_MAX);
- const float *scale = draw->viewport.scale;
- const float *trans = draw->viewport.translate;
+ const float *scale = sp->viewport.scale;
+ const float *trans = sp->viewport.translate;
assert(count <= 4);
@@ -167,9 +166,9 @@ run_vertex_program(struct draw_context *draw,
if (sp->vs.inputs_read & (1 << attr)) {
printf("attr %d: buf_off %d src_off %d pitch %d\n",
attr,
- draw->vertex_buffer[attr].buffer_offset,
- draw->vertex_element[attr].src_offset,
- draw->vertex_buffer[attr].pitch);
+ sp->vertex_buffer[attr].buffer_offset,
+ sp->vertex_element[attr].src_offset,
+ sp->vertex_buffer[attr].pitch);
}
}
}
@@ -180,13 +179,13 @@ run_vertex_program(struct draw_context *draw,
for (attr = 0; attr < 16; attr++) {
if (sp->vs.inputs_read & (1 << attr)) {
const void *src
- = (const void *) ((const ubyte *) vbuffer
- + draw->vertex_buffer[attr].buffer_offset
- + draw->vertex_element[attr].src_offset
- + elts[j] * draw->vertex_buffer[attr].pitch);
+ = (const void *) ((const ubyte *) sp->mapped_vbuffer[attr]
+ + sp->vertex_buffer[attr].buffer_offset
+ + sp->vertex_element[attr].src_offset
+ + elts[j] * sp->vertex_buffer[attr].pitch);
float p[4];
- fetch_attrib4(src, draw->vertex_element[attr].src_format, p);
+ fetch_attrib4(src, sp->vertex_element[attr].src_format, p);
machine.Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/
machine.Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/
@@ -262,7 +261,7 @@ run_vertex_program(struct draw_context *draw,
slot = 1;
for (attr = 1; attr < VERT_RESULT_MAX; attr++) {
if (sp->vs.outputs_written & (1 << attr)) {
- assert(slot < draw->nr_attrs - 2);
+ assert(slot < sp->nr_attrs);
vOut[j]->data[slot][0] = outputs[attr].xyzw[0].f[j];
vOut[j]->data[slot][1] = outputs[attr].xyzw[1].f[j];
vOut[j]->data[slot][2] = outputs[attr].xyzw[2].f[j];
@@ -282,114 +281,16 @@ run_vertex_program(struct draw_context *draw,
/**
- * Stand-in for actual vertex program execution
- * XXX this will probably live in a new file, like "sp_vs.c"
- * \param draw the drawing context
- * \param vbuffer the mapped vertex buffer pointer
- * \param elem which element of the vertex buffer to use as input
- * \param vOut the output vertex
- */
-#if 0
-static void
-run_vertex_program(struct draw_context *draw,
- const void *vbuffer, unsigned elem,
- struct vertex_header *vOut)
-{
- const float *vIn, *cIn;
- const float *scale = draw->viewport.scale;
- const float *trans = draw->viewport.translate;
- const void *mapped = vbuffer;
-
- /* XXX temporary hack: */
- GET_CURRENT_CONTEXT(ctx);
- const float *m = ctx->_ModelProjectMatrix.m;
-
- vIn = (const float *) ((const ubyte *) mapped
- + draw->vertex_buffer[0].buffer_offset
- + draw->vertex_element[0].src_offset
- + elem * draw->vertex_buffer[0].pitch);
-
- cIn = (const float *) ((const ubyte *) mapped
- + draw->vertex_buffer[3].buffer_offset
- + draw->vertex_element[3].src_offset
- + elem * draw->vertex_buffer[3].pitch);
-
- {
- float x = vIn[0];
- float y = vIn[1];
- float z = vIn[2];
- float w = 1.0;
-
- vOut->clipmask = 0x0;
- vOut->edgeflag = 0;
- /* MVP */
- vOut->clip[0] = m[0] * x + m[4] * y + m[ 8] * z + m[12] * w;
- vOut->clip[1] = m[1] * x + m[5] * y + m[ 9] * z + m[13] * w;
- vOut->clip[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
- vOut->clip[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
-
- /* divide by w */
- x = vOut->clip[0] / vOut->clip[3];
- y = vOut->clip[1] / vOut->clip[3];
- z = vOut->clip[2] / vOut->clip[3];
- w = 1.0 / vOut->clip[3];
-
- /* Viewport */
- vOut->data[0][0] = scale[0] * x + trans[0];
- vOut->data[0][1] = scale[1] * y + trans[1];
- vOut->data[0][2] = scale[2] * z + trans[2];
- vOut->data[0][3] = w;
-
- /* color */
- vOut->data[1][0] = cIn[0];
- vOut->data[1][1] = cIn[1];
- vOut->data[1][2] = cIn[2];
- vOut->data[1][3] = 1.0;
- }
-}
-#endif
-
-
-/**
* Called by the draw module when the vertx cache needs to be flushed.
* This involves running the vertex shader.
*/
static void vs_flush( struct draw_context *draw )
{
+ struct softpipe_context *sp = (struct softpipe_context *) draw->pipe;
unsigned i, j;
- /* We're not really running a vertex shader yet, so flushing the vs
- * queue is just a matter of building the vertices and returning.
- */
- /* Actually, I'm cheating even more and pre-building them still
- * with the mesa/vf module. So it's very easy...
- */
-#if 0
- for (i = 0; i < draw->vs.queue_nr; i++) {
-#else
- for (i = 0; i < draw->vs.queue_nr; i+=4) {
-#endif
- /* Would do the following steps here:
- *
- * 1) Loop over vertex element descriptors, fetch data from each
- * to build the pre-tnl vertex. This might require a new struct
- * to represent the pre-tnl vertex.
- *
- * 2) Bundle groups of upto 4 pre-tnl vertices together and pass
- * to vertex shader.
- *
- * 3) Do any necessary unswizzling, make sure vertex headers are
- * correctly populated, store resulting post-transformed
- * vertices in vcache.
- *
- * In this version, just do the last step:
- */
-#if 0
- const unsigned elt = draw->vs.queue[i].elt;
- struct vertex_header *dest = draw->vs.queue[i].dest;
-
- run_vertex_program(draw, draw->mapped_vbuffer, elt, dest);
-#else
+ /* run vertex shader on vertex cache entries, four per invokation */
+ for (i = 0; i < draw->vs.queue_nr; i += 4) {
struct vertex_header *dests[4];
unsigned elts[4];
int n;
@@ -403,9 +304,9 @@ static void vs_flush( struct draw_context *draw )
assert(n > 0);
assert(n <= 4);
- run_vertex_program(draw, draw->mapped_vbuffer, elts, n, dests);
-#endif
+ run_vertex_program(sp, elts, n, dests);
}
+
draw->vs.queue_nr = 0;
}
@@ -417,7 +318,7 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
{
struct softpipe_context *sp = softpipe_context(pipe);
struct draw_context *draw = sp->draw;
- struct pipe_buffer_handle *buf;
+ unsigned int i;
if (sp->dirty)
softpipe_update_derived( sp );
@@ -427,11 +328,14 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
/*
* Map vertex buffers
*/
- buf = sp->vertex_buffer[0].buffer;
- assert(buf);
- draw->mapped_vbuffer
- = pipe->winsys->buffer_map(pipe->winsys, buf, PIPE_BUFFER_FLAG_READ);
-
+ for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+ if (sp->vertex_buffer[i].buffer) {
+ sp->mapped_vbuffer[i]
+ = pipe->winsys->buffer_map(pipe->winsys,
+ sp->vertex_buffer[i].buffer,
+ PIPE_BUFFER_FLAG_READ);
+ }
+ }
/* tell drawing pipeline we're beginning drawing */
draw->pipeline.first->begin( draw->pipeline.first );
@@ -454,9 +358,13 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
draw->pipeline.first->end( draw->pipeline.first );
/*
- * unmap vertex buffer
+ * unmap vertex buffers
*/
- pipe->winsys->buffer_unmap(pipe->winsys, buf);
+ for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
+ if (sp->vertex_buffer[i].buffer) {
+ pipe->winsys->buffer_unmap(pipe->winsys, sp->vertex_buffer[i].buffer);
+ }
+ }
softpipe_unmap_surfaces(sp);
}