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 "lp_context.h"
39 #include "draw/draw_context.h"
40 #include "draw/draw_private.h"
41 #include "draw/draw_vertex.h"
42 #include "pipe/p_shader_tokens.h"
43 #include "util/u_format.h"
44 #include "util/u_math.h"
45 #include "util/u_memory.h"
46 #include "lp_bld_debug.h"
47 #include "lp_tile_cache.h"
48 #include "lp_tile_soa.h"
58 float dx
; /**< X(v1) - X(v0), used only during setup */
59 float dy
; /**< Y(v1) - Y(v0), used only during setup */
60 float dxdy
; /**< dx/dy */
61 float sx
, sy
; /**< first sample point coord */
62 int lines
; /**< number of lines on this edge */
70 * Triangle setup info (derived from draw_stage).
71 * Also used for line drawing (taking some liberties).
73 struct setup_context
{
74 struct llvmpipe_context
*llvmpipe
;
76 /* Vertices are just an array of floats making up each attribute in
77 * turn. Currently fixed at 4 floats, but should change in time.
78 * Codegen will help cope with this.
80 const float (*vmax
)[4];
81 const float (*vmid
)[4];
82 const float (*vmin
)[4];
83 const float (*vprovoke
)[4];
94 struct quad_header quad
[MAX_QUADS
];
95 struct quad_header
*quad_ptrs
[MAX_QUADS
];
98 struct quad_interp_coef coef
;
101 int left
[2]; /**< [0] = row0, [1] = row1 */
107 uint numFragsEmitted
; /**< per primitive */
108 uint numFragsWritten
; /**< per primitive */
111 unsigned winding
; /* which winding to cull */
117 * Execute fragment shader for the four fragments in the quad.
121 shade_quads(struct llvmpipe_context
*llvmpipe
,
122 struct quad_header
*quads
[],
125 struct lp_fragment_shader
*fs
= llvmpipe
->fs
;
126 struct quad_header
*quad
= quads
[0];
127 const unsigned x
= quad
->input
.x0
;
128 const unsigned y
= quad
->input
.y0
;
132 PIPE_ALIGN_VAR(16) uint32_t mask
[4][NUM_CHANNELS
];
141 assert(nr
* QUAD_SIZE
== TILE_VECTOR_HEIGHT
* TILE_VECTOR_WIDTH
);
142 assert(x
% TILE_VECTOR_WIDTH
== 0);
143 assert(y
% TILE_VECTOR_HEIGHT
== 0);
144 for (q
= 0; q
< nr
; ++q
) {
145 assert(quads
[q
]->input
.x0
== x
+ q
*2);
146 assert(quads
[q
]->input
.y0
== y
);
150 for (q
= 0; q
< 4; ++q
)
151 for (chan_index
= 0; chan_index
< NUM_CHANNELS
; ++chan_index
)
152 mask
[q
][chan_index
] = quads
[q
]->inout
.mask
& (1 << chan_index
) ? ~0 : 0;
155 if(llvmpipe
->framebuffer
.nr_cbufs
>= 1 &&
156 llvmpipe
->framebuffer
.cbufs
[0]) {
157 tile
= lp_get_cached_tile(llvmpipe
->cbuf_cache
[0], x
, y
);
158 color
= &TILE_PIXEL(tile
, x
& (TILE_SIZE
-1), y
& (TILE_SIZE
-1), 0);
164 if(llvmpipe
->zsbuf_map
) {
165 assert((x
% 2) == 0);
166 assert((y
% 2) == 0);
167 depth
= llvmpipe
->zsbuf_map
+
168 y
*llvmpipe
->zsbuf_transfer
->stride
+
169 2*x
*util_format_get_blocksize(llvmpipe
->zsbuf_transfer
->texture
->format
);
174 /* XXX: This will most likely fail on 32bit x86 without -mstackrealign */
175 assert(lp_check_alignment(mask
, 16));
177 assert(lp_check_alignment(depth
, 16));
178 assert(lp_check_alignment(color
, 16));
179 assert(lp_check_alignment(llvmpipe
->jit_context
.blend_color
, 16));
182 fs
->current
->jit_function( &llvmpipe
->jit_context
,
196 * Do triangle cull test using tri determinant (sign indicates orientation)
197 * \return true if triangle is to be culled.
199 static INLINE boolean
200 cull_tri(const struct setup_context
*setup
, float det
)
203 /* if (det < 0 then Z points toward camera and triangle is
204 * counter-clockwise winding.
206 unsigned winding
= (det
< 0) ? PIPE_WINDING_CCW
: PIPE_WINDING_CW
;
208 if ((winding
& setup
->winding
) == 0)
220 * Clip setup->quad against the scissor/surface bounds.
223 quad_clip( struct setup_context
*setup
, struct quad_header
*quad
)
225 const struct pipe_scissor_state
*cliprect
= &setup
->llvmpipe
->cliprect
;
226 const int minx
= (int) cliprect
->minx
;
227 const int maxx
= (int) cliprect
->maxx
;
228 const int miny
= (int) cliprect
->miny
;
229 const int maxy
= (int) cliprect
->maxy
;
231 if (quad
->input
.x0
>= maxx
||
232 quad
->input
.y0
>= maxy
||
233 quad
->input
.x0
+ 1 < minx
||
234 quad
->input
.y0
+ 1 < miny
) {
235 /* totally clipped */
236 quad
->inout
.mask
= 0x0;
239 if (quad
->input
.x0
< minx
)
240 quad
->inout
.mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
241 if (quad
->input
.y0
< miny
)
242 quad
->inout
.mask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
243 if (quad
->input
.x0
== maxx
- 1)
244 quad
->inout
.mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
245 if (quad
->input
.y0
== maxy
- 1)
246 quad
->inout
.mask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
252 * Given an X or Y coordinate, return the block/quad coordinate that it
255 static INLINE
int block( int x
)
260 static INLINE
int block_x( int x
)
262 return x
& ~(TILE_VECTOR_WIDTH
- 1);
267 * Emit a quad (pass to next stage) with clipping.
270 clip_emit_quad( struct setup_context
*setup
, struct quad_header
*quad
)
272 quad_clip( setup
, quad
);
274 if (quad
->inout
.mask
) {
275 struct llvmpipe_context
*lp
= setup
->llvmpipe
;
278 /* XXX: The blender expects 4 quads. This is far from efficient, but
279 * until we codegenerate single-quad variants of the fragment pipeline
280 * we need this hack. */
281 const unsigned nr_quads
= TILE_VECTOR_HEIGHT
*TILE_VECTOR_WIDTH
/QUAD_SIZE
;
282 struct quad_header quads
[4];
283 struct quad_header
*quad_ptrs
[4];
284 int x0
= block_x(quad
->input
.x0
);
287 assert(nr_quads
== 4);
289 for(i
= 0; i
< nr_quads
; ++i
) {
291 if(x
== quad
->input
.x0
)
292 memcpy(&quads
[i
], quad
, sizeof quads
[i
]);
294 memset(&quads
[i
], 0, sizeof quads
[i
]);
295 quads
[i
].input
.x0
= x
;
296 quads
[i
].input
.y0
= quad
->input
.y0
;
297 quads
[i
].coef
= quad
->coef
;
299 quad_ptrs
[i
] = &quads
[i
];
302 shade_quads( lp
, quad_ptrs
, nr_quads
);
304 shade_quads( lp
, &quad
, 1 );
311 * Render a horizontal span of quads
313 static void flush_spans( struct setup_context
*setup
)
315 const int step
= TILE_VECTOR_WIDTH
;
316 const int xleft0
= setup
->span
.left
[0];
317 const int xleft1
= setup
->span
.left
[1];
318 const int xright0
= setup
->span
.right
[0];
319 const int xright1
= setup
->span
.right
[1];
322 int minleft
= block_x(MIN2(xleft0
, xleft1
));
323 int maxright
= MAX2(xright0
, xright1
);
326 for (x
= minleft
; x
< maxright
; x
+= step
) {
327 unsigned skip_left0
= CLAMP(xleft0
- x
, 0, step
);
328 unsigned skip_left1
= CLAMP(xleft1
- x
, 0, step
);
329 unsigned skip_right0
= CLAMP(x
+ step
- xright0
, 0, step
);
330 unsigned skip_right1
= CLAMP(x
+ step
- xright1
, 0, step
);
332 const unsigned nr_quads
= TILE_VECTOR_HEIGHT
*TILE_VECTOR_WIDTH
/QUAD_SIZE
;
335 unsigned skipmask_left0
= (1U << skip_left0
) - 1U;
336 unsigned skipmask_left1
= (1U << skip_left1
) - 1U;
338 /* These calculations fail when step == 32 and skip_right == 0.
340 unsigned skipmask_right0
= ~0U << (unsigned)(step
- skip_right0
);
341 unsigned skipmask_right1
= ~0U << (unsigned)(step
- skip_right1
);
343 unsigned mask0
= ~skipmask_left0
& ~skipmask_right0
;
344 unsigned mask1
= ~skipmask_left1
& ~skipmask_right1
;
347 for(q
= 0; q
< nr_quads
; ++q
) {
348 unsigned quadmask
= (mask0
& 3) | ((mask1
& 3) << 2);
349 setup
->quad
[q
].input
.x0
= lx
;
350 setup
->quad
[q
].input
.y0
= setup
->span
.y
;
351 setup
->quad
[q
].inout
.mask
= quadmask
;
352 setup
->quad_ptrs
[q
] = &setup
->quad
[q
];
357 assert(!(mask0
| mask1
));
359 shade_quads(setup
->llvmpipe
, setup
->quad_ptrs
, nr_quads
);
365 setup
->span
.right
[0] = 0;
366 setup
->span
.right
[1] = 0;
367 setup
->span
.left
[0] = 1000000; /* greater than right[0] */
368 setup
->span
.left
[1] = 1000000; /* greater than right[1] */
373 static void print_vertex(const struct setup_context
*setup
,
377 debug_printf(" Vertex: (%p)\n", v
);
378 for (i
= 0; i
< setup
->quad
[0].nr_attrs
; i
++) {
379 debug_printf(" %d: %f %f %f %f\n", i
,
380 v
[i
][0], v
[i
][1], v
[i
][2], v
[i
][3]);
381 if (util_is_inf_or_nan(v
[i
][0])) {
382 debug_printf(" NaN!\n");
389 * Sort the vertices from top to bottom order, setting up the triangle
390 * edge fields (ebot, emaj, etop).
391 * \return FALSE if coords are inf/nan (cull the tri), TRUE otherwise
393 static boolean
setup_sort_vertices( struct setup_context
*setup
,
395 const float (*v0
)[4],
396 const float (*v1
)[4],
397 const float (*v2
)[4] )
399 setup
->vprovoke
= v2
;
401 /* determine bottom to top order of vertices */
448 setup
->ebot
.dx
= setup
->vmid
[0][0] - setup
->vmin
[0][0];
449 setup
->ebot
.dy
= setup
->vmid
[0][1] - setup
->vmin
[0][1];
450 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
451 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
452 setup
->etop
.dx
= setup
->vmax
[0][0] - setup
->vmid
[0][0];
453 setup
->etop
.dy
= setup
->vmax
[0][1] - setup
->vmid
[0][1];
456 * Compute triangle's area. Use 1/area to compute partial
457 * derivatives of attributes later.
459 * The area will be the same as prim->det, but the sign may be
460 * different depending on how the vertices get sorted above.
462 * To determine whether the primitive is front or back facing we
463 * use the prim->det value because its sign is correct.
466 const float area
= (setup
->emaj
.dx
* setup
->ebot
.dy
-
467 setup
->ebot
.dx
* setup
->emaj
.dy
);
469 setup
->oneoverarea
= 1.0f
/ area
;
472 debug_printf("%s one-over-area %f area %f det %f\n",
473 __FUNCTION__, setup->oneoverarea, area, det );
475 if (util_is_inf_or_nan(setup
->oneoverarea
))
479 /* We need to know if this is a front or back-facing triangle for:
480 * - the GLSL gl_FrontFacing fragment attribute (bool)
481 * - two-sided stencil test
485 (setup
->llvmpipe
->rasterizer
->front_winding
== PIPE_WINDING_CW
));
487 /* Prepare pixel offset for rasterisation:
488 * - pixel center (0.5, 0.5) for GL, or
489 * - assume (0.0, 0.0) for other APIs.
491 if (setup
->llvmpipe
->rasterizer
->gl_rasterization_rules
) {
492 setup
->pixel_offset
= 0.5f
;
494 setup
->pixel_offset
= 0.0f
;
502 * Compute a0, dadx and dady for a linearly interpolated coefficient,
505 static void tri_pos_coeff( struct setup_context
*setup
,
506 uint vertSlot
, unsigned i
)
508 float botda
= setup
->vmid
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
509 float majda
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
510 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
511 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
512 float dadx
= a
* setup
->oneoverarea
;
513 float dady
= b
* setup
->oneoverarea
;
517 setup
->coef
.dadx
[0][i
] = dadx
;
518 setup
->coef
.dady
[0][i
] = dady
;
520 /* calculate a0 as the value which would be sampled for the
521 * fragment at (0,0), taking into account that we want to sample at
522 * pixel centers, in other words (pixel_offset, pixel_offset).
524 * this is neat but unfortunately not a good way to do things for
525 * triangles with very large values of dadx or dady as it will
526 * result in the subtraction and re-addition from a0 of a very
527 * large number, which means we'll end up loosing a lot of the
528 * fractional bits and precision from a0. the way to fix this is
529 * to define a0 as the sample at a pixel center somewhere near vmin
530 * instead - i'll switch to this later.
532 setup
->coef
.a0
[0][i
] = (setup
->vmin
[vertSlot
][i
] -
533 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
534 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
537 debug_printf("attr[%d].%c: %f dx:%f dy:%f\n",
539 setup->coef[slot].a0[i],
540 setup->coef[slot].dadx[i],
541 setup->coef[slot].dady[i]);
547 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
548 * The value value comes from vertex[slot][i].
549 * The result will be put into setup->coef[slot].a0[i].
550 * \param slot which attribute slot
551 * \param i which component of the slot (0..3)
553 static void const_pos_coeff( struct setup_context
*setup
,
554 uint vertSlot
, unsigned i
)
556 setup
->coef
.dadx
[0][i
] = 0;
557 setup
->coef
.dady
[0][i
] = 0;
559 /* need provoking vertex info!
561 setup
->coef
.a0
[0][i
] = setup
->vprovoke
[vertSlot
][i
];
566 * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
567 * The value value comes from vertex[slot][i].
568 * The result will be put into setup->coef[slot].a0[i].
569 * \param slot which attribute slot
570 * \param i which component of the slot (0..3)
572 static void const_coeff( struct setup_context
*setup
,
577 for (i
= 0; i
< NUM_CHANNELS
; ++i
) {
578 setup
->coef
.dadx
[1 + attrib
][i
] = 0;
579 setup
->coef
.dady
[1 + attrib
][i
] = 0;
581 /* need provoking vertex info!
583 setup
->coef
.a0
[1 + attrib
][i
] = setup
->vprovoke
[vertSlot
][i
];
589 * Compute a0, dadx and dady for a linearly interpolated coefficient,
592 static void tri_linear_coeff( struct setup_context
*setup
,
597 for (i
= 0; i
< NUM_CHANNELS
; ++i
) {
598 float botda
= setup
->vmid
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
599 float majda
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
600 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
601 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
602 float dadx
= a
* setup
->oneoverarea
;
603 float dady
= b
* setup
->oneoverarea
;
607 setup
->coef
.dadx
[1 + attrib
][i
] = dadx
;
608 setup
->coef
.dady
[1 + attrib
][i
] = dady
;
610 /* calculate a0 as the value which would be sampled for the
611 * fragment at (0,0), taking into account that we want to sample at
612 * pixel centers, in other words (0.5, 0.5).
614 * this is neat but unfortunately not a good way to do things for
615 * triangles with very large values of dadx or dady as it will
616 * result in the subtraction and re-addition from a0 of a very
617 * large number, which means we'll end up loosing a lot of the
618 * fractional bits and precision from a0. the way to fix this is
619 * to define a0 as the sample at a pixel center somewhere near vmin
620 * instead - i'll switch to this later.
622 setup
->coef
.a0
[1 + attrib
][i
] = (setup
->vmin
[vertSlot
][i
] -
623 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
624 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
627 debug_printf("attr[%d].%c: %f dx:%f dy:%f\n",
629 setup->coef[slot].a0[i],
630 setup->coef[slot].dadx[i],
631 setup->coef[slot].dady[i]);
638 * Compute a0, dadx and dady for a perspective-corrected interpolant,
640 * We basically multiply the vertex value by 1/w before computing
641 * the plane coefficients (a0, dadx, dady).
642 * Later, when we compute the value at a particular fragment position we'll
643 * divide the interpolated value by the interpolated W at that fragment.
645 static void tri_persp_coeff( struct setup_context
*setup
,
650 for (i
= 0; i
< NUM_CHANNELS
; ++i
) {
651 /* premultiply by 1/w (v[0][3] is always W):
653 float mina
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
654 float mida
= setup
->vmid
[vertSlot
][i
] * setup
->vmid
[0][3];
655 float maxa
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
656 float botda
= mida
- mina
;
657 float majda
= maxa
- mina
;
658 float a
= setup
->ebot
.dy
* majda
- botda
* setup
->emaj
.dy
;
659 float b
= setup
->emaj
.dx
* botda
- majda
* setup
->ebot
.dx
;
660 float dadx
= a
* setup
->oneoverarea
;
661 float dady
= b
* setup
->oneoverarea
;
664 debug_printf("tri persp %d,%d: %f %f %f\n", vertSlot, i,
665 setup->vmin[vertSlot][i],
666 setup->vmid[vertSlot][i],
667 setup->vmax[vertSlot][i]
672 setup
->coef
.dadx
[1 + attrib
][i
] = dadx
;
673 setup
->coef
.dady
[1 + attrib
][i
] = dady
;
674 setup
->coef
.a0
[1 + attrib
][i
] = (mina
-
675 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
676 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
682 * Special coefficient setup for gl_FragCoord.
683 * X and Y are trivial, though Y has to be inverted for OpenGL.
684 * Z and W are copied from posCoef which should have already been computed.
685 * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
688 setup_fragcoord_coeff(struct setup_context
*setup
, uint slot
)
691 setup
->coef
.a0
[1 + slot
][0] = 0;
692 setup
->coef
.dadx
[1 + slot
][0] = 1.0;
693 setup
->coef
.dady
[1 + slot
][0] = 0.0;
695 setup
->coef
.a0
[1 + slot
][1] = 0.0;
696 setup
->coef
.dadx
[1 + slot
][1] = 0.0;
697 setup
->coef
.dady
[1 + slot
][1] = 1.0;
699 setup
->coef
.a0
[1 + slot
][2] = setup
->coef
.a0
[0][2];
700 setup
->coef
.dadx
[1 + slot
][2] = setup
->coef
.dadx
[0][2];
701 setup
->coef
.dady
[1 + slot
][2] = setup
->coef
.dady
[0][2];
703 setup
->coef
.a0
[1 + slot
][3] = setup
->coef
.a0
[0][3];
704 setup
->coef
.dadx
[1 + slot
][3] = setup
->coef
.dadx
[0][3];
705 setup
->coef
.dady
[1 + slot
][3] = setup
->coef
.dady
[0][3];
711 * Compute the setup->coef[] array dadx, dady, a0 values.
712 * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
714 static void setup_tri_coefficients( struct setup_context
*setup
)
716 struct llvmpipe_context
*llvmpipe
= setup
->llvmpipe
;
717 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
718 const struct vertex_info
*vinfo
= llvmpipe_get_vertex_info(llvmpipe
);
721 /* z and w are done by linear interpolation:
723 tri_pos_coeff(setup
, 0, 2);
724 tri_pos_coeff(setup
, 0, 3);
726 /* setup interpolation for all the remaining attributes:
728 for (fragSlot
= 0; fragSlot
< lpfs
->info
.num_inputs
; fragSlot
++) {
729 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
731 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
732 case INTERP_CONSTANT
:
733 const_coeff(setup
, fragSlot
, vertSlot
);
736 tri_linear_coeff(setup
, fragSlot
, vertSlot
);
738 case INTERP_PERSPECTIVE
:
739 tri_persp_coeff(setup
, fragSlot
, vertSlot
);
742 setup_fragcoord_coeff(setup
, fragSlot
);
748 if (lpfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
749 setup
->coef
.a0
[1 + fragSlot
][0] = 1.0f
- setup
->facing
;
750 setup
->coef
.dadx
[1 + fragSlot
][0] = 0.0;
751 setup
->coef
.dady
[1 + fragSlot
][0] = 0.0;
758 static void setup_tri_edges( struct setup_context
*setup
)
760 float vmin_x
= setup
->vmin
[0][0] + setup
->pixel_offset
;
761 float vmid_x
= setup
->vmid
[0][0] + setup
->pixel_offset
;
763 float vmin_y
= setup
->vmin
[0][1] - setup
->pixel_offset
;
764 float vmid_y
= setup
->vmid
[0][1] - setup
->pixel_offset
;
765 float vmax_y
= setup
->vmax
[0][1] - setup
->pixel_offset
;
767 setup
->emaj
.sy
= ceilf(vmin_y
);
768 setup
->emaj
.lines
= (int) ceilf(vmax_y
- setup
->emaj
.sy
);
769 setup
->emaj
.dxdy
= setup
->emaj
.dx
/ setup
->emaj
.dy
;
770 setup
->emaj
.sx
= vmin_x
+ (setup
->emaj
.sy
- vmin_y
) * setup
->emaj
.dxdy
;
772 setup
->etop
.sy
= ceilf(vmid_y
);
773 setup
->etop
.lines
= (int) ceilf(vmax_y
- setup
->etop
.sy
);
774 setup
->etop
.dxdy
= setup
->etop
.dx
/ setup
->etop
.dy
;
775 setup
->etop
.sx
= vmid_x
+ (setup
->etop
.sy
- vmid_y
) * setup
->etop
.dxdy
;
777 setup
->ebot
.sy
= ceilf(vmin_y
);
778 setup
->ebot
.lines
= (int) ceilf(vmid_y
- setup
->ebot
.sy
);
779 setup
->ebot
.dxdy
= setup
->ebot
.dx
/ setup
->ebot
.dy
;
780 setup
->ebot
.sx
= vmin_x
+ (setup
->ebot
.sy
- vmin_y
) * setup
->ebot
.dxdy
;
785 * Render the upper or lower half of a triangle.
786 * Scissoring/cliprect is applied here too.
788 static void subtriangle( struct setup_context
*setup
,
793 const struct pipe_scissor_state
*cliprect
= &setup
->llvmpipe
->cliprect
;
794 const int minx
= (int) cliprect
->minx
;
795 const int maxx
= (int) cliprect
->maxx
;
796 const int miny
= (int) cliprect
->miny
;
797 const int maxy
= (int) cliprect
->maxy
;
798 int y
, start_y
, finish_y
;
799 int sy
= (int)eleft
->sy
;
801 assert((int)eleft
->sy
== (int) eright
->sy
);
803 /* clip top/bottom */
808 finish_y
= sy
+ lines
;
816 debug_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
819 for (y
= start_y
; y
< finish_y
; y
++) {
821 /* avoid accumulating adds as floats don't have the precision to
822 * accurately iterate large triangle edges that way. luckily we
823 * can just multiply these days.
825 * this is all drowned out by the attribute interpolation anyway.
827 int left
= (int)(eleft
->sx
+ y
* eleft
->dxdy
);
828 int right
= (int)(eright
->sx
+ y
* eright
->dxdy
);
830 /* clip left/right */
838 if (block(_y
) != setup
->span
.y
) {
840 setup
->span
.y
= block(_y
);
843 setup
->span
.left
[_y
&1] = left
;
844 setup
->span
.right
[_y
&1] = right
;
849 /* save the values so that emaj can be restarted:
851 eleft
->sx
+= lines
* eleft
->dxdy
;
852 eright
->sx
+= lines
* eright
->dxdy
;
859 * Recalculate prim's determinant. This is needed as we don't have
860 * get this information through the vbuf_render interface & we must
864 calc_det( const float (*v0
)[4],
865 const float (*v1
)[4],
866 const float (*v2
)[4] )
868 /* edge vectors e = v0 - v2, f = v1 - v2 */
869 const float ex
= v0
[0][0] - v2
[0][0];
870 const float ey
= v0
[0][1] - v2
[0][1];
871 const float fx
= v1
[0][0] - v2
[0][0];
872 const float fy
= v1
[0][1] - v2
[0][1];
874 /* det = cross(e,f).z */
875 return ex
* fy
- ey
* fx
;
880 * Do setup for triangle rasterization, then render the triangle.
882 void llvmpipe_setup_tri( struct setup_context
*setup
,
883 const float (*v0
)[4],
884 const float (*v1
)[4],
885 const float (*v2
)[4] )
890 debug_printf("Setup triangle:\n");
891 print_vertex(setup
, v0
);
892 print_vertex(setup
, v1
);
893 print_vertex(setup
, v2
);
896 if (setup
->llvmpipe
->no_rast
)
899 det
= calc_det(v0
, v1
, v2
);
901 debug_printf("%s\n", __FUNCTION__ );
905 setup
->numFragsEmitted
= 0;
906 setup
->numFragsWritten
= 0;
909 if (cull_tri( setup
, det
))
912 if (!setup_sort_vertices( setup
, det
, v0
, v1
, v2
))
914 setup_tri_coefficients( setup
);
915 setup_tri_edges( setup
);
917 assert(setup
->llvmpipe
->reduced_prim
== PIPE_PRIM_TRIANGLES
);
920 setup
->span
.right
[0] = 0;
921 setup
->span
.right
[1] = 0;
922 /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
924 /* init_constant_attribs( setup ); */
926 if (setup
->oneoverarea
< 0.0) {
929 subtriangle( setup
, &setup
->emaj
, &setup
->ebot
, setup
->ebot
.lines
);
930 subtriangle( setup
, &setup
->emaj
, &setup
->etop
, setup
->etop
.lines
);
935 subtriangle( setup
, &setup
->ebot
, &setup
->emaj
, setup
->ebot
.lines
);
936 subtriangle( setup
, &setup
->etop
, &setup
->emaj
, setup
->etop
.lines
);
939 flush_spans( setup
);
942 printf("Tri: %u frags emitted, %u written\n",
943 setup
->numFragsEmitted
,
944 setup
->numFragsWritten
);
951 * Compute a0, dadx and dady for a linearly interpolated coefficient,
955 linear_pos_coeff(struct setup_context
*setup
,
956 uint vertSlot
, uint i
)
958 const float da
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
959 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
960 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
961 setup
->coef
.dadx
[0][i
] = dadx
;
962 setup
->coef
.dady
[0][i
] = dady
;
963 setup
->coef
.a0
[0][i
] = (setup
->vmin
[vertSlot
][i
] -
964 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
965 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
970 * Compute a0, dadx and dady for a linearly interpolated coefficient,
974 line_linear_coeff(struct setup_context
*setup
,
979 for (i
= 0; i
< NUM_CHANNELS
; ++i
) {
980 const float da
= setup
->vmax
[vertSlot
][i
] - setup
->vmin
[vertSlot
][i
];
981 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
982 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
983 setup
->coef
.dadx
[1 + attrib
][i
] = dadx
;
984 setup
->coef
.dady
[1 + attrib
][i
] = dady
;
985 setup
->coef
.a0
[1 + attrib
][i
] = (setup
->vmin
[vertSlot
][i
] -
986 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
987 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
993 * Compute a0, dadx and dady for a perspective-corrected interpolant,
997 line_persp_coeff(struct setup_context
*setup
,
1002 for (i
= 0; i
< NUM_CHANNELS
; ++i
) {
1003 /* XXX double-check/verify this arithmetic */
1004 const float a0
= setup
->vmin
[vertSlot
][i
] * setup
->vmin
[0][3];
1005 const float a1
= setup
->vmax
[vertSlot
][i
] * setup
->vmax
[0][3];
1006 const float da
= a1
- a0
;
1007 const float dadx
= da
* setup
->emaj
.dx
* setup
->oneoverarea
;
1008 const float dady
= da
* setup
->emaj
.dy
* setup
->oneoverarea
;
1009 setup
->coef
.dadx
[1 + attrib
][i
] = dadx
;
1010 setup
->coef
.dady
[1 + attrib
][i
] = dady
;
1011 setup
->coef
.a0
[1 + attrib
][i
] = (setup
->vmin
[vertSlot
][i
] -
1012 (dadx
* (setup
->vmin
[0][0] - setup
->pixel_offset
) +
1013 dady
* (setup
->vmin
[0][1] - setup
->pixel_offset
)));
1019 * Compute the setup->coef[] array dadx, dady, a0 values.
1020 * Must be called after setup->vmin,vmax are initialized.
1022 static INLINE boolean
1023 setup_line_coefficients(struct setup_context
*setup
,
1024 const float (*v0
)[4],
1025 const float (*v1
)[4])
1027 struct llvmpipe_context
*llvmpipe
= setup
->llvmpipe
;
1028 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
1029 const struct vertex_info
*vinfo
= llvmpipe_get_vertex_info(llvmpipe
);
1033 /* use setup->vmin, vmax to point to vertices */
1034 if (llvmpipe
->rasterizer
->flatshade_first
)
1035 setup
->vprovoke
= v0
;
1037 setup
->vprovoke
= v1
;
1041 setup
->emaj
.dx
= setup
->vmax
[0][0] - setup
->vmin
[0][0];
1042 setup
->emaj
.dy
= setup
->vmax
[0][1] - setup
->vmin
[0][1];
1044 /* NOTE: this is not really area but something proportional to it */
1045 area
= setup
->emaj
.dx
* setup
->emaj
.dx
+ setup
->emaj
.dy
* setup
->emaj
.dy
;
1046 if (area
== 0.0f
|| util_is_inf_or_nan(area
))
1048 setup
->oneoverarea
= 1.0f
/ area
;
1050 /* z and w are done by linear interpolation:
1052 linear_pos_coeff(setup
, 0, 2);
1053 linear_pos_coeff(setup
, 0, 3);
1055 /* setup interpolation for all the remaining attributes:
1057 for (fragSlot
= 0; fragSlot
< lpfs
->info
.num_inputs
; fragSlot
++) {
1058 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1060 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1061 case INTERP_CONSTANT
:
1062 const_coeff(setup
, fragSlot
, vertSlot
);
1065 line_linear_coeff(setup
, fragSlot
, vertSlot
);
1067 case INTERP_PERSPECTIVE
:
1068 line_persp_coeff(setup
, fragSlot
, vertSlot
);
1071 setup_fragcoord_coeff(setup
, fragSlot
);
1077 if (lpfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
1078 setup
->coef
.a0
[1 + fragSlot
][0] = 1.0f
- setup
->facing
;
1079 setup
->coef
.dadx
[1 + fragSlot
][0] = 0.0;
1080 setup
->coef
.dady
[1 + fragSlot
][0] = 0.0;
1088 * Plot a pixel in a line segment.
1091 plot(struct setup_context
*setup
, int x
, int y
)
1093 const int iy
= y
& 1;
1094 const int ix
= x
& 1;
1095 const int quadX
= x
- ix
;
1096 const int quadY
= y
- iy
;
1097 const int mask
= (1 << ix
) << (2 * iy
);
1099 if (quadX
!= setup
->quad
[0].input
.x0
||
1100 quadY
!= setup
->quad
[0].input
.y0
)
1102 /* flush prev quad, start new quad */
1104 if (setup
->quad
[0].input
.x0
!= -1)
1105 clip_emit_quad( setup
, &setup
->quad
[0] );
1107 setup
->quad
[0].input
.x0
= quadX
;
1108 setup
->quad
[0].input
.y0
= quadY
;
1109 setup
->quad
[0].inout
.mask
= 0x0;
1112 setup
->quad
[0].inout
.mask
|= mask
;
1117 * Do setup for line rasterization, then render the line.
1118 * Single-pixel width, no stipple, etc. We rely on the 'draw' module
1119 * to handle stippling and wide lines.
1122 llvmpipe_setup_line(struct setup_context
*setup
,
1123 const float (*v0
)[4],
1124 const float (*v1
)[4])
1126 int x0
= (int) v0
[0][0];
1127 int x1
= (int) v1
[0][0];
1128 int y0
= (int) v0
[0][1];
1129 int y1
= (int) v1
[0][1];
1135 debug_printf("Setup line:\n");
1136 print_vertex(setup
, v0
);
1137 print_vertex(setup
, v1
);
1140 if (setup
->llvmpipe
->no_rast
)
1143 if (dx
== 0 && dy
== 0)
1146 if (!setup_line_coefficients(setup
, v0
, v1
))
1149 assert(v0
[0][0] < 1.0e9
);
1150 assert(v0
[0][1] < 1.0e9
);
1151 assert(v1
[0][0] < 1.0e9
);
1152 assert(v1
[0][1] < 1.0e9
);
1155 dx
= -dx
; /* make positive */
1163 dy
= -dy
; /* make positive */
1172 assert(setup
->llvmpipe
->reduced_prim
== PIPE_PRIM_LINES
);
1174 setup
->quad
[0].input
.x0
= setup
->quad
[0].input
.y0
= -1;
1175 setup
->quad
[0].inout
.mask
= 0x0;
1177 /* XXX temporary: set coverage to 1.0 so the line appears
1178 * if AA mode happens to be enabled.
1180 setup
->quad
[0].input
.coverage
[0] =
1181 setup
->quad
[0].input
.coverage
[1] =
1182 setup
->quad
[0].input
.coverage
[2] =
1183 setup
->quad
[0].input
.coverage
[3] = 1.0;
1186 /*** X-major line ***/
1188 const int errorInc
= dy
+ dy
;
1189 int error
= errorInc
- dx
;
1190 const int errorDec
= error
- dx
;
1192 for (i
= 0; i
< dx
; i
++) {
1193 plot(setup
, x0
, y0
);
1206 /*** Y-major line ***/
1208 const int errorInc
= dx
+ dx
;
1209 int error
= errorInc
- dy
;
1210 const int errorDec
= error
- dy
;
1212 for (i
= 0; i
< dy
; i
++) {
1213 plot(setup
, x0
, y0
);
1226 /* draw final quad */
1227 if (setup
->quad
[0].inout
.mask
) {
1228 clip_emit_quad( setup
, &setup
->quad
[0] );
1234 point_persp_coeff(struct setup_context
*setup
,
1235 const float (*vert
)[4],
1240 for(i
= 0; i
< NUM_CHANNELS
; ++i
) {
1241 setup
->coef
.dadx
[1 + attrib
][i
] = 0.0F
;
1242 setup
->coef
.dady
[1 + attrib
][i
] = 0.0F
;
1243 setup
->coef
.a0
[1 + attrib
][i
] = vert
[vertSlot
][i
] * vert
[0][3];
1249 * Do setup for point rasterization, then render the point.
1250 * Round or square points...
1251 * XXX could optimize a lot for 1-pixel points.
1254 llvmpipe_setup_point( struct setup_context
*setup
,
1255 const float (*v0
)[4] )
1257 struct llvmpipe_context
*llvmpipe
= setup
->llvmpipe
;
1258 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
1259 const int sizeAttr
= setup
->llvmpipe
->psize_slot
;
1261 = sizeAttr
> 0 ? v0
[sizeAttr
][0]
1262 : setup
->llvmpipe
->rasterizer
->point_size
;
1263 const float halfSize
= 0.5F
* size
;
1264 const boolean round
= (boolean
) setup
->llvmpipe
->rasterizer
->point_smooth
;
1265 const float x
= v0
[0][0]; /* Note: data[0] is always position */
1266 const float y
= v0
[0][1];
1267 const struct vertex_info
*vinfo
= llvmpipe_get_vertex_info(llvmpipe
);
1271 debug_printf("Setup point:\n");
1272 print_vertex(setup
, v0
);
1275 if (llvmpipe
->no_rast
)
1278 assert(setup
->llvmpipe
->reduced_prim
== PIPE_PRIM_POINTS
);
1280 /* For points, all interpolants are constant-valued.
1281 * However, for point sprites, we'll need to setup texcoords appropriately.
1282 * XXX: which coefficients are the texcoords???
1283 * We may do point sprites as textured quads...
1285 * KW: We don't know which coefficients are texcoords - ultimately
1286 * the choice of what interpolation mode to use for each attribute
1287 * should be determined by the fragment program, using
1288 * per-attribute declaration statements that include interpolation
1289 * mode as a parameter. So either the fragment program will have
1290 * to be adjusted for pointsprite vs normal point behaviour, or
1291 * otherwise a special interpolation mode will have to be defined
1292 * which matches the required behaviour for point sprites. But -
1293 * the latter is not a feature of normal hardware, and as such
1294 * probably should be ruled out on that basis.
1296 setup
->vprovoke
= v0
;
1299 const_pos_coeff(setup
, 0, 2);
1300 const_pos_coeff(setup
, 0, 3);
1302 for (fragSlot
= 0; fragSlot
< lpfs
->info
.num_inputs
; fragSlot
++) {
1303 const uint vertSlot
= vinfo
->attrib
[fragSlot
].src_index
;
1305 switch (vinfo
->attrib
[fragSlot
].interp_mode
) {
1306 case INTERP_CONSTANT
:
1309 const_coeff(setup
, fragSlot
, vertSlot
);
1311 case INTERP_PERSPECTIVE
:
1312 point_persp_coeff(setup
, setup
->vprovoke
, fragSlot
, vertSlot
);
1315 setup_fragcoord_coeff(setup
, fragSlot
);
1321 if (lpfs
->info
.input_semantic_name
[fragSlot
] == TGSI_SEMANTIC_FACE
) {
1322 setup
->coef
.a0
[1 + fragSlot
][0] = 1.0f
- setup
->facing
;
1323 setup
->coef
.dadx
[1 + fragSlot
][0] = 0.0;
1324 setup
->coef
.dady
[1 + fragSlot
][0] = 0.0;
1329 if (halfSize
<= 0.5 && !round
) {
1330 /* special case for 1-pixel points */
1331 const int ix
= ((int) x
) & 1;
1332 const int iy
= ((int) y
) & 1;
1333 setup
->quad
[0].input
.x0
= (int) x
- ix
;
1334 setup
->quad
[0].input
.y0
= (int) y
- iy
;
1335 setup
->quad
[0].inout
.mask
= (1 << ix
) << (2 * iy
);
1336 clip_emit_quad( setup
, &setup
->quad
[0] );
1340 /* rounded points */
1341 const int ixmin
= block((int) (x
- halfSize
));
1342 const int ixmax
= block((int) (x
+ halfSize
));
1343 const int iymin
= block((int) (y
- halfSize
));
1344 const int iymax
= block((int) (y
+ halfSize
));
1345 const float rmin
= halfSize
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
1346 const float rmax
= halfSize
+ 0.7071F
;
1347 const float rmin2
= MAX2(0.0F
, rmin
* rmin
);
1348 const float rmax2
= rmax
* rmax
;
1349 const float cscale
= 1.0F
/ (rmax2
- rmin2
);
1352 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1353 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1354 float dx
, dy
, dist2
, cover
;
1356 setup
->quad
[0].inout
.mask
= 0x0;
1358 dx
= (ix
+ 0.5f
) - x
;
1359 dy
= (iy
+ 0.5f
) - y
;
1360 dist2
= dx
* dx
+ dy
* dy
;
1361 if (dist2
<= rmax2
) {
1362 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1363 setup
->quad
[0].input
.coverage
[QUAD_TOP_LEFT
] = MIN2(cover
, 1.0f
);
1364 setup
->quad
[0].inout
.mask
|= MASK_TOP_LEFT
;
1367 dx
= (ix
+ 1.5f
) - x
;
1368 dy
= (iy
+ 0.5f
) - y
;
1369 dist2
= dx
* dx
+ dy
* dy
;
1370 if (dist2
<= rmax2
) {
1371 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1372 setup
->quad
[0].input
.coverage
[QUAD_TOP_RIGHT
] = MIN2(cover
, 1.0f
);
1373 setup
->quad
[0].inout
.mask
|= MASK_TOP_RIGHT
;
1376 dx
= (ix
+ 0.5f
) - x
;
1377 dy
= (iy
+ 1.5f
) - y
;
1378 dist2
= dx
* dx
+ dy
* dy
;
1379 if (dist2
<= rmax2
) {
1380 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1381 setup
->quad
[0].input
.coverage
[QUAD_BOTTOM_LEFT
] = MIN2(cover
, 1.0f
);
1382 setup
->quad
[0].inout
.mask
|= MASK_BOTTOM_LEFT
;
1385 dx
= (ix
+ 1.5f
) - x
;
1386 dy
= (iy
+ 1.5f
) - y
;
1387 dist2
= dx
* dx
+ dy
* dy
;
1388 if (dist2
<= rmax2
) {
1389 cover
= 1.0F
- (dist2
- rmin2
) * cscale
;
1390 setup
->quad
[0].input
.coverage
[QUAD_BOTTOM_RIGHT
] = MIN2(cover
, 1.0f
);
1391 setup
->quad
[0].inout
.mask
|= MASK_BOTTOM_RIGHT
;
1394 if (setup
->quad
[0].inout
.mask
) {
1395 setup
->quad
[0].input
.x0
= ix
;
1396 setup
->quad
[0].input
.y0
= iy
;
1397 clip_emit_quad( setup
, &setup
->quad
[0] );
1404 const int xmin
= (int) (x
+ 0.75 - halfSize
);
1405 const int ymin
= (int) (y
+ 0.25 - halfSize
);
1406 const int xmax
= xmin
+ (int) size
;
1407 const int ymax
= ymin
+ (int) size
;
1408 /* XXX could apply scissor to xmin,ymin,xmax,ymax now */
1409 const int ixmin
= block(xmin
);
1410 const int ixmax
= block(xmax
- 1);
1411 const int iymin
= block(ymin
);
1412 const int iymax
= block(ymax
- 1);
1416 debug_printf("(%f, %f) -> X:%d..%d Y:%d..%d\n", x, y, xmin, xmax,ymin,ymax);
1418 for (iy
= iymin
; iy
<= iymax
; iy
+= 2) {
1421 /* above the top edge */
1422 rowMask
&= (MASK_BOTTOM_LEFT
| MASK_BOTTOM_RIGHT
);
1424 if (iy
+ 1 >= ymax
) {
1425 /* below the bottom edge */
1426 rowMask
&= (MASK_TOP_LEFT
| MASK_TOP_RIGHT
);
1429 for (ix
= ixmin
; ix
<= ixmax
; ix
+= 2) {
1430 uint mask
= rowMask
;
1433 /* fragment is past left edge of point, turn off left bits */
1434 mask
&= (MASK_BOTTOM_RIGHT
| MASK_TOP_RIGHT
);
1436 if (ix
+ 1 >= xmax
) {
1437 /* past the right edge */
1438 mask
&= (MASK_BOTTOM_LEFT
| MASK_TOP_LEFT
);
1441 setup
->quad
[0].inout
.mask
= mask
;
1442 setup
->quad
[0].input
.x0
= ix
;
1443 setup
->quad
[0].input
.y0
= iy
;
1444 clip_emit_quad( setup
, &setup
->quad
[0] );
1451 void llvmpipe_setup_prepare( struct setup_context
*setup
)
1453 struct llvmpipe_context
*lp
= setup
->llvmpipe
;
1456 llvmpipe_update_derived(lp
);
1459 if (lp
->reduced_api_prim
== PIPE_PRIM_TRIANGLES
&&
1460 lp
->rasterizer
->fill_cw
== PIPE_POLYGON_MODE_FILL
&&
1461 lp
->rasterizer
->fill_ccw
== PIPE_POLYGON_MODE_FILL
) {
1462 /* we'll do culling */
1463 setup
->winding
= lp
->rasterizer
->cull_mode
;
1466 /* 'draw' will do culling */
1467 setup
->winding
= PIPE_WINDING_NONE
;
1473 void llvmpipe_setup_destroy_context( struct setup_context
*setup
)
1475 align_free( setup
);
1480 * Create a new primitive setup/render stage.
1482 struct setup_context
*llvmpipe_setup_create_context( struct llvmpipe_context
*llvmpipe
)
1484 struct setup_context
*setup
;
1487 setup
= align_malloc(sizeof(struct setup_context
), 16);
1491 memset(setup
, 0, sizeof *setup
);
1492 setup
->llvmpipe
= llvmpipe
;
1494 for (i
= 0; i
< MAX_QUADS
; i
++) {
1495 setup
->quad
[i
].coef
= &setup
->coef
;
1498 setup
->span
.left
[0] = 1000000; /* greater than right[0] */
1499 setup
->span
.left
[1] = 1000000; /* greater than right[1] */