1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 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.
25 *
26 **************************************************************************/
27
28 /*
29 * Binning code for lines
30 */
31
32 #include "util/u_math.h"
33 #include "util/u_memory.h"
34 #include "lp_perf.h"
35 #include "lp_setup_context.h"
36 #include "lp_rast.h"
37 #include "lp_state_fs.h"
38 #include "lp_state_setup.h"
39 #include "lp_context.h"
40 #include "draw/draw_context.h"
41
42 #define NUM_CHANNELS 4
43
44 struct lp_line_info {
45
46 float dx;
47 float dy;
48 float oneoverarea;
49 boolean frontfacing;
50
51 const float (*v1)[4];
52 const float (*v2)[4];
53
54 float (*a0)[4];
55 float (*dadx)[4];
56 float (*dady)[4];
57 };
58
59
60 /**
61 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
62 */
constant_coef(struct lp_setup_context * setup,struct lp_line_info * info,unsigned slot,const float value,unsigned i)63 static void constant_coef( struct lp_setup_context *setup,
64 struct lp_line_info *info,
65 unsigned slot,
66 const float value,
67 unsigned i )
68 {
69 info->a0[slot][i] = value;
70 info->dadx[slot][i] = 0.0f;
71 info->dady[slot][i] = 0.0f;
72 }
73
74
75 /**
76 * Compute a0, dadx and dady for a linearly interpolated coefficient,
77 * for a triangle.
78 */
linear_coef(struct lp_setup_context * setup,struct lp_line_info * info,unsigned slot,unsigned vert_attr,unsigned i)79 static void linear_coef( struct lp_setup_context *setup,
80 struct lp_line_info *info,
81 unsigned slot,
82 unsigned vert_attr,
83 unsigned i)
84 {
85 float a1 = info->v1[vert_attr][i];
86 float a2 = info->v2[vert_attr][i];
87
88 float da21 = a1 - a2;
89 float dadx = da21 * info->dx * info->oneoverarea;
90 float dady = da21 * info->dy * info->oneoverarea;
91
92 info->dadx[slot][i] = dadx;
93 info->dady[slot][i] = dady;
94
95 info->a0[slot][i] = (a1 -
96 (dadx * (info->v1[0][0] - setup->pixel_offset) +
97 dady * (info->v1[0][1] - setup->pixel_offset)));
98 }
99
100
101 /**
102 * Compute a0, dadx and dady for a perspective-corrected interpolant,
103 * for a triangle.
104 * We basically multiply the vertex value by 1/w before computing
105 * the plane coefficients (a0, dadx, dady).
106 * Later, when we compute the value at a particular fragment position we'll
107 * divide the interpolated value by the interpolated W at that fragment.
108 */
perspective_coef(struct lp_setup_context * setup,struct lp_line_info * info,unsigned slot,unsigned vert_attr,unsigned i)109 static void perspective_coef( struct lp_setup_context *setup,
110 struct lp_line_info *info,
111 unsigned slot,
112 unsigned vert_attr,
113 unsigned i)
114 {
115 /* premultiply by 1/w (v[0][3] is always 1/w):
116 */
117 float a1 = info->v1[vert_attr][i] * info->v1[0][3];
118 float a2 = info->v2[vert_attr][i] * info->v2[0][3];
119
120 float da21 = a1 - a2;
121 float dadx = da21 * info->dx * info->oneoverarea;
122 float dady = da21 * info->dy * info->oneoverarea;
123
124 info->dadx[slot][i] = dadx;
125 info->dady[slot][i] = dady;
126
127 info->a0[slot][i] = (a1 -
128 (dadx * (info->v1[0][0] - setup->pixel_offset) +
129 dady * (info->v1[0][1] - setup->pixel_offset)));
130 }
131
132 static void
setup_fragcoord_coef(struct lp_setup_context * setup,struct lp_line_info * info,unsigned slot,unsigned usage_mask)133 setup_fragcoord_coef( struct lp_setup_context *setup,
134 struct lp_line_info *info,
135 unsigned slot,
136 unsigned usage_mask)
137 {
138 /*X*/
139 if (usage_mask & TGSI_WRITEMASK_X) {
140 info->a0[slot][0] = 0.0;
141 info->dadx[slot][0] = 1.0;
142 info->dady[slot][0] = 0.0;
143 }
144
145 /*Y*/
146 if (usage_mask & TGSI_WRITEMASK_Y) {
147 info->a0[slot][1] = 0.0;
148 info->dadx[slot][1] = 0.0;
149 info->dady[slot][1] = 1.0;
150 }
151
152 /*Z*/
153 if (usage_mask & TGSI_WRITEMASK_Z) {
154 linear_coef(setup, info, slot, 0, 2);
155 }
156
157 /*W*/
158 if (usage_mask & TGSI_WRITEMASK_W) {
159 linear_coef(setup, info, slot, 0, 3);
160 }
161 }
162
163 /**
164 * Compute the tri->coef[] array dadx, dady, a0 values.
165 */
setup_line_coefficients(struct lp_setup_context * setup,struct lp_line_info * info)166 static void setup_line_coefficients( struct lp_setup_context *setup,
167 struct lp_line_info *info)
168 {
169 const struct lp_setup_variant_key *key = &setup->setup.variant->key;
170 unsigned fragcoord_usage_mask = TGSI_WRITEMASK_XYZ;
171 unsigned slot;
172
173 /* setup interpolation for all the remaining attributes:
174 */
175 for (slot = 0; slot < key->num_inputs; slot++) {
176 unsigned vert_attr = key->inputs[slot].src_index;
177 unsigned usage_mask = key->inputs[slot].usage_mask;
178 unsigned i;
179
180 switch (key->inputs[slot].interp) {
181 case LP_INTERP_CONSTANT:
182 if (key->flatshade_first) {
183 for (i = 0; i < NUM_CHANNELS; i++)
184 if (usage_mask & (1 << i))
185 constant_coef(setup, info, slot+1, info->v1[vert_attr][i], i);
186 }
187 else {
188 for (i = 0; i < NUM_CHANNELS; i++)
189 if (usage_mask & (1 << i))
190 constant_coef(setup, info, slot+1, info->v2[vert_attr][i], i);
191 }
192 break;
193
194 case LP_INTERP_LINEAR:
195 for (i = 0; i < NUM_CHANNELS; i++)
196 if (usage_mask & (1 << i))
197 linear_coef(setup, info, slot+1, vert_attr, i);
198 break;
199
200 case LP_INTERP_PERSPECTIVE:
201 for (i = 0; i < NUM_CHANNELS; i++)
202 if (usage_mask & (1 << i))
203 perspective_coef(setup, info, slot+1, vert_attr, i);
204 fragcoord_usage_mask |= TGSI_WRITEMASK_W;
205 break;
206
207 case LP_INTERP_POSITION:
208 /*
209 * The generated pixel interpolators will pick up the coeffs from
210 * slot 0, so all need to ensure that the usage mask is covers all
211 * usages.
212 */
213 fragcoord_usage_mask |= usage_mask;
214 break;
215
216 case LP_INTERP_FACING:
217 for (i = 0; i < NUM_CHANNELS; i++)
218 if (usage_mask & (1 << i))
219 constant_coef(setup, info, slot+1,
220 info->frontfacing ? 1.0f : -1.0f, i);
221 break;
222
223 default:
224 assert(0);
225 }
226 }
227
228 /* The internal position input is in slot zero:
229 */
230 setup_fragcoord_coef(setup, info, 0,
231 fragcoord_usage_mask);
232 }
233
234
235
subpixel_snap(float a)236 static inline int subpixel_snap( float a )
237 {
238 return util_iround(FIXED_ONE * a);
239 }
240
241
242 /**
243 * Print line vertex attribs (for debug).
244 */
245 static void
print_line(struct lp_setup_context * setup,const float (* v1)[4],const float (* v2)[4])246 print_line(struct lp_setup_context *setup,
247 const float (*v1)[4],
248 const float (*v2)[4])
249 {
250 const struct lp_setup_variant_key *key = &setup->setup.variant->key;
251 uint i;
252
253 debug_printf("llvmpipe line\n");
254 for (i = 0; i < 1 + key->num_inputs; i++) {
255 debug_printf(" v1[%d]: %f %f %f %f\n", i,
256 v1[i][0], v1[i][1], v1[i][2], v1[i][3]);
257 }
258 for (i = 0; i < 1 + key->num_inputs; i++) {
259 debug_printf(" v2[%d]: %f %f %f %f\n", i,
260 v2[i][0], v2[i][1], v2[i][2], v2[i][3]);
261 }
262 }
263
264
sign(float x)265 static inline boolean sign(float x){
266 return x >= 0;
267 }
268
269
270 /* Used on positive floats only:
271 */
fracf(float f)272 static inline float fracf(float f)
273 {
274 return f - floorf(f);
275 }
276
277
278
279 static boolean
try_setup_line(struct lp_setup_context * setup,const float (* v1)[4],const float (* v2)[4])280 try_setup_line( struct lp_setup_context *setup,
281 const float (*v1)[4],
282 const float (*v2)[4])
283 {
284 struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
285 struct lp_scene *scene = setup->scene;
286 const struct lp_setup_variant_key *key = &setup->setup.variant->key;
287 struct lp_rast_triangle *line;
288 struct lp_rast_plane *plane;
289 struct lp_line_info info;
290 float width = MAX2(1.0, setup->line_width);
291 const struct u_rect *scissor;
292 struct u_rect bbox, bboxpos;
293 boolean s_planes[4];
294 unsigned tri_bytes;
295 int x[4];
296 int y[4];
297 int i;
298 int nr_planes = 4;
299 unsigned viewport_index = 0;
300 unsigned layer = 0;
301 float pixel_offset = setup->multisample ? 0.0 : setup->pixel_offset;
302
303 float dx, dy;
304 float area;
305 const float (*pv)[4];
306
307 if (lp_context->active_statistics_queries) {
308 lp_context->pipeline_statistics.c_primitives++;
309 }
310
311 if (0)
312 print_line(setup, v1, v2);
313
314 if (setup->flatshade_first) {
315 pv = v1;
316 }
317 else {
318 pv = v2;
319 }
320 if (setup->viewport_index_slot > 0) {
321 unsigned *udata = (unsigned*)pv[setup->viewport_index_slot];
322 viewport_index = lp_clamp_viewport_idx(*udata);
323 }
324 if (setup->layer_slot > 0) {
325 layer = *(unsigned*)pv[setup->layer_slot];
326 layer = MIN2(layer, scene->fb_max_layer);
327 }
328
329 dx = v1[0][0] - v2[0][0];
330 dy = v1[0][1] - v2[0][1];
331 area = (dx * dx + dy * dy);
332 if (area == 0) {
333 LP_COUNT(nr_culled_tris);
334 return TRUE;
335 }
336
337 info.oneoverarea = 1.0f / area;
338 info.dx = dx;
339 info.dy = dy;
340 info.v1 = v1;
341 info.v2 = v2;
342
343
344 if (setup->rectangular_lines) {
345 float scale = (setup->line_width * 0.5f) / sqrtf(area);
346 int tx = subpixel_snap(-dy * scale);
347 int ty = subpixel_snap(+dx * scale);
348
349 x[0] = subpixel_snap(v1[0][0] - pixel_offset) - tx;
350 x[1] = subpixel_snap(v2[0][0] - pixel_offset) - tx;
351 x[2] = subpixel_snap(v2[0][0] - pixel_offset) + tx;
352 x[3] = subpixel_snap(v1[0][0] - pixel_offset) + tx;
353
354 y[0] = subpixel_snap(v1[0][1] - pixel_offset) - ty;
355 y[1] = subpixel_snap(v2[0][1] - pixel_offset) - ty;
356 y[2] = subpixel_snap(v2[0][1] - pixel_offset) + ty;
357 y[3] = subpixel_snap(v1[0][1] - pixel_offset) + ty;
358 } else {
359 float x_offset = 0, y_offset=0;
360 float x_offset_end = 0, y_offset_end = 0;
361
362 float x1diff = v1[0][0] - floorf(v1[0][0]) - 0.5f;
363 float y1diff = v1[0][1] - floorf(v1[0][1]) - 0.5f;
364 float x2diff = v2[0][0] - floorf(v2[0][0]) - 0.5f;
365 float y2diff = v2[0][1] - floorf(v2[0][1]) - 0.5f;
366
367 /* linewidth should be interpreted as integer */
368 int fixed_width = util_iround(width) * FIXED_ONE;
369
370 bool draw_start;
371 bool draw_end;
372
373 if (fabsf(dx) >= fabsf(dy)) {
374 float dydx = dy / dx;
375
376 /* X-MAJOR LINE */
377
378 if (y2diff == -0.5 && dy < 0) {
379 y2diff = 0.5;
380 }
381
382 /*
383 * Diamond exit rule test for starting point
384 */
385 if (fabsf(x1diff) + fabsf(y1diff) < 0.5) {
386 draw_start = true;
387 }
388 else if (sign(x1diff) == sign(-dx)) {
389 draw_start = false;
390 }
391 else if (sign(-y1diff) != sign(dy)) {
392 draw_start = true;
393 }
394 else {
395 /* do intersection test */
396 float yintersect = fracf(v1[0][1]) + x1diff * dydx;
397 draw_start = (yintersect < 1.0 && yintersect > 0.0);
398 }
399
400
401 /*
402 * Diamond exit rule test for ending point
403 */
404 if (fabsf(x2diff) + fabsf(y2diff) < 0.5) {
405 draw_end = false;
406 }
407 else if (sign(x2diff) != sign(-dx)) {
408 draw_end = false;
409 }
410 else if (sign(-y2diff) == sign(dy)) {
411 draw_end = true;
412 }
413 else {
414 /* do intersection test */
415 float yintersect = fracf(v2[0][1]) + x2diff * dydx;
416 draw_end = (yintersect < 1.0 && yintersect > 0.0);
417 }
418
419 /* Are we already drawing start/end?
420 */
421 bool will_draw_start = sign(-x1diff) != sign(dx);
422 bool will_draw_end = (sign(x2diff) == sign(-dx)) || x2diff==0;
423
424 /* interpolate using the preferred wide-lines formula */
425 info.dx *= 1 + dydx * dydx;
426 info.dy = 0;
427
428 if (dx < 0) {
429 /* if v2 is to the right of v1, swap pointers */
430 const float (*temp)[4] = v1;
431 v1 = v2;
432 v2 = temp;
433 dx = -dx;
434 dy = -dy;
435 /* Otherwise shift planes appropriately */
436 if (will_draw_start != draw_start) {
437 x_offset_end = -x1diff - 0.5;
438 y_offset_end = x_offset_end * dydx;
439
440 }
441 if (will_draw_end != draw_end) {
442 x_offset = -x2diff - 0.5;
443 y_offset = x_offset * dydx;
444 }
445
446 }
447 else {
448 /* Otherwise shift planes appropriately */
449 if (will_draw_start != draw_start) {
450 x_offset = -x1diff + 0.5;
451 y_offset = x_offset * dydx;
452 }
453 if (will_draw_end != draw_end) {
454 x_offset_end = -x2diff + 0.5;
455 y_offset_end = x_offset_end * dydx;
456 }
457 }
458
459 /* x/y positions in fixed point */
460 x[0] = subpixel_snap(v1[0][0] + x_offset - pixel_offset);
461 x[1] = subpixel_snap(v2[0][0] + x_offset_end - pixel_offset);
462 x[2] = subpixel_snap(v2[0][0] + x_offset_end - pixel_offset);
463 x[3] = subpixel_snap(v1[0][0] + x_offset - pixel_offset);
464
465 y[0] = subpixel_snap(v1[0][1] + y_offset - pixel_offset) - fixed_width/2;
466 y[1] = subpixel_snap(v2[0][1] + y_offset_end - pixel_offset) - fixed_width/2;
467 y[2] = subpixel_snap(v2[0][1] + y_offset_end - pixel_offset) + fixed_width/2;
468 y[3] = subpixel_snap(v1[0][1] + y_offset - pixel_offset) + fixed_width/2;
469 }
470 else {
471 const float dxdy = dx / dy;
472
473 /* Y-MAJOR LINE */
474 x1diff = v1[0][0] - floorf(v1[0][0]) - 0.5f;
475 y1diff = v1[0][1] - floorf(v1[0][1]) - 0.5f;
476 x2diff = v2[0][0] - floorf(v2[0][0]) - 0.5f;
477 y2diff = v2[0][1] - floorf(v2[0][1]) - 0.5f;
478
479 if (x2diff == -0.5 && dx < 0) {
480 x2diff = 0.5;
481 }
482
483 /*
484 * Diamond exit rule test for starting point
485 */
486 if (fabsf(x1diff) + fabsf(y1diff) < 0.5) {
487 draw_start = true;
488 }
489 else if (sign(-y1diff) == sign(dy)) {
490 draw_start = false;
491 }
492 else if (sign(x1diff) != sign(-dx)) {
493 draw_start = true;
494 }
495 else {
496 /* do intersection test */
497 float xintersect = fracf(v1[0][0]) + y1diff * dxdy;
498 draw_start = (xintersect < 1.0 && xintersect > 0.0);
499 }
500
501 /*
502 * Diamond exit rule test for ending point
503 */
504 if (fabsf(x2diff) + fabsf(y2diff) < 0.5) {
505 draw_end = false;
506 }
507 else if (sign(-y2diff) != sign(dy) ) {
508 draw_end = false;
509 }
510 else if (sign(x2diff) == sign(-dx) ) {
511 draw_end = true;
512 }
513 else {
514 /* do intersection test */
515 float xintersect = fracf(v2[0][0]) + y2diff * dxdy;
516 draw_end = (xintersect < 1.0 && xintersect >= 0.0);
517 }
518
519 /* Are we already drawing start/end?
520 */
521 bool will_draw_start = sign(y1diff) == sign(dy);
522 bool will_draw_end = (sign(-y2diff) == sign(dy)) || y2diff==0;
523
524 /* interpolate using the preferred wide-lines formula */
525 info.dx = 0;
526 info.dy *= 1 + dxdy * dxdy;
527
528 if (dy > 0) {
529 /* if v2 is on top of v1, swap pointers */
530 const float (*temp)[4] = v1;
531 v1 = v2;
532 v2 = temp;
533 dx = -dx;
534 dy = -dy;
535
536 /* Otherwise shift planes appropriately */
537 if (will_draw_start != draw_start) {
538 y_offset_end = -y1diff + 0.5;
539 x_offset_end = y_offset_end * dxdy;
540 }
541 if (will_draw_end != draw_end) {
542 y_offset = -y2diff + 0.5;
543 x_offset = y_offset * dxdy;
544 }
545 }
546 else {
547 /* Otherwise shift planes appropriately */
548 if (will_draw_start != draw_start) {
549 y_offset = -y1diff - 0.5;
550 x_offset = y_offset * dxdy;
551 }
552 if (will_draw_end != draw_end) {
553 y_offset_end = -y2diff - 0.5;
554 x_offset_end = y_offset_end * dxdy;
555 }
556 }
557
558 /* x/y positions in fixed point */
559 x[0] = subpixel_snap(v1[0][0] + x_offset - pixel_offset) - fixed_width/2;
560 x[1] = subpixel_snap(v2[0][0] + x_offset_end - pixel_offset) - fixed_width/2;
561 x[2] = subpixel_snap(v2[0][0] + x_offset_end - pixel_offset) + fixed_width/2;
562 x[3] = subpixel_snap(v1[0][0] + x_offset - pixel_offset) + fixed_width/2;
563
564 y[0] = subpixel_snap(v1[0][1] + y_offset - pixel_offset);
565 y[1] = subpixel_snap(v2[0][1] + y_offset_end - pixel_offset);
566 y[2] = subpixel_snap(v2[0][1] + y_offset_end - pixel_offset);
567 y[3] = subpixel_snap(v1[0][1] + y_offset - pixel_offset);
568 }
569 }
570
571 /* Bounding rectangle (in pixels) */
572 {
573 /* Yes this is necessary to accurately calculate bounding boxes
574 * with the two fill-conventions we support. GL (normally) ends
575 * up needing a bottom-left fill convention, which requires
576 * slightly different rounding.
577 */
578 int adj = (setup->bottom_edge_rule != 0) ? 1 : 0;
579
580 bbox.x0 = (MIN4(x[0], x[1], x[2], x[3]) + (FIXED_ONE-1)) >> FIXED_ORDER;
581 bbox.x1 = (MAX4(x[0], x[1], x[2], x[3]) + (FIXED_ONE-1)) >> FIXED_ORDER;
582 bbox.y0 = (MIN4(y[0], y[1], y[2], y[3]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER;
583 bbox.y1 = (MAX4(y[0], y[1], y[2], y[3]) + (FIXED_ONE-1) + adj) >> FIXED_ORDER;
584
585 /* Inclusive coordinates:
586 */
587 bbox.x1--;
588 bbox.y1--;
589 }
590
591 if (!u_rect_test_intersection(&setup->draw_regions[viewport_index], &bbox)) {
592 if (0) debug_printf("no intersection\n");
593 LP_COUNT(nr_culled_tris);
594 return TRUE;
595 }
596
597 int max_szorig = ((bbox.x1 - (bbox.x0 & ~3)) |
598 (bbox.y1 - (bbox.y0 & ~3)));
599 boolean use_32bits = max_szorig <= MAX_FIXED_LENGTH32;
600 bboxpos = bbox;
601
602 /* Can safely discard negative regions:
603 */
604 bboxpos.x0 = MAX2(bboxpos.x0, 0);
605 bboxpos.y0 = MAX2(bboxpos.y0, 0);
606
607 nr_planes = 4;
608 /*
609 * Determine how many scissor planes we need, that is drop scissor
610 * edges if the bounding box of the tri is fully inside that edge.
611 */
612 scissor = &setup->draw_regions[viewport_index];
613 scissor_planes_needed(s_planes, &bboxpos, scissor);
614 nr_planes += s_planes[0] + s_planes[1] + s_planes[2] + s_planes[3];
615
616 line = lp_setup_alloc_triangle(scene,
617 key->num_inputs,
618 nr_planes,
619 &tri_bytes);
620 if (!line)
621 return FALSE;
622
623 #ifdef DEBUG
624 line->v[0][0] = v1[0][0];
625 line->v[1][0] = v2[0][0];
626 line->v[0][1] = v1[0][1];
627 line->v[1][1] = v2[0][1];
628 #endif
629
630 LP_COUNT(nr_tris);
631
632 /* calculate the deltas */
633 plane = GET_PLANES(line);
634 plane[0].dcdy = x[0] - x[1];
635 plane[1].dcdy = x[1] - x[2];
636 plane[2].dcdy = x[2] - x[3];
637 plane[3].dcdy = x[3] - x[0];
638
639 plane[0].dcdx = y[0] - y[1];
640 plane[1].dcdx = y[1] - y[2];
641 plane[2].dcdx = y[2] - y[3];
642 plane[3].dcdx = y[3] - y[0];
643
644 if (draw_will_inject_frontface(lp_context->draw) &&
645 setup->face_slot > 0) {
646 line->inputs.frontfacing = v1[setup->face_slot][0];
647 } else {
648 line->inputs.frontfacing = TRUE;
649 }
650
651 /* Setup parameter interpolants:
652 */
653 info.a0 = GET_A0(&line->inputs);
654 info.dadx = GET_DADX(&line->inputs);
655 info.dady = GET_DADY(&line->inputs);
656 info.frontfacing = line->inputs.frontfacing;
657 setup_line_coefficients(setup, &info);
658
659 line->inputs.disable = FALSE;
660 line->inputs.layer = layer;
661 line->inputs.viewport_index = viewport_index;
662 line->inputs.view_index = setup->view_index;
663
664 /*
665 * XXX: this code is mostly identical to the one in lp_setup_tri, except it
666 * uses 4 planes instead of 3. Could share the code (including the sse
667 * assembly, in fact we'd get the 4th plane for free).
668 * The only difference apart from storing the 4th plane would be some
669 * different shuffle for calculating dcdx/dcdy.
670 */
671 for (i = 0; i < 4; i++) {
672
673 /* half-edge constants, will be iterated over the whole render
674 * target.
675 */
676 plane[i].c = IMUL64(plane[i].dcdx, x[i]) - IMUL64(plane[i].dcdy, y[i]);
677
678 /* correct for top-left vs. bottom-left fill convention.
679 */
680 if (plane[i].dcdx < 0) {
681 /* both fill conventions want this - adjust for left edges */
682 plane[i].c++;
683 }
684 else if (plane[i].dcdx == 0) {
685 if (setup->bottom_edge_rule == 0) {
686 /* correct for top-left fill convention:
687 */
688 if (plane[i].dcdy > 0) plane[i].c++;
689 }
690 else {
691 /* correct for bottom-left fill convention:
692 */
693 if (plane[i].dcdy < 0) plane[i].c++;
694 }
695 }
696
697 plane[i].dcdx *= FIXED_ONE;
698 plane[i].dcdy *= FIXED_ONE;
699
700 /* find trivial reject offsets for each edge for a single-pixel
701 * sized block. These will be scaled up at each recursive level to
702 * match the active blocksize. Scaling in this way works best if
703 * the blocks are square.
704 */
705 plane[i].eo = 0;
706 if (plane[i].dcdx < 0) plane[i].eo -= plane[i].dcdx;
707 if (plane[i].dcdy > 0) plane[i].eo += plane[i].dcdy;
708 }
709
710 if (nr_planes > 4) {
711 lp_setup_add_scissor_planes(scissor, &plane[4], s_planes, setup->multisample);
712 }
713
714 return lp_setup_bin_triangle(setup, line, use_32bits, false, &bboxpos, nr_planes, viewport_index);
715 }
716
717
lp_setup_line_discard(struct lp_setup_context * setup,const float (* v0)[4],const float (* v1)[4])718 static void lp_setup_line_discard(struct lp_setup_context *setup,
719 const float (*v0)[4],
720 const float (*v1)[4])
721 {
722 }
723
lp_setup_line(struct lp_setup_context * setup,const float (* v0)[4],const float (* v1)[4])724 static void lp_setup_line(struct lp_setup_context *setup,
725 const float (*v0)[4],
726 const float (*v1)[4])
727 {
728 if (!try_setup_line(setup, v0, v1)) {
729 if (!lp_setup_flush_and_restart(setup))
730 return;
731
732 if (!try_setup_line(setup, v0, v1))
733 return;
734 }
735 }
736
737
lp_setup_choose_line(struct lp_setup_context * setup)738 void lp_setup_choose_line(struct lp_setup_context *setup)
739 {
740 if (setup->rasterizer_discard) {
741 setup->line = lp_setup_line_discard;
742 } else {
743 setup->line = lp_setup_line;
744 }
745 }
746
747
748