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
)
92 uint32_t batch_flags
= LOOP_CLIPRECTS
;
95 intel
->vtbl
.emit_state(intel
);
97 intel
->no_batch_wrap
= GL_TRUE
;
99 /*_mesa_printf("%s *", __progname);*/
101 /* Emit a slot which will be filled with the inline primitive
104 BEGIN_BATCH(2, batch_flags
);
107 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
109 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
110 intel
->prim
.primitive
= prim
;
111 intel
->prim
.flush
= intel_flush_inline_primitive
;
116 intel
->no_batch_wrap
= GL_FALSE
;
117 /* _mesa_printf(">"); */
120 static void intel_wrap_inline(struct intel_context
*intel
)
122 GLuint prim
= intel
->prim
.primitive
;
124 intel_flush_inline_primitive(intel
);
125 intel_batchbuffer_flush(intel
->batch
);
126 intel_start_inline(intel
, prim
); /* ??? */
129 static GLuint
*intel_extend_inline(struct intel_context
*intel
, GLuint dwords
)
131 GLuint sz
= dwords
* sizeof(GLuint
);
134 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
136 if (intel_batchbuffer_space(intel
->batch
) < sz
)
137 intel_wrap_inline(intel
);
139 /* _mesa_printf("."); */
141 intel
->vtbl
.assert_not_dirty(intel
);
143 ptr
= (GLuint
*) intel
->batch
->ptr
;
144 intel
->batch
->ptr
+= sz
;
149 /** Sets the primitive type for a primitive sequence, flushing as needed. */
150 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
152 /* if we have no VBOs */
154 if (intel
->intelScreen
->no_vbo
) {
155 intel_start_inline(intel
, prim
);
158 if (prim
!= intel
->prim
.primitive
) {
159 INTEL_FIREVERTICES(intel
);
160 intel
->prim
.primitive
= prim
;
164 /** Returns mapped VB space for the given number of vertices */
165 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
169 if (intel
->intelScreen
->no_vbo
) {
170 return intel_extend_inline(intel
, count
* intel
->vertex_size
);
173 /* Check for space in the existing VB */
174 if (intel
->prim
.vb_bo
== NULL
||
175 (intel
->prim
.current_offset
+
176 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
177 (intel
->prim
.count
+ count
) >= (1 << 16)) {
178 /* Flush existing prim if any */
179 INTEL_FIREVERTICES(intel
);
181 intel_finish_vb(intel
);
184 if (intel
->prim
.vb
== NULL
)
185 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
186 intel
->prim
.vb_bo
= dri_bo_alloc(intel
->bufmgr
, "vb",
188 intel
->prim
.start_offset
= 0;
189 intel
->prim
.current_offset
= 0;
192 intel
->prim
.flush
= intel_flush_prim
;
194 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
195 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
196 intel
->prim
.count
+= count
;
201 /** Dispatches the accumulated primitive to the batchbuffer. */
202 void intel_flush_prim(struct intel_context
*intel
)
204 dri_bo
*aper_array
[2];
206 unsigned int offset
, count
;
209 /* Must be called after an intel_start_prim. */
210 assert(intel
->prim
.primitive
!= ~0);
212 if (intel
->prim
.count
== 0)
215 /* Clear the current prims out of the context state so that a batch flush
216 * flush triggered by emit_state doesn't loop back to flush_prim again.
218 vb_bo
= intel
->prim
.vb_bo
;
219 dri_bo_reference(vb_bo
);
220 count
= intel
->prim
.count
;
221 intel
->prim
.count
= 0;
222 offset
= intel
->prim
.start_offset
;
223 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
224 if (!IS_9XX(intel
->intelScreen
->deviceID
))
225 intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
226 intel
->prim
.flush
= NULL
;
228 intel
->vtbl
.emit_state(intel
);
230 aper_array
[0] = intel
->batch
->buf
;
231 aper_array
[1] = vb_bo
;
232 if (dri_bufmgr_check_aperture_space(aper_array
, 2)) {
233 intel_batchbuffer_flush(intel
->batch
);
234 intel
->vtbl
.emit_state(intel
);
237 /* Ensure that we don't start a new batch for the following emit, which
238 * depends on the state just emitted. emit_state should be making sure we
239 * have the space for this.
241 intel
->no_batch_wrap
= GL_TRUE
;
243 /* Check that we actually emitted the state into this batch, using the
244 * UPLOAD_CTX bit as the signal.
246 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
249 printf("emitting %d..%d=%d vertices size %d\n", offset
,
250 intel
->prim
.current_offset
, count
,
251 intel
->vertex_size
* 4);
254 if (IS_9XX(intel
->intelScreen
->deviceID
)) {
255 BEGIN_BATCH(5, LOOP_CLIPRECTS
);
256 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
257 I1_LOAD_S(0) | I1_LOAD_S(1) | 1);
258 assert((offset
& !S0_VB_OFFSET_MASK
) == 0);
259 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0, offset
);
260 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
261 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
263 OUT_BATCH(_3DPRIMITIVE
|
265 PRIM_INDIRECT_SEQUENTIAL
|
266 intel
->prim
.primitive
|
268 OUT_BATCH(0); /* Beginning vertex index */
271 struct i830_context
*i830
= i830_context(&intel
->ctx
);
273 BEGIN_BATCH(5, LOOP_CLIPRECTS
);
274 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
275 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
277 assert((offset
& !S0_VB_OFFSET_MASK_830
) == 0);
278 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
279 offset
| (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
282 * This is somewhat unfortunate -- VB width is tied up with
283 * vertex format data that we've already uploaded through
284 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
285 * STATE_IMMEDIATE_1 like this to avoid duplication.
287 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
288 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
289 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
290 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
292 OUT_BATCH(_3DPRIMITIVE
|
294 PRIM_INDIRECT_SEQUENTIAL
|
295 intel
->prim
.primitive
|
297 OUT_BATCH(0); /* Beginning vertex index */
301 intel
->no_batch_wrap
= GL_FALSE
;
303 dri_bo_unreference(vb_bo
);
307 * Uploads the locally-accumulated VB into the buffer object.
309 * This avoids us thrashing the cachelines in and out as the buffer gets
310 * filled, dispatched, then reused as the hardware completes rendering from it,
311 * and also lets us clflush less if we dispatch with a partially-filled VB.
313 * This is called normally from get_space when we're finishing a BO, but also
314 * at batch flush time so that we don't try accessing the contents of a
315 * just-dispatched buffer.
317 void intel_finish_vb(struct intel_context
*intel
)
319 if (intel
->prim
.vb_bo
== NULL
)
322 dri_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
324 dri_bo_unreference(intel
->prim
.vb_bo
);
325 intel
->prim
.vb_bo
= NULL
;
328 /***********************************************************************
329 * Emit primitives as inline vertices *
330 ***********************************************************************/
333 #define COPY_DWORDS( j, vb, vertsize, v ) \
336 __asm__ __volatile__( "rep ; movsl" \
337 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
343 #define COPY_DWORDS( j, vb, vertsize, v ) \
345 for ( j = 0 ; j < vertsize ; j++ ) { \
346 vb[j] = ((GLuint *)v)[j]; \
353 intel_draw_quad(struct intel_context
*intel
,
355 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
357 GLuint vertsize
= intel
->vertex_size
;
358 GLuint
*vb
= intel_get_prim_space(intel
, 6);
361 COPY_DWORDS(j
, vb
, vertsize
, v0
);
362 COPY_DWORDS(j
, vb
, vertsize
, v1
);
364 /* If smooth shading, draw like a trifan which gives better
365 * rasterization. Otherwise draw as two triangles with provoking
366 * vertex in third position as required for flat shading.
368 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
369 COPY_DWORDS(j
, vb
, vertsize
, v3
);
370 COPY_DWORDS(j
, vb
, vertsize
, v1
);
373 COPY_DWORDS(j
, vb
, vertsize
, v2
);
374 COPY_DWORDS(j
, vb
, vertsize
, v0
);
377 COPY_DWORDS(j
, vb
, vertsize
, v2
);
378 COPY_DWORDS(j
, vb
, vertsize
, v3
);
382 intel_draw_triangle(struct intel_context
*intel
,
383 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
385 GLuint vertsize
= intel
->vertex_size
;
386 GLuint
*vb
= intel_get_prim_space(intel
, 3);
389 COPY_DWORDS(j
, vb
, vertsize
, v0
);
390 COPY_DWORDS(j
, vb
, vertsize
, v1
);
391 COPY_DWORDS(j
, vb
, vertsize
, v2
);
396 intel_draw_line(struct intel_context
*intel
,
397 intelVertexPtr v0
, intelVertexPtr v1
)
399 GLuint vertsize
= intel
->vertex_size
;
400 GLuint
*vb
= intel_get_prim_space(intel
, 2);
403 COPY_DWORDS(j
, vb
, vertsize
, v0
);
404 COPY_DWORDS(j
, vb
, vertsize
, v1
);
409 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
411 GLuint vertsize
= intel
->vertex_size
;
412 GLuint
*vb
= intel_get_prim_space(intel
, 1);
415 /* Adjust for sub pixel position -- still required for conform. */
416 *(float *) &vb
[0] = v0
->v
.x
;
417 *(float *) &vb
[1] = v0
->v
.y
;
418 for (j
= 2; j
< vertsize
; j
++)
424 /***********************************************************************
425 * Fixup for ARB_point_parameters *
426 ***********************************************************************/
428 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
429 * represented in the fragment program InputsRead field.
432 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
434 GLcontext
*ctx
= &intel
->ctx
;
435 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
437 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
438 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
440 restore_psz
= psz
[0];
441 restore_alpha
= col
[3];
443 if (psz
[0] >= ctx
->Point
.Threshold
) {
444 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
447 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
448 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
449 col
[3] *= dsize
* dsize
;
455 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
456 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
457 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
459 intel_draw_point(intel
, v0
);
461 psz
[0] = restore_psz
;
462 col
[3] = restore_alpha
;
464 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
465 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
468 intel_draw_point(intel
, v0
);
475 /***********************************************************************
476 * Fixup for I915 WPOS texture coordinate *
477 ***********************************************************************/
482 intel_wpos_triangle(struct intel_context
*intel
,
483 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
485 GLuint offset
= intel
->wpos_offset
;
486 GLuint size
= intel
->wpos_size
;
487 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
488 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
489 GLfloat
*v2_wpos
= (GLfloat
*)((char *)v2
+ offset
);
491 __memcpy(v0_wpos
, v0
, size
);
492 __memcpy(v1_wpos
, v1
, size
);
493 __memcpy(v2_wpos
, v2
, size
);
495 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
496 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
497 v2_wpos
[1] = -v2_wpos
[1] + intel
->driDrawable
->h
;
500 intel_draw_triangle(intel
, v0
, v1
, v2
);
505 intel_wpos_line(struct intel_context
*intel
,
506 intelVertexPtr v0
, intelVertexPtr v1
)
508 GLuint offset
= intel
->wpos_offset
;
509 GLuint size
= intel
->wpos_size
;
510 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
511 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
513 __memcpy(v0_wpos
, v0
, size
);
514 __memcpy(v1_wpos
, v1
, size
);
516 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
517 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
519 intel_draw_line(intel
, v0
, v1
);
524 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
526 GLuint offset
= intel
->wpos_offset
;
527 GLuint size
= intel
->wpos_size
;
528 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
530 __memcpy(v0_wpos
, v0
, size
);
531 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
533 intel_draw_point(intel
, v0
);
541 /***********************************************************************
542 * Macros for t_dd_tritmp.h to draw basic primitives *
543 ***********************************************************************/
545 #define TRI( a, b, c ) \
548 intel->draw_tri( intel, a, b, c ); \
550 intel_draw_triangle( intel, a, b, c ); \
553 #define QUAD( a, b, c, d ) \
556 intel->draw_tri( intel, a, b, d ); \
557 intel->draw_tri( intel, b, c, d ); \
559 intel_draw_quad( intel, a, b, c, d ); \
562 #define LINE( v0, v1 ) \
565 intel->draw_line( intel, v0, v1 ); \
567 intel_draw_line( intel, v0, v1 ); \
570 #define POINT( v0 ) \
573 intel->draw_point( intel, v0 ); \
575 intel_draw_point( intel, v0 ); \
579 /***********************************************************************
580 * Build render functions from dd templates *
581 ***********************************************************************/
583 #define INTEL_OFFSET_BIT 0x01
584 #define INTEL_TWOSIDE_BIT 0x02
585 #define INTEL_UNFILLED_BIT 0x04
586 #define INTEL_FALLBACK_BIT 0x08
587 #define INTEL_MAX_TRIFUNC 0x10
592 tnl_points_func points
;
594 tnl_triangle_func triangle
;
596 } rast_tab
[INTEL_MAX_TRIFUNC
];
599 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
600 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
601 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
602 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
608 #define DO_FULL_QUAD 1
612 #define HAVE_BACK_COLORS 0
613 #define HAVE_HW_FLATSHADE 1
614 #define VERTEX intelVertex
617 /* Only used to pull back colors into vertices (ie, we know color is
620 #define INTEL_COLOR( dst, src ) \
622 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
623 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
624 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
625 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
628 #define INTEL_SPEC( dst, src ) \
630 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
631 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
632 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
636 #define DEPTH_SCALE intel->polygon_offset_scale
637 #define UNFILLED_TRI unfilled_tri
638 #define UNFILLED_QUAD unfilled_quad
639 #define VERT_X(_v) _v->v.x
640 #define VERT_Y(_v) _v->v.y
641 #define VERT_Z(_v) _v->v.z
642 #define AREA_IS_CCW( a ) (a > 0)
643 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
645 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
646 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
647 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
648 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
650 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
651 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
652 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
653 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
655 #define LOCAL_VARS(n) \
656 struct intel_context *intel = intel_context(ctx); \
657 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
658 GLuint coloroffset = intel->coloroffset; \
659 GLboolean specoffset = intel->specoffset; \
660 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
663 /***********************************************************************
664 * Helpers for rendering unfilled primitives *
665 ***********************************************************************/
667 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
680 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
681 #define RENDER_PRIMITIVE intel->render_primitive
683 #define IND INTEL_FALLBACK_BIT
684 #include "tnl_dd/t_dd_unfilled.h"
687 /***********************************************************************
688 * Generate GL render functions *
689 ***********************************************************************/
693 #include "tnl_dd/t_dd_tritmp.h"
695 #define IND (INTEL_OFFSET_BIT)
696 #define TAG(x) x##_offset
697 #include "tnl_dd/t_dd_tritmp.h"
699 #define IND (INTEL_TWOSIDE_BIT)
700 #define TAG(x) x##_twoside
701 #include "tnl_dd/t_dd_tritmp.h"
703 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
704 #define TAG(x) x##_twoside_offset
705 #include "tnl_dd/t_dd_tritmp.h"
707 #define IND (INTEL_UNFILLED_BIT)
708 #define TAG(x) x##_unfilled
709 #include "tnl_dd/t_dd_tritmp.h"
711 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
712 #define TAG(x) x##_offset_unfilled
713 #include "tnl_dd/t_dd_tritmp.h"
715 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
716 #define TAG(x) x##_twoside_unfilled
717 #include "tnl_dd/t_dd_tritmp.h"
719 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
720 #define TAG(x) x##_twoside_offset_unfilled
721 #include "tnl_dd/t_dd_tritmp.h"
723 #define IND (INTEL_FALLBACK_BIT)
724 #define TAG(x) x##_fallback
725 #include "tnl_dd/t_dd_tritmp.h"
727 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
728 #define TAG(x) x##_offset_fallback
729 #include "tnl_dd/t_dd_tritmp.h"
731 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
732 #define TAG(x) x##_twoside_fallback
733 #include "tnl_dd/t_dd_tritmp.h"
735 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
736 #define TAG(x) x##_twoside_offset_fallback
737 #include "tnl_dd/t_dd_tritmp.h"
739 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
740 #define TAG(x) x##_unfilled_fallback
741 #include "tnl_dd/t_dd_tritmp.h"
743 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
744 #define TAG(x) x##_offset_unfilled_fallback
745 #include "tnl_dd/t_dd_tritmp.h"
747 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
748 #define TAG(x) x##_twoside_unfilled_fallback
749 #include "tnl_dd/t_dd_tritmp.h"
751 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
753 #define TAG(x) x##_twoside_offset_unfilled_fallback
754 #include "tnl_dd/t_dd_tritmp.h"
763 init_twoside_offset();
765 init_offset_unfilled();
766 init_twoside_unfilled();
767 init_twoside_offset_unfilled();
769 init_offset_fallback();
770 init_twoside_fallback();
771 init_twoside_offset_fallback();
772 init_unfilled_fallback();
773 init_offset_unfilled_fallback();
774 init_twoside_unfilled_fallback();
775 init_twoside_offset_unfilled_fallback();
779 /***********************************************************************
780 * Rasterization fallback helpers *
781 ***********************************************************************/
784 /* This code is hit only when a mix of accelerated and unaccelerated
785 * primitives are being drawn, and only for the unaccelerated
789 intel_fallback_tri(struct intel_context
*intel
,
790 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
792 GLcontext
*ctx
= &intel
->ctx
;
796 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
798 INTEL_FIREVERTICES(intel
);
800 _swsetup_Translate(ctx
, v0
, &v
[0]);
801 _swsetup_Translate(ctx
, v1
, &v
[1]);
802 _swsetup_Translate(ctx
, v2
, &v
[2]);
803 intelSpanRenderStart(ctx
);
804 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
805 intelSpanRenderFinish(ctx
);
810 intel_fallback_line(struct intel_context
*intel
,
811 intelVertex
* v0
, intelVertex
* v1
)
813 GLcontext
*ctx
= &intel
->ctx
;
817 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
819 INTEL_FIREVERTICES(intel
);
821 _swsetup_Translate(ctx
, v0
, &v
[0]);
822 _swsetup_Translate(ctx
, v1
, &v
[1]);
823 intelSpanRenderStart(ctx
);
824 _swrast_Line(ctx
, &v
[0], &v
[1]);
825 intelSpanRenderFinish(ctx
);
829 intel_fallback_point(struct intel_context
*intel
,
832 GLcontext
*ctx
= &intel
->ctx
;
836 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
838 INTEL_FIREVERTICES(intel
);
840 _swsetup_Translate(ctx
, v0
, &v
[0]);
841 intelSpanRenderStart(ctx
);
842 _swrast_Point(ctx
, &v
[0]);
843 intelSpanRenderFinish(ctx
);
847 /**********************************************************************/
848 /* Render unclipped begin/end objects */
849 /**********************************************************************/
852 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
853 #define RENDER_POINTS( start, count ) \
854 for ( ; start < count ; start++) POINT( V(ELT(start)) );
855 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
856 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
857 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
858 #define INIT(x) intelRenderPrimitive( ctx, x )
861 struct intel_context *intel = intel_context(ctx); \
862 GLubyte *vertptr = (GLubyte *)intel->verts; \
863 const GLuint vertsize = intel->vertex_size; \
864 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
866 #define RESET_STIPPLE
867 #define RESET_OCCLUSION
868 #define PRESERVE_VB_DEFS
870 #define TAG(x) intel_##x##_verts
871 #include "tnl/t_vb_rendertmp.h"
874 #define TAG(x) intel_##x##_elts
875 #define ELT(x) elt[x]
876 #include "tnl/t_vb_rendertmp.h"
878 /**********************************************************************/
879 /* Render clipped primitives */
880 /**********************************************************************/
885 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
887 struct intel_context
*intel
= intel_context(ctx
);
888 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
889 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
890 GLuint prim
= intel
->render_primitive
;
892 /* Render the new vertices as an unclipped polygon.
895 GLuint
*tmp
= VB
->Elts
;
896 VB
->Elts
= (GLuint
*) elts
;
897 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
898 PRIM_BEGIN
| PRIM_END
);
902 /* Restore the render primitive
904 if (prim
!= GL_POLYGON
)
905 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
909 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
911 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
913 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
917 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
919 struct intel_context
*intel
= intel_context(ctx
);
920 const GLuint vertsize
= intel
->vertex_size
;
921 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
922 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
923 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
926 for (i
= 2; i
< n
; i
++) {
927 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
928 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
929 COPY_DWORDS(j
, vb
, vertsize
, start
);
933 /**********************************************************************/
934 /* Choose render functions */
935 /**********************************************************************/
940 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
941 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
944 intelChooseRenderState(GLcontext
* ctx
)
946 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
947 struct intel_context
*intel
= intel_context(ctx
);
948 GLuint flags
= ctx
->_TriangleCaps
;
949 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
950 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
953 if (INTEL_DEBUG
& DEBUG_STATE
)
954 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
956 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
958 if (flags
& ANY_RASTER_FLAGS
) {
959 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
960 index
|= INTEL_TWOSIDE_BIT
;
961 if (flags
& DD_TRI_OFFSET
)
962 index
|= INTEL_OFFSET_BIT
;
963 if (flags
& DD_TRI_UNFILLED
)
964 index
|= INTEL_UNFILLED_BIT
;
968 intel
->draw_point
= intel_wpos_point
;
969 intel
->draw_line
= intel_wpos_line
;
970 intel
->draw_tri
= intel_wpos_triangle
;
972 /* Make sure these get called:
974 index
|= INTEL_FALLBACK_BIT
;
977 intel
->draw_point
= intel_draw_point
;
978 intel
->draw_line
= intel_draw_line
;
979 intel
->draw_tri
= intel_draw_triangle
;
982 /* Hook in fallbacks for specific primitives.
984 if (flags
& ANY_FALLBACK_FLAGS
) {
985 if (flags
& DD_LINE_STIPPLE
)
986 intel
->draw_line
= intel_fallback_line
;
988 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
989 intel
->draw_tri
= intel_fallback_tri
;
991 if (flags
& DD_TRI_SMOOTH
) {
992 if (intel
->conformance_mode
> 0)
993 intel
->draw_tri
= intel_fallback_tri
;
996 if (flags
& DD_POINT_ATTEN
) {
998 intel
->draw_point
= intel_atten_point
;
1000 intel
->draw_point
= intel_fallback_point
;
1003 if (flags
& DD_POINT_SMOOTH
) {
1004 if (intel
->conformance_mode
> 0)
1005 intel
->draw_point
= intel_fallback_point
;
1008 index
|= INTEL_FALLBACK_BIT
;
1012 if (intel
->RenderIndex
!= index
) {
1013 intel
->RenderIndex
= index
;
1015 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
1016 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
1017 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
1018 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
1021 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
1022 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
1023 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
1024 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
1027 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
1028 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
1029 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
1030 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1035 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1049 /**********************************************************************/
1050 /* High level hooks for t_vb_render.c */
1051 /**********************************************************************/
1057 intelRunPipeline(GLcontext
* ctx
)
1059 struct intel_context
*intel
= intel_context(ctx
);
1061 _mesa_lock_context_textures(ctx
);
1064 _mesa_update_state_locked(ctx
);
1066 if (intel
->NewGLState
) {
1067 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1068 intel
->vtbl
.update_texture_state(intel
);
1071 if (!intel
->Fallback
) {
1072 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1073 intelChooseRenderState(ctx
);
1076 intel
->NewGLState
= 0;
1079 intel_map_vertex_shader_textures(ctx
);
1080 _tnl_run_pipeline(ctx
);
1081 intel_unmap_vertex_shader_textures(ctx
);
1083 _mesa_unlock_context_textures(ctx
);
1087 intelRenderStart(GLcontext
* ctx
)
1089 struct intel_context
*intel
= intel_context(ctx
);
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
;
1253 /**********************************************************************/
1254 /* Used only with the metaops callbacks. */
1255 /**********************************************************************/
1257 intel_meta_draw_poly(struct intel_context
*intel
,
1260 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1264 unsigned int saved_vertex_size
= intel
->vertex_size
;
1266 LOCK_HARDWARE(intel
);
1268 intel
->vertex_size
= 6;
1270 /* All 3d primitives should be emitted with LOOP_CLIPRECTS,
1271 * otherwise the drawing origin (DR4) might not be set correctly.
1273 intel_set_prim(intel
, PRIM3D_TRIFAN
);
1274 vb
= (union fi
*) intel_get_prim_space(intel
, n
);
1276 for (i
= 0; i
< n
; i
++) {
1281 vb
[4].f
= tex
[i
][0];
1282 vb
[5].f
= tex
[i
][1];
1286 INTEL_FIREVERTICES(intel
);
1288 intel
->vertex_size
= saved_vertex_size
;
1290 UNLOCK_HARDWARE(intel
);
1294 intel_meta_draw_quad(struct intel_context
*intel
,
1295 GLfloat x0
, GLfloat x1
,
1296 GLfloat y0
, GLfloat y1
,
1299 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1322 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1327 /**********************************************************************/
1328 /* Initialization. */
1329 /**********************************************************************/
1333 intelInitTriFuncs(GLcontext
* ctx
)
1335 struct intel_context
*intel
= intel_context(ctx
);
1336 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1337 static int firsttime
= 1;
1344 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1345 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1346 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1347 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1348 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1349 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1350 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1351 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1353 intel
->vtbl
.meta_draw_quad
= intel_meta_draw_quad
;