summaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe/draw
diff options
context:
space:
mode:
authorBrian <[email protected]>2008-01-23 12:48:41 -0700
committerBrian <[email protected]>2008-01-23 12:48:41 -0700
commitcd3643698eafa0869a8317b002e5b066de0172e7 (patch)
treee7474c2e8079b5069b68adca09bd9882bf65c4c9 /src/mesa/pipe/draw
parentb3f081999f8eb904370df7492e39184268c77c13 (diff)
gallium: overhaul usage of vertex_info in draw module.
Remove all dependencies on vertex_info, except for draw_vbuf. Drawing stages now strictly operate on post-transformed vertices and don't know anything about hw vertices. Use vertex program output info for two-side/flat/etc stages. Temporarily disable vbuf module in softpipe driver.
Diffstat (limited to 'src/mesa/pipe/draw')
-rw-r--r--src/mesa/pipe/draw/draw_clip.c4
-rw-r--r--src/mesa/pipe/draw/draw_context.c6
-rw-r--r--src/mesa/pipe/draw/draw_context.h1
-rw-r--r--src/mesa/pipe/draw/draw_flatshade.c73
-rw-r--r--src/mesa/pipe/draw/draw_private.h14
-rw-r--r--src/mesa/pipe/draw/draw_stipple.c30
-rw-r--r--src/mesa/pipe/draw/draw_twoside.c35
-rw-r--r--src/mesa/pipe/draw/draw_vertex.c70
-rw-r--r--src/mesa/pipe/draw/draw_vertex.h14
-rw-r--r--src/mesa/pipe/draw/draw_vertex_cache.c1
-rw-r--r--src/mesa/pipe/draw/draw_vertex_fetch.c1
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader.c5
-rw-r--r--src/mesa/pipe/draw/draw_vertex_shader_llvm.c5
13 files changed, 97 insertions, 162 deletions
diff --git a/src/mesa/pipe/draw/draw_clip.c b/src/mesa/pipe/draw/draw_clip.c
index c50376f11fe..e0eb656364d 100644
--- a/src/mesa/pipe/draw/draw_clip.c
+++ b/src/mesa/pipe/draw/draw_clip.c
@@ -93,7 +93,7 @@ static void interp( const struct clipper *clip,
const struct vertex_header *out,
const struct vertex_header *in )
{
- const unsigned nr_attrs = clip->stage.draw->vertex_info.num_attribs;
+ const unsigned nr_attrs = clip->stage.draw->num_vs_outputs;
unsigned j;
/* Vertex header.
@@ -349,7 +349,7 @@ do_clip_line( struct draw_stage *stage,
static void clip_begin( struct draw_stage *stage )
{
/* should always have position, at least */
- assert(stage->draw->vertex_info.num_attribs >= 1);
+ assert(stage->draw->num_vs_outputs > 0);
stage->next->begin( stage->next );
}
diff --git a/src/mesa/pipe/draw/draw_context.c b/src/mesa/pipe/draw/draw_context.c
index 5b9ea556300..ff23288fa87 100644
--- a/src/mesa/pipe/draw/draw_context.c
+++ b/src/mesa/pipe/draw/draw_context.c
@@ -77,11 +77,6 @@ struct draw_context *draw_create( void )
draw->vcache.vertex[i] = (struct vertex_header *)(tmp + i * MAX_VERTEX_SIZE);
}
- draw->attrib_front0 = 0;
- draw->attrib_back0 = 0;
- draw->attrib_front1 = 0;
- draw->attrib_back1 = 0;
-
draw->convert_wide_points = TRUE;
draw->convert_wide_lines = TRUE;
@@ -242,7 +237,6 @@ draw_convert_wide_lines(struct draw_context *draw, boolean enable)
}
-
/**
* Allocate space for temporary post-transform vertices, such as for clipping.
*/
diff --git a/src/mesa/pipe/draw/draw_context.h b/src/mesa/pipe/draw/draw_context.h
index cfde26ceb7b..ddeb184497a 100644
--- a/src/mesa/pipe/draw/draw_context.h
+++ b/src/mesa/pipe/draw/draw_context.h
@@ -122,7 +122,6 @@ void draw_set_mapped_constant_buffer(struct draw_context *draw,
const void *buffer);
-
/***********************************************************************
* draw_prim.c
*/
diff --git a/src/mesa/pipe/draw/draw_flatshade.c b/src/mesa/pipe/draw/draw_flatshade.c
index d7551e79481..46b0f7970fd 100644
--- a/src/mesa/pipe/draw/draw_flatshade.c
+++ b/src/mesa/pipe/draw/draw_flatshade.c
@@ -29,42 +29,59 @@
*/
#include "pipe/p_util.h"
+#include "pipe/p_shader_tokens.h"
#include "draw_private.h"
-static void flatshade_begin( struct draw_stage *stage )
+/** subclass of draw_stage */
+struct flat_stage
{
- stage->next->begin( stage->next );
-}
+ struct draw_stage stage;
+
+ uint num_color_attribs;
+ uint color_attribs[4]; /* front/back primary/secondary colors */
+};
+static INLINE struct flat_stage *
+flat_stage(struct draw_stage *stage)
+{
+ return (struct flat_stage *) stage;
+}
+
-static INLINE void copy_attr( unsigned attr,
- struct vertex_header *dst,
- const struct vertex_header *src )
+static void flatshade_begin( struct draw_stage *stage )
{
- if (attr) {
- memcpy( dst->data[attr],
- src->data[attr],
- sizeof(src->data[0]) );
+ struct flat_stage *flat = flat_stage(stage);
+ const struct pipe_shader_state *vs = stage->draw->vertex_shader->state;
+ uint i;
+
+ /* Find which vertex shader outputs are colors, make a list */
+ flat->num_color_attribs = 0;
+ for (i = 0; i < vs->num_outputs; i++) {
+ if (vs->output_semantic_name[i] == TGSI_SEMANTIC_COLOR ||
+ vs->output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) {
+ flat->color_attribs[flat->num_color_attribs++] = i;
+ }
}
+
+ stage->next->begin( stage->next );
}
+/** Copy all the color attributes from 'src' vertex to 'dst' vertex */
static INLINE void copy_colors( struct draw_stage *stage,
struct vertex_header *dst,
const struct vertex_header *src )
{
- const uint num_attribs = stage->draw->vertex_info.num_attribs;
- const enum interp_mode *interp = stage->draw->vertex_info.interp_mode;
+ const struct flat_stage *flat = flat_stage(stage);
uint i;
/* Look for constant/flat attribs and duplicate from src to dst vertex */
/* skip attrib[0] which is vert pos */
- for (i = 1; i < num_attribs; i++) {
- if (interp[i] == INTERP_CONSTANT) {
- copy_attr( i, dst, src );
- }
+ for (i = 0; i < flat->num_color_attribs; i++) {
+ const uint attr = flat->color_attribs[i];
+ memcpy(dst->data[attr], src->data[attr], sizeof(src->data[0]));
}
}
@@ -139,21 +156,21 @@ static void flatshade_destroy( struct draw_stage *stage )
*/
struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
{
- struct draw_stage *flatshade = CALLOC_STRUCT(draw_stage);
+ struct flat_stage *flatshade = CALLOC_STRUCT(flat_stage);
- draw_alloc_tmps( flatshade, 2 );
+ draw_alloc_tmps( &flatshade->stage, 2 );
- flatshade->draw = draw;
- flatshade->next = NULL;
- flatshade->begin = flatshade_begin;
- flatshade->point = flatshade_point;
- flatshade->line = flatshade_line;
- flatshade->tri = flatshade_tri;
- flatshade->end = flatshade_end;
- flatshade->reset_stipple_counter = flatshade_reset_stipple_counter;
- flatshade->destroy = flatshade_destroy;
+ flatshade->stage.draw = draw;
+ flatshade->stage.next = NULL;
+ flatshade->stage.begin = flatshade_begin;
+ flatshade->stage.point = flatshade_point;
+ flatshade->stage.line = flatshade_line;
+ flatshade->stage.tri = flatshade_tri;
+ flatshade->stage.end = flatshade_end;
+ flatshade->stage.reset_stipple_counter = flatshade_reset_stipple_counter;
+ flatshade->stage.destroy = flatshade_destroy;
- return flatshade;
+ return &flatshade->stage;
}
diff --git a/src/mesa/pipe/draw/draw_private.h b/src/mesa/pipe/draw/draw_private.h
index a264fabfb48..685ec4a6443 100644
--- a/src/mesa/pipe/draw/draw_private.h
+++ b/src/mesa/pipe/draw/draw_private.h
@@ -44,8 +44,6 @@
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
-#include "draw_vertex.h"
-
#include "x86/rtasm/x86sse.h"
#include "pipe/tgsi/exec/tgsi_exec.h"
@@ -170,6 +168,8 @@ struct draw_context
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
const struct draw_vertex_shader *vertex_shader;
+ uint num_vs_outputs; /**< convenience, from vertex_shader */
+
/* user-space vertex data, buffers */
struct {
/** vertex element/index buffer (ex: glDrawElements) */
@@ -189,12 +189,6 @@ struct draw_context
float plane[12][4];
unsigned nr_planes;
- /** Describes the layout of post-transformation vertices */
- struct vertex_info vertex_info;
- /** Two-sided attributes: */
- uint attrib_front0, attrib_back0;
- uint attrib_front1, attrib_back1;
-
boolean convert_wide_points; /**< convert wide points to tris? */
boolean convert_wide_lines; /**< convert side lines to tris? */
@@ -309,7 +303,9 @@ dup_vert( struct draw_stage *stage,
unsigned idx )
{
struct vertex_header *tmp = stage->tmp[idx];
- memcpy(tmp, vert, stage->draw->vertex_info.size * sizeof(float) );
+ const uint vsize = sizeof(struct vertex_header)
+ + stage->draw->num_vs_outputs * 4 * sizeof(float);
+ memcpy(tmp, vert, vsize);
tmp->vertex_id = UNDEFINED_VERTEX_ID;
return tmp;
}
diff --git a/src/mesa/pipe/draw/draw_stipple.c b/src/mesa/pipe/draw/draw_stipple.c
index 3e0d5689e18..2a47eb7be23 100644
--- a/src/mesa/pipe/draw/draw_stipple.c
+++ b/src/mesa/pipe/draw/draw_stipple.c
@@ -61,6 +61,7 @@ stipple_stage(struct draw_stage *stage)
/**
* Compute interpolated vertex attributes for 'dst' at position 't'
* between 'v0' and 'v1'.
+ * XXX using linear interpolation for all attribs at this time.
*/
static void
screen_interp( struct draw_context *draw,
@@ -70,28 +71,13 @@ screen_interp( struct draw_context *draw,
const struct vertex_header *v1 )
{
uint attr;
- for (attr = 0; attr < draw->vertex_info.num_attribs; attr++) {
- switch (draw->vertex_info.interp_mode[attr]) {
- case INTERP_NONE:
- case INTERP_CONSTANT:
- COPY_4FV(dst->data[attr], v0->data[attr]);
- break;
- case INTERP_PERSPECTIVE:
- /* Fall-through */
- /* XXX special-case perspective? */
- case INTERP_LINEAR:
- {
- const float *val0 = v0->data[attr];
- const float *val1 = v1->data[attr];
- float *newv = dst->data[attr];
- uint i;
- for (i = 0; i < 4; i++) {
- newv[i] = val0[i] + t * (val1[i] - val0[i]);
- }
- }
- break;
- default:
- abort();
+ for (attr = 0; attr < draw->num_vs_outputs; attr++) {
+ const float *val0 = v0->data[attr];
+ const float *val1 = v1->data[attr];
+ float *newv = dst->data[attr];
+ uint i;
+ for (i = 0; i < 4; i++) {
+ newv[i] = val0[i] + t * (val1[i] - val0[i]);
}
}
}
diff --git a/src/mesa/pipe/draw/draw_twoside.c b/src/mesa/pipe/draw/draw_twoside.c
index c7e268f11ed..da8e7bd90df 100644
--- a/src/mesa/pipe/draw/draw_twoside.c
+++ b/src/mesa/pipe/draw/draw_twoside.c
@@ -30,12 +30,15 @@
#include "pipe/p_util.h"
#include "pipe/p_defines.h"
+#include "pipe/p_shader_tokens.h"
#include "draw_private.h"
struct twoside_stage {
struct draw_stage stage;
float sign; /**< +1 or -1 */
+ uint attrib_front0, attrib_back0;
+ uint attrib_front1, attrib_back1;
};
@@ -48,6 +51,29 @@ static INLINE struct twoside_stage *twoside_stage( struct draw_stage *stage )
static void twoside_begin( struct draw_stage *stage )
{
struct twoside_stage *twoside = twoside_stage(stage);
+ const struct pipe_shader_state *vs = stage->draw->vertex_shader->state;
+ uint i;
+
+ twoside->attrib_front0 = 0;
+ twoside->attrib_front1 = 0;
+ twoside->attrib_back0 = 0;
+ twoside->attrib_back1 = 0;
+
+ /* Find which vertex shader outputs are front/back colors */
+ for (i = 0; i < vs->num_outputs; i++) {
+ if (vs->output_semantic_name[i] == TGSI_SEMANTIC_COLOR) {
+ if (vs->output_semantic_index[i] == 0)
+ twoside->attrib_front0 = i;
+ else
+ twoside->attrib_front1 = i;
+ }
+ if (vs->output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) {
+ if (vs->output_semantic_index[i] == 0)
+ twoside->attrib_back0 = i;
+ else
+ twoside->attrib_back1 = i;
+ }
+ }
/*
* We'll multiply the primitive's determinant by this sign to determine
@@ -76,13 +102,12 @@ static struct vertex_header *copy_bfc( struct twoside_stage *twoside,
unsigned idx )
{
struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx );
- const struct draw_context *draw = twoside->stage.draw;
- if (draw->attrib_front0 && draw->attrib_back0) {
- copy_attrib(draw->attrib_front0, draw->attrib_back0, tmp);
+ if (twoside->attrib_front0 && twoside->attrib_back0) {
+ copy_attrib(twoside->attrib_front0, twoside->attrib_back0, tmp);
}
- if (draw->attrib_front1 && draw->attrib_back1) {
- copy_attrib(draw->attrib_front1, draw->attrib_back1, tmp);
+ if (twoside->attrib_front1 && twoside->attrib_back1) {
+ copy_attrib(twoside->attrib_front1, twoside->attrib_back1, tmp);
}
return tmp;
diff --git a/src/mesa/pipe/draw/draw_vertex.c b/src/mesa/pipe/draw/draw_vertex.c
index 6191fcedbf9..1ab004be101 100644
--- a/src/mesa/pipe/draw/draw_vertex.c
+++ b/src/mesa/pipe/draw/draw_vertex.c
@@ -38,17 +38,6 @@
#include "pipe/draw/draw_vertex.h"
-static INLINE void
-emit_vertex_attr(struct vertex_info *vinfo,
- enum attrib_format format, enum interp_mode interp)
-{
- const uint n = vinfo->num_attribs;
- vinfo->interp_mode[n] = interp;
- vinfo->format[n] = format;
- vinfo->num_attribs++;
-}
-
-
/**
* Compute the size of a vertex, in dwords/floats, to update the
* vinfo->size field.
@@ -86,62 +75,3 @@ draw_compute_vertex_size(struct vertex_info *vinfo)
assert(vinfo->size * 4 <= MAX_VERTEX_SIZE);
}
-
-
-/**
- * Tell the drawing module about the contents of post-transformation vertices.
- * Note that the vertex attribute format info isn't used by 'draw'; all
- * attributes are handled as float[4]. But when the driver emits vertices
- * it'll use that info.
- * We _do_ care about the number of attributes and their interpolation modes.
- */
-void
-draw_set_vertex_info( struct draw_context *draw,
- const struct vertex_info *info)
-{
- assert(info->interp_mode[0] == INTERP_LINEAR); /* should be vert pos */
- assert(info->num_attribs <= PIPE_MAX_SHADER_OUTPUTS);
-
- memcpy(&draw->vertex_info, info, sizeof(*info));
-
- /* Need to know vertex size (in words) for vertex copying elsewhere.
- * Four words per attribute, plus vertex header (uint) and clip
- * position (float[4]).
- */
- draw->vertex_info.size = draw->vertex_info.num_attribs * 4 + 5;
-}
-
-
-/**
- * This function is used to tell the draw module about attributes
- * (like colors) that need to be selected based on front/back face
- * orientation.
- *
- * The logic is:
- * if (polygon is back-facing) {
- * vertex->attrib[front0] = vertex->attrib[back0];
- * vertex->attrib[front1] = vertex->attrib[back1];
- * }
- *
- * \param front0 first attrib to replace if the polygon is back-facing
- * \param back0 first attrib to copy if the polygon is back-facing
- * \param front1 second attrib to replace if the polygon is back-facing
- * \param back1 second attrib to copy if the polygon is back-facing
- *
- * Pass -1 to disable two-sided attributes.
- */
-void
-draw_set_twoside_attributes(struct draw_context *draw,
- uint front0, uint back0,
- uint front1, uint back1)
-{
- /* XXX we could alternately pass an array of front/back attribs if there's
- * ever need for more than two. One could imagine a shader extension
- * that allows arbitrary attributes to be selected based on polygon
- * orientation...
- */
- draw->attrib_front0 = front0;
- draw->attrib_back0 = back0;
- draw->attrib_front1 = front1;
- draw->attrib_back1 = back1;
-}
diff --git a/src/mesa/pipe/draw/draw_vertex.h b/src/mesa/pipe/draw/draw_vertex.h
index e4f85bc49f8..28abd8ab910 100644
--- a/src/mesa/pipe/draw/draw_vertex.h
+++ b/src/mesa/pipe/draw/draw_vertex.h
@@ -34,9 +34,6 @@
#define DRAW_VERTEX_H
-struct draw_context;
-
-
/**
* Vertex attribute format
*/
@@ -63,7 +60,7 @@ enum interp_mode {
/**
- * Information about post-transformed vertex layout.
+ * Information about hardware/rasterization vertex layout.
*/
struct vertex_info
{
@@ -71,7 +68,7 @@ struct vertex_info
uint hwfmt[4]; /**< hardware format info for this format */
enum interp_mode interp_mode[PIPE_MAX_SHADER_OUTPUTS];
enum attrib_format format[PIPE_MAX_SHADER_OUTPUTS]; /**< FORMAT_x */
- uint src_index[PIPE_MAX_SHADER_OUTPUTS];
+ uint src_index[PIPE_MAX_SHADER_OUTPUTS]; /**< map to post-xform attribs */
uint size; /**< total vertex size in dwords */
};
@@ -98,13 +95,6 @@ draw_emit_vertex_attr(struct vertex_info *vinfo,
}
-extern void draw_set_vertex_info( struct draw_context *draw,
- const struct vertex_info *info);
-
-extern void draw_set_twoside_attributes(struct draw_context *draw,
- uint front0, uint back0,
- uint front1, uint back1);
-
extern void draw_compute_vertex_size(struct vertex_info *vinfo);
diff --git a/src/mesa/pipe/draw/draw_vertex_cache.c b/src/mesa/pipe/draw/draw_vertex_cache.c
index 29993f14d2f..97a40b876ea 100644
--- a/src/mesa/pipe/draw/draw_vertex_cache.c
+++ b/src/mesa/pipe/draw/draw_vertex_cache.c
@@ -33,7 +33,6 @@
#include "pipe/p_util.h"
#include "draw_private.h"
#include "draw_context.h"
-#include "draw_vertex.h"
void draw_vertex_cache_invalidate( struct draw_context *draw )
diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c
index 3ca17f8829c..4d64d3d4f28 100644
--- a/src/mesa/pipe/draw/draw_vertex_fetch.c
+++ b/src/mesa/pipe/draw/draw_vertex_fetch.c
@@ -34,7 +34,6 @@
#include "pipe/p_shader_tokens.h"
#include "draw_private.h"
#include "draw_context.h"
-#include "draw_vertex.h"
#define DRAW_DBG 0
diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c
index c2e038453ec..5ca659dbf59 100644
--- a/src/mesa/pipe/draw/draw_vertex_shader.c
+++ b/src/mesa/pipe/draw/draw_vertex_shader.c
@@ -38,7 +38,6 @@
#endif
#include "draw_private.h"
#include "draw_context.h"
-#include "draw_vertex.h"
#include "x86/rtasm/x86sse.h"
#include "pipe/llvm/gallivm.h"
@@ -176,7 +175,7 @@ run_vertex_program(struct draw_context *draw,
/* Remaining attributes are packed into sequential post-transform
* vertex attrib slots.
*/
- for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) {
+ for (slot = 1; slot < draw->num_vs_outputs; slot++) {
vOut[j]->data[slot][0] = machine->Outputs[slot].xyzw[0].f[j];
vOut[j]->data[slot][1] = machine->Outputs[slot].xyzw[1].f[j];
vOut[j]->data[slot][2] = machine->Outputs[slot].xyzw[2].f[j];
@@ -275,6 +274,8 @@ draw_bind_vertex_shader(struct draw_context *draw,
draw_flush(draw);
draw->vertex_shader = dvs;
+ draw->num_vs_outputs = dvs->state->num_outputs;
+
/* specify the fragment program to interpret/execute */
tgsi_exec_machine_init(&draw->machine,
draw->vertex_shader->state->tokens,
diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
index acd61163faa..08be1b83f86 100644
--- a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
+++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c
@@ -33,7 +33,6 @@
#include "pipe/p_util.h"
#include "draw_private.h"
#include "draw_context.h"
-#include "draw_vertex.h"
#ifdef MESA_LLVM
@@ -132,7 +131,7 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
gallivm_prog_exec(prog, inputs, outputs, consts,
draw->vs.queue_nr,
draw->vertex_shader->state->num_inputs,
- draw->vertex_info.num_attribs - 2);
+ draw->vertex_shader->state->num_outputs);
/* store machine results */
@@ -173,7 +172,7 @@ void draw_vertex_shader_queue_flush_llvm(struct draw_context *draw)
/* Remaining attributes are packed into sequential post-transform
* vertex attrib slots.
*/
- for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) {
+ for (slot = 1; slot < draw->vs_num_outputs; slot++) {
vOut->data[slot][0] = dests[slot][0];
vOut->data[slot][1] = dests[slot][1];
vOut->data[slot][2] = dests[slot][2];