softpipe: expand quad pipeline to process >1 quad at a time
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_earlyz.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * \brief Quad early-z testing
30 */
31
32 #include "pipe/p_defines.h"
33 #include "util/u_memory.h"
34 #include "sp_quad.h"
35 #include "sp_quad_pipe.h"
36
37
38 /**
39 * All this stage does is compute the quad's Z values (which is normally
40 * done by the shading stage).
41 * The next stage will do the actual depth test.
42 */
43 static void
44 earlyz_quad(
45 struct quad_stage *qs,
46 struct quad_header *quads[],
47 unsigned nr )
48 {
49 const float a0z = quads[0]->posCoef->a0[2];
50 const float dzdx = quads[0]->posCoef->dadx[2];
51 const float dzdy = quads[0]->posCoef->dady[2];
52 unsigned i;
53
54 for (i = 0; i < nr; i++) {
55 const float fx = (float) quads[i]->input.x0;
56 const float fy = (float) quads[i]->input.y0;
57 const float z0 = a0z + dzdx * fx + dzdy * fy;
58
59 quads[i]->output.depth[0] = z0;
60 quads[i]->output.depth[1] = z0 + dzdx;
61 quads[i]->output.depth[2] = z0 + dzdy;
62 quads[i]->output.depth[3] = z0 + dzdx + dzdy;
63 }
64
65 qs->next->run( qs->next, quads, nr );
66 }
67
68 static void
69 earlyz_begin(
70 struct quad_stage *qs )
71 {
72 qs->next->begin( qs->next );
73 }
74
75 static void
76 earlyz_destroy(
77 struct quad_stage *qs )
78 {
79 FREE( qs );
80 }
81
82 struct quad_stage *
83 sp_quad_earlyz_stage(
84 struct softpipe_context *softpipe )
85 {
86 struct quad_stage *stage = CALLOC_STRUCT( quad_stage );
87
88 stage->softpipe = softpipe;
89 stage->begin = earlyz_begin;
90 stage->run = earlyz_quad;
91 stage->destroy = earlyz_destroy;
92
93 return stage;
94 }