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
34 #include "main/glheader.h"
35 #include "main/context.h"
36 #include "main/macros.h"
37 #include "main/enums.h"
38 #include "main/texobj.h"
39 #include "main/state.h"
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
,
65 intel_flush_inline_primitive(struct intel_context
*intel
)
67 GLuint used
= intel
->batch
->ptr
- intel
->prim
.start_ptr
;
69 assert(intel
->prim
.primitive
!= ~0);
71 /* _mesa_printf("/\n"); */
76 *(int *) intel
->prim
.start_ptr
= (_3DPRIMITIVE
|
77 intel
->prim
.primitive
| (used
/ 4 - 2));
82 intel
->batch
->ptr
-= used
;
85 intel
->prim
.primitive
= ~0;
86 intel
->prim
.start_ptr
= 0;
87 intel
->prim
.flush
= 0;
90 static void intel_start_inline(struct intel_context
*intel
, uint32_t prim
)
94 intel
->vtbl
.emit_state(intel
);
96 intel
->no_batch_wrap
= GL_TRUE
;
98 /*_mesa_printf("%s *", __progname);*/
100 /* Emit a slot which will be filled with the inline primitive
106 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
108 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
109 intel
->prim
.primitive
= prim
;
110 intel
->prim
.flush
= intel_flush_inline_primitive
;
115 intel
->no_batch_wrap
= GL_FALSE
;
116 /* _mesa_printf(">"); */
119 static void intel_wrap_inline(struct intel_context
*intel
)
121 GLuint prim
= intel
->prim
.primitive
;
123 intel_flush_inline_primitive(intel
);
124 intel_batchbuffer_flush(intel
->batch
);
125 intel_start_inline(intel
, prim
); /* ??? */
128 static GLuint
*intel_extend_inline(struct intel_context
*intel
, GLuint dwords
)
130 GLuint sz
= dwords
* sizeof(GLuint
);
133 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
135 if (intel_batchbuffer_space(intel
->batch
) < sz
)
136 intel_wrap_inline(intel
);
138 /* _mesa_printf("."); */
140 intel
->vtbl
.assert_not_dirty(intel
);
142 ptr
= (GLuint
*) intel
->batch
->ptr
;
143 intel
->batch
->ptr
+= sz
;
148 /** Sets the primitive type for a primitive sequence, flushing as needed. */
149 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
151 /* if we have no VBOs */
153 if (intel
->intelScreen
->no_vbo
) {
154 intel_start_inline(intel
, prim
);
157 if (prim
!= intel
->prim
.primitive
) {
158 INTEL_FIREVERTICES(intel
);
159 intel
->prim
.primitive
= prim
;
163 /** Returns mapped VB space for the given number of vertices */
164 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
168 if (intel
->intelScreen
->no_vbo
) {
169 return intel_extend_inline(intel
, count
* intel
->vertex_size
);
172 /* Check for space in the existing VB */
173 if (intel
->prim
.vb_bo
== NULL
||
174 (intel
->prim
.current_offset
+
175 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
176 (intel
->prim
.count
+ count
) >= (1 << 16)) {
177 /* Flush existing prim if any */
178 INTEL_FIREVERTICES(intel
);
180 intel_finish_vb(intel
);
183 if (intel
->prim
.vb
== NULL
)
184 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
185 intel
->prim
.vb_bo
= dri_bo_alloc(intel
->bufmgr
, "vb",
187 intel
->prim
.start_offset
= 0;
188 intel
->prim
.current_offset
= 0;
191 intel
->prim
.flush
= intel_flush_prim
;
193 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
194 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
195 intel
->prim
.count
+= count
;
200 /** Dispatches the accumulated primitive to the batchbuffer. */
201 void intel_flush_prim(struct intel_context
*intel
)
203 dri_bo
*aper_array
[2];
205 unsigned int offset
, count
;
208 /* Must be called after an intel_start_prim. */
209 assert(intel
->prim
.primitive
!= ~0);
211 if (intel
->prim
.count
== 0)
214 /* Clear the current prims out of the context state so that a batch flush
215 * flush triggered by emit_state doesn't loop back to flush_prim again.
217 vb_bo
= intel
->prim
.vb_bo
;
218 dri_bo_reference(vb_bo
);
219 count
= intel
->prim
.count
;
220 intel
->prim
.count
= 0;
221 offset
= intel
->prim
.start_offset
;
222 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
223 if (!intel
->gen
>= 3)
224 intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
225 intel
->prim
.flush
= NULL
;
227 intel
->vtbl
.emit_state(intel
);
229 aper_array
[0] = intel
->batch
->buf
;
230 aper_array
[1] = vb_bo
;
231 if (dri_bufmgr_check_aperture_space(aper_array
, 2)) {
232 intel_batchbuffer_flush(intel
->batch
);
233 intel
->vtbl
.emit_state(intel
);
236 /* Ensure that we don't start a new batch for the following emit, which
237 * depends on the state just emitted. emit_state should be making sure we
238 * have the space for this.
240 intel
->no_batch_wrap
= GL_TRUE
;
242 /* Check that we actually emitted the state into this batch, using the
243 * UPLOAD_CTX bit as the signal.
245 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
248 printf("emitting %d..%d=%d vertices size %d\n", offset
,
249 intel
->prim
.current_offset
, count
,
250 intel
->vertex_size
* 4);
253 if (intel
->gen
>= 3) {
255 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
256 I1_LOAD_S(0) | I1_LOAD_S(1) | 1);
257 assert((offset
& !S0_VB_OFFSET_MASK
) == 0);
258 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0, offset
);
259 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
260 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
262 OUT_BATCH(_3DPRIMITIVE
|
264 PRIM_INDIRECT_SEQUENTIAL
|
265 intel
->prim
.primitive
|
267 OUT_BATCH(0); /* Beginning vertex index */
270 struct i830_context
*i830
= i830_context(&intel
->ctx
);
273 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
274 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
276 assert((offset
& !S0_VB_OFFSET_MASK_830
) == 0);
277 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
278 offset
| (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
281 * This is somewhat unfortunate -- VB width is tied up with
282 * vertex format data that we've already uploaded through
283 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
284 * STATE_IMMEDIATE_1 like this to avoid duplication.
286 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
287 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
288 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
289 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
291 OUT_BATCH(_3DPRIMITIVE
|
293 PRIM_INDIRECT_SEQUENTIAL
|
294 intel
->prim
.primitive
|
296 OUT_BATCH(0); /* Beginning vertex index */
300 intel
->no_batch_wrap
= GL_FALSE
;
302 dri_bo_unreference(vb_bo
);
306 * Uploads the locally-accumulated VB into the buffer object.
308 * This avoids us thrashing the cachelines in and out as the buffer gets
309 * filled, dispatched, then reused as the hardware completes rendering from it,
310 * and also lets us clflush less if we dispatch with a partially-filled VB.
312 * This is called normally from get_space when we're finishing a BO, but also
313 * at batch flush time so that we don't try accessing the contents of a
314 * just-dispatched buffer.
316 void intel_finish_vb(struct intel_context
*intel
)
318 if (intel
->prim
.vb_bo
== NULL
)
321 dri_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
323 dri_bo_unreference(intel
->prim
.vb_bo
);
324 intel
->prim
.vb_bo
= NULL
;
327 /***********************************************************************
328 * Emit primitives as inline vertices *
329 ***********************************************************************/
332 #define COPY_DWORDS( j, vb, vertsize, v ) \
335 __asm__ __volatile__( "rep ; movsl" \
336 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
342 #define COPY_DWORDS( j, vb, vertsize, v ) \
344 for ( j = 0 ; j < vertsize ; j++ ) { \
345 vb[j] = ((GLuint *)v)[j]; \
352 intel_draw_quad(struct intel_context
*intel
,
354 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
356 GLuint vertsize
= intel
->vertex_size
;
357 GLuint
*vb
= intel_get_prim_space(intel
, 6);
360 COPY_DWORDS(j
, vb
, vertsize
, v0
);
361 COPY_DWORDS(j
, vb
, vertsize
, v1
);
363 /* If smooth shading, draw like a trifan which gives better
364 * rasterization. Otherwise draw as two triangles with provoking
365 * vertex in third position as required for flat shading.
367 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
368 COPY_DWORDS(j
, vb
, vertsize
, v3
);
369 COPY_DWORDS(j
, vb
, vertsize
, v1
);
372 COPY_DWORDS(j
, vb
, vertsize
, v2
);
373 COPY_DWORDS(j
, vb
, vertsize
, v0
);
376 COPY_DWORDS(j
, vb
, vertsize
, v2
);
377 COPY_DWORDS(j
, vb
, vertsize
, v3
);
381 intel_draw_triangle(struct intel_context
*intel
,
382 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
384 GLuint vertsize
= intel
->vertex_size
;
385 GLuint
*vb
= intel_get_prim_space(intel
, 3);
388 COPY_DWORDS(j
, vb
, vertsize
, v0
);
389 COPY_DWORDS(j
, vb
, vertsize
, v1
);
390 COPY_DWORDS(j
, vb
, vertsize
, v2
);
395 intel_draw_line(struct intel_context
*intel
,
396 intelVertexPtr v0
, intelVertexPtr v1
)
398 GLuint vertsize
= intel
->vertex_size
;
399 GLuint
*vb
= intel_get_prim_space(intel
, 2);
402 COPY_DWORDS(j
, vb
, vertsize
, v0
);
403 COPY_DWORDS(j
, vb
, vertsize
, v1
);
408 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
410 GLuint vertsize
= intel
->vertex_size
;
411 GLuint
*vb
= intel_get_prim_space(intel
, 1);
414 /* Adjust for sub pixel position -- still required for conform. */
415 *(float *) &vb
[0] = v0
->v
.x
;
416 *(float *) &vb
[1] = v0
->v
.y
;
417 for (j
= 2; j
< vertsize
; j
++)
423 /***********************************************************************
424 * Fixup for ARB_point_parameters *
425 ***********************************************************************/
427 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
428 * represented in the fragment program InputsRead field.
431 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
433 GLcontext
*ctx
= &intel
->ctx
;
434 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
436 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
437 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
439 restore_psz
= psz
[0];
440 restore_alpha
= col
[3];
442 if (psz
[0] >= ctx
->Point
.Threshold
) {
443 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
446 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
447 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
448 col
[3] *= dsize
* dsize
;
454 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
455 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
456 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
458 intel_draw_point(intel
, v0
);
460 psz
[0] = restore_psz
;
461 col
[3] = restore_alpha
;
463 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
464 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
467 intel_draw_point(intel
, v0
);
474 /***********************************************************************
475 * Fixup for I915 WPOS texture coordinate *
476 ***********************************************************************/
481 intel_wpos_triangle(struct intel_context
*intel
,
482 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
484 GLuint offset
= intel
->wpos_offset
;
485 GLuint size
= intel
->wpos_size
;
486 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
487 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
488 GLfloat
*v2_wpos
= (GLfloat
*)((char *)v2
+ offset
);
490 __memcpy(v0_wpos
, v0
, size
);
491 __memcpy(v1_wpos
, v1
, size
);
492 __memcpy(v2_wpos
, v2
, size
);
494 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
495 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
496 v2_wpos
[1] = -v2_wpos
[1] + intel
->driDrawable
->h
;
499 intel_draw_triangle(intel
, v0
, v1
, v2
);
504 intel_wpos_line(struct intel_context
*intel
,
505 intelVertexPtr v0
, intelVertexPtr v1
)
507 GLuint offset
= intel
->wpos_offset
;
508 GLuint size
= intel
->wpos_size
;
509 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
510 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
512 __memcpy(v0_wpos
, v0
, size
);
513 __memcpy(v1_wpos
, v1
, size
);
515 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
516 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
518 intel_draw_line(intel
, v0
, v1
);
523 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
525 GLuint offset
= intel
->wpos_offset
;
526 GLuint size
= intel
->wpos_size
;
527 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
529 __memcpy(v0_wpos
, v0
, size
);
530 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
532 intel_draw_point(intel
, v0
);
540 /***********************************************************************
541 * Macros for t_dd_tritmp.h to draw basic primitives *
542 ***********************************************************************/
544 #define TRI( a, b, c ) \
547 intel->draw_tri( intel, a, b, c ); \
549 intel_draw_triangle( intel, a, b, c ); \
552 #define QUAD( a, b, c, d ) \
555 intel->draw_tri( intel, a, b, d ); \
556 intel->draw_tri( intel, b, c, d ); \
558 intel_draw_quad( intel, a, b, c, d ); \
561 #define LINE( v0, v1 ) \
564 intel->draw_line( intel, v0, v1 ); \
566 intel_draw_line( intel, v0, v1 ); \
569 #define POINT( v0 ) \
572 intel->draw_point( intel, v0 ); \
574 intel_draw_point( intel, v0 ); \
578 /***********************************************************************
579 * Build render functions from dd templates *
580 ***********************************************************************/
582 #define INTEL_OFFSET_BIT 0x01
583 #define INTEL_TWOSIDE_BIT 0x02
584 #define INTEL_UNFILLED_BIT 0x04
585 #define INTEL_FALLBACK_BIT 0x08
586 #define INTEL_MAX_TRIFUNC 0x10
591 tnl_points_func points
;
593 tnl_triangle_func triangle
;
595 } rast_tab
[INTEL_MAX_TRIFUNC
];
598 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
599 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
600 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
601 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
607 #define DO_FULL_QUAD 1
611 #define HAVE_BACK_COLORS 0
612 #define HAVE_HW_FLATSHADE 1
613 #define VERTEX intelVertex
616 /* Only used to pull back colors into vertices (ie, we know color is
619 #define INTEL_COLOR( dst, src ) \
621 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
622 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
623 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
624 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
627 #define INTEL_SPEC( dst, src ) \
629 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
630 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
631 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
635 #define DEPTH_SCALE intel->polygon_offset_scale
636 #define UNFILLED_TRI unfilled_tri
637 #define UNFILLED_QUAD unfilled_quad
638 #define VERT_X(_v) _v->v.x
639 #define VERT_Y(_v) _v->v.y
640 #define VERT_Z(_v) _v->v.z
641 #define AREA_IS_CCW( a ) (a > 0)
642 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
644 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
645 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
646 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
647 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
649 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
650 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
651 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
652 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
654 #define LOCAL_VARS(n) \
655 struct intel_context *intel = intel_context(ctx); \
656 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
657 GLuint coloroffset = intel->coloroffset; \
658 GLboolean specoffset = intel->specoffset; \
659 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
662 /***********************************************************************
663 * Helpers for rendering unfilled primitives *
664 ***********************************************************************/
666 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
679 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
680 #define RENDER_PRIMITIVE intel->render_primitive
682 #define IND INTEL_FALLBACK_BIT
683 #include "tnl_dd/t_dd_unfilled.h"
686 /***********************************************************************
687 * Generate GL render functions *
688 ***********************************************************************/
692 #include "tnl_dd/t_dd_tritmp.h"
694 #define IND (INTEL_OFFSET_BIT)
695 #define TAG(x) x##_offset
696 #include "tnl_dd/t_dd_tritmp.h"
698 #define IND (INTEL_TWOSIDE_BIT)
699 #define TAG(x) x##_twoside
700 #include "tnl_dd/t_dd_tritmp.h"
702 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
703 #define TAG(x) x##_twoside_offset
704 #include "tnl_dd/t_dd_tritmp.h"
706 #define IND (INTEL_UNFILLED_BIT)
707 #define TAG(x) x##_unfilled
708 #include "tnl_dd/t_dd_tritmp.h"
710 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
711 #define TAG(x) x##_offset_unfilled
712 #include "tnl_dd/t_dd_tritmp.h"
714 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
715 #define TAG(x) x##_twoside_unfilled
716 #include "tnl_dd/t_dd_tritmp.h"
718 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
719 #define TAG(x) x##_twoside_offset_unfilled
720 #include "tnl_dd/t_dd_tritmp.h"
722 #define IND (INTEL_FALLBACK_BIT)
723 #define TAG(x) x##_fallback
724 #include "tnl_dd/t_dd_tritmp.h"
726 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
727 #define TAG(x) x##_offset_fallback
728 #include "tnl_dd/t_dd_tritmp.h"
730 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
731 #define TAG(x) x##_twoside_fallback
732 #include "tnl_dd/t_dd_tritmp.h"
734 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
735 #define TAG(x) x##_twoside_offset_fallback
736 #include "tnl_dd/t_dd_tritmp.h"
738 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
739 #define TAG(x) x##_unfilled_fallback
740 #include "tnl_dd/t_dd_tritmp.h"
742 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
743 #define TAG(x) x##_offset_unfilled_fallback
744 #include "tnl_dd/t_dd_tritmp.h"
746 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
747 #define TAG(x) x##_twoside_unfilled_fallback
748 #include "tnl_dd/t_dd_tritmp.h"
750 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
752 #define TAG(x) x##_twoside_offset_unfilled_fallback
753 #include "tnl_dd/t_dd_tritmp.h"
762 init_twoside_offset();
764 init_offset_unfilled();
765 init_twoside_unfilled();
766 init_twoside_offset_unfilled();
768 init_offset_fallback();
769 init_twoside_fallback();
770 init_twoside_offset_fallback();
771 init_unfilled_fallback();
772 init_offset_unfilled_fallback();
773 init_twoside_unfilled_fallback();
774 init_twoside_offset_unfilled_fallback();
778 /***********************************************************************
779 * Rasterization fallback helpers *
780 ***********************************************************************/
783 /* This code is hit only when a mix of accelerated and unaccelerated
784 * primitives are being drawn, and only for the unaccelerated
788 intel_fallback_tri(struct intel_context
*intel
,
789 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
791 GLcontext
*ctx
= &intel
->ctx
;
795 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
797 INTEL_FIREVERTICES(intel
);
799 _swsetup_Translate(ctx
, v0
, &v
[0]);
800 _swsetup_Translate(ctx
, v1
, &v
[1]);
801 _swsetup_Translate(ctx
, v2
, &v
[2]);
802 intelSpanRenderStart(ctx
);
803 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
804 intelSpanRenderFinish(ctx
);
809 intel_fallback_line(struct intel_context
*intel
,
810 intelVertex
* v0
, intelVertex
* v1
)
812 GLcontext
*ctx
= &intel
->ctx
;
816 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
818 INTEL_FIREVERTICES(intel
);
820 _swsetup_Translate(ctx
, v0
, &v
[0]);
821 _swsetup_Translate(ctx
, v1
, &v
[1]);
822 intelSpanRenderStart(ctx
);
823 _swrast_Line(ctx
, &v
[0], &v
[1]);
824 intelSpanRenderFinish(ctx
);
828 intel_fallback_point(struct intel_context
*intel
,
831 GLcontext
*ctx
= &intel
->ctx
;
835 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
837 INTEL_FIREVERTICES(intel
);
839 _swsetup_Translate(ctx
, v0
, &v
[0]);
840 intelSpanRenderStart(ctx
);
841 _swrast_Point(ctx
, &v
[0]);
842 intelSpanRenderFinish(ctx
);
846 /**********************************************************************/
847 /* Render unclipped begin/end objects */
848 /**********************************************************************/
851 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
852 #define RENDER_POINTS( start, count ) \
853 for ( ; start < count ; start++) POINT( V(ELT(start)) );
854 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
855 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
856 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
857 #define INIT(x) intelRenderPrimitive( ctx, x )
860 struct intel_context *intel = intel_context(ctx); \
861 GLubyte *vertptr = (GLubyte *)intel->verts; \
862 const GLuint vertsize = intel->vertex_size; \
863 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
865 #define RESET_STIPPLE
866 #define RESET_OCCLUSION
867 #define PRESERVE_VB_DEFS
869 #define TAG(x) intel_##x##_verts
870 #include "tnl/t_vb_rendertmp.h"
873 #define TAG(x) intel_##x##_elts
874 #define ELT(x) elt[x]
875 #include "tnl/t_vb_rendertmp.h"
877 /**********************************************************************/
878 /* Render clipped primitives */
879 /**********************************************************************/
884 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
886 struct intel_context
*intel
= intel_context(ctx
);
887 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
888 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
889 GLuint prim
= intel
->render_primitive
;
891 /* Render the new vertices as an unclipped polygon.
894 GLuint
*tmp
= VB
->Elts
;
895 VB
->Elts
= (GLuint
*) elts
;
896 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
897 PRIM_BEGIN
| PRIM_END
);
901 /* Restore the render primitive
903 if (prim
!= GL_POLYGON
)
904 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
908 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
910 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
912 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
916 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
918 struct intel_context
*intel
= intel_context(ctx
);
919 const GLuint vertsize
= intel
->vertex_size
;
920 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
921 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
922 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
925 for (i
= 2; i
< n
; i
++) {
926 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
927 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
928 COPY_DWORDS(j
, vb
, vertsize
, start
);
932 /**********************************************************************/
933 /* Choose render functions */
934 /**********************************************************************/
939 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
940 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
943 intelChooseRenderState(GLcontext
* ctx
)
945 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
946 struct intel_context
*intel
= intel_context(ctx
);
947 GLuint flags
= ctx
->_TriangleCaps
;
948 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
949 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
952 if (INTEL_DEBUG
& DEBUG_STATE
)
953 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
955 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
957 if (flags
& ANY_RASTER_FLAGS
) {
958 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
959 index
|= INTEL_TWOSIDE_BIT
;
960 if (flags
& DD_TRI_OFFSET
)
961 index
|= INTEL_OFFSET_BIT
;
962 if (flags
& DD_TRI_UNFILLED
)
963 index
|= INTEL_UNFILLED_BIT
;
967 intel
->draw_point
= intel_wpos_point
;
968 intel
->draw_line
= intel_wpos_line
;
969 intel
->draw_tri
= intel_wpos_triangle
;
971 /* Make sure these get called:
973 index
|= INTEL_FALLBACK_BIT
;
976 intel
->draw_point
= intel_draw_point
;
977 intel
->draw_line
= intel_draw_line
;
978 intel
->draw_tri
= intel_draw_triangle
;
981 /* Hook in fallbacks for specific primitives.
983 if (flags
& ANY_FALLBACK_FLAGS
) {
984 if (flags
& DD_LINE_STIPPLE
)
985 intel
->draw_line
= intel_fallback_line
;
987 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
988 intel
->draw_tri
= intel_fallback_tri
;
990 if (flags
& DD_TRI_SMOOTH
) {
991 if (intel
->conformance_mode
> 0)
992 intel
->draw_tri
= intel_fallback_tri
;
995 if (flags
& DD_POINT_ATTEN
) {
997 intel
->draw_point
= intel_atten_point
;
999 intel
->draw_point
= intel_fallback_point
;
1002 if (flags
& DD_POINT_SMOOTH
) {
1003 if (intel
->conformance_mode
> 0)
1004 intel
->draw_point
= intel_fallback_point
;
1007 index
|= INTEL_FALLBACK_BIT
;
1011 if (intel
->RenderIndex
!= index
) {
1012 intel
->RenderIndex
= index
;
1014 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
1015 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
1016 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
1017 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
1020 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
1021 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
1022 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
1023 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
1026 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
1027 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
1028 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
1029 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1034 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1048 /**********************************************************************/
1049 /* High level hooks for t_vb_render.c */
1050 /**********************************************************************/
1056 intelRunPipeline(GLcontext
* ctx
)
1058 struct intel_context
*intel
= intel_context(ctx
);
1060 _mesa_lock_context_textures(ctx
);
1063 _mesa_update_state_locked(ctx
);
1065 if (intel
->NewGLState
) {
1066 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1067 intel
->vtbl
.update_texture_state(intel
);
1070 if (!intel
->Fallback
) {
1071 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1072 intelChooseRenderState(ctx
);
1075 intel
->NewGLState
= 0;
1078 intel_map_vertex_shader_textures(ctx
);
1079 _tnl_run_pipeline(ctx
);
1080 intel_unmap_vertex_shader_textures(ctx
);
1082 _mesa_unlock_context_textures(ctx
);
1086 intelRenderStart(GLcontext
* ctx
)
1088 struct intel_context
*intel
= intel_context(ctx
);
1090 intel_check_front_buffer_rendering(intel
);
1091 intel
->vtbl
.render_start(intel_context(ctx
));
1092 intel
->vtbl
.emit_state(intel
);
1096 intelRenderFinish(GLcontext
* ctx
)
1098 struct intel_context
*intel
= intel_context(ctx
);
1100 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1103 INTEL_FIREVERTICES(intel
);
1109 /* System to flush dma and emit state changes based on the rasterized
1113 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
1115 struct intel_context
*intel
= intel_context(ctx
);
1118 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
1119 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
1121 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1123 /* Start a new primitive. Arrange to have it flushed later on.
1125 if (hwprim
!= intel
->prim
.primitive
) {
1126 INTEL_FIREVERTICES(intel
);
1128 intel_set_prim(intel
, hwprim
);
1136 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
1138 struct intel_context
*intel
= intel_context(ctx
);
1141 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
1143 /* Let some clipping routines know which primitive they're dealing
1146 intel
->render_primitive
= prim
;
1148 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
1149 * triangles. The rasterized primitive will always be reset by
1150 * lower level functions in that case, potentially pingponging the
1153 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
1154 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
1157 /* Set some primitive-dependent state and Start? a new primitive.
1159 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1163 /**********************************************************************/
1164 /* Transition to/from hardware rasterization. */
1165 /**********************************************************************/
1167 static char *fallbackStrings
[] = {
1168 [0] = "Draw buffer",
1169 [1] = "Read buffer",
1170 [2] = "Depth buffer",
1171 [3] = "Stencil buffer",
1172 [4] = "User disable",
1173 [5] = "Render mode",
1176 [13] = "Color mask",
1181 [18] = "Smooth polygon",
1182 [19] = "Smooth point",
1187 getFallbackString(GLuint bit
)
1194 return fallbackStrings
[i
];
1200 * Enable/disable a fallback flag.
1201 * \param bit one of INTEL_FALLBACK_x flags.
1204 intelFallback(struct intel_context
*intel
, GLbitfield bit
, GLboolean mode
)
1206 GLcontext
*ctx
= &intel
->ctx
;
1207 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1208 const GLbitfield oldfallback
= intel
->Fallback
;
1211 intel
->Fallback
|= bit
;
1212 if (oldfallback
== 0) {
1214 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1215 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1216 bit
, getFallbackString(bit
));
1217 _swsetup_Wakeup(ctx
);
1218 intel
->RenderIndex
= ~0;
1222 intel
->Fallback
&= ~bit
;
1223 if (oldfallback
== bit
) {
1225 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1226 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1227 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1228 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1229 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1230 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1231 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1232 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1234 _tnl_invalidate_vertex_state(ctx
, ~0);
1235 _tnl_invalidate_vertices(ctx
, ~0);
1236 _tnl_install_attrs(ctx
,
1237 intel
->vertex_attrs
,
1238 intel
->vertex_attr_count
,
1239 intel
->ViewportMatrix
.m
, 0);
1241 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1252 /**********************************************************************/
1253 /* Initialization. */
1254 /**********************************************************************/
1258 intelInitTriFuncs(GLcontext
* ctx
)
1260 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1261 static int firsttime
= 1;
1268 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1269 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1270 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1271 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1272 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1273 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1274 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1275 tnl
->Driver
.Render
.Interp
= _tnl_interp
;