diff options
-rw-r--r-- | src/mesa/pipe/softpipe/sp_context.c | 1 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_context.h | 3 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad.c | 10 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad.h | 1 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad_blend.c | 536 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad_bufloop.c | 59 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad_colormask.c | 6 | ||||
-rw-r--r-- | src/mesa/pipe/softpipe/sp_quad_output.c | 28 | ||||
-rw-r--r-- | src/mesa/sources | 1 |
9 files changed, 351 insertions, 294 deletions
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 9511254a96c..cc4b8d59141 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -88,6 +88,7 @@ struct pipe_context *softpipe_create( void ) softpipe->quad.alpha_test = sp_quad_alpha_test_stage(softpipe); softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe); softpipe->quad.stencil_test = sp_quad_stencil_test_stage(softpipe); + softpipe->quad.bufloop = sp_quad_bufloop_stage(softpipe); softpipe->quad.blend = sp_quad_blend_stage(softpipe); softpipe->quad.colormask = sp_quad_colormask_stage(softpipe); softpipe->quad.output = sp_quad_output_stage(softpipe); diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 3ae1de71cf7..81d2b58cf93 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -122,6 +122,7 @@ struct softpipe_context { struct quad_stage *alpha_test; struct quad_stage *stencil_test; struct quad_stage *depth_test; + struct quad_stage *bufloop; struct quad_stage *blend; struct quad_stage *colormask; struct quad_stage *output; @@ -131,6 +132,8 @@ struct softpipe_context { /** The primitive drawing context */ struct draw_context *draw; + + struct pipe_surface *cbuf; /**< current color buffer (one of cbufs) */ }; diff --git a/src/mesa/pipe/softpipe/sp_quad.c b/src/mesa/pipe/softpipe/sp_quad.c index 419a720de9a..5f34f5f1b34 100644 --- a/src/mesa/pipe/softpipe/sp_quad.c +++ b/src/mesa/pipe/softpipe/sp_quad.c @@ -21,6 +21,16 @@ sp_build_quad_pipeline(struct softpipe_context *sp) sp->quad.first = sp->quad.blend; } + if (sp->framebuffer.num_cbufs == 1) { + /* the usual case: write to exactly one colorbuf */ + sp->cbuf = sp->framebuffer.cbufs[0]; + } + else { + /* insert bufloop stage */ + sp->quad.bufloop->next = sp->quad.first; + sp->quad.first = sp->quad.bufloop; + } + if ( sp->stencil.front_enabled || sp->stencil.front_enabled) { sp->quad.stencil_test->next = sp->quad.first; diff --git a/src/mesa/pipe/softpipe/sp_quad.h b/src/mesa/pipe/softpipe/sp_quad.h index 966f72d3b5b..719d4774cca 100644 --- a/src/mesa/pipe/softpipe/sp_quad.h +++ b/src/mesa/pipe/softpipe/sp_quad.h @@ -51,6 +51,7 @@ struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_alpha_test_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_stencil_test_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_colormask_stage( struct softpipe_context *softpipe ); struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe ); diff --git a/src/mesa/pipe/softpipe/sp_quad_blend.c b/src/mesa/pipe/softpipe/sp_quad_blend.c index 2599e7a2f98..3d097aea65e 100644 --- a/src/mesa/pipe/softpipe/sp_quad_blend.c +++ b/src/mesa/pipe/softpipe/sp_quad_blend.c @@ -104,287 +104,281 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad) static const GLfloat zero[4] = { 0, 0, 0, 0 }; static const GLfloat one[4] = { 1, 1, 1, 1 }; struct softpipe_context *softpipe = qs->softpipe; + struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf); GLfloat source[4][QUAD_SIZE], dest[4][QUAD_SIZE]; - GLuint i; - - /* XXX we're also looping in output_quad() !?! */ - - for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { - struct softpipe_surface *sps - = softpipe_surface(softpipe->framebuffer.cbufs[i]); - sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest); + /* get colors from framebuffer */ + sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest); - /* - * Compute src/first term RGB - */ - switch (softpipe->blend.rgb_src_factor) { - case PIPE_BLENDFACTOR_ONE: - VEC4_COPY(source[0], quad->outputs.color[0]); /* R */ - VEC4_COPY(source[1], quad->outputs.color[1]); /* G */ - VEC4_COPY(source[2], quad->outputs.color[2]); /* B */ - break; - case PIPE_BLENDFACTOR_SRC_COLOR: - VEC4_MUL(source[0], quad->outputs.color[0], quad->outputs.color[0]); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], quad->outputs.color[1]); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], quad->outputs.color[2]); /* B */ - break; - case PIPE_BLENDFACTOR_SRC_ALPHA: - { - const GLfloat *alpha = quad->outputs.color[3]; - VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_DST_COLOR: - VEC4_MUL(source[0], quad->outputs.color[0], dest[0]); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], dest[1]); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], dest[2]); /* B */ - break; - case PIPE_BLENDFACTOR_DST_ALPHA: - { - const GLfloat *alpha = dest[3]; - VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: - assert(0); /* to do */ - break; - case PIPE_BLENDFACTOR_CONST_COLOR: - { - GLfloat comp[4]; - VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */ - VEC4_MUL(source[0], quad->outputs.color[0], comp); /* R */ - VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */ - VEC4_MUL(source[1], quad->outputs.color[1], comp); /* G */ - VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */ - VEC4_MUL(source[2], quad->outputs.color[2], comp); /* B */ - } - break; - case PIPE_BLENDFACTOR_CONST_ALPHA: - { - GLfloat alpha[4]; - VEC4_SCALAR(alpha, softpipe->blend_color.color[3]); - VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_SRC1_COLOR: - assert(0); /* to do */ - break; - case PIPE_BLENDFACTOR_SRC1_ALPHA: - assert(0); /* to do */ - break; - case PIPE_BLENDFACTOR_ZERO: - VEC4_COPY(source[0], zero); /* R */ - VEC4_COPY(source[1], zero); /* G */ - VEC4_COPY(source[2], zero); /* B */ - break; - case PIPE_BLENDFACTOR_INV_SRC_COLOR: - { - GLfloat inv_comp[4]; - VEC4_SUB(inv_comp, one, quad->outputs.color[0]); /* R */ - VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */ - VEC4_SUB(inv_comp, one, quad->outputs.color[1]); /* G */ - VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */ - VEC4_SUB(inv_comp, one, quad->outputs.color[2]); /* B */ - VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */ - } - break; - case PIPE_BLENDFACTOR_INV_SRC_ALPHA: - { - GLfloat inv_alpha[4]; - VEC4_SUB(inv_alpha, one, quad->outputs.color[3]); - VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_INV_DST_ALPHA: - { - GLfloat inv_alpha[4]; - VEC4_SUB(inv_alpha, one, dest[3]); - VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_INV_DST_COLOR: - { - GLfloat inv_comp[4]; - VEC4_SUB(inv_comp, one, dest[0]); /* R */ - VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */ - VEC4_SUB(inv_comp, one, dest[1]); /* G */ - VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */ - VEC4_SUB(inv_comp, one, dest[2]); /* B */ - VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */ - } - break; - case PIPE_BLENDFACTOR_INV_CONST_COLOR: - { - GLfloat inv_comp[4]; - /* R */ - VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[0]); - VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); - /* G */ - VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[1]); - VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); - /* B */ - VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[2]); - VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); - } - break; - case PIPE_BLENDFACTOR_INV_CONST_ALPHA: - { - GLfloat alpha[4], inv_alpha[4]; - VEC4_SCALAR(alpha, 1.0 - softpipe->blend_color.color[3]); - VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ - VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ - VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_INV_SRC1_COLOR: - assert(0); /* to do */ - break; - case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: - assert(0); /* to do */ - break; - default: - abort(); + /* + * Compute src/first term RGB + */ + switch (softpipe->blend.rgb_src_factor) { + case PIPE_BLENDFACTOR_ONE: + VEC4_COPY(source[0], quad->outputs.color[0]); /* R */ + VEC4_COPY(source[1], quad->outputs.color[1]); /* G */ + VEC4_COPY(source[2], quad->outputs.color[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_COLOR: + VEC4_MUL(source[0], quad->outputs.color[0], quad->outputs.color[0]); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], quad->outputs.color[1]); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], quad->outputs.color[2]); /* B */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + { + const GLfloat *alpha = quad->outputs.color[3]; + VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ } - - /* - * Compute src/first term A - */ - switch (softpipe->blend.alpha_src_factor) { - case PIPE_BLENDFACTOR_ONE: - VEC4_COPY(source[3], quad->outputs.color[3]); /* A */ - break; - case PIPE_BLENDFACTOR_SRC_ALPHA: - { - const GLfloat *alpha = quad->outputs.color[3]; - VEC4_MUL(source[3], quad->outputs.color[3], alpha); /* A */ - } - break; - case PIPE_BLENDFACTOR_ZERO: - VEC4_COPY(source[3], zero); /* A */ - break; - /* XXX fill in remaining terms */ - default: - abort(); + break; + case PIPE_BLENDFACTOR_DST_COLOR: + VEC4_MUL(source[0], quad->outputs.color[0], dest[0]); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], dest[1]); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], dest[2]); /* B */ + break; + case PIPE_BLENDFACTOR_DST_ALPHA: + { + const GLfloat *alpha = dest[3]; + VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ } - - - /* - * Compute dest/second term RGB - */ - switch (softpipe->blend.rgb_dst_factor) { - case PIPE_BLENDFACTOR_ONE: - /* dest = dest * 1 NO-OP, leave dest as-is */ - break; - case PIPE_BLENDFACTOR_INV_SRC_ALPHA: - { - GLfloat one_minus_alpha[QUAD_SIZE]; - VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]); - VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */ - VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */ - VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */ - } - break; - case PIPE_BLENDFACTOR_ZERO: - VEC4_COPY(dest[0], zero); /* R */ - VEC4_COPY(dest[1], zero); /* G */ - VEC4_COPY(dest[2], zero); /* B */ - break; - /* XXX fill in remaining terms */ - default: - abort(); + break; + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_CONST_COLOR: + { + GLfloat comp[4]; + VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */ + VEC4_MUL(source[0], quad->outputs.color[0], comp); /* R */ + VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */ + VEC4_MUL(source[1], quad->outputs.color[1], comp); /* G */ + VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */ + VEC4_MUL(source[2], quad->outputs.color[2], comp); /* B */ } - - /* - * Compute dest/second term A - */ - switch (softpipe->blend.alpha_dst_factor) { - case PIPE_BLENDFACTOR_ONE: - /* dest = dest * 1 NO-OP, leave dest as-is */ - break; - case PIPE_BLENDFACTOR_INV_SRC_ALPHA: - { - GLfloat one_minus_alpha[QUAD_SIZE]; - VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]); - VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */ - } - break; - case PIPE_BLENDFACTOR_ZERO: - VEC4_COPY(dest[3], zero); /* A */ - break; - /* XXX fill in remaining terms */ - default: - abort(); + break; + case PIPE_BLENDFACTOR_CONST_ALPHA: + { + GLfloat alpha[4]; + VEC4_SCALAR(alpha, softpipe->blend_color.color[3]); + VEC4_MUL(source[0], quad->outputs.color[0], alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], alpha); /* B */ } - - /* - * Combine RGB terms - */ - switch (softpipe->blend.rgb_func) { - case PIPE_BLEND_ADD: - VEC4_ADD(quad->outputs.color[0], source[0], dest[0]); /* R */ - VEC4_ADD(quad->outputs.color[1], source[1], dest[1]); /* G */ - VEC4_ADD(quad->outputs.color[2], source[2], dest[2]); /* B */ - break; - case PIPE_BLEND_SUBTRACT: - VEC4_SUB(quad->outputs.color[0], source[0], dest[0]); /* R */ - VEC4_SUB(quad->outputs.color[1], source[1], dest[1]); /* G */ - VEC4_SUB(quad->outputs.color[2], source[2], dest[2]); /* B */ - break; - case PIPE_BLEND_REVERSE_SUBTRACT: - VEC4_SUB(quad->outputs.color[0], dest[0], source[0]); /* R */ - VEC4_SUB(quad->outputs.color[1], dest[1], source[1]); /* G */ - VEC4_SUB(quad->outputs.color[2], dest[2], source[2]); /* B */ - break; - case PIPE_BLEND_MIN: - VEC4_MIN(quad->outputs.color[0], source[0], dest[0]); /* R */ - VEC4_MIN(quad->outputs.color[1], source[1], dest[1]); /* G */ - VEC4_MIN(quad->outputs.color[2], source[2], dest[2]); /* B */ - break; - case PIPE_BLEND_MAX: - VEC4_MAX(quad->outputs.color[0], source[0], dest[0]); /* R */ - VEC4_MAX(quad->outputs.color[1], source[1], dest[1]); /* G */ - VEC4_MAX(quad->outputs.color[2], source[2], dest[2]); /* B */ - break; - default: - abort(); + break; + case PIPE_BLENDFACTOR_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_SRC1_ALPHA: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(source[0], zero); /* R */ + VEC4_COPY(source[1], zero); /* G */ + VEC4_COPY(source[2], zero); /* B */ + break; + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + { + GLfloat inv_comp[4]; + VEC4_SUB(inv_comp, one, quad->outputs.color[0]); /* R */ + VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */ + VEC4_SUB(inv_comp, one, quad->outputs.color[1]); /* G */ + VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */ + VEC4_SUB(inv_comp, one, quad->outputs.color[2]); /* B */ + VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */ } - - /* - * Combine A terms - */ - switch (softpipe->blend.alpha_func) { - case PIPE_BLEND_ADD: - VEC4_ADD(quad->outputs.color[3], source[3], dest[3]); /* A */ - break; - case PIPE_BLEND_SUBTRACT: - VEC4_SUB(quad->outputs.color[3], source[3], dest[3]); /* A */ - break; - case PIPE_BLEND_REVERSE_SUBTRACT: - VEC4_SUB(quad->outputs.color[3], dest[3], source[3]); /* A */ - break; - case PIPE_BLEND_MIN: - VEC4_MIN(quad->outputs.color[3], source[3], dest[3]); /* A */ - break; - case PIPE_BLEND_MAX: - VEC4_MAX(quad->outputs.color[3], source[3], dest[3]); /* A */ - default: - abort(); + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + GLfloat inv_alpha[4]; + VEC4_SUB(inv_alpha, one, quad->outputs.color[3]); + VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ } - - /* pass blended quad to next stage */ - qs->next->run(qs->next, quad); + break; + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + { + GLfloat inv_alpha[4]; + VEC4_SUB(inv_alpha, one, dest[3]); + VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_DST_COLOR: + { + GLfloat inv_comp[4]; + VEC4_SUB(inv_comp, one, dest[0]); /* R */ + VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); /* R */ + VEC4_SUB(inv_comp, one, dest[1]); /* G */ + VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); /* G */ + VEC4_SUB(inv_comp, one, dest[2]); /* B */ + VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + { + GLfloat inv_comp[4]; + /* R */ + VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[0]); + VEC4_MUL(source[0], quad->outputs.color[0], inv_comp); + /* G */ + VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[1]); + VEC4_MUL(source[1], quad->outputs.color[1], inv_comp); + /* B */ + VEC4_SCALAR(inv_comp, 1.0 - softpipe->blend_color.color[2]); + VEC4_MUL(source[2], quad->outputs.color[2], inv_comp); + } + break; + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + { + GLfloat alpha[4], inv_alpha[4]; + VEC4_SCALAR(alpha, 1.0 - softpipe->blend_color.color[3]); + VEC4_MUL(source[0], quad->outputs.color[0], inv_alpha); /* R */ + VEC4_MUL(source[1], quad->outputs.color[1], inv_alpha); /* G */ + VEC4_MUL(source[2], quad->outputs.color[2], inv_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + assert(0); /* to do */ + break; + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + assert(0); /* to do */ + break; + default: + abort(); + } + + /* + * Compute src/first term A + */ + switch (softpipe->blend.alpha_src_factor) { + case PIPE_BLENDFACTOR_ONE: + VEC4_COPY(source[3], quad->outputs.color[3]); /* A */ + break; + case PIPE_BLENDFACTOR_SRC_ALPHA: + { + const GLfloat *alpha = quad->outputs.color[3]; + VEC4_MUL(source[3], quad->outputs.color[3], alpha); /* A */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(source[3], zero); /* A */ + break; + /* XXX fill in remaining terms */ + default: + abort(); + } + + + /* + * Compute dest/second term RGB + */ + switch (softpipe->blend.rgb_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* dest = dest * 1 NO-OP, leave dest as-is */ + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + GLfloat one_minus_alpha[QUAD_SIZE]; + VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]); + VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */ + VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */ + VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(dest[0], zero); /* R */ + VEC4_COPY(dest[1], zero); /* G */ + VEC4_COPY(dest[2], zero); /* B */ + break; + /* XXX fill in remaining terms */ + default: + abort(); + } + + /* + * Compute dest/second term A + */ + switch (softpipe->blend.alpha_dst_factor) { + case PIPE_BLENDFACTOR_ONE: + /* dest = dest * 1 NO-OP, leave dest as-is */ + break; + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + { + GLfloat one_minus_alpha[QUAD_SIZE]; + VEC4_SUB(one_minus_alpha, one, quad->outputs.color[3]); + VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */ + } + break; + case PIPE_BLENDFACTOR_ZERO: + VEC4_COPY(dest[3], zero); /* A */ + break; + /* XXX fill in remaining terms */ + default: + abort(); + } + + /* + * Combine RGB terms + */ + switch (softpipe->blend.rgb_func) { + case PIPE_BLEND_ADD: + VEC4_ADD(quad->outputs.color[0], source[0], dest[0]); /* R */ + VEC4_ADD(quad->outputs.color[1], source[1], dest[1]); /* G */ + VEC4_ADD(quad->outputs.color[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_SUBTRACT: + VEC4_SUB(quad->outputs.color[0], source[0], dest[0]); /* R */ + VEC4_SUB(quad->outputs.color[1], source[1], dest[1]); /* G */ + VEC4_SUB(quad->outputs.color[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + VEC4_SUB(quad->outputs.color[0], dest[0], source[0]); /* R */ + VEC4_SUB(quad->outputs.color[1], dest[1], source[1]); /* G */ + VEC4_SUB(quad->outputs.color[2], dest[2], source[2]); /* B */ + break; + case PIPE_BLEND_MIN: + VEC4_MIN(quad->outputs.color[0], source[0], dest[0]); /* R */ + VEC4_MIN(quad->outputs.color[1], source[1], dest[1]); /* G */ + VEC4_MIN(quad->outputs.color[2], source[2], dest[2]); /* B */ + break; + case PIPE_BLEND_MAX: + VEC4_MAX(quad->outputs.color[0], source[0], dest[0]); /* R */ + VEC4_MAX(quad->outputs.color[1], source[1], dest[1]); /* G */ + VEC4_MAX(quad->outputs.color[2], source[2], dest[2]); /* B */ + break; + default: + abort(); } + + /* + * Combine A terms + */ + switch (softpipe->blend.alpha_func) { + case PIPE_BLEND_ADD: + VEC4_ADD(quad->outputs.color[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_SUBTRACT: + VEC4_SUB(quad->outputs.color[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_REVERSE_SUBTRACT: + VEC4_SUB(quad->outputs.color[3], dest[3], source[3]); /* A */ + break; + case PIPE_BLEND_MIN: + VEC4_MIN(quad->outputs.color[3], source[3], dest[3]); /* A */ + break; + case PIPE_BLEND_MAX: + VEC4_MAX(quad->outputs.color[3], source[3], dest[3]); /* A */ + default: + abort(); + } + + /* pass blended quad to next stage */ + qs->next->run(qs->next, quad); } diff --git a/src/mesa/pipe/softpipe/sp_quad_bufloop.c b/src/mesa/pipe/softpipe/sp_quad_bufloop.c new file mode 100644 index 00000000000..977cc74c263 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_quad_bufloop.c @@ -0,0 +1,59 @@ + + +#include "main/glheader.h" +#include "main/imports.h" +#include "sp_context.h" +#include "sp_headers.h" +#include "sp_surface.h" +#include "sp_quad.h" + + +/** + * Loop over colorbuffers, passing quad to next stage each time. + */ +static void +cbuf_loop_quad(struct quad_stage *qs, struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + const GLuint sz = sizeof(quad->outputs.color); + GLfloat tmp[4][QUAD_SIZE]; + GLuint i; + + assert(sz == sizeof(tmp)); + + /* make copy of original colors since they can get modified + * by blending and masking. + */ + memcpy(tmp, quad->outputs.color, sz); + + for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { + /* set current cbuffer */ + softpipe->cbuf = softpipe->framebuffer.cbufs[i]; + + /* pass blended quad to next stage */ + qs->next->run(qs->next, quad); + + if (i + 1 < softpipe->framebuffer.num_cbufs) { + /* restore quad's colors for next buffer */ + memcpy(quad->outputs.color, tmp, sz); + } + } + + softpipe->cbuf = NULL; /* prevent accidental use */ +} + + +/** + * Create the colorbuffer loop stage. + * This is used to implement GL_FRONT_AND_BACK rendering. + */ +struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->run = cbuf_loop_quad; + + return stage; +} + diff --git a/src/mesa/pipe/softpipe/sp_quad_colormask.c b/src/mesa/pipe/softpipe/sp_quad_colormask.c index 6fb228fddaf..fff6efa8f6a 100644 --- a/src/mesa/pipe/softpipe/sp_quad_colormask.c +++ b/src/mesa/pipe/softpipe/sp_quad_colormask.c @@ -45,12 +45,8 @@ static void colormask_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; + struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf); GLfloat dest[4][QUAD_SIZE]; - - /* XXX buffer looping */ - - struct softpipe_surface *sps - = softpipe_surface(softpipe->framebuffer.cbufs[0]); sps->read_quad_f_swz(sps, quad->x0, quad->y0, dest); diff --git a/src/mesa/pipe/softpipe/sp_quad_output.c b/src/mesa/pipe/softpipe/sp_quad_output.c index e898757a065..12ab1eca1c7 100644 --- a/src/mesa/pipe/softpipe/sp_quad_output.c +++ b/src/mesa/pipe/softpipe/sp_quad_output.c @@ -65,28 +65,21 @@ static void output_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; - GLuint i; + struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf); - for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { - struct softpipe_surface *sps - = softpipe_surface(softpipe->framebuffer.cbufs[i]); + if (quad->mask != MASK_ALL) { + GLfloat tmp[4][QUAD_SIZE]; - if (quad->mask != MASK_ALL) { - GLfloat tmp[4][QUAD_SIZE]; + /* XXX probably add a masked-write function someday */ - /* Yes, we'll probably have a masked write as well, but this is - * how blend will be done at least. - */ + sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp); - sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp); + mask_copy( tmp, quad->outputs.color, quad->mask ); - mask_copy( tmp, quad->outputs.color, quad->mask ); - - sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp); - } - else { - sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color); - } + sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp); + } + else if (quad->mask) { + sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color); } } @@ -100,4 +93,3 @@ struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe ) return stage; } - diff --git a/src/mesa/sources b/src/mesa/sources index 78a030b767d..4856f7b023c 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -160,6 +160,7 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_quad.c \ pipe/softpipe/sp_quad_alpha_test.c \ pipe/softpipe/sp_quad_blend.c \ + pipe/softpipe/sp_quad_bufloop.c \ pipe/softpipe/sp_quad_colormask.c \ pipe/softpipe/sp_quad_depth_test.c \ pipe/softpipe/sp_quad_fs.c \ |