fcb8e2b05d27debe60ccc97ec116a69856cef7cb
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, plane
[j
].step
);
56 /* Now pass to the shader:
59 lp_rast_shade_quads_mask(task
, &tri
->inputs
, x
, y
, mask
);
63 * Evaluate a 16x16 block of pixels to determine which 4x4 subblocks are in/out
64 * of the triangle's bounds.
67 TAG(do_block_16
)(struct lp_rasterizer_task
*task
,
68 const struct lp_rast_triangle
*tri
,
69 const struct lp_rast_plane
*plane
,
73 unsigned outmask
, inmask
, partmask
, partial_mask
;
76 outmask
= 0; /* outside one or more trivial reject planes */
77 partmask
= 0; /* outside one or more trivial accept planes */
79 for (j
= 0; j
< NR_PLANES
; j
++) {
80 const int *step
= plane
[j
].step
;
81 const int eo
= plane
[j
].eo
* 4;
82 const int ei
= plane
[j
].ei
* 4;
83 const int cox
= c
[j
] + eo
;
84 const int cio
= ei
- 1 - eo
;
86 for (i
= 0; i
< 16; i
++) {
87 int out
= cox
+ step
[i
] * 4;
89 outmask
|= (out
>> 31) & (1 << i
);
90 partmask
|= (part
>> 31) & (1 << i
);
94 if (outmask
== 0xffff)
97 /* Mask of sub-blocks which are inside all trivial accept planes:
99 inmask
= ~partmask
& 0xffff;
101 /* Mask of sub-blocks which are inside all trivial reject planes,
102 * but outside at least one trivial accept plane:
104 partial_mask
= partmask
& ~outmask
;
106 assert((partial_mask
& inmask
) == 0);
108 /* Iterate over partials:
110 while (partial_mask
) {
111 int i
= ffs(partial_mask
) - 1;
112 int px
= x
+ pos_table4
[i
][0];
113 int py
= y
+ pos_table4
[i
][1];
116 for (j
= 0; j
< NR_PLANES
; j
++)
117 cx
[j
] = c
[j
] + plane
[j
].step
[i
] * 4;
119 partial_mask
&= ~(1 << i
);
121 TAG(do_block_4
)(task
, tri
, plane
, px
, py
, cx
);
124 /* Iterate over fulls:
127 int i
= ffs(inmask
) - 1;
128 int px
= x
+ pos_table4
[i
][0];
129 int py
= y
+ pos_table4
[i
][1];
133 block_full_4(task
, tri
, px
, py
);
139 * Scan the tile in chunks and figure out which pixels to rasterize
143 TAG(lp_rast_triangle
)(struct lp_rasterizer_task
*task
,
144 const union lp_rast_cmd_arg arg
)
146 const struct lp_rast_triangle
*tri
= arg
.triangle
.tri
;
147 unsigned plane_mask
= arg
.triangle
.plane_mask
;
148 const int x
= task
->x
, y
= task
->y
;
149 struct lp_rast_plane plane
[NR_PLANES
];
151 unsigned outmask
, inmask
, partmask
, partial_mask
;
152 unsigned i
, j
, nr_planes
= 0;
155 int i
= ffs(plane_mask
) - 1;
156 plane
[nr_planes
] = tri
->plane
[i
];
157 plane_mask
&= ~(1 << i
);
161 assert(nr_planes
== NR_PLANES
);
162 outmask
= 0; /* outside one or more trivial reject planes */
163 partmask
= 0; /* outside one or more trivial accept planes */
165 for (j
= 0; j
< NR_PLANES
; j
++) {
166 const int *step
= plane
[j
].step
;
167 const int eo
= plane
[j
].eo
* 16;
168 const int ei
= plane
[j
].ei
* 16;
171 c
[j
] = plane
[j
].c
+ plane
[j
].dcdy
* y
- plane
[j
].dcdx
* x
;
175 for (i
= 0; i
< 16; i
++) {
176 int out
= cox
+ step
[i
] * 16;
177 int part
= out
+ cio
;
178 outmask
|= (out
>> 31) & (1 << i
);
179 partmask
|= (part
>> 31) & (1 << i
);
183 if (outmask
== 0xffff)
186 /* Mask of sub-blocks which are inside all trivial accept planes:
188 inmask
= ~partmask
& 0xffff;
190 /* Mask of sub-blocks which are inside all trivial reject planes,
191 * but outside at least one trivial accept plane:
193 partial_mask
= partmask
& ~outmask
;
195 assert((partial_mask
& inmask
) == 0);
197 /* Iterate over partials:
199 while (partial_mask
) {
200 int i
= ffs(partial_mask
) - 1;
201 int px
= x
+ pos_table16
[i
][0];
202 int py
= y
+ pos_table16
[i
][1];
205 for (j
= 0; j
< NR_PLANES
; j
++)
206 cx
[j
] = c
[j
] + plane
[j
].step
[i
] * 16;
208 partial_mask
&= ~(1 << i
);
210 LP_COUNT(nr_partially_covered_16
);
211 TAG(do_block_16
)(task
, tri
, plane
, px
, py
, cx
);
214 /* Iterate over fulls:
217 int i
= ffs(inmask
) - 1;
218 int px
= x
+ pos_table16
[i
][0];
219 int py
= y
+ pos_table16
[i
][1];
223 LP_COUNT(nr_fully_covered_16
);
224 block_full_16(task
, tri
, px
, py
);