1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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"
41 #include "main/fbobject.h"
42 #include "main/state.h"
44 #include "swrast/swrast.h"
45 #include "swrast_setup/swrast_setup.h"
46 #include "tnl/t_context.h"
47 #include "tnl/t_pipeline.h"
48 #include "tnl/t_vertex.h"
50 #include "intel_screen.h"
51 #include "intel_context.h"
52 #include "intel_tris.h"
53 #include "intel_batchbuffer.h"
54 #include "intel_buffers.h"
55 #include "intel_reg.h"
56 #include "i830_context.h"
58 #include "i915_context.h"
60 static void intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
);
61 static void intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
,
65 intel_flush_inline_primitive(struct intel_context
*intel
)
67 GLuint used
= intel
->batch
.used
- intel
->prim
.start_ptr
;
69 assert(intel
->prim
.primitive
!= ~0);
76 intel
->batch
.map
[intel
->prim
.start_ptr
] =
77 _3DPRIMITIVE
| intel
->prim
.primitive
| (used
- 2);
82 intel
->batch
.used
= intel
->prim
.start_ptr
;
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
= true;
98 /* Emit a slot which will be filled with the inline primitive
103 intel
->prim
.start_ptr
= intel
->batch
.used
;
104 intel
->prim
.primitive
= prim
;
105 intel
->prim
.flush
= intel_flush_inline_primitive
;
110 intel
->no_batch_wrap
= false;
114 static void intel_wrap_inline(struct intel_context
*intel
)
116 GLuint prim
= intel
->prim
.primitive
;
118 intel_flush_inline_primitive(intel
);
119 intel_batchbuffer_flush(intel
);
120 intel_start_inline(intel
, prim
); /* ??? */
123 static GLuint
*intel_extend_inline(struct intel_context
*intel
, GLuint dwords
)
127 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
129 if (intel_batchbuffer_space(intel
) < dwords
* sizeof(GLuint
))
130 intel_wrap_inline(intel
);
134 intel
->vtbl
.assert_not_dirty(intel
);
136 ptr
= intel
->batch
.map
+ intel
->batch
.used
;
137 intel
->batch
.used
+= dwords
;
142 /** Sets the primitive type for a primitive sequence, flushing as needed. */
143 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
145 /* if we have no VBOs */
147 if (intel
->intelScreen
->no_vbo
) {
148 intel_start_inline(intel
, prim
);
151 if (prim
!= intel
->prim
.primitive
) {
152 INTEL_FIREVERTICES(intel
);
153 intel
->prim
.primitive
= prim
;
157 /** Returns mapped VB space for the given number of vertices */
158 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
162 if (intel
->intelScreen
->no_vbo
) {
163 return intel_extend_inline(intel
, count
* intel
->vertex_size
);
166 /* Check for space in the existing VB */
167 if (intel
->prim
.vb_bo
== NULL
||
168 (intel
->prim
.current_offset
+
169 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
170 (intel
->prim
.count
+ count
) >= (1 << 16)) {
171 /* Flush existing prim if any */
172 INTEL_FIREVERTICES(intel
);
174 intel_finish_vb(intel
);
177 if (intel
->prim
.vb
== NULL
)
178 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
179 intel
->prim
.vb_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "vb",
181 intel
->prim
.start_offset
= 0;
182 intel
->prim
.current_offset
= 0;
185 intel
->prim
.flush
= intel_flush_prim
;
187 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
188 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
189 intel
->prim
.count
+= count
;
194 /** Dispatches the accumulated primitive to the batchbuffer. */
195 void intel_flush_prim(struct intel_context
*intel
)
197 drm_intel_bo
*aper_array
[2];
199 unsigned int offset
, count
;
202 /* Must be called after an intel_start_prim. */
203 assert(intel
->prim
.primitive
!= ~0);
205 if (intel
->prim
.count
== 0)
208 /* Clear the current prims out of the context state so that a batch flush
209 * flush triggered by emit_state doesn't loop back to flush_prim again.
211 vb_bo
= intel
->prim
.vb_bo
;
212 drm_intel_bo_reference(vb_bo
);
213 count
= intel
->prim
.count
;
214 intel
->prim
.count
= 0;
215 offset
= intel
->prim
.start_offset
;
216 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
218 intel
->prim
.current_offset
= intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
219 intel
->prim
.flush
= NULL
;
221 intel
->vtbl
.emit_state(intel
);
223 aper_array
[0] = intel
->batch
.bo
;
224 aper_array
[1] = vb_bo
;
225 if (dri_bufmgr_check_aperture_space(aper_array
, 2)) {
226 intel_batchbuffer_flush(intel
);
227 intel
->vtbl
.emit_state(intel
);
230 /* Ensure that we don't start a new batch for the following emit, which
231 * depends on the state just emitted. emit_state should be making sure we
232 * have the space for this.
234 intel
->no_batch_wrap
= true;
236 if (intel
->always_flush_cache
) {
237 intel_batchbuffer_emit_mi_flush(intel
);
241 printf("emitting %d..%d=%d vertices size %d\n", offset
,
242 intel
->prim
.current_offset
, count
,
243 intel
->vertex_size
* 4);
246 if (intel
->gen
>= 3) {
247 struct i915_context
*i915
= i915_context(&intel
->ctx
);
248 unsigned int cmd
= 0, len
= 0;
250 if (vb_bo
!= i915
->current_vb_bo
) {
255 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
264 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
| cmd
| (len
- 2));
265 if (vb_bo
!= i915
->current_vb_bo
) {
266 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0, 0);
267 i915
->current_vb_bo
= vb_bo
;
269 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
270 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
271 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
272 i915
->current_vertex_size
= intel
->vertex_size
;
274 OUT_BATCH(_3DPRIMITIVE
|
276 PRIM_INDIRECT_SEQUENTIAL
|
277 intel
->prim
.primitive
|
279 OUT_BATCH(offset
/ (intel
->vertex_size
* 4));
282 struct i830_context
*i830
= i830_context(&intel
->ctx
);
285 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
286 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
288 assert((offset
& ~S0_VB_OFFSET_MASK_830
) == 0);
289 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
290 offset
| (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
293 * This is somewhat unfortunate -- VB width is tied up with
294 * vertex format data that we've already uploaded through
295 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
296 * STATE_IMMEDIATE_1 like this to avoid duplication.
298 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
299 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
300 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
301 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
303 OUT_BATCH(_3DPRIMITIVE
|
305 PRIM_INDIRECT_SEQUENTIAL
|
306 intel
->prim
.primitive
|
308 OUT_BATCH(0); /* Beginning vertex index */
312 if (intel
->always_flush_cache
) {
313 intel_batchbuffer_emit_mi_flush(intel
);
316 intel
->no_batch_wrap
= false;
318 drm_intel_bo_unreference(vb_bo
);
322 * Uploads the locally-accumulated VB into the buffer object.
324 * This avoids us thrashing the cachelines in and out as the buffer gets
325 * filled, dispatched, then reused as the hardware completes rendering from it,
326 * and also lets us clflush less if we dispatch with a partially-filled VB.
328 * This is called normally from get_space when we're finishing a BO, but also
329 * at batch flush time so that we don't try accessing the contents of a
330 * just-dispatched buffer.
332 void intel_finish_vb(struct intel_context
*intel
)
334 if (intel
->prim
.vb_bo
== NULL
)
337 drm_intel_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
339 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
340 intel
->prim
.vb_bo
= NULL
;
343 /***********************************************************************
344 * Emit primitives as inline vertices *
345 ***********************************************************************/
348 #define COPY_DWORDS( j, vb, vertsize, v ) \
351 __asm__ __volatile__( "rep ; movsl" \
352 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
358 #define COPY_DWORDS( j, vb, vertsize, v ) \
360 for ( j = 0 ; j < vertsize ; j++ ) { \
361 vb[j] = ((GLuint *)v)[j]; \
368 intel_draw_quad(struct intel_context
*intel
,
370 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
372 GLuint vertsize
= intel
->vertex_size
;
373 GLuint
*vb
= intel_get_prim_space(intel
, 6);
376 COPY_DWORDS(j
, vb
, vertsize
, v0
);
377 COPY_DWORDS(j
, vb
, vertsize
, v1
);
379 /* If smooth shading, draw like a trifan which gives better
380 * rasterization. Otherwise draw as two triangles with provoking
381 * vertex in third position as required for flat shading.
383 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
384 COPY_DWORDS(j
, vb
, vertsize
, v3
);
385 COPY_DWORDS(j
, vb
, vertsize
, v1
);
388 COPY_DWORDS(j
, vb
, vertsize
, v2
);
389 COPY_DWORDS(j
, vb
, vertsize
, v0
);
392 COPY_DWORDS(j
, vb
, vertsize
, v2
);
393 COPY_DWORDS(j
, vb
, vertsize
, v3
);
397 intel_draw_triangle(struct intel_context
*intel
,
398 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
400 GLuint vertsize
= intel
->vertex_size
;
401 GLuint
*vb
= intel_get_prim_space(intel
, 3);
404 COPY_DWORDS(j
, vb
, vertsize
, v0
);
405 COPY_DWORDS(j
, vb
, vertsize
, v1
);
406 COPY_DWORDS(j
, vb
, vertsize
, v2
);
411 intel_draw_line(struct intel_context
*intel
,
412 intelVertexPtr v0
, intelVertexPtr v1
)
414 GLuint vertsize
= intel
->vertex_size
;
415 GLuint
*vb
= intel_get_prim_space(intel
, 2);
418 COPY_DWORDS(j
, vb
, vertsize
, v0
);
419 COPY_DWORDS(j
, vb
, vertsize
, v1
);
424 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
426 GLuint vertsize
= intel
->vertex_size
;
427 GLuint
*vb
= intel_get_prim_space(intel
, 1);
430 COPY_DWORDS(j
, vb
, vertsize
, v0
);
435 /***********************************************************************
436 * Fixup for ARB_point_parameters *
437 ***********************************************************************/
439 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
440 * represented in the fragment program info.inputs_read field.
443 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
445 struct gl_context
*ctx
= &intel
->ctx
;
446 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
448 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
449 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
451 restore_psz
= psz
[0];
452 restore_alpha
= col
[3];
454 if (psz
[0] >= ctx
->Point
.Threshold
) {
455 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
458 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
459 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
460 col
[3] *= dsize
* dsize
;
466 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
467 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
468 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
470 intel_draw_point(intel
, v0
);
472 psz
[0] = restore_psz
;
473 col
[3] = restore_alpha
;
475 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
476 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
479 intel_draw_point(intel
, v0
);
486 /***********************************************************************
487 * Fixup for I915 WPOS texture coordinate *
488 ***********************************************************************/
491 intel_emit_fragcoord(struct intel_context
*intel
, intelVertexPtr v
)
493 struct gl_context
*ctx
= &intel
->ctx
;
494 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
495 GLuint offset
= intel
->wpos_offset
;
496 float *vertex_position
= (float *)v
;
497 float *fragcoord
= (float *)((char *)v
+ offset
);
499 fragcoord
[0] = vertex_position
[0];
501 if (_mesa_is_user_fbo(fb
))
502 fragcoord
[1] = vertex_position
[1];
504 fragcoord
[1] = fb
->Height
- vertex_position
[1];
506 fragcoord
[2] = vertex_position
[2];
507 fragcoord
[3] = vertex_position
[3];
511 intel_wpos_triangle(struct intel_context
*intel
,
512 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
514 intel_emit_fragcoord(intel
, v0
);
515 intel_emit_fragcoord(intel
, v1
);
516 intel_emit_fragcoord(intel
, v2
);
518 intel_draw_triangle(intel
, v0
, v1
, v2
);
523 intel_wpos_line(struct intel_context
*intel
,
524 intelVertexPtr v0
, intelVertexPtr v1
)
526 intel_emit_fragcoord(intel
, v0
);
527 intel_emit_fragcoord(intel
, v1
);
528 intel_draw_line(intel
, v0
, v1
);
533 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
535 intel_emit_fragcoord(intel
, v0
);
536 intel_draw_point(intel
, v0
);
544 /***********************************************************************
545 * Macros for t_dd_tritmp.h to draw basic primitives *
546 ***********************************************************************/
548 #define TRI( a, b, c ) \
551 intel->draw_tri( intel, a, b, c ); \
553 intel_draw_triangle( intel, a, b, c ); \
556 #define QUAD( a, b, c, d ) \
559 intel->draw_tri( intel, a, b, d ); \
560 intel->draw_tri( intel, b, c, d ); \
562 intel_draw_quad( intel, a, b, c, d ); \
565 #define LINE( v0, v1 ) \
568 intel->draw_line( intel, v0, v1 ); \
570 intel_draw_line( intel, v0, v1 ); \
573 #define POINT( v0 ) \
576 intel->draw_point( intel, v0 ); \
578 intel_draw_point( intel, v0 ); \
582 /***********************************************************************
583 * Build render functions from dd templates *
584 ***********************************************************************/
586 #define INTEL_OFFSET_BIT 0x01
587 #define INTEL_TWOSIDE_BIT 0x02
588 #define INTEL_UNFILLED_BIT 0x04
589 #define INTEL_FALLBACK_BIT 0x08
590 #define INTEL_MAX_TRIFUNC 0x10
595 tnl_points_func points
;
597 tnl_triangle_func triangle
;
599 } rast_tab
[INTEL_MAX_TRIFUNC
];
602 #define DO_FALLBACK ((IND & INTEL_FALLBACK_BIT) != 0)
603 #define DO_OFFSET ((IND & INTEL_OFFSET_BIT) != 0)
604 #define DO_UNFILLED ((IND & INTEL_UNFILLED_BIT) != 0)
605 #define DO_TWOSIDE ((IND & INTEL_TWOSIDE_BIT) != 0)
611 #define DO_FULL_QUAD 1
614 #define HAVE_BACK_COLORS 0
615 #define HAVE_HW_FLATSHADE 1
616 #define VERTEX intelVertex
619 /* Only used to pull back colors into vertices (ie, we know color is
622 #define INTEL_COLOR( dst, src ) \
624 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
625 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
626 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
627 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
630 #define INTEL_SPEC( dst, src ) \
632 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
633 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
634 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
638 #define DEPTH_SCALE (ctx->DrawBuffer->Visual.depthBits == 16 ? 1.0 : 2.0)
639 #define UNFILLED_TRI unfilled_tri
640 #define UNFILLED_QUAD unfilled_quad
641 #define VERT_X(_v) _v->v.x
642 #define VERT_Y(_v) _v->v.y
643 #define VERT_Z(_v) _v->v.z
644 #define AREA_IS_CCW( a ) (a > 0)
645 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
647 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
648 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
649 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
650 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
652 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
653 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
654 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
655 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
657 #define LOCAL_VARS(n) \
658 struct intel_context *intel = intel_context(ctx); \
659 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
660 GLuint coloroffset = intel->coloroffset; \
661 GLuint specoffset = intel->specoffset; \
662 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
665 /***********************************************************************
666 * Helpers for rendering unfilled primitives *
667 ***********************************************************************/
669 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
670 [GL_POINTS
] = PRIM3D_POINTLIST
,
671 [GL_LINES
] = PRIM3D_LINELIST
,
672 [GL_LINE_LOOP
] = PRIM3D_LINELIST
,
673 [GL_LINE_STRIP
] = PRIM3D_LINELIST
,
674 [GL_TRIANGLES
] = PRIM3D_TRILIST
,
675 [GL_TRIANGLE_STRIP
] = PRIM3D_TRILIST
,
676 [GL_TRIANGLE_FAN
] = PRIM3D_TRILIST
,
677 [GL_QUADS
] = PRIM3D_TRILIST
,
678 [GL_QUAD_STRIP
] = PRIM3D_TRILIST
,
679 [GL_POLYGON
] = PRIM3D_TRILIST
,
682 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
683 #define RENDER_PRIMITIVE intel->render_primitive
685 #define IND INTEL_FALLBACK_BIT
686 #include "tnl_dd/t_dd_unfilled.h"
689 /***********************************************************************
690 * Generate GL render functions *
691 ***********************************************************************/
695 #include "tnl_dd/t_dd_tritmp.h"
697 #define IND (INTEL_OFFSET_BIT)
698 #define TAG(x) x##_offset
699 #include "tnl_dd/t_dd_tritmp.h"
701 #define IND (INTEL_TWOSIDE_BIT)
702 #define TAG(x) x##_twoside
703 #include "tnl_dd/t_dd_tritmp.h"
705 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
706 #define TAG(x) x##_twoside_offset
707 #include "tnl_dd/t_dd_tritmp.h"
709 #define IND (INTEL_UNFILLED_BIT)
710 #define TAG(x) x##_unfilled
711 #include "tnl_dd/t_dd_tritmp.h"
713 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
714 #define TAG(x) x##_offset_unfilled
715 #include "tnl_dd/t_dd_tritmp.h"
717 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
718 #define TAG(x) x##_twoside_unfilled
719 #include "tnl_dd/t_dd_tritmp.h"
721 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
722 #define TAG(x) x##_twoside_offset_unfilled
723 #include "tnl_dd/t_dd_tritmp.h"
725 #define IND (INTEL_FALLBACK_BIT)
726 #define TAG(x) x##_fallback
727 #include "tnl_dd/t_dd_tritmp.h"
729 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
730 #define TAG(x) x##_offset_fallback
731 #include "tnl_dd/t_dd_tritmp.h"
733 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
734 #define TAG(x) x##_twoside_fallback
735 #include "tnl_dd/t_dd_tritmp.h"
737 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
738 #define TAG(x) x##_twoside_offset_fallback
739 #include "tnl_dd/t_dd_tritmp.h"
741 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
742 #define TAG(x) x##_unfilled_fallback
743 #include "tnl_dd/t_dd_tritmp.h"
745 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
746 #define TAG(x) x##_offset_unfilled_fallback
747 #include "tnl_dd/t_dd_tritmp.h"
749 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
750 #define TAG(x) x##_twoside_unfilled_fallback
751 #include "tnl_dd/t_dd_tritmp.h"
753 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
755 #define TAG(x) x##_twoside_offset_unfilled_fallback
756 #include "tnl_dd/t_dd_tritmp.h"
765 init_twoside_offset();
767 init_offset_unfilled();
768 init_twoside_unfilled();
769 init_twoside_offset_unfilled();
771 init_offset_fallback();
772 init_twoside_fallback();
773 init_twoside_offset_fallback();
774 init_unfilled_fallback();
775 init_offset_unfilled_fallback();
776 init_twoside_unfilled_fallback();
777 init_twoside_offset_unfilled_fallback();
781 /***********************************************************************
782 * Rasterization fallback helpers *
783 ***********************************************************************/
786 /* This code is hit only when a mix of accelerated and unaccelerated
787 * primitives are being drawn, and only for the unaccelerated
791 intel_fallback_tri(struct intel_context
*intel
,
792 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
794 struct gl_context
*ctx
= &intel
->ctx
;
798 fprintf(stderr
, "\n%s\n", __func__
);
800 INTEL_FIREVERTICES(intel
);
802 _swsetup_Translate(ctx
, v0
, &v
[0]);
803 _swsetup_Translate(ctx
, v1
, &v
[1]);
804 _swsetup_Translate(ctx
, v2
, &v
[2]);
805 _swrast_render_start(ctx
);
806 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
807 _swrast_render_finish(ctx
);
812 intel_fallback_line(struct intel_context
*intel
,
813 intelVertex
* v0
, intelVertex
* v1
)
815 struct gl_context
*ctx
= &intel
->ctx
;
819 fprintf(stderr
, "\n%s\n", __func__
);
821 INTEL_FIREVERTICES(intel
);
823 _swsetup_Translate(ctx
, v0
, &v
[0]);
824 _swsetup_Translate(ctx
, v1
, &v
[1]);
825 _swrast_render_start(ctx
);
826 _swrast_Line(ctx
, &v
[0], &v
[1]);
827 _swrast_render_finish(ctx
);
831 intel_fallback_point(struct intel_context
*intel
,
834 struct gl_context
*ctx
= &intel
->ctx
;
838 fprintf(stderr
, "\n%s\n", __func__
);
840 INTEL_FIREVERTICES(intel
);
842 _swsetup_Translate(ctx
, v0
, &v
[0]);
843 _swrast_render_start(ctx
);
844 _swrast_Point(ctx
, &v
[0]);
845 _swrast_render_finish(ctx
);
849 /**********************************************************************/
850 /* Render unclipped begin/end objects */
851 /**********************************************************************/
854 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
855 #define RENDER_POINTS( start, count ) \
856 for ( ; start < count ; start++) POINT( V(ELT(start)) );
857 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
858 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
859 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
860 #define INIT(x) intelRenderPrimitive( ctx, x )
863 struct intel_context *intel = intel_context(ctx); \
864 GLubyte *vertptr = (GLubyte *)intel->verts; \
865 const GLuint vertsize = intel->vertex_size; \
866 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
868 #define RESET_STIPPLE
869 #define RESET_OCCLUSION
870 #define PRESERVE_VB_DEFS
872 #define TAG(x) intel_##x##_verts
873 #include "tnl/t_vb_rendertmp.h"
876 #define TAG(x) intel_##x##_elts
877 #define ELT(x) elt[x]
878 #include "tnl/t_vb_rendertmp.h"
880 /**********************************************************************/
881 /* Render clipped primitives */
882 /**********************************************************************/
887 intelRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
889 struct intel_context
*intel
= intel_context(ctx
);
890 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
891 GLuint prim
= intel
->render_primitive
;
893 /* Render the new vertices as an unclipped polygon.
895 _tnl_RenderClippedPolygon(ctx
, elts
, n
);
897 /* Restore the render primitive
899 if (prim
!= GL_POLYGON
)
900 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
904 intelFastRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
906 struct intel_context
*intel
= intel_context(ctx
);
907 const GLuint vertsize
= intel
->vertex_size
;
908 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
909 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
910 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
913 if (ctx
->Light
.ProvokingVertex
== GL_LAST_VERTEX_CONVENTION
) {
914 for (i
= 2; i
< n
; i
++) {
915 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
916 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
917 COPY_DWORDS(j
, vb
, vertsize
, start
);
920 for (i
= 2; i
< n
; i
++) {
921 COPY_DWORDS(j
, vb
, vertsize
, start
);
922 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
923 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
928 /**********************************************************************/
929 /* Choose render functions */
930 /**********************************************************************/
933 #define DD_TRI_LIGHT_TWOSIDE (1 << 1)
934 #define DD_TRI_UNFILLED (1 << 2)
935 #define DD_TRI_STIPPLE (1 << 4)
936 #define DD_TRI_OFFSET (1 << 5)
937 #define DD_LINE_STIPPLE (1 << 7)
938 #define DD_POINT_ATTEN (1 << 9)
940 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
941 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
944 intelChooseRenderState(struct gl_context
* ctx
)
946 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
947 struct intel_context
*intel
= intel_context(ctx
);
949 ((ctx
->Light
.Enabled
&&
950 ctx
->Light
.Model
.TwoSide
) ? DD_TRI_LIGHT_TWOSIDE
: 0) |
951 ((ctx
->Polygon
.FrontMode
!= GL_FILL
||
952 ctx
->Polygon
.BackMode
!= GL_FILL
) ? DD_TRI_UNFILLED
: 0) |
953 (ctx
->Polygon
.StippleFlag
? DD_TRI_STIPPLE
: 0) |
954 ((ctx
->Polygon
.OffsetPoint
||
955 ctx
->Polygon
.OffsetLine
||
956 ctx
->Polygon
.OffsetFill
) ? DD_TRI_OFFSET
: 0) |
957 (ctx
->Line
.StippleFlag
? DD_LINE_STIPPLE
: 0) |
958 (ctx
->Point
._Attenuated
? DD_POINT_ATTEN
: 0);
959 const struct gl_program
*fprog
= ctx
->FragmentProgram
._Current
;
960 bool have_wpos
= (fprog
&& (fprog
->info
.inputs_read
& VARYING_BIT_POS
));
963 if (INTEL_DEBUG
& DEBUG_STATE
)
964 fprintf(stderr
, "\n%s\n", __func__
);
966 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
968 if (flags
& ANY_RASTER_FLAGS
) {
969 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
970 index
|= INTEL_TWOSIDE_BIT
;
971 if (flags
& DD_TRI_OFFSET
)
972 index
|= INTEL_OFFSET_BIT
;
973 if (flags
& DD_TRI_UNFILLED
)
974 index
|= INTEL_UNFILLED_BIT
;
978 intel
->draw_point
= intel_wpos_point
;
979 intel
->draw_line
= intel_wpos_line
;
980 intel
->draw_tri
= intel_wpos_triangle
;
982 /* Make sure these get called:
984 index
|= INTEL_FALLBACK_BIT
;
987 intel
->draw_point
= intel_draw_point
;
988 intel
->draw_line
= intel_draw_line
;
989 intel
->draw_tri
= intel_draw_triangle
;
992 /* Hook in fallbacks for specific primitives.
994 if (flags
& ANY_FALLBACK_FLAGS
) {
995 if (flags
& DD_LINE_STIPPLE
)
996 intel
->draw_line
= intel_fallback_line
;
998 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
999 intel
->draw_tri
= intel_fallback_tri
;
1001 if (flags
& DD_POINT_ATTEN
) {
1003 intel
->draw_point
= intel_atten_point
;
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
= _tnl_RenderClippedLine
;
1030 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1035 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1036 [GL_POINTS
] = GL_POINTS
,
1037 [GL_LINES
] = GL_LINES
,
1038 [GL_LINE_LOOP
] = GL_LINES
,
1039 [GL_LINE_STRIP
] = GL_LINES
,
1040 [GL_TRIANGLES
] = GL_TRIANGLES
,
1041 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
1042 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
1043 [GL_QUADS
] = GL_TRIANGLES
,
1044 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
1045 [GL_POLYGON
] = GL_TRIANGLES
1049 /**********************************************************************/
1050 /* High level hooks for t_vb_render.c */
1051 /**********************************************************************/
1057 intelRunPipeline(struct gl_context
* ctx
)
1059 struct intel_context
*intel
= intel_context(ctx
);
1061 _mesa_lock_context_textures(ctx
);
1064 _mesa_update_state_locked(ctx
);
1066 /* We need to get this done before we start the pipeline, or a
1067 * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
1068 * while the pipeline is running will result in mismatched swrast
1069 * map/unmaps, and later assertion failures.
1071 intel_prepare_render(intel
);
1073 if (intel
->NewGLState
) {
1074 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1075 intel
->vtbl
.update_texture_state(intel
);
1078 if (!intel
->Fallback
) {
1079 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1080 intelChooseRenderState(ctx
);
1083 intel
->NewGLState
= 0;
1086 intel
->tnl_pipeline_running
= true;
1087 _tnl_run_pipeline(ctx
);
1088 intel
->tnl_pipeline_running
= false;
1090 _mesa_unlock_context_textures(ctx
);
1094 intelRenderStart(struct gl_context
* ctx
)
1096 struct intel_context
*intel
= intel_context(ctx
);
1098 intel_check_front_buffer_rendering(intel
);
1099 intel
->vtbl
.render_start(intel_context(ctx
));
1100 intel
->vtbl
.emit_state(intel
);
1104 intelRenderFinish(struct gl_context
* ctx
)
1106 struct intel_context
*intel
= intel_context(ctx
);
1108 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1111 INTEL_FIREVERTICES(intel
);
1117 /* System to flush dma and emit state changes based on the rasterized
1121 intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
, GLuint hwprim
)
1123 struct intel_context
*intel
= intel_context(ctx
);
1126 fprintf(stderr
, "%s %s %x\n", __func__
,
1127 _mesa_enum_to_string(rprim
), hwprim
);
1129 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1131 /* Start a new primitive. Arrange to have it flushed later on.
1133 if (hwprim
!= intel
->prim
.primitive
) {
1134 INTEL_FIREVERTICES(intel
);
1136 intel_set_prim(intel
, hwprim
);
1144 intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
)
1146 struct intel_context
*intel
= intel_context(ctx
);
1147 GLboolean unfilled
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
1148 ctx
->Polygon
.BackMode
!= GL_FILL
);
1151 fprintf(stderr
, "%s %s\n", __func__
, _mesa_enum_to_string(prim
));
1153 /* Let some clipping routines know which primitive they're dealing
1156 intel
->render_primitive
= prim
;
1158 /* Shortcircuit this when called for unfilled triangles. The rasterized
1159 * primitive will always be reset by lower level functions in that case,
1160 * potentially pingponging the state:
1162 if (reduced_prim
[prim
] == GL_TRIANGLES
&& unfilled
)
1165 /* Set some primitive-dependent state and Start? a new primitive.
1167 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1171 /**********************************************************************/
1172 /* Transition to/from hardware rasterization. */
1173 /**********************************************************************/
1175 static char *fallbackStrings
[] = {
1176 [0] = "Draw buffer",
1177 [1] = "Read buffer",
1178 [2] = "Depth buffer",
1179 [3] = "Stencil buffer",
1180 [4] = "User disable",
1181 [5] = "Render mode",
1184 [13] = "Color mask",
1189 [18] = "Smooth polygon",
1190 [19] = "Smooth point",
1191 [20] = "point sprite coord origin",
1192 [21] = "depth/color drawing offset",
1193 [22] = "coord replace(SPRITE POINT ENABLE)",
1198 getFallbackString(GLuint bit
)
1205 return fallbackStrings
[i
];
1211 * Enable/disable a fallback flag.
1212 * \param bit one of INTEL_FALLBACK_x flags.
1215 intelFallback(struct intel_context
*intel
, GLbitfield bit
, bool mode
)
1217 struct gl_context
*ctx
= &intel
->ctx
;
1218 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1219 const GLbitfield oldfallback
= intel
->Fallback
;
1222 intel
->Fallback
|= bit
;
1223 if (oldfallback
== 0) {
1224 assert(!intel
->tnl_pipeline_running
);
1227 if (INTEL_DEBUG
& DEBUG_PERF
)
1228 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1229 bit
, getFallbackString(bit
));
1230 _swsetup_Wakeup(ctx
);
1231 intel
->RenderIndex
= ~0;
1235 intel
->Fallback
&= ~bit
;
1236 if (oldfallback
== bit
) {
1237 assert(!intel
->tnl_pipeline_running
);
1240 if (INTEL_DEBUG
& DEBUG_PERF
)
1241 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1242 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1243 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1244 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1245 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1246 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1247 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1249 _tnl_invalidate_vertex_state(ctx
, ~0);
1250 _tnl_invalidate_vertices(ctx
, ~0);
1251 _tnl_install_attrs(ctx
,
1252 intel
->vertex_attrs
,
1253 intel
->vertex_attr_count
,
1254 intel
->ViewportMatrix
.m
, 0);
1256 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1261 /**********************************************************************/
1262 /* Initialization. */
1263 /**********************************************************************/
1267 intelInitTriFuncs(struct gl_context
* ctx
)
1269 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1270 static int firsttime
= 1;
1277 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1278 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1279 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1280 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1281 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1282 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1283 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1284 tnl
->Driver
.Render
.Interp
= _tnl_interp
;