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 * \brief Primitive rasterization/rendering (points, lines, triangles)
31 * \author Keith Whitwell <keith@tungstengraphics.com>
35 #include "sp_context.h"
36 #include "sp_prim_setup.h"
38 #include "sp_quad_pipe.h"
41 #include "draw/draw_context.h"
42 #include "draw/draw_private.h"
43 #include "draw/draw_vertex.h"
44 #include "pipe/p_shader_tokens.h"
45 #include "pipe/p_thread.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
57 float dx
; /**< X(v1) - X(v0), used only during setup */
58 float dy
; /**< Y(v1) - Y(v0), used only during setup */
59 float dxdy
; /**< dx/dy */
60 float sx
, sy
; /**< first sample point coord */
61 int lines
; /**< number of lines on this edge */
64 #if SP_NUM_QUAD_THREADS > 1
66 /* Set to 1 if you want other threads to be instantly
67 * notified of pending jobs.
69 #define INSTANT_NOTEMPTY_NOTIFY 0
73 struct setup_context
*setup
;
80 typedef void (* quad_job_routine
)( struct setup_context
*setup
, uint thread
, struct quad_job
*job
);
84 struct quad_header_input input
;
85 struct quad_header_inout inout
;
86 quad_job_routine routine
;
89 #define NUM_QUAD_JOBS 64
93 struct quad_job jobs
[NUM_QUAD_JOBS
];
97 pipe_condvar que_notfull_condvar
;
98 pipe_condvar que_notempty_condvar
;
101 pipe_condvar que_done_condvar
;
105 add_quad_job( struct quad_job_que
*que
, struct quad_header
*quad
, quad_job_routine routine
)
107 #if INSTANT_NOTEMPTY_NOTIFY
111 /* Wait for empty slot, see if the que is empty.
113 pipe_mutex_lock( que
->que_mutex
);
114 while ((que
->last
+ 1) % NUM_QUAD_JOBS
== que
->first
) {
115 #if !INSTANT_NOTEMPTY_NOTIFY
116 pipe_condvar_broadcast( que
->que_notempty_condvar
);
118 pipe_condvar_wait( que
->que_notfull_condvar
, que
->que_mutex
);
120 #if INSTANT_NOTEMPTY_NOTIFY
121 empty
= que
->last
== que
->first
;
124 pipe_mutex_unlock( que
->que_mutex
);
128 que
->jobs
[que
->last
].input
= quad
->input
;
129 que
->jobs
[que
->last
].inout
= quad
->inout
;
130 que
->jobs
[que
->last
].routine
= routine
;
131 que
->last
= (que
->last
+ 1) % NUM_QUAD_JOBS
;
133 #if INSTANT_NOTEMPTY_NOTIFY
134 /* If the que was empty, notify consumers there's a job to be done.
137 pipe_mutex_lock( que
->que_mutex
);
138 pipe_condvar_broadcast( que
->que_notempty_condvar
);
139 pipe_mutex_unlock( que
->que_mutex
);
147 * Triangle setup info (derived from draw_stage).
148 * Also used for line drawing (taking some liberties).
150 struct setup_context
{
151 struct softpipe_context
*softpipe
;
153 /* Vertices are just an array of floats making up each attribute in
154 * turn. Currently fixed at 4 floats, but should change in time.
155 * Codegen will help cope with this.
157 const float (*vmax
)[4];
158 const float (*vmid
)[4];
159 const float (*vmin
)[4];
160 const float (*vprovoke
)[4];
168 struct tgsi_interp_coef coef
[PIPE_MAX_SHADER_INPUTS
];
169 struct tgsi_interp_coef posCoef
; /* For Z, W */
170 struct quad_header quad
;
172 #if SP_NUM_QUAD_THREADS > 1
173 struct quad_job_que que
;
174 struct thread_info threads
[SP_NUM_QUAD_THREADS
];
178 int left
[2]; /**< [0] = row0, [1] = row1 */
182 unsigned mask
; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
186 uint numFragsEmitted
; /**< per primitive */
187 uint numFragsWritten
; /**< per primitive */
190 unsigned winding
; /* which winding to cull */
193 #if SP_NUM_QUAD_THREADS > 1
195 static PIPE_THREAD_ROUTINE( quad_thread
, param
)
197 struct thread_info
*info
= (struct thread_info
*) param
;
198 struct quad_job_que
*que
= &info
->setup
->que
;
204 /* Wait for an available job.
206 pipe_mutex_lock( que
->que_mutex
);
207 while (que
->last
== que
->first
)
208 pipe_condvar_wait( que
->que_notempty_condvar
, que
->que_mutex
);
210 /* See if the que is full.
212 full
= (que
->last
+ 1) % NUM_QUAD_JOBS
== que
->first
;
214 /* Take a job and remove it from que.
216 job
= que
->jobs
[que
->first
];
217 que
->first
= (que
->first
+ 1) % NUM_QUAD_JOBS
;
219 /* Notify the producer if the que is not full.
222 pipe_condvar_signal( que
->que_notfull_condvar
);
223 pipe_mutex_unlock( que
->que_mutex
);
225 job
.routine( info
->setup
, info
->id
, &job
);
227 /* Notify the producer if that's the last finished job.
229 pipe_mutex_lock( que
->que_mutex
);
231 if (que
->jobs_added
== que
->jobs_done
)
232 pipe_condvar_signal( que
->que_done_condvar
);
233 pipe_mutex_unlock( que
->que_mutex
);
239 #define WAIT_FOR_COMPLETION(setup) \
241 pipe_mutex_lock( setup->que.que_mutex );\
242 if (!INSTANT_NOTEMPTY_NOTIFY)\
243 pipe_condvar_broadcast( setup->que.que_notempty_condvar );\
244 while (setup->que.jobs_added != setup->que.jobs_done)\
245 pipe_condvar_wait( setup->que.que_done_condvar, setup->que.que_mutex );\
246 pipe_mutex_unlock( setup->que.que_mutex );\
251 #define WAIT_FOR_COMPLETION(setup) ((void) 0)
258 * Do triangle cull test using tri determinant (sign indicates orientation)
259 * \return true if triangle is to be culled.
261 static INLINE boolean
262 cull_tri(const struct setup_context
*setup
, float det
)
265 /* if (det < 0 then Z points toward camera and triangle is
266 * counter-clockwise winding.
268 unsigned winding
= (det
< 0) ? PIPE_WINDING_CCW
: PIPE_WINDING_CW
;
270 if ((winding
& setup
->winding
) == 0)
282 * Clip setup->quad against the scissor/surface bounds.
285 quad_clip( struct setup_context
*setup
, struct quad_header
*quad
)
287 const struct pipe_scissor_state
*cliprect
= &setup
->softpipe
->cliprect
;
288 const int minx
= (int) cliprect
->minx
;
289 const int maxx
= (int) cliprect
->maxx
;
290 const int miny
= (int) cliprect
->miny
;
291 const int maxy
= (int) cliprect
->maxy
;
293 if (quad
->input
.x0
>= maxx
||
294 quad
->input
.y0
>= maxy
||
295 quad
->input
.x0
+ 1 < minx
||
296 quad
->input
.y0
+ 1 < miny
) {
297 /* totally clipped */
298 quad
->inout
.mask
= 0x0;
301 if (quad
->input
.x0
< minx
)
302 quad
->inout
.mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
303 if (quad
->input
.y0
< miny
)
304 quad
->inout
.mask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
305 if (quad
->input
.x0
== maxx
- 1)
306 quad
->inout
.mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
307 if (quad
->input
.y0
== maxy
- 1)
308 quad
->inout
.mask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
313 * Emit a quad (pass to next stage) with clipping.
316 clip_emit_quad( struct setup_context
*setup
, struct quad_header
*quad
, uint thread
)
318 quad_clip( setup
, quad
);
319 if (quad
->inout
.mask
) {
320 struct softpipe_context
*sp
= setup
->softpipe
;
322 sp
->quad
[thread
].first
->run( sp
->quad
[thread
].first
, quad
);
326 #if SP_NUM_QUAD_THREADS > 1
329 clip_emit_quad_job( struct setup_context
*setup
, uint thread
, struct quad_job
*job
)
331 struct quad_header quad
;
333 quad
.input
= job
->input
;
334 quad
.inout
= job
->inout
;
335 quad
.coef
= setup
->quad
.coef
;
336 quad
.posCoef
= setup
->quad
.posCoef
;
337 quad
.nr_attrs
= setup
->quad
.nr_attrs
;
338 clip_emit_quad( setup
, &quad
, thread
);
341 #define CLIP_EMIT_QUAD(setup) add_quad_job( &setup->que, &setup->quad, clip_emit_quad_job )
345 #define CLIP_EMIT_QUAD(setup) clip_emit_quad( setup, &setup->quad, 0 )
350 * Emit a quad (pass to next stage). No clipping is done.
353 emit_quad( struct setup_context
*setup
, struct quad_header
*quad
, uint thread
)
355 struct softpipe_context
*sp
= setup
->softpipe
;
357 uint mask
= quad
->inout
.mask
;
361 if (mask
& 1) setup
->numFragsEmitted
++;
362 if (mask
& 2) setup
->numFragsEmitted
++;
363 if (mask
& 4) setup
->numFragsEmitted
++;
364 if (mask
& 8) setup
->numFragsEmitted
++;
366 sp
->quad
[thread
].first
->run( sp
->quad
[thread
].first
, quad
);
368 mask
= quad
->inout
.mask
;
369 if (mask
& 1) setup
->numFragsWritten
++;
370 if (mask
& 2) setup
->numFragsWritten
++;
371 if (mask
& 4) setup
->numFragsWritten
++;
372 if (mask
& 8) setup
->numFragsWritten
++;
376 #if SP_NUM_QUAD_THREADS > 1
379 emit_quad_job( struct setup_context
*setup
, uint thread
, struct quad_job
*job
)
381 struct quad_header quad
;
383 quad
.input
= job
->input
;
384 quad
.inout
= job
->inout
;
385 quad
.coef
= setup
->quad
.coef
;
386 quad
.posCoef
= setup
->quad
.posCoef
;
387 quad
.nr_attrs
= setup
->quad
.nr_attrs
;
388 emit_quad( setup
, &quad
, thread
);
391 #define EMIT_QUAD(setup,x,y,mask) do {\
392 setup->quad.input.x0 = x;\
393 setup->quad.input.y0 = y;\
394 setup->quad.inout.mask = mask;\
395 add_quad_job( &setup->que, &setup->quad, emit_quad_job );\
400 #define EMIT_QUAD(setup,x,y,mask) do {\
401 setup->quad.input.x0 = x;\
402 setup->quad.input.y0 = y;\
403 setup->quad.inout.mask = mask;\
404 emit_quad( setup, &setup->quad, 0 );\
410 * Given an X or Y coordinate, return the block/quad coordinate that it
413 static INLINE
int block( int x
)
420 * Render a horizontal span of quads
422 static void flush_spans( struct setup_context
*setup
)
424 const int xleft0
= setup
->span
.left
[0];
425 const int xleft1
= setup
->span
.left
[1];
426 const int xright0
= setup
->span
.right
[0];
427 const int xright1
= setup
->span
.right
[1];
428 int minleft
, maxright
;
431 switch (setup
->span
.y_flags
) {
433 /* both odd and even lines written (both quad rows) */
434 minleft
= block(MIN2(xleft0
, xleft1
));
435 maxright
= block(MAX2(xright0
, xright1
));
436 for (x
= minleft
; x
<= maxright
; x
+= 2) {
437 /* determine which of the four pixels is inside the span bounds */
439 if (x
>= xleft0
&& x
< xright0
)
440 mask
|= MASK_TOP_LEFT
;
441 if (x
>= xleft1
&& x
< xright1
)
442 mask
|= MASK_BOTTOM_LEFT
;
443 if (x
+1 >= xleft0
&& x
+1 < xright0
)
444 mask
|= MASK_TOP_RIGHT
;
445 if (x
+1 >= xleft1
&& x
+1 < xright1
)
446 mask
|= MASK_BOTTOM_RIGHT
;
448 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
453 /* only even line written (quad top row) */
454 minleft
= block(xleft0
);
455 maxright
= block(xright0
);
456 for (x
= minleft
; x
<= maxright
; x
+= 2) {
458 if (x
>= xleft0
&& x
< xright0
)
459 mask
|= MASK_TOP_LEFT
;
460 if (x
+1 >= xleft0
&& x
+1 < xright0
)
461 mask
|= MASK_TOP_RIGHT
;
463 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
468 /* only odd line written (quad bottom row) */
469 minleft
= block(xleft1
);
470 maxright
= block(xright1
);
471 for (x
= minleft
; x
<= maxright
; x
+= 2) {
473 if (x
>= xleft1
&& x
< xright1
)
474 mask
|= MASK_BOTTOM_LEFT
;
475 if (x
+1 >= xleft1
&& x
+1 < xright1
)
476 mask
|= MASK_BOTTOM_RIGHT
;
478 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
487 setup
->span
.y_flags
= 0;
488 setup
->span
.right
[0] = 0;
489 setup
->span
.right
[1] = 0;
494 static void print_vertex(const struct setup_context
*setup
,
498 debug_printf(" Vertex: (%p)\n", v
);
499 for (i
= 0; i
< setup
->quad
.nr_attrs
; i
++) {
500 debug_printf(" %d: %f %f %f %f\n", i
,
501 v
[i
][0], v
[i
][1], v
[i
][2], v
[i
][3]);
502 if (util_is_inf_or_nan(v
[i
][0])) {
503 debug_printf(" NaN!\n");
510 * Sort the vertices from top to bottom order, setting up the triangle
511 * edge fields (ebot, emaj, etop).
512 * \return FALSE if coords are inf/nan (cull the tri), TRUE otherwise
514 static boolean
setup_sort_vertices( struct setup_context
*setup
,
516 const float (*v0
)[4],
517 const float (*v1
)[4],
518 const float (*v2
)[4] )
520 setup
->vprovoke
= v2
;
522 /* determine bottom to top order of vertices */
569 setup
->ebot
.dx
= setup
->vmid
[0][0] - setup
->vmin
[0][0];
570 setup
->ebot
.dy
= setup
->vmid
[0][1] - setup
->vmin
[0][1];
571 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
572 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
573 setup
->etop
.dx
= setup
->vmax
[0][0] - setup
->vmid
[0][0];
574 setup
->etop
.dy
= setup
->vmax
[0][1] - setup
->vmid
[0][1];
577 * Compute triangle's area. Use 1/area to compute partial
578 * derivatives of attributes later.
580 * The area will be the same as prim->det, but the sign may be
581 * different depending on how the vertices get sorted above.
583 * To determine whether the primitive is front or back facing we
584 * use the prim->det value because its sign is correct.
587 const float area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
588 setup
->ebot
.dx
* setup
->emaj
.dy
);
590 setup
->oneoverarea
= 1.0f
/ area
;
593 debug_printf("%s one-over-area %f area %f det %f\n",
594 __FUNCTION__, setup->oneoverarea, area, det );
596 if (util_is_inf_or_nan(setup
->oneoverarea
))
600 /* We need to know if this is a front or back-facing triangle for:
601 * - the GLSL gl_FrontFacing fragment attribute (bool)
602 * - two-sided stencil test
604 setup
->quad
.input
.facing
= (det
> 0.0) ^ (setup
->softpipe
->rasterizer
->front_winding
== PIPE_WINDING_CW
);
611 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
612 * The value value comes from vertex[slot][i].
613 * The result will be put into setup->coef[slot].a0[i].
614 * \param slot which attribute slot
615 * \param i which component of the slot (0..3)
617 static void const_coeff( struct setup_context
*setup
,
618 struct tgsi_interp_coef
*coef
,
619 uint vertSlot
, uint i
)
626 /* need provoking vertex info!
628 coef
->a0
[i
] = setup
->vprovoke
[vertSlot
][i
];
633 * Compute a0, dadx and dady for a linearly interpolated coefficient,
636 static void tri_linear_coeff( struct setup_context
*setup
,
637 struct tgsi_interp_coef
*coef
,
638 uint vertSlot
, uint i
)
640 float botda
= setup
->vmid
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
641 float majda
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
642 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
643 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
644 float dadx
= a
* setup
->oneoverarea
;
645 float dady
= b
* setup
->oneoverarea
;
649 coef
->dadx
[i
] = dadx
;
650 coef
->dady
[i
] = dady
;
652 /* calculate a0 as the value which would be sampled for the
653 * fragment at (0,0), taking into account that we want to sample at
654 * pixel centers, in other words (0.5, 0.5).
656 * this is neat but unfortunately not a good way to do things for
657 * triangles with very large values of dadx or dady as it will
658 * result in the subtraction and re-addition from a0 of a very
659 * large number, which means we'll end up loosing a lot of the
660 * fractional bits and precision from a0. the way to fix this is
661 * to define a0 as the sample at a pixel center somewhere near vmin
662 * instead - i'll switch to this later.
664 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
665 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
666 dady
* (setup
->vmin
[0][1] - 0.5f
)));
669 debug_printf("attr[%d].%c: %f dx:%f dy:%f\n",
671 setup->coef[slot].a0[i],
672 setup->coef[slot].dadx[i],
673 setup->coef[slot].dady[i]);
679 * Compute a0, dadx and dady for a perspective-corrected interpolant,
681 * We basically multiply the vertex value by 1/w before computing
682 * the plane coefficients (a0, dadx, dady).
683 * Later, when we compute the value at a particular fragment position we'll
684 * divide the interpolated value by the interpolated W at that fragment.
686 static void tri_persp_coeff( struct setup_context
*setup
,
687 struct tgsi_interp_coef
*coef
,
688 uint vertSlot
, uint i
)
690 /* premultiply by 1/w (v[0][3] is always W):
692 float mina
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
693 float mida
= setup
->vmid
[vertSlot
][i
] * setup
->vmid
[0][3];
694 float maxa
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
695 float botda
= mida
- mina
;
696 float majda
= maxa
- mina
;
697 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
698 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
699 float dadx
= a
* setup
->oneoverarea
;
700 float dady
= b
* setup
->oneoverarea
;
703 debug_printf("tri persp %d,%d: %f %f %f\n", vertSlot, i,
704 setup->vmin[vertSlot][i],
705 setup->vmid[vertSlot][i],
706 setup->vmax[vertSlot][i]
711 coef
->dadx
[i
] = dadx
;
712 coef
->dady
[i
] = dady
;
713 coef
->a0
[i
] = (mina
-
714 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
715 dady
* (setup
->vmin
[0][1] - 0.5f
)));
720 * Special coefficient setup for gl_FragCoord.
721 * X and Y are trivial, though Y has to be inverted for OpenGL.
722 * Z and W are copied from posCoef which should have already been computed.
723 * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
726 setup_fragcoord_coeff(struct setup_context
*setup
, uint slot
)
729 setup
->coef
[slot
].a0
[0] = 0;
730 setup
->coef
[slot
].dadx
[0] = 1.0;
731 setup
->coef
[slot
].dady
[0] = 0.0;
733 setup
->coef
[slot
].a0
[1] = 0.0;
734 setup
->coef
[slot
].dadx
[1] = 0.0;
735 setup
->coef
[slot
].dady
[1] = 1.0;
737 setup
->coef
[slot
].a0
[2] = setup
->posCoef
.a0
[2];
738 setup
->coef
[slot
].dadx
[2] = setup
->posCoef
.dadx
[2];
739 setup
->coef
[slot
].dady
[2] = setup
->posCoef
.dady
[2];
741 setup
->coef
[slot
].a0
[3] = setup
->posCoef
.a0
[3];
742 setup
->coef
[slot
].dadx
[3] = setup
->posCoef
.dadx
[3];
743 setup
->coef
[slot
].dady
[3] = setup
->posCoef
.dady
[3];
749 * Compute the setup->coef[] array dadx, dady, a0 values.
750 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
752 static void setup_tri_coefficients( struct setup_context
*setup
)
754 struct softpipe_context
*softpipe
= setup
->softpipe
;
755 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
756 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
759 /* z and w are done by linear interpolation:
761 tri_linear_coeff(setup
, &setup
->posCoef
, 0, 2);
762 tri_linear_coeff(setup
, &setup
->posCoef
, 0, 3);
764 /* setup interpolation for all the remaining attributes:
766 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
767 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
770 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
771 case INTERP_CONSTANT
:
772 for (j
= 0; j
< NUM_CHANNELS
; j
++)
773 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
776 for (j
= 0; j
< NUM_CHANNELS
; j
++)
777 tri_linear_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
779 case INTERP_PERSPECTIVE
:
780 for (j
= 0; j
< NUM_CHANNELS
; j
++)
781 tri_persp_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
784 setup_fragcoord_coeff(setup
, fragSlot
);
790 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
791 setup
->coef
[fragSlot
].a0
[0] = 1.0f
- setup
->quad
.input
.facing
;
792 setup
->coef
[fragSlot
].dadx
[0] = 0.0;
793 setup
->coef
[fragSlot
].dady
[0] = 0.0;
800 static void setup_tri_edges( struct setup_context
*setup
)
802 float vmin_x
= setup
->vmin
[0][0] + 0.5f
;
803 float vmid_x
= setup
->vmid
[0][0] + 0.5f
;
805 float vmin_y
= setup
->vmin
[0][1] - 0.5f
;
806 float vmid_y
= setup
->vmid
[0][1] - 0.5f
;
807 float vmax_y
= setup
->vmax
[0][1] - 0.5f
;
809 setup
->emaj
.sy
= ceilf(vmin_y
);
810 setup
->emaj
.lines
= (int) ceilf(vmax_y
- setup
->emaj
.sy
);
811 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
812 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
814 setup
->etop
.sy
= ceilf(vmid_y
);
815 setup
->etop
.lines
= (int) ceilf(vmax_y
- setup
->etop
.sy
);
816 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
817 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
819 setup
->ebot
.sy
= ceilf(vmin_y
);
820 setup
->ebot
.lines
= (int) ceilf(vmid_y
- setup
->ebot
.sy
);
821 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
822 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
827 * Render the upper or lower half of a triangle.
828 * Scissoring/cliprect is applied here too.
830 static void subtriangle( struct setup_context
*setup
,
835 const struct pipe_scissor_state
*cliprect
= &setup
->softpipe
->cliprect
;
836 const int minx
= (int) cliprect
->minx
;
837 const int maxx
= (int) cliprect
->maxx
;
838 const int miny
= (int) cliprect
->miny
;
839 const int maxy
= (int) cliprect
->maxy
;
840 int y
, start_y
, finish_y
;
841 int sy
= (int)eleft
->sy
;
843 assert((int)eleft
->sy
== (int) eright
->sy
);
845 /* clip top/bottom */
847 finish_y
= sy
+ lines
;
859 debug_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
862 for (y
= start_y
; y
< finish_y
; y
++) {
864 /* avoid accumulating adds as floats don't have the precision to
865 * accurately iterate large triangle edges that way. luckily we
866 * can just multiply these days.
868 * this is all drowned out by the attribute interpolation anyway.
870 int left
= (int)(eleft
->sx
+ y
* eleft
->dxdy
);
871 int right
= (int)(eright
->sx
+ y
* eright
->dxdy
);
873 /* clip left/right */
881 if (block(_y
) != setup
->span
.y
) {
883 setup
->span
.y
= block(_y
);
886 setup
->span
.left
[_y
&1] = left
;
887 setup
->span
.right
[_y
&1] = right
;
888 setup
->span
.y_flags
|= 1<<(_y
&1);
893 /* save the values so that emaj can be restarted:
895 eleft
->sx
+= lines
* eleft
->dxdy
;
896 eright
->sx
+= lines
* eright
->dxdy
;
903 * Recalculate prim's determinant. This is needed as we don't have
904 * get this information through the vbuf_render interface & we must
908 calc_det( const float (*v0
)[4],
909 const float (*v1
)[4],
910 const float (*v2
)[4] )
912 /* edge vectors e = v0 - v2, f = v1 - v2 */
913 const float ex
= v0
[0][0] - v2
[0][0];
914 const float ey
= v0
[0][1] - v2
[0][1];
915 const float fx
= v1
[0][0] - v2
[0][0];
916 const float fy
= v1
[0][1] - v2
[0][1];
918 /* det = cross(e,f).z */
919 return ex
* fy
- ey
* fx
;
924 * Do setup for triangle rasterization, then render the triangle.
926 void setup_tri( struct setup_context
*setup
,
927 const float (*v0
)[4],
928 const float (*v1
)[4],
929 const float (*v2
)[4] )
934 debug_printf("Setup triangle:\n");
935 print_vertex(setup
, v0
);
936 print_vertex(setup
, v1
);
937 print_vertex(setup
, v2
);
940 if (setup
->softpipe
->no_rast
)
943 det
= calc_det(v0
, v1
, v2
);
945 debug_printf("%s\n", __FUNCTION__ );
949 setup
->numFragsEmitted
= 0;
950 setup
->numFragsWritten
= 0;
953 if (cull_tri( setup
, det
))
956 if (!setup_sort_vertices( setup
, det
, v0
, v1
, v2
))
958 setup_tri_coefficients( setup
);
959 setup_tri_edges( setup
);
961 setup
->quad
.input
.prim
= QUAD_PRIM_TRI
;
964 setup
->span
.y_flags
= 0;
965 setup
->span
.right
[0] = 0;
966 setup
->span
.right
[1] = 0;
967 /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
969 /* init_constant_attribs( setup ); */
971 if (setup
->oneoverarea
< 0.0) {
974 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
975 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
980 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
981 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
984 flush_spans( setup
);
986 WAIT_FOR_COMPLETION(setup
);
989 printf("Tri: %u frags emitted, %u written\n",
990 setup
->numFragsEmitted
,
991 setup
->numFragsWritten
);
998 * Compute a0, dadx and dady for a linearly interpolated coefficient,
1002 line_linear_coeff(const struct setup_context
*setup
,
1003 struct tgsi_interp_coef
*coef
,
1004 uint vertSlot
, uint i
)
1006 const float da
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
1007 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
1008 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
1009 coef
->dadx
[i
] = dadx
;
1010 coef
->dady
[i
] = dady
;
1011 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
1012 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
1013 dady
* (setup
->vmin
[0][1] - 0.5f
)));
1018 * Compute a0, dadx and dady for a perspective-corrected interpolant,
1022 line_persp_coeff(const struct setup_context
*setup
,
1023 struct tgsi_interp_coef
*coef
,
1024 uint vertSlot
, uint i
)
1026 /* XXX double-check/verify this arithmetic */
1027 const float a0
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
1028 const float a1
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
1029 const float da
= a1
- a0
;
1030 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
1031 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
1032 coef
->dadx
[i
] = dadx
;
1033 coef
->dady
[i
] = dady
;
1034 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
1035 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
1036 dady
* (setup
->vmin
[0][1] - 0.5f
)));
1041 * Compute the setup->coef[] array dadx, dady, a0 values.
1042 * Must be called after setup->vmin,vmax are initialized.
1044 static INLINE boolean
1045 setup_line_coefficients(struct setup_context
*setup
,
1046 const float (*v0
)[4],
1047 const float (*v1
)[4])
1049 struct softpipe_context
*softpipe
= setup
->softpipe
;
1050 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
1051 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
1055 /* use setup->vmin, vmax to point to vertices */
1056 if (softpipe
->rasterizer
->flatshade_first
)
1057 setup
->vprovoke
= v0
;
1059 setup
->vprovoke
= v1
;
1063 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
1064 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
1066 /* NOTE: this is not really area but something proportional to it */
1067 area
= setup
->emaj
.dx
* setup
->emaj
.dx
+ setup
->emaj
.dy
* setup
->emaj
.dy
;
1068 if (area
== 0.0f
|| util_is_inf_or_nan(area
))
1070 setup
->oneoverarea
= 1.0f
/ area
;
1072 /* z and w are done by linear interpolation:
1074 line_linear_coeff(setup
, &setup
->posCoef
, 0, 2);
1075 line_linear_coeff(setup
, &setup
->posCoef
, 0, 3);
1077 /* setup interpolation for all the remaining attributes:
1079 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
1080 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1083 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1084 case INTERP_CONSTANT
:
1085 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1086 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1089 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1090 line_linear_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1092 case INTERP_PERSPECTIVE
:
1093 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1094 line_persp_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1097 setup_fragcoord_coeff(setup
, fragSlot
);
1103 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
1104 setup
->coef
[fragSlot
].a0
[0] = 1.0f
- setup
->quad
.input
.facing
;
1105 setup
->coef
[fragSlot
].dadx
[0] = 0.0;
1106 setup
->coef
[fragSlot
].dady
[0] = 0.0;
1114 * Plot a pixel in a line segment.
1117 plot(struct setup_context
*setup
, int x
, int y
)
1119 const int iy
= y
& 1;
1120 const int ix
= x
& 1;
1121 const int quadX
= x
- ix
;
1122 const int quadY
= y
- iy
;
1123 const int mask
= (1 << ix
) << (2 * iy
);
1125 if (quadX
!= setup
->quad
.input
.x0
||
1126 quadY
!= setup
->quad
.input
.y0
)
1128 /* flush prev quad, start new quad */
1130 if (setup
->quad
.input
.x0
!= -1)
1131 CLIP_EMIT_QUAD(setup
);
1133 setup
->quad
.input
.x0
= quadX
;
1134 setup
->quad
.input
.y0
= quadY
;
1135 setup
->quad
.inout
.mask
= 0x0;
1138 setup
->quad
.inout
.mask
|= mask
;
1143 * Do setup for line rasterization, then render the line.
1144 * Single-pixel width, no stipple, etc. We rely on the 'draw' module
1145 * to handle stippling and wide lines.
1148 setup_line(struct setup_context
*setup
,
1149 const float (*v0
)[4],
1150 const float (*v1
)[4])
1152 int x0
= (int) v0
[0][0];
1153 int x1
= (int) v1
[0][0];
1154 int y0
= (int) v0
[0][1];
1155 int y1
= (int) v1
[0][1];
1161 debug_printf("Setup line:\n");
1162 print_vertex(setup
, v0
);
1163 print_vertex(setup
, v1
);
1166 if (setup
->softpipe
->no_rast
)
1169 if (dx
== 0 && dy
== 0)
1172 if (!setup_line_coefficients(setup
, v0
, v1
))
1175 assert(v0
[0][0] < 1.0e9
);
1176 assert(v0
[0][1] < 1.0e9
);
1177 assert(v1
[0][0] < 1.0e9
);
1178 assert(v1
[0][1] < 1.0e9
);
1181 dx
= -dx
; /* make positive */
1189 dy
= -dy
; /* make positive */
1199 setup
->quad
.input
.x0
= setup
->quad
.input
.y0
= -1;
1200 setup
->quad
.inout
.mask
= 0x0;
1201 setup
->quad
.input
.prim
= QUAD_PRIM_LINE
;
1202 /* XXX temporary: set coverage to 1.0 so the line appears
1203 * if AA mode happens to be enabled.
1205 setup
->quad
.input
.coverage
[0] =
1206 setup
->quad
.input
.coverage
[1] =
1207 setup
->quad
.input
.coverage
[2] =
1208 setup
->quad
.input
.coverage
[3] = 1.0;
1211 /*** X-major line ***/
1213 const int errorInc
= dy
+ dy
;
1214 int error
= errorInc
- dx
;
1215 const int errorDec
= error
- dx
;
1217 for (i
= 0; i
< dx
; i
++) {
1218 plot(setup
, x0
, y0
);
1231 /*** Y-major line ***/
1233 const int errorInc
= dx
+ dx
;
1234 int error
= errorInc
- dy
;
1235 const int errorDec
= error
- dy
;
1237 for (i
= 0; i
< dy
; i
++) {
1238 plot(setup
, x0
, y0
);
1251 /* draw final quad */
1252 if (setup
->quad
.inout
.mask
) {
1253 CLIP_EMIT_QUAD(setup
);
1256 WAIT_FOR_COMPLETION(setup
);
1261 point_persp_coeff(const struct setup_context
*setup
,
1262 const float (*vert
)[4],
1263 struct tgsi_interp_coef
*coef
,
1264 uint vertSlot
, uint i
)
1267 coef
->dadx
[i
] = 0.0F
;
1268 coef
->dady
[i
] = 0.0F
;
1269 coef
->a0
[i
] = vert
[vertSlot
][i
] * vert
[0][3];
1274 * Do setup for point rasterization, then render the point.
1275 * Round or square points...
1276 * XXX could optimize a lot for 1-pixel points.
1279 setup_point( struct setup_context
*setup
,
1280 const float (*v0
)[4] )
1282 struct softpipe_context
*softpipe
= setup
->softpipe
;
1283 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
1284 const int sizeAttr
= setup
->softpipe
->psize_slot
;
1286 = sizeAttr
> 0 ? v0
[sizeAttr
][0]
1287 : setup
->softpipe
->rasterizer
->point_size
;
1288 const float halfSize
= 0.5F
* size
;
1289 const boolean round
= (boolean
) setup
->softpipe
->rasterizer
->point_smooth
;
1290 const float x
= v0
[0][0]; /* Note: data[0] is always position */
1291 const float y
= v0
[0][1];
1292 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
1296 debug_printf("Setup point:\n");
1297 print_vertex(setup
, v0
);
1300 if (softpipe
->no_rast
)
1303 /* For points, all interpolants are constant-valued.
1304 * However, for point sprites, we'll need to setup texcoords appropriately.
1305 * XXX: which coefficients are the texcoords???
1306 * We may do point sprites as textured quads...
1308 * KW: We don't know which coefficients are texcoords - ultimately
1309 * the choice of what interpolation mode to use for each attribute
1310 * should be determined by the fragment program, using
1311 * per-attribute declaration statements that include interpolation
1312 * mode as a parameter. So either the fragment program will have
1313 * to be adjusted for pointsprite vs normal point behaviour, or
1314 * otherwise a special interpolation mode will have to be defined
1315 * which matches the required behaviour for point sprites. But -
1316 * the latter is not a feature of normal hardware, and as such
1317 * probably should be ruled out on that basis.
1319 setup
->vprovoke
= v0
;
1322 const_coeff(setup
, &setup
->posCoef
, 0, 2);
1323 const_coeff(setup
, &setup
->posCoef
, 0, 3);
1325 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
1326 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1329 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1330 case INTERP_CONSTANT
:
1333 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1334 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1336 case INTERP_PERSPECTIVE
:
1337 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1338 point_persp_coeff(setup
, setup
->vprovoke
,
1339 &setup
->coef
[fragSlot
], vertSlot
, j
);
1342 setup_fragcoord_coeff(setup
, fragSlot
);
1348 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
1349 setup
->coef
[fragSlot
].a0
[0] = 1.0f
- setup
->quad
.input
.facing
;
1350 setup
->coef
[fragSlot
].dadx
[0] = 0.0;
1351 setup
->coef
[fragSlot
].dady
[0] = 0.0;
1355 setup
->quad
.input
.prim
= QUAD_PRIM_POINT
;
1357 if (halfSize
<= 0.5 && !round
) {
1358 /* special case for 1-pixel points */
1359 const int ix
= ((int) x
) & 1;
1360 const int iy
= ((int) y
) & 1;
1361 setup
->quad
.input
.x0
= (int) x
- ix
;
1362 setup
->quad
.input
.y0
= (int) y
- iy
;
1363 setup
->quad
.inout
.mask
= (1 << ix
) << (2 * iy
);
1364 CLIP_EMIT_QUAD(setup
);
1368 /* rounded points */
1369 const int ixmin
= block((int) (x
- halfSize
));
1370 const int ixmax
= block((int) (x
+ halfSize
));
1371 const int iymin
= block((int) (y
- halfSize
));
1372 const int iymax
= block((int) (y
+ halfSize
));
1373 const float rmin
= halfSize
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
1374 const float rmax
= halfSize
+ 0.7071F
;
1375 const float rmin2
= MAX2(0.0F
, rmin
* rmin
);
1376 const float rmax2
= rmax
* rmax
;
1377 const float cscale
= 1.0F
/ (rmax2
- rmin2
);
1380 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1381 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1382 float dx
, dy
, dist2
, cover
;
1384 setup
->quad
.inout
.mask
= 0x0;
1386 dx
= (ix
+ 0.5f
) - x
;
1387 dy
= (iy
+ 0.5f
) - y
;
1388 dist2
= dx
* dx
+ dy
* dy
;
1389 if (dist2
<= rmax2
) {
1390 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1391 setup
->quad
.input
.coverage
[QUAD_TOP_LEFT
] = MIN2(cover
, 1.0f
);
1392 setup
->quad
.inout
.mask
|= MASK_TOP_LEFT
;
1395 dx
= (ix
+ 1.5f
) - x
;
1396 dy
= (iy
+ 0.5f
) - y
;
1397 dist2
= dx
* dx
+ dy
* dy
;
1398 if (dist2
<= rmax2
) {
1399 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1400 setup
->quad
.input
.coverage
[QUAD_TOP_RIGHT
] = MIN2(cover
, 1.0f
);
1401 setup
->quad
.inout
.mask
|= MASK_TOP_RIGHT
;
1404 dx
= (ix
+ 0.5f
) - x
;
1405 dy
= (iy
+ 1.5f
) - y
;
1406 dist2
= dx
* dx
+ dy
* dy
;
1407 if (dist2
<= rmax2
) {
1408 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1409 setup
->quad
.input
.coverage
[QUAD_BOTTOM_LEFT
] = MIN2(cover
, 1.0f
);
1410 setup
->quad
.inout
.mask
|= MASK_BOTTOM_LEFT
;
1413 dx
= (ix
+ 1.5f
) - x
;
1414 dy
= (iy
+ 1.5f
) - y
;
1415 dist2
= dx
* dx
+ dy
* dy
;
1416 if (dist2
<= rmax2
) {
1417 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1418 setup
->quad
.input
.coverage
[QUAD_BOTTOM_RIGHT
] = MIN2(cover
, 1.0f
);
1419 setup
->quad
.inout
.mask
|= MASK_BOTTOM_RIGHT
;
1422 if (setup
->quad
.inout
.mask
) {
1423 setup
->quad
.input
.x0
= ix
;
1424 setup
->quad
.input
.y0
= iy
;
1425 CLIP_EMIT_QUAD(setup
);
1432 const int xmin
= (int) (x
+ 0.75 - halfSize
);
1433 const int ymin
= (int) (y
+ 0.25 - halfSize
);
1434 const int xmax
= xmin
+ (int) size
;
1435 const int ymax
= ymin
+ (int) size
;
1436 /* XXX could apply scissor to xmin,ymin,xmax,ymax now */
1437 const int ixmin
= block(xmin
);
1438 const int ixmax
= block(xmax
- 1);
1439 const int iymin
= block(ymin
);
1440 const int iymax
= block(ymax
- 1);
1444 debug_printf("(%f, %f) -> X:%d..%d Y:%d..%d\n", x, y, xmin, xmax,ymin,ymax);
1446 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1449 /* above the top edge */
1450 rowMask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
1452 if (iy
+ 1 >= ymax
) {
1453 /* below the bottom edge */
1454 rowMask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
1457 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1458 uint mask
= rowMask
;
1461 /* fragment is past left edge of point, turn off left bits */
1462 mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
1464 if (ix
+ 1 >= xmax
) {
1465 /* past the right edge */
1466 mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
1469 setup
->quad
.inout
.mask
= mask
;
1470 setup
->quad
.input
.x0
= ix
;
1471 setup
->quad
.input
.y0
= iy
;
1472 CLIP_EMIT_QUAD(setup
);
1478 WAIT_FOR_COMPLETION(setup
);
1481 void setup_prepare( struct setup_context
*setup
)
1483 struct softpipe_context
*sp
= setup
->softpipe
;
1487 softpipe_update_derived(sp
);
1490 /* Note: nr_attrs is only used for debugging (vertex printing) */
1491 setup
->quad
.nr_attrs
= draw_num_vs_outputs(sp
->draw
);
1493 for (i
= 0; i
< SP_NUM_QUAD_THREADS
; i
++) {
1494 sp
->quad
[i
].first
->begin( sp
->quad
[i
].first
);
1497 if (sp
->reduced_api_prim
== PIPE_PRIM_TRIANGLES
&&
1498 sp
->rasterizer
->fill_cw
== PIPE_POLYGON_MODE_FILL
&&
1499 sp
->rasterizer
->fill_ccw
== PIPE_POLYGON_MODE_FILL
) {
1500 /* we'll do culling */
1501 setup
->winding
= sp
->rasterizer
->cull_mode
;
1504 /* 'draw' will do culling */
1505 setup
->winding
= PIPE_WINDING_NONE
;
1511 void setup_destroy_context( struct setup_context
*setup
)
1518 * Create a new primitive setup/render stage.
1520 struct setup_context
*setup_create_context( struct softpipe_context
*softpipe
)
1522 struct setup_context
*setup
= CALLOC_STRUCT(setup_context
);
1523 #if SP_NUM_QUAD_THREADS > 1
1527 setup
->softpipe
= softpipe
;
1529 setup
->quad
.coef
= setup
->coef
;
1530 setup
->quad
.posCoef
= &setup
->posCoef
;
1532 #if SP_NUM_QUAD_THREADS > 1
1533 setup
->que
.first
= 0;
1534 setup
->que
.last
= 0;
1535 pipe_mutex_init( setup
->que
.que_mutex
);
1536 pipe_condvar_init( setup
->que
.que_notfull_condvar
);
1537 pipe_condvar_init( setup
->que
.que_notempty_condvar
);
1538 setup
->que
.jobs_added
= 0;
1539 setup
->que
.jobs_done
= 0;
1540 pipe_condvar_init( setup
->que
.que_done_condvar
);
1541 for (i
= 0; i
< SP_NUM_QUAD_THREADS
; i
++) {
1542 setup
->threads
[i
].setup
= setup
;
1543 setup
->threads
[i
].id
= i
;
1544 setup
->threads
[i
].handle
= pipe_thread_create( quad_thread
, &setup
->threads
[i
] );