1 /**************************************************************************
3 * Copyright 2003 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 **************************************************************************/
28 /** @file intel_tris.c
30 * This file contains functions for managing the vertex buffer and emitting
42 #include "swrast/swrast.h"
43 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_context.h"
45 #include "tnl/t_pipeline.h"
46 #include "tnl/t_vertex.h"
48 #include "intel_screen.h"
49 #include "intel_context.h"
50 #include "intel_tris.h"
51 #include "intel_batchbuffer.h"
52 #include "intel_buffers.h"
53 #include "intel_reg.h"
54 #include "intel_span.h"
55 #include "intel_tex.h"
56 #include "intel_chipset.h"
57 #include "i830_context.h"
60 static void intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
);
61 static void intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
,
64 /** Sets the primitive type for a primitive sequence, flushing as needed. */
65 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
67 if (prim
!= intel
->prim
.primitive
) {
68 INTEL_FIREVERTICES(intel
);
69 intel
->prim
.primitive
= prim
;
73 /** Returns mapped VB space for the given number of vertices */
74 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
78 /* Check for space in the existing VB */
79 if (intel
->prim
.vb_bo
== NULL
||
80 (intel
->prim
.current_offset
+
81 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
82 (intel
->prim
.count
+ count
) >= (1 << 16)) {
83 /* Flush existing prim if any */
84 INTEL_FIREVERTICES(intel
);
86 intel_finish_vb(intel
);
89 if (intel
->prim
.vb
== NULL
)
90 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
91 intel
->prim
.vb_bo
= dri_bo_alloc(intel
->bufmgr
, "vb",
93 intel
->prim
.start_offset
= 0;
94 intel
->prim
.current_offset
= 0;
96 dri_bufmgr_check_aperture_space(intel
->prim
.vb_bo
);
99 intel
->prim
.flush
= intel_flush_prim
;
101 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
102 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
103 intel
->prim
.count
+= count
;
108 /** Dispatches the accumulated primitive to the batchbuffer. */
109 void intel_flush_prim(struct intel_context
*intel
)
114 /* Must be called after an intel_start_prim. */
115 assert(intel
->prim
.primitive
!= ~0);
117 if (intel
->prim
.count
== 0)
120 /* Keep a reference on the BO as it may get finished as we start the
123 vb_bo
= intel
->prim
.vb_bo
;
124 dri_bo_reference(vb_bo
);
126 intel_wait_flips(intel
);
128 intel
->vtbl
.emit_state(intel
);
130 /* Ensure that we don't start a new batch for the following emit, which
131 * depends on the state just emitted. emit_state should be making sure we
132 * have the space for this.
134 intel
->no_batch_wrap
= GL_TRUE
;
136 /* Check that we actually emitted the state into this batch, using the
137 * UPLOAD_CTX bit as the signal.
139 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
142 printf("emitting %d..%d=%d vertices size %d\n", intel
->prim
.start_offset
,
143 intel
->prim
.current_offset
, intel
->prim
.count
,
144 intel
->vertex_size
* 4);
147 if (IS_9XX(intel
->intelScreen
->deviceID
)) {
148 BEGIN_BATCH(5, LOOP_CLIPRECTS
);
149 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
150 I1_LOAD_S(0) | I1_LOAD_S(1) | 1);
151 assert((intel
->prim
.start_offset
& !S0_VB_OFFSET_MASK
) == 0);
152 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
153 intel
->prim
.start_offset
);
154 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
155 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
157 OUT_BATCH(_3DPRIMITIVE
|
159 PRIM_INDIRECT_SEQUENTIAL
|
160 intel
->prim
.primitive
|
162 OUT_BATCH(0); /* Beginning vertex index */
165 struct i830_context
*i830
= i830_context(&intel
->ctx
);
167 BEGIN_BATCH(5, LOOP_CLIPRECTS
);
168 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
169 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
171 assert((intel
->prim
.start_offset
& !S0_VB_OFFSET_MASK_830
) == 0);
172 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
173 intel
->prim
.start_offset
|
174 (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
177 * This is somewhat unfortunate -- VB width is tied up with
178 * vertex format data that we've already uploaded through
179 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
180 * STATE_IMMEDIATE_1 like this to avoid duplication.
182 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
183 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
184 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
185 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
187 OUT_BATCH(_3DPRIMITIVE
|
189 PRIM_INDIRECT_SEQUENTIAL
|
190 intel
->prim
.primitive
|
192 OUT_BATCH(0); /* Beginning vertex index */
196 intel
->no_batch_wrap
= GL_FALSE
;
198 intel
->prim
.flush
= NULL
;
199 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
200 if (!IS_9XX(intel
->intelScreen
->deviceID
))
201 intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
202 intel
->prim
.count
= 0;
204 dri_bo_unreference(vb_bo
);
208 * Uploads the locally-accumulated VB into the buffer object.
210 * This avoids us thrashing the cachelines in and out as the buffer gets
211 * filled, dispatched, then reused as the hardware completes rendering from it,
212 * and also lets us clflush less if we dispatch with a partially-filled VB.
214 * This is called normally from get_space when we're finishing a BO, but also
215 * at batch flush time so that we don't try accessing the contents of a
216 * just-dispatched buffer.
218 void intel_finish_vb(struct intel_context
*intel
)
220 if (intel
->prim
.vb_bo
== NULL
)
223 dri_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
225 dri_bo_unreference(intel
->prim
.vb_bo
);
226 intel
->prim
.vb_bo
= NULL
;
229 /***********************************************************************
230 * Emit primitives as inline vertices *
231 ***********************************************************************/
234 #define COPY_DWORDS( j, vb, vertsize, v ) \
237 __asm__ __volatile__( "rep ; movsl" \
238 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
244 #define COPY_DWORDS( j, vb, vertsize, v ) \
246 for ( j = 0 ; j < vertsize ; j++ ) { \
247 vb[j] = ((GLuint *)v)[j]; \
254 intel_draw_quad(struct intel_context
*intel
,
256 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
258 GLuint vertsize
= intel
->vertex_size
;
259 GLuint
*vb
= intel_get_prim_space(intel
, 6);
262 COPY_DWORDS(j
, vb
, vertsize
, v0
);
263 COPY_DWORDS(j
, vb
, vertsize
, v1
);
265 /* If smooth shading, draw like a trifan which gives better
266 * rasterization. Otherwise draw as two triangles with provoking
267 * vertex in third position as required for flat shading.
269 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
270 COPY_DWORDS(j
, vb
, vertsize
, v3
);
271 COPY_DWORDS(j
, vb
, vertsize
, v1
);
274 COPY_DWORDS(j
, vb
, vertsize
, v2
);
275 COPY_DWORDS(j
, vb
, vertsize
, v0
);
278 COPY_DWORDS(j
, vb
, vertsize
, v2
);
279 COPY_DWORDS(j
, vb
, vertsize
, v3
);
283 intel_draw_triangle(struct intel_context
*intel
,
284 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
286 GLuint vertsize
= intel
->vertex_size
;
287 GLuint
*vb
= intel_get_prim_space(intel
, 3);
290 COPY_DWORDS(j
, vb
, vertsize
, v0
);
291 COPY_DWORDS(j
, vb
, vertsize
, v1
);
292 COPY_DWORDS(j
, vb
, vertsize
, v2
);
297 intel_draw_line(struct intel_context
*intel
,
298 intelVertexPtr v0
, intelVertexPtr v1
)
300 GLuint vertsize
= intel
->vertex_size
;
301 GLuint
*vb
= intel_get_prim_space(intel
, 2);
304 COPY_DWORDS(j
, vb
, vertsize
, v0
);
305 COPY_DWORDS(j
, vb
, vertsize
, v1
);
310 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
312 GLuint vertsize
= intel
->vertex_size
;
313 GLuint
*vb
= intel_get_prim_space(intel
, 1);
316 /* Adjust for sub pixel position -- still required for conform. */
317 *(float *) &vb
[0] = v0
->v
.x
;
318 *(float *) &vb
[1] = v0
->v
.y
;
319 for (j
= 2; j
< vertsize
; j
++)
325 /***********************************************************************
326 * Fixup for ARB_point_parameters *
327 ***********************************************************************/
329 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
330 * represented in the fragment program InputsRead field.
333 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
335 GLcontext
*ctx
= &intel
->ctx
;
336 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
338 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
339 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
341 restore_psz
= psz
[0];
342 restore_alpha
= col
[3];
344 if (psz
[0] >= ctx
->Point
.Threshold
) {
345 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
348 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
349 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
350 col
[3] *= dsize
* dsize
;
356 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
357 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
358 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
360 intel_draw_point(intel
, v0
);
362 psz
[0] = restore_psz
;
363 col
[3] = restore_alpha
;
365 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
366 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
369 intel_draw_point(intel
, v0
);
376 /***********************************************************************
377 * Fixup for I915 WPOS texture coordinate *
378 ***********************************************************************/
383 intel_wpos_triangle(struct intel_context
*intel
,
384 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
386 GLuint offset
= intel
->wpos_offset
;
387 GLuint size
= intel
->wpos_size
;
388 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
389 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
390 GLfloat
*v2_wpos
= (GLfloat
*)((char *)v2
+ offset
);
392 __memcpy(v0_wpos
, v0
, size
);
393 __memcpy(v1_wpos
, v1
, size
);
394 __memcpy(v2_wpos
, v2
, size
);
396 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
397 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
398 v2_wpos
[1] = -v2_wpos
[1] + intel
->driDrawable
->h
;
401 intel_draw_triangle(intel
, v0
, v1
, v2
);
406 intel_wpos_line(struct intel_context
*intel
,
407 intelVertexPtr v0
, intelVertexPtr v1
)
409 GLuint offset
= intel
->wpos_offset
;
410 GLuint size
= intel
->wpos_size
;
411 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
412 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
414 __memcpy(v0_wpos
, v0
, size
);
415 __memcpy(v1_wpos
, v1
, size
);
417 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
418 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
420 intel_draw_line(intel
, v0
, v1
);
425 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
427 GLuint offset
= intel
->wpos_offset
;
428 GLuint size
= intel
->wpos_size
;
429 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
431 __memcpy(v0_wpos
, v0
, size
);
432 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
434 intel_draw_point(intel
, v0
);
442 /***********************************************************************
443 * Macros for t_dd_tritmp.h to draw basic primitives *
444 ***********************************************************************/
446 #define TRI( a, b, c ) \
449 intel->draw_tri( intel, a, b, c ); \
451 intel_draw_triangle( intel, a, b, c ); \
454 #define QUAD( a, b, c, d ) \
457 intel->draw_tri( intel, a, b, d ); \
458 intel->draw_tri( intel, b, c, d ); \
460 intel_draw_quad( intel, a, b, c, d ); \
463 #define LINE( v0, v1 ) \
466 intel->draw_line( intel, v0, v1 ); \
468 intel_draw_line( intel, v0, v1 ); \
471 #define POINT( v0 ) \
474 intel->draw_point( intel, v0 ); \
476 intel_draw_point( intel, v0 ); \
480 /***********************************************************************
481 * Build render functions from dd templates *
482 ***********************************************************************/
484 #define INTEL_OFFSET_BIT 0x01
485 #define INTEL_TWOSIDE_BIT 0x02
486 #define INTEL_UNFILLED_BIT 0x04
487 #define INTEL_FALLBACK_BIT 0x08
488 #define INTEL_MAX_TRIFUNC 0x10
493 tnl_points_func points
;
495 tnl_triangle_func triangle
;
497 } rast_tab
[INTEL_MAX_TRIFUNC
];
500 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
501 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
502 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
503 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
509 #define DO_FULL_QUAD 1
513 #define HAVE_BACK_COLORS 0
514 #define HAVE_HW_FLATSHADE 1
515 #define VERTEX intelVertex
518 /* Only used to pull back colors into vertices (ie, we know color is
521 #define INTEL_COLOR( dst, src ) \
523 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
524 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
525 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
526 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
529 #define INTEL_SPEC( dst, src ) \
531 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
532 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
533 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
537 #define DEPTH_SCALE intel->polygon_offset_scale
538 #define UNFILLED_TRI unfilled_tri
539 #define UNFILLED_QUAD unfilled_quad
540 #define VERT_X(_v) _v->v.x
541 #define VERT_Y(_v) _v->v.y
542 #define VERT_Z(_v) _v->v.z
543 #define AREA_IS_CCW( a ) (a > 0)
544 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
546 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
547 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
548 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
549 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
551 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
552 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
553 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
554 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
556 #define LOCAL_VARS(n) \
557 struct intel_context *intel = intel_context(ctx); \
558 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
559 GLuint coloroffset = intel->coloroffset; \
560 GLboolean specoffset = intel->specoffset; \
561 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
564 /***********************************************************************
565 * Helpers for rendering unfilled primitives *
566 ***********************************************************************/
568 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
581 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
582 #define RENDER_PRIMITIVE intel->render_primitive
584 #define IND INTEL_FALLBACK_BIT
585 #include "tnl_dd/t_dd_unfilled.h"
588 /***********************************************************************
589 * Generate GL render functions *
590 ***********************************************************************/
594 #include "tnl_dd/t_dd_tritmp.h"
596 #define IND (INTEL_OFFSET_BIT)
597 #define TAG(x) x##_offset
598 #include "tnl_dd/t_dd_tritmp.h"
600 #define IND (INTEL_TWOSIDE_BIT)
601 #define TAG(x) x##_twoside
602 #include "tnl_dd/t_dd_tritmp.h"
604 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
605 #define TAG(x) x##_twoside_offset
606 #include "tnl_dd/t_dd_tritmp.h"
608 #define IND (INTEL_UNFILLED_BIT)
609 #define TAG(x) x##_unfilled
610 #include "tnl_dd/t_dd_tritmp.h"
612 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
613 #define TAG(x) x##_offset_unfilled
614 #include "tnl_dd/t_dd_tritmp.h"
616 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
617 #define TAG(x) x##_twoside_unfilled
618 #include "tnl_dd/t_dd_tritmp.h"
620 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
621 #define TAG(x) x##_twoside_offset_unfilled
622 #include "tnl_dd/t_dd_tritmp.h"
624 #define IND (INTEL_FALLBACK_BIT)
625 #define TAG(x) x##_fallback
626 #include "tnl_dd/t_dd_tritmp.h"
628 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
629 #define TAG(x) x##_offset_fallback
630 #include "tnl_dd/t_dd_tritmp.h"
632 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
633 #define TAG(x) x##_twoside_fallback
634 #include "tnl_dd/t_dd_tritmp.h"
636 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
637 #define TAG(x) x##_twoside_offset_fallback
638 #include "tnl_dd/t_dd_tritmp.h"
640 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
641 #define TAG(x) x##_unfilled_fallback
642 #include "tnl_dd/t_dd_tritmp.h"
644 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
645 #define TAG(x) x##_offset_unfilled_fallback
646 #include "tnl_dd/t_dd_tritmp.h"
648 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
649 #define TAG(x) x##_twoside_unfilled_fallback
650 #include "tnl_dd/t_dd_tritmp.h"
652 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
654 #define TAG(x) x##_twoside_offset_unfilled_fallback
655 #include "tnl_dd/t_dd_tritmp.h"
664 init_twoside_offset();
666 init_offset_unfilled();
667 init_twoside_unfilled();
668 init_twoside_offset_unfilled();
670 init_offset_fallback();
671 init_twoside_fallback();
672 init_twoside_offset_fallback();
673 init_unfilled_fallback();
674 init_offset_unfilled_fallback();
675 init_twoside_unfilled_fallback();
676 init_twoside_offset_unfilled_fallback();
680 /***********************************************************************
681 * Rasterization fallback helpers *
682 ***********************************************************************/
685 /* This code is hit only when a mix of accelerated and unaccelerated
686 * primitives are being drawn, and only for the unaccelerated
690 intel_fallback_tri(struct intel_context
*intel
,
691 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
693 GLcontext
*ctx
= &intel
->ctx
;
697 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
699 INTEL_FIREVERTICES(intel
);
701 _swsetup_Translate(ctx
, v0
, &v
[0]);
702 _swsetup_Translate(ctx
, v1
, &v
[1]);
703 _swsetup_Translate(ctx
, v2
, &v
[2]);
704 intelSpanRenderStart(ctx
);
705 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
706 intelSpanRenderFinish(ctx
);
711 intel_fallback_line(struct intel_context
*intel
,
712 intelVertex
* v0
, intelVertex
* v1
)
714 GLcontext
*ctx
= &intel
->ctx
;
718 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
720 INTEL_FIREVERTICES(intel
);
722 _swsetup_Translate(ctx
, v0
, &v
[0]);
723 _swsetup_Translate(ctx
, v1
, &v
[1]);
724 intelSpanRenderStart(ctx
);
725 _swrast_Line(ctx
, &v
[0], &v
[1]);
726 intelSpanRenderFinish(ctx
);
730 intel_fallback_point(struct intel_context
*intel
,
733 GLcontext
*ctx
= &intel
->ctx
;
737 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
739 INTEL_FIREVERTICES(intel
);
741 _swsetup_Translate(ctx
, v0
, &v
[0]);
742 intelSpanRenderStart(ctx
);
743 _swrast_Point(ctx
, &v
[0]);
744 intelSpanRenderFinish(ctx
);
748 /**********************************************************************/
749 /* Render unclipped begin/end objects */
750 /**********************************************************************/
753 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
754 #define RENDER_POINTS( start, count ) \
755 for ( ; start < count ; start++) POINT( V(ELT(start)) );
756 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
757 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
758 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
759 #define INIT(x) intelRenderPrimitive( ctx, x )
762 struct intel_context *intel = intel_context(ctx); \
763 GLubyte *vertptr = (GLubyte *)intel->verts; \
764 const GLuint vertsize = intel->vertex_size; \
765 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
767 #define RESET_STIPPLE
768 #define RESET_OCCLUSION
769 #define PRESERVE_VB_DEFS
771 #define TAG(x) intel_##x##_verts
772 #include "tnl/t_vb_rendertmp.h"
775 #define TAG(x) intel_##x##_elts
776 #define ELT(x) elt[x]
777 #include "tnl/t_vb_rendertmp.h"
779 /**********************************************************************/
780 /* Render clipped primitives */
781 /**********************************************************************/
786 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
788 struct intel_context
*intel
= intel_context(ctx
);
789 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
790 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
791 GLuint prim
= intel
->render_primitive
;
793 /* Render the new vertices as an unclipped polygon.
796 GLuint
*tmp
= VB
->Elts
;
797 VB
->Elts
= (GLuint
*) elts
;
798 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
799 PRIM_BEGIN
| PRIM_END
);
803 /* Restore the render primitive
805 if (prim
!= GL_POLYGON
)
806 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
810 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
812 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
814 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
818 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
820 struct intel_context
*intel
= intel_context(ctx
);
821 const GLuint vertsize
= intel
->vertex_size
;
822 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
823 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
824 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
827 for (i
= 2; i
< n
; i
++) {
828 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
829 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
830 COPY_DWORDS(j
, vb
, vertsize
, start
);
834 /**********************************************************************/
835 /* Choose render functions */
836 /**********************************************************************/
841 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
842 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
845 intelChooseRenderState(GLcontext
* ctx
)
847 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
848 struct intel_context
*intel
= intel_context(ctx
);
849 GLuint flags
= ctx
->_TriangleCaps
;
850 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
851 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
854 if (INTEL_DEBUG
& DEBUG_STATE
)
855 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
857 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
859 if (flags
& ANY_RASTER_FLAGS
) {
860 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
861 index
|= INTEL_TWOSIDE_BIT
;
862 if (flags
& DD_TRI_OFFSET
)
863 index
|= INTEL_OFFSET_BIT
;
864 if (flags
& DD_TRI_UNFILLED
)
865 index
|= INTEL_UNFILLED_BIT
;
869 intel
->draw_point
= intel_wpos_point
;
870 intel
->draw_line
= intel_wpos_line
;
871 intel
->draw_tri
= intel_wpos_triangle
;
873 /* Make sure these get called:
875 index
|= INTEL_FALLBACK_BIT
;
878 intel
->draw_point
= intel_draw_point
;
879 intel
->draw_line
= intel_draw_line
;
880 intel
->draw_tri
= intel_draw_triangle
;
883 /* Hook in fallbacks for specific primitives.
885 if (flags
& ANY_FALLBACK_FLAGS
) {
886 if (flags
& DD_LINE_STIPPLE
)
887 intel
->draw_line
= intel_fallback_line
;
889 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
890 intel
->draw_tri
= intel_fallback_tri
;
892 if (flags
& DD_TRI_SMOOTH
) {
893 if (intel
->strict_conformance
)
894 intel
->draw_tri
= intel_fallback_tri
;
897 if (flags
& DD_POINT_ATTEN
) {
899 intel
->draw_point
= intel_atten_point
;
901 intel
->draw_point
= intel_fallback_point
;
904 if (flags
& DD_POINT_SMOOTH
) {
905 if (intel
->strict_conformance
)
906 intel
->draw_point
= intel_fallback_point
;
909 index
|= INTEL_FALLBACK_BIT
;
913 if (intel
->RenderIndex
!= index
) {
914 intel
->RenderIndex
= index
;
916 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
917 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
918 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
919 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
922 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
923 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
924 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
925 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
928 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
929 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
930 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
931 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
936 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
950 /**********************************************************************/
951 /* High level hooks for t_vb_render.c */
952 /**********************************************************************/
958 intelRunPipeline(GLcontext
* ctx
)
960 struct intel_context
*intel
= intel_context(ctx
);
962 _mesa_lock_context_textures(ctx
);
965 _mesa_update_state_locked(ctx
);
967 if (intel
->NewGLState
) {
968 if (intel
->NewGLState
& _NEW_TEXTURE
) {
969 intel
->vtbl
.update_texture_state(intel
);
972 if (!intel
->Fallback
) {
973 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
974 intelChooseRenderState(ctx
);
977 intel
->NewGLState
= 0;
980 _tnl_run_pipeline(ctx
);
982 _mesa_unlock_context_textures(ctx
);
986 intelRenderStart(GLcontext
* ctx
)
988 struct intel_context
*intel
= intel_context(ctx
);
990 intel
->vtbl
.render_start(intel_context(ctx
));
991 intel
->vtbl
.emit_state(intel
);
995 intelRenderFinish(GLcontext
* ctx
)
997 struct intel_context
*intel
= intel_context(ctx
);
999 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1002 INTEL_FIREVERTICES(intel
);
1008 /* System to flush dma and emit state changes based on the rasterized
1012 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
1014 struct intel_context
*intel
= intel_context(ctx
);
1017 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
1018 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
1020 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1022 /* Start a new primitive. Arrange to have it flushed later on.
1024 if (hwprim
!= intel
->prim
.primitive
) {
1025 INTEL_FIREVERTICES(intel
);
1027 intel_set_prim(intel
, hwprim
);
1035 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
1037 struct intel_context
*intel
= intel_context(ctx
);
1040 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
1042 /* Let some clipping routines know which primitive they're dealing
1045 intel
->render_primitive
= prim
;
1047 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
1048 * triangles. The rasterized primitive will always be reset by
1049 * lower level functions in that case, potentially pingponging the
1052 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
1053 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
1056 /* Set some primitive-dependent state and Start? a new primitive.
1058 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1062 /**********************************************************************/
1063 /* Transition to/from hardware rasterization. */
1064 /**********************************************************************/
1066 static char *fallbackStrings
[] = {
1067 [0] = "Draw buffer",
1068 [1] = "Read buffer",
1069 [2] = "Depth buffer",
1070 [3] = "Stencil buffer",
1071 [4] = "User disable",
1072 [5] = "Render mode",
1075 [13] = "Color mask",
1080 [18] = "Smooth polygon",
1081 [19] = "Smooth point",
1086 getFallbackString(GLuint bit
)
1093 return fallbackStrings
[i
];
1099 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1101 GLcontext
*ctx
= &intel
->ctx
;
1102 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1103 GLuint oldfallback
= intel
->Fallback
;
1106 intel
->Fallback
|= bit
;
1107 if (oldfallback
== 0) {
1109 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1110 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1111 bit
, getFallbackString(bit
));
1112 _swsetup_Wakeup(ctx
);
1113 intel
->RenderIndex
= ~0;
1117 intel
->Fallback
&= ~bit
;
1118 if (oldfallback
== bit
) {
1120 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1121 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1122 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1123 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1124 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1125 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1126 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1127 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1129 _tnl_invalidate_vertex_state(ctx
, ~0);
1130 _tnl_invalidate_vertices(ctx
, ~0);
1131 _tnl_install_attrs(ctx
,
1132 intel
->vertex_attrs
,
1133 intel
->vertex_attr_count
,
1134 intel
->ViewportMatrix
.m
, 0);
1136 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1148 /**********************************************************************/
1149 /* Used only with the metaops callbacks. */
1150 /**********************************************************************/
1152 intel_meta_draw_poly(struct intel_context
*intel
,
1155 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1159 GLboolean was_locked
= intel
->locked
;
1160 unsigned int saved_vertex_size
= intel
->vertex_size
;
1163 LOCK_HARDWARE(intel
);
1165 intel
->vertex_size
= 6;
1167 /* All 3d primitives should be emitted with LOOP_CLIPRECTS,
1168 * otherwise the drawing origin (DR4) might not be set correctly.
1170 intel_set_prim(intel
, PRIM3D_TRIFAN
);
1171 vb
= (union fi
*) intel_get_prim_space(intel
, n
);
1173 for (i
= 0; i
< n
; i
++) {
1178 vb
[4].f
= tex
[i
][0];
1179 vb
[5].f
= tex
[i
][1];
1183 INTEL_FIREVERTICES(intel
);
1185 intel
->vertex_size
= saved_vertex_size
;
1188 UNLOCK_HARDWARE(intel
);
1192 intel_meta_draw_quad(struct intel_context
*intel
,
1193 GLfloat x0
, GLfloat x1
,
1194 GLfloat y0
, GLfloat y1
,
1197 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1220 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1225 /**********************************************************************/
1226 /* Initialization. */
1227 /**********************************************************************/
1231 intelInitTriFuncs(GLcontext
* ctx
)
1233 struct intel_context
*intel
= intel_context(ctx
);
1234 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1235 static int firsttime
= 1;
1242 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1243 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1244 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1245 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1246 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1247 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1248 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1249 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1251 intel
->vtbl
.meta_draw_quad
= intel_meta_draw_quad
;