1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
26 **************************************************************************/
29 * Triangle rendering within a tile.
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_format.h"
34 #include "util/u_math.h"
35 #include "spu_colorpack.h"
37 #include "spu_shuffle.h"
38 #include "spu_texture.h"
43 /** Masks are uint[4] vectors with each element being 0 or 0xffffffff */
44 typedef vector unsigned int mask_t;
49 * Simplified types taken from other parts of Gallium
51 struct vertex_header {
59 #define CEILF(X) ((float) (int) ((X) + 0.99999f))
62 #define QUAD_TOP_LEFT 0
63 #define QUAD_TOP_RIGHT 1
64 #define QUAD_BOTTOM_LEFT 2
65 #define QUAD_BOTTOM_RIGHT 3
66 #define MASK_TOP_LEFT (1 << QUAD_TOP_LEFT)
67 #define MASK_TOP_RIGHT (1 << QUAD_TOP_RIGHT)
68 #define MASK_BOTTOM_LEFT (1 << QUAD_BOTTOM_LEFT)
69 #define MASK_BOTTOM_RIGHT (1 << QUAD_BOTTOM_RIGHT)
87 float dx; /**< X(v1) - X(v0), used only during setup */
88 float dy; /**< Y(v1) - Y(v0), used only during setup */
90 vec_float4 ds; /**< vector accessor for dx and dy */
92 float dxdy; /**< dx/dy */
93 float sx, sy; /**< first sample point coord */
94 int lines; /**< number of lines on this edge */
107 * Triangle setup info (derived from draw_stage).
108 * Also used for line drawing (taking some liberties).
112 /* Vertices are just an array of floats making up each attribute in
113 * turn. Currently fixed at 4 floats, but should change in time.
114 * Codegen will help cope with this.
118 const struct vertex_header *vmin;
119 const struct vertex_header *vmid;
120 const struct vertex_header *vmax;
121 const struct vertex_header *vprovoke;
123 qword vertex_headers;
130 float oneOverArea; /* XXX maybe make into vector? */
134 uint tx, ty; /**< position of current tile (x, y) */
146 struct interp_coef coef[PIPE_MAX_SHADER_INPUTS];
149 vec_int4 quad; /**< [0] = row0, [1] = row1; {left[0],left[1],right[0],right[1]} */
152 unsigned mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
157 static struct setup_stage setup;
160 static INLINE vector float
161 splatx(vector float v)
163 return spu_splats(spu_extract(v, CHAN0));
166 static INLINE vector float
167 splaty(vector float v)
169 return spu_splats(spu_extract(v, CHAN1));
172 static INLINE vector float
173 splatz(vector float v)
175 return spu_splats(spu_extract(v, CHAN2));
178 static INLINE vector float
179 splatw(vector float v)
181 return spu_splats(spu_extract(v, CHAN3));
186 * Setup fragment shader inputs by evaluating triangle's vertex
187 * attribute coefficient info.
188 * \param x quad x pos
189 * \param y quad y pos
190 * \param fragZ returns quad Z values
191 * \param fragInputs returns fragment program inputs
192 * Note: this code could be incorporated into the fragment program
193 * itself to avoid the loop and switch.
196 eval_inputs(float x, float y, vector float *fragZ, vector float fragInputs[])
198 static const vector float deltaX = (const vector float) {0, 1, 0, 1};
199 static const vector float deltaY = (const vector float) {0, 0, 1, 1};
201 const uint posSlot = 0;
202 const vector float pos = setup.coef[posSlot].a0;
203 const vector float dposdx = setup.coef[posSlot].dadx;
204 const vector float dposdy = setup.coef[posSlot].dady;
205 const vector float fragX = spu_splats(x) + deltaX;
206 const vector float fragY = spu_splats(y) + deltaY;
207 vector float fragW, wInv;
210 *fragZ = splatz(pos) + fragX * splatz(dposdx) + fragY * splatz(dposdy);
211 fragW = splatw(pos) + fragX * splatw(dposdx) + fragY * splatw(dposdy);
212 wInv = spu_re(fragW); /* 1 / w */
214 /* loop over fragment program inputs */
215 for (i = 0; i < spu.vertex_info.num_attribs; i++) {
217 enum interp_mode interp = spu.vertex_info.attrib[attr].interp_mode;
220 vector float a0 = setup.coef[attr].a0;
221 vector float r0 = splatx(a0);
222 vector float r1 = splaty(a0);
223 vector float r2 = splatz(a0);
224 vector float r3 = splatw(a0);
226 if (interp == INTERP_LINEAR || interp == INTERP_PERSPECTIVE) {
228 vector float dadx = setup.coef[attr].dadx;
229 vector float dady = setup.coef[attr].dady;
230 /* Use SPU intrinsics here to get slightly better code.
231 * originally: r0 += fragX * splatx(dadx) + fragY * splatx(dady);
233 r0 = spu_madd(fragX, splatx(dadx), spu_madd(fragY, splatx(dady), r0));
234 r1 = spu_madd(fragX, splaty(dadx), spu_madd(fragY, splaty(dady), r1));
235 r2 = spu_madd(fragX, splatz(dadx), spu_madd(fragY, splatz(dady), r2));
236 r3 = spu_madd(fragX, splatw(dadx), spu_madd(fragY, splatw(dady), r3));
237 if (interp == INTERP_PERSPECTIVE) {
238 /* perspective term */
245 fragInputs[CHAN0] = r0;
246 fragInputs[CHAN1] = r1;
247 fragInputs[CHAN2] = r2;
248 fragInputs[CHAN3] = r3;
255 * Emit a quad (pass to next stage). No clipping is done.
256 * Note: about 1/5 to 1/7 of the time, mask is zero and this function
257 * should be skipped. But adding the test for that slows things down
261 emit_quad( int x, int y, mask_t mask)
263 /* If any bits in mask are set... */
264 if (spu_extract(spu_orx(mask), 0)) {
265 const int ix = x - setup.cliprect_minx;
266 const int iy = y - setup.cliprect_miny;
268 spu.cur_ctile_status = TILE_STATUS_DIRTY;
269 spu.cur_ztile_status = TILE_STATUS_DIRTY;
273 * Run fragment shader, execute per-fragment ops, update fb/tile.
275 vector float inputs[4*4], outputs[2*4];
276 vector unsigned int kill_mask;
279 eval_inputs((float) x, (float) y, &fragZ, inputs);
281 ASSERT(spu.fragment_program);
282 ASSERT(spu.fragment_ops);
284 /* Execute the current fragment program */
285 kill_mask = spu.fragment_program(inputs, outputs, spu.constants);
287 mask = spu_andc(mask, kill_mask);
289 /* Execute per-fragment/quad operations, including:
290 * alpha test, z test, stencil test, blend and framebuffer writing.
291 * Note that there are two different fragment operations functions
292 * that can be called, one for front-facing fragments, and one
293 * for back-facing fragments. (Often the two are the same;
294 * but in some cases, like two-sided stenciling, they can be
295 * very different.) So choose the correct function depending
296 * on the calculated facing.
298 spu.fragment_ops[setup.facing](ix, iy, &spu.ctile, &spu.ztile,
311 * Given an X or Y coordinate, return the block/quad coordinate that it
322 * Render a horizontal span of quads
327 int minleft, maxright;
329 const int l0 = spu_extract(setup.span.quad, 0);
330 const int l1 = spu_extract(setup.span.quad, 1);
331 const int r0 = spu_extract(setup.span.quad, 2);
332 const int r1 = spu_extract(setup.span.quad, 3);
334 switch (setup.span.y_flags) {
336 /* both odd and even lines written (both quad rows) */
337 minleft = MIN2(l0, l1);
338 maxright = MAX2(r0, r1);
342 /* only even line written (quad top row) */
348 /* only odd line written (quad bottom row) */
357 /* OK, we're very likely to need the tile data now.
358 * clear or finish waiting if needed.
360 if (spu.cur_ctile_status == TILE_STATUS_GETTING) {
361 /* wait for mfc_get() to complete */
362 //printf("SPU: %u: waiting for ctile\n", spu.init.id);
363 wait_on_mask(1 << TAG_READ_TILE_COLOR);
364 spu.cur_ctile_status = TILE_STATUS_CLEAN;
366 else if (spu.cur_ctile_status == TILE_STATUS_CLEAR) {
367 //printf("SPU %u: clearing C tile %u, %u\n", spu.init.id, setup.tx, setup.ty);
368 clear_c_tile(&spu.ctile);
369 spu.cur_ctile_status = TILE_STATUS_DIRTY;
371 ASSERT(spu.cur_ctile_status != TILE_STATUS_DEFINED);
373 if (spu.read_depth_stencil) {
374 if (spu.cur_ztile_status == TILE_STATUS_GETTING) {
375 /* wait for mfc_get() to complete */
376 //printf("SPU: %u: waiting for ztile\n", spu.init.id);
377 wait_on_mask(1 << TAG_READ_TILE_Z);
378 spu.cur_ztile_status = TILE_STATUS_CLEAN;
380 else if (spu.cur_ztile_status == TILE_STATUS_CLEAR) {
381 //printf("SPU %u: clearing Z tile %u, %u\n", spu.init.id, setup.tx, setup.ty);
382 clear_z_tile(&spu.ztile);
383 spu.cur_ztile_status = TILE_STATUS_DIRTY;
385 ASSERT(spu.cur_ztile_status != TILE_STATUS_DEFINED);
388 /* XXX this loop could be moved into the above switch cases... */
390 /* Setup for mask calculation */
391 const vec_int4 quad_LlRr = setup.span.quad;
392 const vec_int4 quad_RrLl = spu_rlqwbyte(quad_LlRr, 8);
393 const vec_int4 quad_LLll = spu_shuffle(quad_LlRr, quad_LlRr, SHUFFLE4(A,A,B,B));
394 const vec_int4 quad_RRrr = spu_shuffle(quad_RrLl, quad_RrLl, SHUFFLE4(A,A,B,B));
396 const vec_int4 twos = spu_splats(2);
398 const int x = block(minleft);
399 vec_int4 xs = {x, x+1, x, x+1};
401 for (; spu_extract(xs, 0) <= block(maxright); xs += twos) {
403 * Computes mask to indicate which pixels in the 2x2 quad are actually
404 * inside the triangle's bounds.
407 /* Calculate ({x,x+1,x,x+1} >= {l[0],l[0],l[1],l[1]}) */
408 const mask_t gt_LLll_xs = spu_cmpgt(quad_LLll, xs);
409 const mask_t gte_xs_LLll = spu_nand(gt_LLll_xs, gt_LLll_xs);
411 /* Calculate ({r[0],r[0],r[1],r[1]} > {x,x+1,x,x+1}) */
412 const mask_t gt_RRrr_xs = spu_cmpgt(quad_RRrr, xs);
414 /* Combine results to create mask */
415 const mask_t mask = spu_and(gte_xs_LLll, gt_RRrr_xs);
417 emit_quad(spu_extract(xs, 0), setup.span.y, mask);
421 setup.span.y_flags = 0;
422 /* Zero right elements */
423 setup.span.quad = spu_shuffle(setup.span.quad, setup.span.quad, SHUFFLE4(A,B,0,0));
429 print_vertex(const struct vertex_header *v)
432 fprintf(stderr, " Vertex: (%p)\n", v);
433 for (i = 0; i < spu.vertex_info.num_attribs; i++) {
434 fprintf(stderr, " %d: %f %f %f %f\n", i,
435 spu_extract(v->data[i], 0),
436 spu_extract(v->data[i], 1),
437 spu_extract(v->data[i], 2),
438 spu_extract(v->data[i], 3));
443 /* Returns the minimum of each slot of two vec_float4s as qwords.
444 * i.e. return[n] = min(q0[n],q1[n]);
447 minfq(qword q0, qword q1)
449 const qword q0q1m = si_fcgt(q0, q1);
450 return si_selb(q0, q1, q0q1m);
453 /* Returns the minimum of each slot of three vec_float4s as qwords.
454 * i.e. return[n] = min(q0[n],q1[n],q2[n]);
457 min3fq(qword q0, qword q1, qword q2)
459 return minfq(minfq(q0, q1), q2);
462 /* Returns the maximum of each slot of two vec_float4s as qwords.
463 * i.e. return[n] = min(q0[n],q1[n],q2[n]);
466 maxfq(qword q0, qword q1) {
467 const qword q0q1m = si_fcgt(q0, q1);
468 return si_selb(q1, q0, q0q1m);
471 /* Returns the maximum of each slot of three vec_float4s as qwords.
472 * i.e. return[n] = min(q0[n],q1[n],q2[n]);
475 max3fq(qword q0, qword q1, qword q2) {
476 return maxfq(maxfq(q0, q1), q2);
480 * Sort vertices from top to bottom.
481 * Compute area and determine front vs. back facing.
482 * Do coarse clip test against tile bounds
483 * \return FALSE if tri is totally outside tile, TRUE otherwise
486 setup_sort_vertices(const qword vs)
491 if (spu.init.id==0) {
492 fprintf(stderr, "SPU %u: Triangle:\n", spu.init.id);
500 /* Load the float values for various processing... */
501 const qword f0 = (qword)(((const struct vertex_header*)si_to_ptr(vs))->data[0]);
502 const qword f1 = (qword)(((const struct vertex_header*)si_to_ptr(si_rotqbyi(vs, 4)))->data[0]);
503 const qword f2 = (qword)(((const struct vertex_header*)si_to_ptr(si_rotqbyi(vs, 8)))->data[0]);
505 /* Check if triangle is completely outside the tile bounds
506 * Find the min and max x and y positions of the three poits */
507 const qword minf = min3fq(f0, f1, f2);
508 const qword maxf = max3fq(f0, f1, f2);
510 /* Compare min and max against cliprect vals */
511 const qword maxsmins = si_shufb(maxf, minf, SHUFB4(A,B,a,b));
512 const qword outside = si_fcgt(maxsmins, si_csflt(setup.cliprect, 0));
514 /* Use a little magic to work out of the tri is visible or not */
515 if(si_to_uint(si_xori(si_gb(outside), 0xc))) return FALSE;
517 /* determine bottom to top order of vertices */
518 /* A table of shuffle patterns for putting vertex_header pointers into
519 correct order. Quite magical. */
520 const qword sort_order_patterns[] = {
528 /* Collate y values into two vectors for comparison.
529 Using only one shuffle constant! ;) */
530 const qword y_02_ = si_shufb(f0, f2, SHUFB4(0,B,b,C));
531 const qword y_10_ = si_shufb(f1, f0, SHUFB4(0,B,b,C));
532 const qword y_012 = si_shufb(y_02_, f1, SHUFB4(0,B,b,C));
533 const qword y_120 = si_shufb(y_10_, f2, SHUFB4(0,B,b,C));
535 /* Perform comparison: {y0,y1,y2} > {y1,y2,y0} */
536 const qword compare = si_fcgt(y_012, y_120);
537 /* Compress the result of the comparison into 4 bits */
538 const qword gather = si_gb(compare);
539 /* Subtract one to attain the index into the LUT. Magical. */
540 const unsigned int index = si_to_uint(gather) - 1;
542 /* Load the appropriate pattern and construct the desired vector. */
543 setup.vertex_headers = si_shufb(vs, vs, sort_order_patterns[index]);
545 /* Using the result of the comparison, set sign.
547 sign = ((si_to_uint(si_cntb(gather)) == 2) ? 1.0f : -1.0f);
550 setup.ebot.ds = spu_sub(setup.vmid->data[0], setup.vmin->data[0]);
551 setup.emaj.ds = spu_sub(setup.vmax->data[0], setup.vmin->data[0]);
552 setup.etop.ds = spu_sub(setup.vmax->data[0], setup.vmid->data[0]);
555 * Compute triangle's area. Use 1/area to compute partial
556 * derivatives of attributes later.
558 area = setup.emaj.dx * setup.ebot.dy - setup.ebot.dx * setup.emaj.dy;
560 setup.oneOverArea = 1.0f / area;
562 /* The product of area * sign indicates front/back orientation (0/1).
563 * Just in case someone gets the bright idea of switching the front
564 * and back constants without noticing that we're assuming their
565 * values in this operation, also assert that the values are
566 * what we think they are.
568 ASSERT(CELL_FACING_FRONT == 0);
569 ASSERT(CELL_FACING_BACK == 1);
570 setup.facing = (area * sign > 0.0f)
571 ^ (!spu.rasterizer.front_ccw);
578 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
579 * The value value comes from vertex->data[slot].
580 * The result will be put into setup.coef[slot].a0.
581 * \param slot which attribute slot
584 const_coeff4(uint slot)
586 setup.coef[slot].dadx = (vector float) {0.0, 0.0, 0.0, 0.0};
587 setup.coef[slot].dady = (vector float) {0.0, 0.0, 0.0, 0.0};
588 setup.coef[slot].a0 = setup.vprovoke->data[slot];
593 * As above, but interp setup all four vector components.
596 tri_linear_coeff4(uint slot)
598 const vector float vmin_d = setup.vmin->data[slot];
599 const vector float vmid_d = setup.vmid->data[slot];
600 const vector float vmax_d = setup.vmax->data[slot];
601 const vector float xxxx = spu_splats(spu_extract(setup.vmin->data[0], 0) - 0.5f);
602 const vector float yyyy = spu_splats(spu_extract(setup.vmin->data[0], 1) - 0.5f);
604 vector float botda = vmid_d - vmin_d;
605 vector float majda = vmax_d - vmin_d;
607 vector float a = spu_sub(spu_mul(spu_splats(setup.ebot.dy), majda),
608 spu_mul(botda, spu_splats(setup.emaj.dy)));
609 vector float b = spu_sub(spu_mul(spu_splats(setup.emaj.dx), botda),
610 spu_mul(majda, spu_splats(setup.ebot.dx)));
612 setup.coef[slot].dadx = spu_mul(a, spu_splats(setup.oneOverArea));
613 setup.coef[slot].dady = spu_mul(b, spu_splats(setup.oneOverArea));
615 vector float tempx = spu_mul(setup.coef[slot].dadx, xxxx);
616 vector float tempy = spu_mul(setup.coef[slot].dady, yyyy);
618 setup.coef[slot].a0 = spu_sub(vmin_d, spu_add(tempx, tempy));
623 * Compute a0, dadx and dady for a perspective-corrected interpolant,
625 * We basically multiply the vertex value by 1/w before computing
626 * the plane coefficients (a0, dadx, dady).
627 * Later, when we compute the value at a particular fragment position we'll
628 * divide the interpolated value by the interpolated W at that fragment.
631 tri_persp_coeff4(uint slot)
633 const vector float xxxx = spu_splats(spu_extract(setup.vmin->data[0], 0) - 0.5f);
634 const vector float yyyy = spu_splats(spu_extract(setup.vmin->data[0], 1) - 0.5f);
636 const vector float vmin_w = spu_splats(spu_extract(setup.vmin->data[0], 3));
637 const vector float vmid_w = spu_splats(spu_extract(setup.vmid->data[0], 3));
638 const vector float vmax_w = spu_splats(spu_extract(setup.vmax->data[0], 3));
640 vector float vmin_d = setup.vmin->data[slot];
641 vector float vmid_d = setup.vmid->data[slot];
642 vector float vmax_d = setup.vmax->data[slot];
644 vmin_d = spu_mul(vmin_d, vmin_w);
645 vmid_d = spu_mul(vmid_d, vmid_w);
646 vmax_d = spu_mul(vmax_d, vmax_w);
648 vector float botda = vmid_d - vmin_d;
649 vector float majda = vmax_d - vmin_d;
651 vector float a = spu_sub(spu_mul(spu_splats(setup.ebot.dy), majda),
652 spu_mul(botda, spu_splats(setup.emaj.dy)));
653 vector float b = spu_sub(spu_mul(spu_splats(setup.emaj.dx), botda),
654 spu_mul(majda, spu_splats(setup.ebot.dx)));
656 setup.coef[slot].dadx = spu_mul(a, spu_splats(setup.oneOverArea));
657 setup.coef[slot].dady = spu_mul(b, spu_splats(setup.oneOverArea));
659 vector float tempx = spu_mul(setup.coef[slot].dadx, xxxx);
660 vector float tempy = spu_mul(setup.coef[slot].dady, yyyy);
662 setup.coef[slot].a0 = spu_sub(vmin_d, spu_add(tempx, tempy));
668 * Compute the setup.coef[] array dadx, dady, a0 values.
669 * Must be called after setup.vmin,vmid,vmax,vprovoke are initialized.
672 setup_tri_coefficients(void)
676 for (i = 0; i < spu.vertex_info.num_attribs; i++) {
677 switch (spu.vertex_info.attrib[i].interp_mode) {
680 case INTERP_CONSTANT:
686 tri_linear_coeff4(i);
688 case INTERP_PERSPECTIVE:
699 setup_tri_edges(void)
701 float vmin_x = spu_extract(setup.vmin->data[0], 0) + 0.5f;
702 float vmid_x = spu_extract(setup.vmid->data[0], 0) + 0.5f;
704 float vmin_y = spu_extract(setup.vmin->data[0], 1) - 0.5f;
705 float vmid_y = spu_extract(setup.vmid->data[0], 1) - 0.5f;
706 float vmax_y = spu_extract(setup.vmax->data[0], 1) - 0.5f;
708 setup.emaj.sy = CEILF(vmin_y);
709 setup.emaj.lines = (int) CEILF(vmax_y - setup.emaj.sy);
710 setup.emaj.dxdy = setup.emaj.dx / setup.emaj.dy;
711 setup.emaj.sx = vmin_x + (setup.emaj.sy - vmin_y) * setup.emaj.dxdy;
713 setup.etop.sy = CEILF(vmid_y);
714 setup.etop.lines = (int) CEILF(vmax_y - setup.etop.sy);
715 setup.etop.dxdy = setup.etop.dx / setup.etop.dy;
716 setup.etop.sx = vmid_x + (setup.etop.sy - vmid_y) * setup.etop.dxdy;
718 setup.ebot.sy = CEILF(vmin_y);
719 setup.ebot.lines = (int) CEILF(vmid_y - setup.ebot.sy);
720 setup.ebot.dxdy = setup.ebot.dx / setup.ebot.dy;
721 setup.ebot.sx = vmin_x + (setup.ebot.sy - vmin_y) * setup.ebot.dxdy;
726 * Render the upper or lower half of a triangle.
727 * Scissoring/cliprect is applied here too.
730 subtriangle(struct edge *eleft, struct edge *eright, unsigned lines)
732 const int minx = setup.cliprect_minx;
733 const int maxx = setup.cliprect_maxx;
734 const int miny = setup.cliprect_miny;
735 const int maxy = setup.cliprect_maxy;
736 int y, start_y, finish_y;
737 int sy = (int)eleft->sy;
739 ASSERT((int)eleft->sy == (int) eright->sy);
741 /* clip top/bottom */
743 finish_y = sy + lines;
755 printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
758 for (y = start_y; y < finish_y; y++) {
760 /* avoid accumulating adds as floats don't have the precision to
761 * accurately iterate large triangle edges that way. luckily we
762 * can just multiply these days.
764 * this is all drowned out by the attribute interpolation anyway.
766 int left = (int)(eleft->sx + y * eleft->dxdy);
767 int right = (int)(eright->sx + y * eright->dxdy);
769 /* clip left/right */
777 if (block(_y) != setup.span.y) {
779 setup.span.y = block(_y);
783 vec_int4 quad_LlRr = {left, left, right, right};
784 /* Store left and right in 0 or 1 row of quad based on offset */
785 setup.span.quad = spu_sel(quad_LlRr, setup.span.quad, spu_maskw(5<<offset));
786 setup.span.y_flags |= 1<<offset;
791 /* save the values so that emaj can be restarted:
793 eleft->sx += lines * eleft->dxdy;
794 eright->sx += lines * eright->dxdy;
801 * Draw triangle into tile at (tx, ty) (tile coords)
802 * The tile data should have already been fetched.
805 tri_draw(const qword vs,
811 /* set clipping bounds to tile bounds */
812 const qword clipbase = (qword)((vec_uint4){tx, ty});
813 const qword clipmin = si_mpyui(clipbase, TILE_SIZE);
814 const qword clipmax = si_ai(clipmin, TILE_SIZE);
815 setup.cliprect = si_shufb(clipmin, clipmax, SHUFB4(A,B,a,b));
817 if(!setup_sort_vertices(vs)) {
818 return FALSE; /* totally clipped */
821 setup_tri_coefficients();
825 setup.span.y_flags = 0;
826 /* Zero right elements */
827 setup.span.quad = spu_shuffle(setup.span.quad, setup.span.quad, SHUFFLE4(A,B,0,0));
829 if (setup.oneOverArea < 0.0) {
831 subtriangle( &setup.emaj, &setup.ebot, setup.ebot.lines );
832 subtriangle( &setup.emaj, &setup.etop, setup.etop.lines );
836 subtriangle( &setup.ebot, &setup.emaj, setup.ebot.lines );
837 subtriangle( &setup.etop, &setup.emaj, setup.etop.lines );