From: Brian Date: Wed, 20 Jun 2007 20:29:14 +0000 (-0600) Subject: Initial implementation of a software pipeline for quad rasterization (fragment ops). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fb5cdbd078d4d44fb43d417843debe41148f3714;p=mesa.git Initial implementation of a software pipeline for quad rasterization (fragment ops). This is very much like the clipper/setup pipeline for primitives. --- diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 7ab65162bd9..d1023fb7822 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -32,9 +32,6 @@ #include "imports.h" #include "macros.h" -#include "tnl/t_context.h" -#include "vf/vf.h" - #include "sp_context.h" #include "sp_clear.h" #include "sp_prim.h" @@ -88,6 +85,9 @@ struct pipe_context *softpipe_create( void ) softpipe->prim.flatshade = prim_flatshade( softpipe ); softpipe->prim.cull = prim_cull( softpipe ); + softpipe->quad.blend = sp_quad_blend_stage(softpipe); + softpipe->quad.shade = sp_quad_shade_stage(softpipe); + softpipe->quad.output = sp_quad_output_stage(softpipe); softpipe->draw = draw_create( softpipe ); diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 0a183ea3855..4e6168fe334 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -36,6 +36,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" +#include "sp_tile.h" struct softpipe_surface; @@ -129,6 +130,18 @@ struct softpipe_context { GLuint vertex_size; } prim; + /* + * Software quad rendering pipeline + */ + struct { + struct quad_stage *shade; + struct quad_stage *depth_test; + struct quad_stage *blend; + struct quad_stage *output; + + struct quad_stage *first; /**< points to one of the above stages */ + } quad; + /* Temp kludge: */ struct draw_context *draw; @@ -144,6 +157,4 @@ softpipe_context( struct pipe_context *pipe ) } - - #endif diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 8ef0fcbf9c5..29bb9365401 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -36,6 +36,18 @@ #include "sp_tile.h" + +/** + * Emit/render a quad. + * This passes the quad to the first stage of per-fragment operations. + */ +static INLINE void +quad_emit(struct softpipe_context *sp, struct quad_header *quad) +{ + sp->quad.first->run(sp->quad.first, quad); +} + + /** * Triangle edge info */ @@ -121,7 +133,7 @@ static void run_shader_block( struct setup_stage *setup, setup->quad.y0 = y; setup->quad.mask = mask; - quad_shade( setup->stage.softpipe, &setup->quad ); + quad_emit(setup->stage.softpipe, &setup->quad); } @@ -652,7 +664,7 @@ plot(struct setup_stage *setup, GLint x, GLint y) /* flush prev quad, start new quad */ if (setup->quad.x0 != -1) - quad_shade(setup->stage.softpipe, &setup->quad); + quad_emit(setup->stage.softpipe, &setup->quad); setup->quad.x0 = quadX; setup->quad.y0 = quadY; @@ -755,7 +767,7 @@ setup_line(struct prim_stage *stage, struct prim_header *prim) /* draw final quad */ if (setup->quad.mask) { - quad_shade(setup->stage.softpipe, &setup->quad); + quad_emit(setup->stage.softpipe, &setup->quad); } } @@ -810,7 +822,7 @@ setup_point(struct prim_stage *stage, struct prim_header *prim) setup->quad.x0 = x - ix; setup->quad.y0 = y - iy; setup->quad.mask = (1 << ix) << (2 * iy); - quad_shade(setup->stage.softpipe, &setup->quad); + quad_emit(setup->stage.softpipe, &setup->quad); } else { const GLint ixmin = block((GLint) (x - halfSize)); @@ -870,7 +882,7 @@ setup_point(struct prim_stage *stage, struct prim_header *prim) if (setup->quad.mask) { setup->quad.x0 = ix; setup->quad.y0 = iy; - quad_shade( setup->stage.softpipe, &setup->quad ); + quad_emit( setup->stage.softpipe, &setup->quad ); } } } diff --git a/src/mesa/pipe/softpipe/sp_state_derived.c b/src/mesa/pipe/softpipe/sp_state_derived.c index 1f7329600ab..b53c842366c 100644 --- a/src/mesa/pipe/softpipe/sp_state_derived.c +++ b/src/mesa/pipe/softpipe/sp_state_derived.c @@ -132,5 +132,8 @@ void softpipe_update_derived( struct softpipe_context *softpipe ) if (softpipe->dirty & (G_NEW_SETUP | G_NEW_FS)) calculate_vertex_layout( softpipe ); + if (softpipe->dirty & (G_NEW_BLEND | G_NEW_FS)) + sp_build_quad_pipeline(softpipe); + softpipe->dirty = 0; } diff --git a/src/mesa/pipe/softpipe/sp_tile.c b/src/mesa/pipe/softpipe/sp_tile.c new file mode 100644 index 00000000000..168872c64d0 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_tile.c @@ -0,0 +1,24 @@ + + +#include "sp_context.h" + + + +void +sp_build_quad_pipeline(struct softpipe_context *sp) +{ + + sp->quad.first = sp->quad.output; + + if (sp->blend.blend_enable) { + sp->quad.blend->next = sp->quad.first; + sp->quad.first = sp->quad.blend; + } + + /* XXX always enable shader? */ + if (1) { + sp->quad.shade->next = sp->quad.first; + sp->quad.first = sp->quad.shade; + } + +} diff --git a/src/mesa/pipe/softpipe/sp_tile.h b/src/mesa/pipe/softpipe/sp_tile.h index f4808b99d29..86c17180bf6 100644 --- a/src/mesa/pipe/softpipe/sp_tile.h +++ b/src/mesa/pipe/softpipe/sp_tile.h @@ -33,10 +33,24 @@ struct softpipe_context; struct quad_header; -void quad_shade( struct softpipe_context *softpipe, - struct quad_header *quad ); -void quad_output( struct softpipe_context *softpipe, - struct quad_header *quad ); +struct quad_stage { + struct softpipe_context *softpipe; + + struct quad_stage *next; + + /** the stage action */ + void (*run)(struct quad_stage *qs, struct quad_header *quad); +}; + + + +struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe ); +struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe ); + +void +sp_build_quad_pipeline(struct softpipe_context *sp); #endif diff --git a/src/mesa/pipe/softpipe/sp_tile_blend.c b/src/mesa/pipe/softpipe/sp_tile_blend.c new file mode 100644 index 00000000000..5681528d067 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_tile_blend.c @@ -0,0 +1,70 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * quad blending + */ + +#include "glheader.h" +#include "imports.h" +#include "sp_context.h" +#include "sp_headers.h" +#include "sp_surface.h" +#include "sp_tile.h" + + + +static void +blend_quad(struct quad_stage *qs, struct quad_header *quad) +{ + struct softpipe_context *softpipe = qs->softpipe; + GLfloat dest[4][QUAD_SIZE], result[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); + + /* XXX do blend here */ + + qs->next->run(qs->next, quad); + } +} + + + + +struct quad_stage *sp_quad_blend_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->run = blend_quad; + + return stage; +} diff --git a/src/mesa/pipe/softpipe/sp_tile_depth_test.c b/src/mesa/pipe/softpipe/sp_tile_depth_test.c new file mode 100644 index 00000000000..5bc26485311 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_tile_depth_test.c @@ -0,0 +1,73 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5 + * + * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * quad blending + */ + +#include "glheader.h" +#include "imports.h" +#include "sp_context.h" +#include "sp_headers.h" +#include "sp_surface.h" +#include "sp_tile.h" + + + +static void +depth_test_quad(struct quad_stage *qs, struct quad_header *quad) +{ +#if 0 + struct softpipe_context *softpipe = qs->softpipe; + GLfloat dest[4][QUAD_SIZE], result[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); + + /* XXX do blend here */ + + } +#endif + + qs->next->run(qs->next, quad); +} + + + + +struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->run = depth_test_quad; + + return stage; +} diff --git a/src/mesa/pipe/softpipe/sp_tile_fs.c b/src/mesa/pipe/softpipe/sp_tile_fs.c index c145fcf089a..912831fefa4 100644 --- a/src/mesa/pipe/softpipe/sp_tile_fs.c +++ b/src/mesa/pipe/softpipe/sp_tile_fs.c @@ -33,6 +33,7 @@ */ #include "glheader.h" +#include "imports.h" #include "sp_context.h" #include "sp_headers.h" #include "sp_tile.h" @@ -116,9 +117,10 @@ static INLINE void pinterp( struct exec_machine *exec, /* This should be done by the fragment shader execution unit (code * generated from the decl instructions). Do it here for now. */ -void quad_shade( struct softpipe_context *softpipe, - struct quad_header *quad ) +static void +shade_quad( struct quad_stage *qs, struct quad_header *quad ) { + struct softpipe_context *softpipe = qs->softpipe; struct exec_machine exec; GLfloat fx = quad->x0; GLfloat fy = quad->y0; @@ -190,14 +192,17 @@ void quad_shade( struct softpipe_context *softpipe, } #endif - - if (quad->mask) - quad_output( softpipe, quad ); + qs->next->run(qs->next, quad); } +struct quad_stage *sp_quad_shade_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + stage->softpipe = softpipe; + stage->run = shade_quad; - - + return stage; +} diff --git a/src/mesa/pipe/softpipe/sp_tile_output.c b/src/mesa/pipe/softpipe/sp_tile_output.c index 23086b70208..4f4421891b2 100644 --- a/src/mesa/pipe/softpipe/sp_tile_output.c +++ b/src/mesa/pipe/softpipe/sp_tile_output.c @@ -33,6 +33,7 @@ */ #include "glheader.h" +#include "imports.h" #include "sp_context.h" #include "sp_headers.h" #include "sp_surface.h" @@ -60,9 +61,10 @@ static void mask_copy( GLfloat (*dest)[4], * * Note that surfaces support only full quad reads and writes. */ -void quad_output( struct softpipe_context *softpipe, - struct quad_header *quad ) +static void +output_quad(struct quad_stage *qs, struct quad_header *quad) { + struct softpipe_context *softpipe = qs->softpipe; GLuint i; for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) { @@ -87,3 +89,15 @@ void quad_output( struct softpipe_context *softpipe, } } } + + +struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe ) +{ + struct quad_stage *stage = CALLOC_STRUCT(quad_stage); + + stage->softpipe = softpipe; + stage->run = output_quad; + + return stage; +} + diff --git a/src/mesa/sources b/src/mesa/sources index 97801648c42..d07bd3fbe08 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -171,6 +171,9 @@ SOFTPIPE_SOURCES = \ pipe/softpipe/sp_state_point.c \ pipe/softpipe/sp_state_setup.c \ pipe/softpipe/sp_state_surface.c \ + pipe/softpipe/sp_tile.c \ + pipe/softpipe/sp_tile_blend.c \ + pipe/softpipe/sp_tile_depth_test.c \ pipe/softpipe/sp_tile_fs.c \ pipe/softpipe/sp_tile_output.c