98ebcfa870976b490f79fcf7face0f2d2a5a799c
1 /**************************************************************************
3 * Copyright 2007-2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 VMWARE 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.
26 **************************************************************************/
29 * Rasterization for binned triangles within a tile
35 * Prototype for a 7 plane rasterizer function. Will codegenerate
38 * XXX: Varients for more/fewer planes.
39 * XXX: Need ways of dropping planes as we descend.
43 TAG(do_block_4
)(struct lp_rasterizer_task
*task
,
44 const struct lp_rast_triangle
*tri
,
45 const struct lp_rast_plane
*plane
,
49 unsigned mask
= 0xffff;
52 for (j
= 0; j
< NR_PLANES
; j
++) {
53 mask
&= ~build_mask(c
[j
] - 1,
58 /* Now pass to the shader:
61 lp_rast_shade_quads_mask(task
, &tri
->inputs
, x
, y
, mask
);
65 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
66 * of the triangle's bounds.
69 TAG(do_block_16
)(struct lp_rasterizer_task
*task
,
70 const struct lp_rast_triangle
*tri
,
71 const struct lp_rast_plane
*plane
,
75 unsigned outmask
, inmask
, partmask
, partial_mask
;
78 outmask
= 0; /* outside one or more trivial reject planes */
79 partmask
= 0; /* outside one or more trivial accept planes */
81 for (j
= 0; j
< NR_PLANES
; j
++) {
82 const int dcdx
= -plane
[j
].dcdx
* 4;
83 const int dcdy
= plane
[j
].dcdy
* 4;
84 const int cox
= c
[j
] + plane
[j
].eo
* 4;
85 const int cio
= c
[j
] + plane
[j
].ei
* 4 - 1;
87 outmask
|= build_mask_linear(cox
, dcdx
, dcdy
);
88 partmask
|= build_mask_linear(cio
, dcdx
, dcdy
);
91 if (outmask
== 0xffff)
94 /* Mask of sub-blocks which are inside all trivial accept planes:
96 inmask
= ~partmask
& 0xffff;
98 /* Mask of sub-blocks which are inside all trivial reject planes,
99 * but outside at least one trivial accept plane:
101 partial_mask
= partmask
& ~outmask
;
103 assert((partial_mask
& inmask
) == 0);
105 /* Iterate over partials:
107 while (partial_mask
) {
108 int i
= ffs(partial_mask
) - 1;
109 int ix
= (i
& 3) * 4;
110 int iy
= (i
>> 2) * 4;
115 partial_mask
&= ~(1 << i
);
117 for (j
= 0; j
< NR_PLANES
; j
++)
120 + plane
[j
].dcdy
* iy
);
122 TAG(do_block_4
)(task
, tri
, plane
, px
, py
, cx
);
125 /* Iterate over fulls:
128 int i
= ffs(inmask
) - 1;
129 int ix
= (i
& 3) * 4;
130 int iy
= (i
>> 2) * 4;
136 block_full_4(task
, tri
, px
, py
);
142 * Scan the tile in chunks and figure out which pixels to rasterize
146 TAG(lp_rast_triangle
)(struct lp_rasterizer_task
*task
,
147 const union lp_rast_cmd_arg arg
)
149 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
150 unsigned plane_mask
= arg
.triangle
.plane_mask
;
151 const int x
= task
->x
, y
= task
->y
;
152 struct lp_rast_plane plane
[NR_PLANES
];
154 unsigned outmask
, inmask
, partmask
, partial_mask
;
155 unsigned j
, nr_planes
= 0;
158 int i
= ffs(plane_mask
) - 1;
159 plane
[nr_planes
] = tri
->plane
[i
];
160 plane_mask
&= ~(1 << i
);
164 assert(nr_planes
== NR_PLANES
);
165 outmask
= 0; /* outside one or more trivial reject planes */
166 partmask
= 0; /* outside one or more trivial accept planes */
168 for (j
= 0; j
< NR_PLANES
; j
++) {
169 c
[j
] = plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
172 for (j
= 0; j
< NR_PLANES
; j
++) {
173 const int dcdx
= -plane
[j
].dcdx
* 16;
174 const int dcdy
= plane
[j
].dcdy
* 16;
175 const int cox
= c
[j
] + plane
[j
].eo
* 16;
176 const int cio
= c
[j
] + plane
[j
].ei
* 16 - 1;
178 outmask
|= build_mask_linear(cox
, dcdx
, dcdy
);
179 partmask
|= build_mask_linear(cio
, dcdx
, dcdy
);
182 if (outmask
== 0xffff)
185 /* Mask of sub-blocks which are inside all trivial accept planes:
187 inmask
= ~partmask
& 0xffff;
189 /* Mask of sub-blocks which are inside all trivial reject planes,
190 * but outside at least one trivial accept plane:
192 partial_mask
= partmask
& ~outmask
;
194 assert((partial_mask
& inmask
) == 0);
196 /* Iterate over partials:
198 while (partial_mask
) {
199 int i
= ffs(partial_mask
) - 1;
200 int ix
= (i
& 3) * 16;
201 int iy
= (i
>> 2) * 16;
206 for (j
= 0; j
< NR_PLANES
; j
++)
209 + plane
[j
].dcdy
* iy
);
211 partial_mask
&= ~(1 << i
);
213 LP_COUNT(nr_partially_covered_16
);
214 TAG(do_block_16
)(task
, tri
, plane
, px
, py
, cx
);
217 /* Iterate over fulls:
220 int i
= ffs(inmask
) - 1;
221 int ix
= (i
& 3) * 16;
222 int iy
= (i
>> 2) * 16;
228 LP_COUNT(nr_fully_covered_16
);
229 block_full_16(task
, tri
, px
, py
);