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
;
447 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
452 /* only even line written (quad top row) */
453 minleft
= block(xleft0
);
454 maxright
= block(xright0
);
455 for (x
= minleft
; x
<= maxright
; x
+= 2) {
457 if (x
>= xleft0
&& x
< xright0
)
458 mask
|= MASK_TOP_LEFT
;
459 if (x
+1 >= xleft0
&& x
+1 < xright0
)
460 mask
|= MASK_TOP_RIGHT
;
461 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
466 /* only odd line written (quad bottom row) */
467 minleft
= block(xleft1
);
468 maxright
= block(xright1
);
469 for (x
= minleft
; x
<= maxright
; x
+= 2) {
471 if (x
>= xleft1
&& x
< xright1
)
472 mask
|= MASK_BOTTOM_LEFT
;
473 if (x
+1 >= xleft1
&& x
+1 < xright1
)
474 mask
|= MASK_BOTTOM_RIGHT
;
475 EMIT_QUAD( setup
, x
, setup
->span
.y
, mask
);
484 setup
->span
.y_flags
= 0;
485 setup
->span
.right
[0] = 0;
486 setup
->span
.right
[1] = 0;
491 static void print_vertex(const struct setup_context
*setup
,
495 debug_printf(" Vertex: (%p)\n", v
);
496 for (i
= 0; i
< setup
->quad
.nr_attrs
; i
++) {
497 debug_printf(" %d: %f %f %f %f\n", i
,
498 v
[i
][0], v
[i
][1], v
[i
][2], v
[i
][3]);
499 if (util_is_inf_or_nan(v
[i
][0])) {
500 debug_printf(" NaN!\n");
507 * Sort the vertices from top to bottom order, setting up the triangle
508 * edge fields (ebot, emaj, etop).
509 * \return FALSE if coords are inf/nan (cull the tri), TRUE otherwise
511 static boolean
setup_sort_vertices( struct setup_context
*setup
,
513 const float (*v0
)[4],
514 const float (*v1
)[4],
515 const float (*v2
)[4] )
517 setup
->vprovoke
= v2
;
519 /* determine bottom to top order of vertices */
566 setup
->ebot
.dx
= setup
->vmid
[0][0] - setup
->vmin
[0][0];
567 setup
->ebot
.dy
= setup
->vmid
[0][1] - setup
->vmin
[0][1];
568 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
569 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
570 setup
->etop
.dx
= setup
->vmax
[0][0] - setup
->vmid
[0][0];
571 setup
->etop
.dy
= setup
->vmax
[0][1] - setup
->vmid
[0][1];
574 * Compute triangle's area. Use 1/area to compute partial
575 * derivatives of attributes later.
577 * The area will be the same as prim->det, but the sign may be
578 * different depending on how the vertices get sorted above.
580 * To determine whether the primitive is front or back facing we
581 * use the prim->det value because its sign is correct.
584 const float area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
585 setup
->ebot
.dx
* setup
->emaj
.dy
);
587 setup
->oneoverarea
= 1.0f
/ area
;
590 debug_printf("%s one-over-area %f area %f det %f\n",
591 __FUNCTION__, setup->oneoverarea, area, det );
593 if (util_is_inf_or_nan(setup
->oneoverarea
))
597 /* We need to know if this is a front or back-facing triangle for:
598 * - the GLSL gl_FrontFacing fragment attribute (bool)
599 * - two-sided stencil test
601 setup
->quad
.input
.facing
= (det
> 0.0) ^ (setup
->softpipe
->rasterizer
->front_winding
== PIPE_WINDING_CW
);
608 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
609 * The value value comes from vertex[slot][i].
610 * The result will be put into setup->coef[slot].a0[i].
611 * \param slot which attribute slot
612 * \param i which component of the slot (0..3)
614 static void const_coeff( struct setup_context
*setup
,
615 struct tgsi_interp_coef
*coef
,
616 uint vertSlot
, uint i
)
623 /* need provoking vertex info!
625 coef
->a0
[i
] = setup
->vprovoke
[vertSlot
][i
];
630 * Compute a0, dadx and dady for a linearly interpolated coefficient,
633 static void tri_linear_coeff( struct setup_context
*setup
,
634 struct tgsi_interp_coef
*coef
,
635 uint vertSlot
, uint i
)
637 float botda
= setup
->vmid
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
638 float majda
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
639 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
640 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
641 float dadx
= a
* setup
->oneoverarea
;
642 float dady
= b
* setup
->oneoverarea
;
646 coef
->dadx
[i
] = dadx
;
647 coef
->dady
[i
] = dady
;
649 /* calculate a0 as the value which would be sampled for the
650 * fragment at (0,0), taking into account that we want to sample at
651 * pixel centers, in other words (0.5, 0.5).
653 * this is neat but unfortunately not a good way to do things for
654 * triangles with very large values of dadx or dady as it will
655 * result in the subtraction and re-addition from a0 of a very
656 * large number, which means we'll end up loosing a lot of the
657 * fractional bits and precision from a0. the way to fix this is
658 * to define a0 as the sample at a pixel center somewhere near vmin
659 * instead - i'll switch to this later.
661 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
662 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
663 dady
* (setup
->vmin
[0][1] - 0.5f
)));
666 debug_printf("attr[%d].%c: %f dx:%f dy:%f\n",
668 setup->coef[slot].a0[i],
669 setup->coef[slot].dadx[i],
670 setup->coef[slot].dady[i]);
676 * Compute a0, dadx and dady for a perspective-corrected interpolant,
678 * We basically multiply the vertex value by 1/w before computing
679 * the plane coefficients (a0, dadx, dady).
680 * Later, when we compute the value at a particular fragment position we'll
681 * divide the interpolated value by the interpolated W at that fragment.
683 static void tri_persp_coeff( struct setup_context
*setup
,
684 struct tgsi_interp_coef
*coef
,
685 uint vertSlot
, uint i
)
687 /* premultiply by 1/w (v[0][3] is always W):
689 float mina
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
690 float mida
= setup
->vmid
[vertSlot
][i
] * setup
->vmid
[0][3];
691 float maxa
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
692 float botda
= mida
- mina
;
693 float majda
= maxa
- mina
;
694 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
695 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
696 float dadx
= a
* setup
->oneoverarea
;
697 float dady
= b
* setup
->oneoverarea
;
700 debug_printf("tri persp %d,%d: %f %f %f\n", vertSlot, i,
701 setup->vmin[vertSlot][i],
702 setup->vmid[vertSlot][i],
703 setup->vmax[vertSlot][i]
708 coef
->dadx
[i
] = dadx
;
709 coef
->dady
[i
] = dady
;
710 coef
->a0
[i
] = (mina
-
711 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
712 dady
* (setup
->vmin
[0][1] - 0.5f
)));
717 * Special coefficient setup for gl_FragCoord.
718 * X and Y are trivial, though Y has to be inverted for OpenGL.
719 * Z and W are copied from posCoef which should have already been computed.
720 * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
723 setup_fragcoord_coeff(struct setup_context
*setup
, uint slot
)
726 setup
->coef
[slot
].a0
[0] = 0;
727 setup
->coef
[slot
].dadx
[0] = 1.0;
728 setup
->coef
[slot
].dady
[0] = 0.0;
730 setup
->coef
[slot
].a0
[1] = 0.0;
731 setup
->coef
[slot
].dadx
[1] = 0.0;
732 setup
->coef
[slot
].dady
[1] = 1.0;
734 setup
->coef
[slot
].a0
[2] = setup
->posCoef
.a0
[2];
735 setup
->coef
[slot
].dadx
[2] = setup
->posCoef
.dadx
[2];
736 setup
->coef
[slot
].dady
[2] = setup
->posCoef
.dady
[2];
738 setup
->coef
[slot
].a0
[3] = setup
->posCoef
.a0
[3];
739 setup
->coef
[slot
].dadx
[3] = setup
->posCoef
.dadx
[3];
740 setup
->coef
[slot
].dady
[3] = setup
->posCoef
.dady
[3];
746 * Compute the setup->coef[] array dadx, dady, a0 values.
747 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
749 static void setup_tri_coefficients( struct setup_context
*setup
)
751 struct softpipe_context
*softpipe
= setup
->softpipe
;
752 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
753 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
756 /* z and w are done by linear interpolation:
758 tri_linear_coeff(setup
, &setup
->posCoef
, 0, 2);
759 tri_linear_coeff(setup
, &setup
->posCoef
, 0, 3);
761 /* setup interpolation for all the remaining attributes:
763 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
764 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
767 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
768 case INTERP_CONSTANT
:
769 for (j
= 0; j
< NUM_CHANNELS
; j
++)
770 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
773 for (j
= 0; j
< NUM_CHANNELS
; j
++)
774 tri_linear_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
776 case INTERP_PERSPECTIVE
:
777 for (j
= 0; j
< NUM_CHANNELS
; j
++)
778 tri_persp_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
781 setup_fragcoord_coeff(setup
, fragSlot
);
787 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FOG
) {
788 /* FOG.y = front/back facing XXX fix this */
789 setup
->coef
[fragSlot
].a0
[1] = 1.0f
- setup
->quad
.input
.facing
;
790 setup
->coef
[fragSlot
].dadx
[1] = 0.0;
791 setup
->coef
[fragSlot
].dady
[1] = 0.0;
798 static void setup_tri_edges( struct setup_context
*setup
)
800 float vmin_x
= setup
->vmin
[0][0] + 0.5f
;
801 float vmid_x
= setup
->vmid
[0][0] + 0.5f
;
803 float vmin_y
= setup
->vmin
[0][1] - 0.5f
;
804 float vmid_y
= setup
->vmid
[0][1] - 0.5f
;
805 float vmax_y
= setup
->vmax
[0][1] - 0.5f
;
807 setup
->emaj
.sy
= ceilf(vmin_y
);
808 setup
->emaj
.lines
= (int) ceilf(vmax_y
- setup
->emaj
.sy
);
809 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
810 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
812 setup
->etop
.sy
= ceilf(vmid_y
);
813 setup
->etop
.lines
= (int) ceilf(vmax_y
- setup
->etop
.sy
);
814 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
815 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
817 setup
->ebot
.sy
= ceilf(vmin_y
);
818 setup
->ebot
.lines
= (int) ceilf(vmid_y
- setup
->ebot
.sy
);
819 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
820 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
825 * Render the upper or lower half of a triangle.
826 * Scissoring/cliprect is applied here too.
828 static void subtriangle( struct setup_context
*setup
,
833 const struct pipe_scissor_state
*cliprect
= &setup
->softpipe
->cliprect
;
834 const int minx
= (int) cliprect
->minx
;
835 const int maxx
= (int) cliprect
->maxx
;
836 const int miny
= (int) cliprect
->miny
;
837 const int maxy
= (int) cliprect
->maxy
;
838 int y
, start_y
, finish_y
;
839 int sy
= (int)eleft
->sy
;
841 assert((int)eleft
->sy
== (int) eright
->sy
);
843 /* clip top/bottom */
845 finish_y
= sy
+ lines
;
857 debug_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
860 for (y
= start_y
; y
< finish_y
; y
++) {
862 /* avoid accumulating adds as floats don't have the precision to
863 * accurately iterate large triangle edges that way. luckily we
864 * can just multiply these days.
866 * this is all drowned out by the attribute interpolation anyway.
868 int left
= (int)(eleft
->sx
+ y
* eleft
->dxdy
);
869 int right
= (int)(eright
->sx
+ y
* eright
->dxdy
);
871 /* clip left/right */
879 if (block(_y
) != setup
->span
.y
) {
881 setup
->span
.y
= block(_y
);
884 setup
->span
.left
[_y
&1] = left
;
885 setup
->span
.right
[_y
&1] = right
;
886 setup
->span
.y_flags
|= 1<<(_y
&1);
891 /* save the values so that emaj can be restarted:
893 eleft
->sx
+= lines
* eleft
->dxdy
;
894 eright
->sx
+= lines
* eright
->dxdy
;
901 * Recalculate prim's determinant. This is needed as we don't have
902 * get this information through the vbuf_render interface & we must
906 calc_det( const float (*v0
)[4],
907 const float (*v1
)[4],
908 const float (*v2
)[4] )
910 /* edge vectors e = v0 - v2, f = v1 - v2 */
911 const float ex
= v0
[0][0] - v2
[0][0];
912 const float ey
= v0
[0][1] - v2
[0][1];
913 const float fx
= v1
[0][0] - v2
[0][0];
914 const float fy
= v1
[0][1] - v2
[0][1];
916 /* det = cross(e,f).z */
917 return ex
* fy
- ey
* fx
;
922 * Do setup for triangle rasterization, then render the triangle.
924 void setup_tri( struct setup_context
*setup
,
925 const float (*v0
)[4],
926 const float (*v1
)[4],
927 const float (*v2
)[4] )
932 debug_printf("Setup triangle:\n");
933 print_vertex(setup
, v0
);
934 print_vertex(setup
, v1
);
935 print_vertex(setup
, v2
);
938 if (setup
->softpipe
->no_rast
)
941 det
= calc_det(v0
, v1
, v2
);
943 debug_printf("%s\n", __FUNCTION__ );
947 setup
->numFragsEmitted
= 0;
948 setup
->numFragsWritten
= 0;
951 if (cull_tri( setup
, det
))
954 if (!setup_sort_vertices( setup
, det
, v0
, v1
, v2
))
956 setup_tri_coefficients( setup
);
957 setup_tri_edges( setup
);
959 setup
->quad
.input
.prim
= QUAD_PRIM_TRI
;
962 setup
->span
.y_flags
= 0;
963 setup
->span
.right
[0] = 0;
964 setup
->span
.right
[1] = 0;
965 /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
967 /* init_constant_attribs( setup ); */
969 if (setup
->oneoverarea
< 0.0) {
972 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
973 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
978 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
979 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
982 flush_spans( setup
);
984 WAIT_FOR_COMPLETION(setup
);
987 printf("Tri: %u frags emitted, %u written\n",
988 setup
->numFragsEmitted
,
989 setup
->numFragsWritten
);
996 * Compute a0, dadx and dady for a linearly interpolated coefficient,
1000 line_linear_coeff(const struct setup_context
*setup
,
1001 struct tgsi_interp_coef
*coef
,
1002 uint vertSlot
, uint i
)
1004 const float da
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
1005 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
1006 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
1007 coef
->dadx
[i
] = dadx
;
1008 coef
->dady
[i
] = dady
;
1009 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
1010 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
1011 dady
* (setup
->vmin
[0][1] - 0.5f
)));
1016 * Compute a0, dadx and dady for a perspective-corrected interpolant,
1020 line_persp_coeff(const struct setup_context
*setup
,
1021 struct tgsi_interp_coef
*coef
,
1022 uint vertSlot
, uint i
)
1024 /* XXX double-check/verify this arithmetic */
1025 const float a0
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
1026 const float a1
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
1027 const float da
= a1
- a0
;
1028 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
1029 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
1030 coef
->dadx
[i
] = dadx
;
1031 coef
->dady
[i
] = dady
;
1032 coef
->a0
[i
] = (setup
->vmin
[vertSlot
][i
] -
1033 (dadx
* (setup
->vmin
[0][0] - 0.5f
) +
1034 dady
* (setup
->vmin
[0][1] - 0.5f
)));
1039 * Compute the setup->coef[] array dadx, dady, a0 values.
1040 * Must be called after setup->vmin,vmax are initialized.
1042 static INLINE boolean
1043 setup_line_coefficients(struct setup_context
*setup
,
1044 const float (*v0
)[4],
1045 const float (*v1
)[4])
1047 struct softpipe_context
*softpipe
= setup
->softpipe
;
1048 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
1049 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
1053 /* use setup->vmin, vmax to point to vertices */
1054 setup
->vprovoke
= v1
;
1058 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
1059 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
1061 /* NOTE: this is not really area but something proportional to it */
1062 area
= setup
->emaj
.dx
* setup
->emaj
.dx
+ setup
->emaj
.dy
* setup
->emaj
.dy
;
1063 if (area
== 0.0f
|| util_is_inf_or_nan(area
))
1065 setup
->oneoverarea
= 1.0f
/ area
;
1067 /* z and w are done by linear interpolation:
1069 line_linear_coeff(setup
, &setup
->posCoef
, 0, 2);
1070 line_linear_coeff(setup
, &setup
->posCoef
, 0, 3);
1072 /* setup interpolation for all the remaining attributes:
1074 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
1075 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1078 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1079 case INTERP_CONSTANT
:
1080 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1081 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1084 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1085 line_linear_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1087 case INTERP_PERSPECTIVE
:
1088 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1089 line_persp_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1092 setup_fragcoord_coeff(setup
, fragSlot
);
1098 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FOG
) {
1099 /* FOG.y = front/back facing XXX fix this */
1100 setup
->coef
[fragSlot
].a0
[1] = 1.0f
- setup
->quad
.input
.facing
;
1101 setup
->coef
[fragSlot
].dadx
[1] = 0.0;
1102 setup
->coef
[fragSlot
].dady
[1] = 0.0;
1110 * Plot a pixel in a line segment.
1113 plot(struct setup_context
*setup
, int x
, int y
)
1115 const int iy
= y
& 1;
1116 const int ix
= x
& 1;
1117 const int quadX
= x
- ix
;
1118 const int quadY
= y
- iy
;
1119 const int mask
= (1 << ix
) << (2 * iy
);
1121 if (quadX
!= setup
->quad
.input
.x0
||
1122 quadY
!= setup
->quad
.input
.y0
)
1124 /* flush prev quad, start new quad */
1126 if (setup
->quad
.input
.x0
!= -1)
1127 CLIP_EMIT_QUAD(setup
);
1129 setup
->quad
.input
.x0
= quadX
;
1130 setup
->quad
.input
.y0
= quadY
;
1131 setup
->quad
.inout
.mask
= 0x0;
1134 setup
->quad
.inout
.mask
|= mask
;
1139 * Do setup for line rasterization, then render the line.
1140 * Single-pixel width, no stipple, etc. We rely on the 'draw' module
1141 * to handle stippling and wide lines.
1144 setup_line(struct setup_context
*setup
,
1145 const float (*v0
)[4],
1146 const float (*v1
)[4])
1148 int x0
= (int) v0
[0][0];
1149 int x1
= (int) v1
[0][0];
1150 int y0
= (int) v0
[0][1];
1151 int y1
= (int) v1
[0][1];
1157 debug_printf("Setup line:\n");
1158 print_vertex(setup
, v0
);
1159 print_vertex(setup
, v1
);
1162 if (setup
->softpipe
->no_rast
)
1165 if (dx
== 0 && dy
== 0)
1168 if (!setup_line_coefficients(setup
, v0
, v1
))
1171 assert(v0
[0][0] < 1.0e9
);
1172 assert(v0
[0][1] < 1.0e9
);
1173 assert(v1
[0][0] < 1.0e9
);
1174 assert(v1
[0][1] < 1.0e9
);
1177 dx
= -dx
; /* make positive */
1185 dy
= -dy
; /* make positive */
1195 setup
->quad
.input
.x0
= setup
->quad
.input
.y0
= -1;
1196 setup
->quad
.inout
.mask
= 0x0;
1197 setup
->quad
.input
.prim
= QUAD_PRIM_LINE
;
1198 /* XXX temporary: set coverage to 1.0 so the line appears
1199 * if AA mode happens to be enabled.
1201 setup
->quad
.input
.coverage
[0] =
1202 setup
->quad
.input
.coverage
[1] =
1203 setup
->quad
.input
.coverage
[2] =
1204 setup
->quad
.input
.coverage
[3] = 1.0;
1207 /*** X-major line ***/
1209 const int errorInc
= dy
+ dy
;
1210 int error
= errorInc
- dx
;
1211 const int errorDec
= error
- dx
;
1213 for (i
= 0; i
< dx
; i
++) {
1214 plot(setup
, x0
, y0
);
1227 /*** Y-major line ***/
1229 const int errorInc
= dx
+ dx
;
1230 int error
= errorInc
- dy
;
1231 const int errorDec
= error
- dy
;
1233 for (i
= 0; i
< dy
; i
++) {
1234 plot(setup
, x0
, y0
);
1247 /* draw final quad */
1248 if (setup
->quad
.inout
.mask
) {
1249 CLIP_EMIT_QUAD(setup
);
1252 WAIT_FOR_COMPLETION(setup
);
1257 point_persp_coeff(const struct setup_context
*setup
,
1258 const float (*vert
)[4],
1259 struct tgsi_interp_coef
*coef
,
1260 uint vertSlot
, uint i
)
1263 coef
->dadx
[i
] = 0.0F
;
1264 coef
->dady
[i
] = 0.0F
;
1265 coef
->a0
[i
] = vert
[vertSlot
][i
] * vert
[0][3];
1270 * Do setup for point rasterization, then render the point.
1271 * Round or square points...
1272 * XXX could optimize a lot for 1-pixel points.
1275 setup_point( struct setup_context
*setup
,
1276 const float (*v0
)[4] )
1278 struct softpipe_context
*softpipe
= setup
->softpipe
;
1279 const struct sp_fragment_shader
*spfs
= softpipe
->fs
;
1280 const int sizeAttr
= setup
->softpipe
->psize_slot
;
1282 = sizeAttr
> 0 ? v0
[sizeAttr
][0]
1283 : setup
->softpipe
->rasterizer
->point_size
;
1284 const float halfSize
= 0.5F
* size
;
1285 const boolean round
= (boolean
) setup
->softpipe
->rasterizer
->point_smooth
;
1286 const float x
= v0
[0][0]; /* Note: data[0] is always position */
1287 const float y
= v0
[0][1];
1288 const struct vertex_info
*vinfo
= softpipe_get_vertex_info(softpipe
);
1292 debug_printf("Setup point:\n");
1293 print_vertex(setup
, v0
);
1296 if (softpipe
->no_rast
)
1299 /* For points, all interpolants are constant-valued.
1300 * However, for point sprites, we'll need to setup texcoords appropriately.
1301 * XXX: which coefficients are the texcoords???
1302 * We may do point sprites as textured quads...
1304 * KW: We don't know which coefficients are texcoords - ultimately
1305 * the choice of what interpolation mode to use for each attribute
1306 * should be determined by the fragment program, using
1307 * per-attribute declaration statements that include interpolation
1308 * mode as a parameter. So either the fragment program will have
1309 * to be adjusted for pointsprite vs normal point behaviour, or
1310 * otherwise a special interpolation mode will have to be defined
1311 * which matches the required behaviour for point sprites. But -
1312 * the latter is not a feature of normal hardware, and as such
1313 * probably should be ruled out on that basis.
1315 setup
->vprovoke
= v0
;
1318 const_coeff(setup
, &setup
->posCoef
, 0, 2);
1319 const_coeff(setup
, &setup
->posCoef
, 0, 3);
1321 for (fragSlot
= 0; fragSlot
< spfs
->info
.num_inputs
; fragSlot
++) {
1322 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1325 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1326 case INTERP_CONSTANT
:
1329 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1330 const_coeff(setup
, &setup
->coef
[fragSlot
], vertSlot
, j
);
1332 case INTERP_PERSPECTIVE
:
1333 for (j
= 0; j
< NUM_CHANNELS
; j
++)
1334 point_persp_coeff(setup
, setup
->vprovoke
,
1335 &setup
->coef
[fragSlot
], vertSlot
, j
);
1338 setup_fragcoord_coeff(setup
, fragSlot
);
1344 if (spfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FOG
) {
1345 /* FOG.y = front/back facing XXX fix this */
1346 setup
->coef
[fragSlot
].a0
[1] = 1.0f
- setup
->quad
.input
.facing
;
1347 setup
->coef
[fragSlot
].dadx
[1] = 0.0;
1348 setup
->coef
[fragSlot
].dady
[1] = 0.0;
1352 setup
->quad
.input
.prim
= QUAD_PRIM_POINT
;
1354 if (halfSize
<= 0.5 && !round
) {
1355 /* special case for 1-pixel points */
1356 const int ix
= ((int) x
) & 1;
1357 const int iy
= ((int) y
) & 1;
1358 setup
->quad
.input
.x0
= (int) x
- ix
;
1359 setup
->quad
.input
.y0
= (int) y
- iy
;
1360 setup
->quad
.inout
.mask
= (1 << ix
) << (2 * iy
);
1361 CLIP_EMIT_QUAD(setup
);
1365 /* rounded points */
1366 const int ixmin
= block((int) (x
- halfSize
));
1367 const int ixmax
= block((int) (x
+ halfSize
));
1368 const int iymin
= block((int) (y
- halfSize
));
1369 const int iymax
= block((int) (y
+ halfSize
));
1370 const float rmin
= halfSize
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
1371 const float rmax
= halfSize
+ 0.7071F
;
1372 const float rmin2
= MAX2(0.0F
, rmin
* rmin
);
1373 const float rmax2
= rmax
* rmax
;
1374 const float cscale
= 1.0F
/ (rmax2
- rmin2
);
1377 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1378 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1379 float dx
, dy
, dist2
, cover
;
1381 setup
->quad
.inout
.mask
= 0x0;
1383 dx
= (ix
+ 0.5f
) - x
;
1384 dy
= (iy
+ 0.5f
) - y
;
1385 dist2
= dx
* dx
+ dy
* dy
;
1386 if (dist2
<= rmax2
) {
1387 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1388 setup
->quad
.input
.coverage
[QUAD_TOP_LEFT
] = MIN2(cover
, 1.0f
);
1389 setup
->quad
.inout
.mask
|= MASK_TOP_LEFT
;
1392 dx
= (ix
+ 1.5f
) - x
;
1393 dy
= (iy
+ 0.5f
) - y
;
1394 dist2
= dx
* dx
+ dy
* dy
;
1395 if (dist2
<= rmax2
) {
1396 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1397 setup
->quad
.input
.coverage
[QUAD_TOP_RIGHT
] = MIN2(cover
, 1.0f
);
1398 setup
->quad
.inout
.mask
|= MASK_TOP_RIGHT
;
1401 dx
= (ix
+ 0.5f
) - x
;
1402 dy
= (iy
+ 1.5f
) - y
;
1403 dist2
= dx
* dx
+ dy
* dy
;
1404 if (dist2
<= rmax2
) {
1405 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1406 setup
->quad
.input
.coverage
[QUAD_BOTTOM_LEFT
] = MIN2(cover
, 1.0f
);
1407 setup
->quad
.inout
.mask
|= MASK_BOTTOM_LEFT
;
1410 dx
= (ix
+ 1.5f
) - x
;
1411 dy
= (iy
+ 1.5f
) - y
;
1412 dist2
= dx
* dx
+ dy
* dy
;
1413 if (dist2
<= rmax2
) {
1414 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1415 setup
->quad
.input
.coverage
[QUAD_BOTTOM_RIGHT
] = MIN2(cover
, 1.0f
);
1416 setup
->quad
.inout
.mask
|= MASK_BOTTOM_RIGHT
;
1419 if (setup
->quad
.inout
.mask
) {
1420 setup
->quad
.input
.x0
= ix
;
1421 setup
->quad
.input
.y0
= iy
;
1422 CLIP_EMIT_QUAD(setup
);
1429 const int xmin
= (int) (x
+ 0.75 - halfSize
);
1430 const int ymin
= (int) (y
+ 0.25 - halfSize
);
1431 const int xmax
= xmin
+ (int) size
;
1432 const int ymax
= ymin
+ (int) size
;
1433 /* XXX could apply scissor to xmin,ymin,xmax,ymax now */
1434 const int ixmin
= block(xmin
);
1435 const int ixmax
= block(xmax
- 1);
1436 const int iymin
= block(ymin
);
1437 const int iymax
= block(ymax
- 1);
1441 debug_printf("(%f, %f) -> X:%d..%d Y:%d..%d\n", x, y, xmin, xmax,ymin,ymax);
1443 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1446 /* above the top edge */
1447 rowMask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
1449 if (iy
+ 1 >= ymax
) {
1450 /* below the bottom edge */
1451 rowMask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
1454 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1455 uint mask
= rowMask
;
1458 /* fragment is past left edge of point, turn off left bits */
1459 mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
1461 if (ix
+ 1 >= xmax
) {
1462 /* past the right edge */
1463 mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
1466 setup
->quad
.inout
.mask
= mask
;
1467 setup
->quad
.input
.x0
= ix
;
1468 setup
->quad
.input
.y0
= iy
;
1469 CLIP_EMIT_QUAD(setup
);
1475 WAIT_FOR_COMPLETION(setup
);
1478 void setup_prepare( struct setup_context
*setup
)
1480 struct softpipe_context
*sp
= setup
->softpipe
;
1484 softpipe_update_derived(sp
);
1487 /* Note: nr_attrs is only used for debugging (vertex printing) */
1488 setup
->quad
.nr_attrs
= draw_num_vs_outputs(sp
->draw
);
1490 for (i
= 0; i
< SP_NUM_QUAD_THREADS
; i
++) {
1491 sp
->quad
[i
].first
->begin( sp
->quad
[i
].first
);
1494 if (sp
->reduced_api_prim
== PIPE_PRIM_TRIANGLES
&&
1495 sp
->rasterizer
->fill_cw
== PIPE_POLYGON_MODE_FILL
&&
1496 sp
->rasterizer
->fill_ccw
== PIPE_POLYGON_MODE_FILL
) {
1497 /* we'll do culling */
1498 setup
->winding
= sp
->rasterizer
->cull_mode
;
1501 /* 'draw' will do culling */
1502 setup
->winding
= PIPE_WINDING_NONE
;
1508 void setup_destroy_context( struct setup_context
*setup
)
1515 * Create a new primitive setup/render stage.
1517 struct setup_context
*setup_create_context( struct softpipe_context
*softpipe
)
1519 struct setup_context
*setup
= CALLOC_STRUCT(setup_context
);
1520 #if SP_NUM_QUAD_THREADS > 1
1524 setup
->softpipe
= softpipe
;
1526 setup
->quad
.coef
= setup
->coef
;
1527 setup
->quad
.posCoef
= &setup
->posCoef
;
1529 #if SP_NUM_QUAD_THREADS > 1
1530 setup
->que
.first
= 0;
1531 setup
->que
.last
= 0;
1532 pipe_mutex_init( setup
->que
.que_mutex
);
1533 pipe_condvar_init( setup
->que
.que_notfull_condvar
);
1534 pipe_condvar_init( setup
->que
.que_notempty_condvar
);
1535 setup
->que
.jobs_added
= 0;
1536 setup
->que
.jobs_done
= 0;
1537 pipe_condvar_init( setup
->que
.que_done_condvar
);
1538 for (i
= 0; i
< SP_NUM_QUAD_THREADS
; i
++) {
1539 setup
->threads
[i
].setup
= setup
;
1540 setup
->threads
[i
].id
= i
;
1541 setup
->threads
[i
].handle
= pipe_thread_create( quad_thread
, &setup
->threads
[i
] );