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"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
45 #include "tnl/t_context.h"
46 #include "tnl/t_pipeline.h"
47 #include "tnl/t_vertex.h"
49 #include "intel_screen.h"
50 #include "intel_context.h"
51 #include "intel_tris.h"
52 #include "intel_batchbuffer.h"
53 #include "intel_buffers.h"
54 #include "intel_reg.h"
55 #include "i830_context.h"
57 #include "i915_context.h"
59 static void intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
);
60 static void intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
,
64 intel_flush_inline_primitive(struct intel_context
*intel
)
66 GLuint used
= intel
->batch
.used
- intel
->prim
.start_ptr
;
68 assert(intel
->prim
.primitive
!= ~0);
75 intel
->batch
.map
[intel
->prim
.start_ptr
] =
76 _3DPRIMITIVE
| intel
->prim
.primitive
| (used
- 2);
81 intel
->batch
.used
= intel
->prim
.start_ptr
;
84 intel
->prim
.primitive
= ~0;
85 intel
->prim
.start_ptr
= 0;
86 intel
->prim
.flush
= 0;
89 static void intel_start_inline(struct intel_context
*intel
, uint32_t prim
)
93 intel
->vtbl
.emit_state(intel
);
95 intel
->no_batch_wrap
= true;
97 /* Emit a slot which will be filled with the inline primitive
102 intel
->prim
.start_ptr
= intel
->batch
.used
;
103 intel
->prim
.primitive
= prim
;
104 intel
->prim
.flush
= intel_flush_inline_primitive
;
109 intel
->no_batch_wrap
= false;
113 static void intel_wrap_inline(struct intel_context
*intel
)
115 GLuint prim
= intel
->prim
.primitive
;
117 intel_flush_inline_primitive(intel
);
118 intel_batchbuffer_flush(intel
);
119 intel_start_inline(intel
, prim
); /* ??? */
122 static GLuint
*intel_extend_inline(struct intel_context
*intel
, GLuint dwords
)
126 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
128 if (intel_batchbuffer_space(intel
) < dwords
* sizeof(GLuint
))
129 intel_wrap_inline(intel
);
133 intel
->vtbl
.assert_not_dirty(intel
);
135 ptr
= intel
->batch
.map
+ intel
->batch
.used
;
136 intel
->batch
.used
+= dwords
;
141 /** Sets the primitive type for a primitive sequence, flushing as needed. */
142 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
144 /* if we have no VBOs */
146 if (intel
->intelScreen
->no_vbo
) {
147 intel_start_inline(intel
, prim
);
150 if (prim
!= intel
->prim
.primitive
) {
151 INTEL_FIREVERTICES(intel
);
152 intel
->prim
.primitive
= prim
;
156 /** Returns mapped VB space for the given number of vertices */
157 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
161 if (intel
->intelScreen
->no_vbo
) {
162 return intel_extend_inline(intel
, count
* intel
->vertex_size
);
165 /* Check for space in the existing VB */
166 if (intel
->prim
.vb_bo
== NULL
||
167 (intel
->prim
.current_offset
+
168 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
169 (intel
->prim
.count
+ count
) >= (1 << 16)) {
170 /* Flush existing prim if any */
171 INTEL_FIREVERTICES(intel
);
173 intel_finish_vb(intel
);
176 if (intel
->prim
.vb
== NULL
)
177 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
178 intel
->prim
.vb_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "vb",
180 intel
->prim
.start_offset
= 0;
181 intel
->prim
.current_offset
= 0;
184 intel
->prim
.flush
= intel_flush_prim
;
186 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
187 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
188 intel
->prim
.count
+= count
;
193 /** Dispatches the accumulated primitive to the batchbuffer. */
194 void intel_flush_prim(struct intel_context
*intel
)
196 drm_intel_bo
*aper_array
[2];
198 unsigned int offset
, count
;
201 /* Must be called after an intel_start_prim. */
202 assert(intel
->prim
.primitive
!= ~0);
204 if (intel
->prim
.count
== 0)
207 /* Clear the current prims out of the context state so that a batch flush
208 * flush triggered by emit_state doesn't loop back to flush_prim again.
210 vb_bo
= intel
->prim
.vb_bo
;
211 drm_intel_bo_reference(vb_bo
);
212 count
= intel
->prim
.count
;
213 intel
->prim
.count
= 0;
214 offset
= intel
->prim
.start_offset
;
215 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
217 intel
->prim
.current_offset
= intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
218 intel
->prim
.flush
= NULL
;
220 intel
->vtbl
.emit_state(intel
);
222 aper_array
[0] = intel
->batch
.bo
;
223 aper_array
[1] = vb_bo
;
224 if (dri_bufmgr_check_aperture_space(aper_array
, 2)) {
225 intel_batchbuffer_flush(intel
);
226 intel
->vtbl
.emit_state(intel
);
229 /* Ensure that we don't start a new batch for the following emit, which
230 * depends on the state just emitted. emit_state should be making sure we
231 * have the space for this.
233 intel
->no_batch_wrap
= true;
235 if (intel
->always_flush_cache
) {
236 intel_batchbuffer_emit_mi_flush(intel
);
240 printf("emitting %d..%d=%d vertices size %d\n", offset
,
241 intel
->prim
.current_offset
, count
,
242 intel
->vertex_size
* 4);
245 if (intel
->gen
>= 3) {
246 struct i915_context
*i915
= i915_context(&intel
->ctx
);
247 unsigned int cmd
= 0, len
= 0;
249 if (vb_bo
!= i915
->current_vb_bo
) {
254 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
263 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
| cmd
| (len
- 2));
264 if (vb_bo
!= i915
->current_vb_bo
) {
265 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0, 0);
266 i915
->current_vb_bo
= vb_bo
;
268 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
269 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
270 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
271 i915
->current_vertex_size
= intel
->vertex_size
;
273 OUT_BATCH(_3DPRIMITIVE
|
275 PRIM_INDIRECT_SEQUENTIAL
|
276 intel
->prim
.primitive
|
278 OUT_BATCH(offset
/ (intel
->vertex_size
* 4));
281 struct i830_context
*i830
= i830_context(&intel
->ctx
);
284 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
285 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
287 assert((offset
& ~S0_VB_OFFSET_MASK_830
) == 0);
288 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
289 offset
| (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
292 * This is somewhat unfortunate -- VB width is tied up with
293 * vertex format data that we've already uploaded through
294 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
295 * STATE_IMMEDIATE_1 like this to avoid duplication.
297 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
298 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
299 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
300 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
302 OUT_BATCH(_3DPRIMITIVE
|
304 PRIM_INDIRECT_SEQUENTIAL
|
305 intel
->prim
.primitive
|
307 OUT_BATCH(0); /* Beginning vertex index */
311 if (intel
->always_flush_cache
) {
312 intel_batchbuffer_emit_mi_flush(intel
);
315 intel
->no_batch_wrap
= false;
317 drm_intel_bo_unreference(vb_bo
);
321 * Uploads the locally-accumulated VB into the buffer object.
323 * This avoids us thrashing the cachelines in and out as the buffer gets
324 * filled, dispatched, then reused as the hardware completes rendering from it,
325 * and also lets us clflush less if we dispatch with a partially-filled VB.
327 * This is called normally from get_space when we're finishing a BO, but also
328 * at batch flush time so that we don't try accessing the contents of a
329 * just-dispatched buffer.
331 void intel_finish_vb(struct intel_context
*intel
)
333 if (intel
->prim
.vb_bo
== NULL
)
336 drm_intel_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
338 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
339 intel
->prim
.vb_bo
= NULL
;
342 /***********************************************************************
343 * Emit primitives as inline vertices *
344 ***********************************************************************/
347 #define COPY_DWORDS( j, vb, vertsize, v ) \
350 __asm__ __volatile__( "rep ; movsl" \
351 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
357 #define COPY_DWORDS( j, vb, vertsize, v ) \
359 for ( j = 0 ; j < vertsize ; j++ ) { \
360 vb[j] = ((GLuint *)v)[j]; \
367 intel_draw_quad(struct intel_context
*intel
,
369 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
371 GLuint vertsize
= intel
->vertex_size
;
372 GLuint
*vb
= intel_get_prim_space(intel
, 6);
375 COPY_DWORDS(j
, vb
, vertsize
, v0
);
376 COPY_DWORDS(j
, vb
, vertsize
, v1
);
378 /* If smooth shading, draw like a trifan which gives better
379 * rasterization. Otherwise draw as two triangles with provoking
380 * vertex in third position as required for flat shading.
382 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
383 COPY_DWORDS(j
, vb
, vertsize
, v3
);
384 COPY_DWORDS(j
, vb
, vertsize
, v1
);
387 COPY_DWORDS(j
, vb
, vertsize
, v2
);
388 COPY_DWORDS(j
, vb
, vertsize
, v0
);
391 COPY_DWORDS(j
, vb
, vertsize
, v2
);
392 COPY_DWORDS(j
, vb
, vertsize
, v3
);
396 intel_draw_triangle(struct intel_context
*intel
,
397 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
399 GLuint vertsize
= intel
->vertex_size
;
400 GLuint
*vb
= intel_get_prim_space(intel
, 3);
403 COPY_DWORDS(j
, vb
, vertsize
, v0
);
404 COPY_DWORDS(j
, vb
, vertsize
, v1
);
405 COPY_DWORDS(j
, vb
, vertsize
, v2
);
410 intel_draw_line(struct intel_context
*intel
,
411 intelVertexPtr v0
, intelVertexPtr v1
)
413 GLuint vertsize
= intel
->vertex_size
;
414 GLuint
*vb
= intel_get_prim_space(intel
, 2);
417 COPY_DWORDS(j
, vb
, vertsize
, v0
);
418 COPY_DWORDS(j
, vb
, vertsize
, v1
);
423 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
425 GLuint vertsize
= intel
->vertex_size
;
426 GLuint
*vb
= intel_get_prim_space(intel
, 1);
429 COPY_DWORDS(j
, vb
, vertsize
, v0
);
434 /***********************************************************************
435 * Fixup for ARB_point_parameters *
436 ***********************************************************************/
438 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
439 * represented in the fragment program InputsRead field.
442 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
444 struct gl_context
*ctx
= &intel
->ctx
;
445 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
447 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
448 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
450 restore_psz
= psz
[0];
451 restore_alpha
= col
[3];
453 if (psz
[0] >= ctx
->Point
.Threshold
) {
454 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
457 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
458 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
459 col
[3] *= dsize
* dsize
;
465 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
466 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
467 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
469 intel_draw_point(intel
, v0
);
471 psz
[0] = restore_psz
;
472 col
[3] = restore_alpha
;
474 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
475 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
478 intel_draw_point(intel
, v0
);
485 /***********************************************************************
486 * Fixup for I915 WPOS texture coordinate *
487 ***********************************************************************/
490 intel_emit_fragcoord(struct intel_context
*intel
, intelVertexPtr v
)
492 struct gl_context
*ctx
= &intel
->ctx
;
493 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
494 GLuint offset
= intel
->wpos_offset
;
495 float *vertex_position
= (float *)v
;
496 float *fragcoord
= (float *)((char *)v
+ offset
);
498 fragcoord
[0] = vertex_position
[0];
500 if (_mesa_is_user_fbo(fb
))
501 fragcoord
[1] = vertex_position
[1];
503 fragcoord
[1] = fb
->Height
- vertex_position
[1];
505 fragcoord
[2] = vertex_position
[2];
506 fragcoord
[3] = vertex_position
[3];
510 intel_wpos_triangle(struct intel_context
*intel
,
511 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
513 intel_emit_fragcoord(intel
, v0
);
514 intel_emit_fragcoord(intel
, v1
);
515 intel_emit_fragcoord(intel
, v2
);
517 intel_draw_triangle(intel
, v0
, v1
, v2
);
522 intel_wpos_line(struct intel_context
*intel
,
523 intelVertexPtr v0
, intelVertexPtr v1
)
525 intel_emit_fragcoord(intel
, v0
);
526 intel_emit_fragcoord(intel
, v1
);
527 intel_draw_line(intel
, v0
, v1
);
532 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
534 intel_emit_fragcoord(intel
, v0
);
535 intel_draw_point(intel
, v0
);
543 /***********************************************************************
544 * Macros for t_dd_tritmp.h to draw basic primitives *
545 ***********************************************************************/
547 #define TRI( a, b, c ) \
550 intel->draw_tri( intel, a, b, c ); \
552 intel_draw_triangle( intel, a, b, c ); \
555 #define QUAD( a, b, c, d ) \
558 intel->draw_tri( intel, a, b, d ); \
559 intel->draw_tri( intel, b, c, d ); \
561 intel_draw_quad( intel, a, b, c, d ); \
564 #define LINE( v0, v1 ) \
567 intel->draw_line( intel, v0, v1 ); \
569 intel_draw_line( intel, v0, v1 ); \
572 #define POINT( v0 ) \
575 intel->draw_point( intel, v0 ); \
577 intel_draw_point( intel, v0 ); \
581 /***********************************************************************
582 * Build render functions from dd templates *
583 ***********************************************************************/
585 #define INTEL_OFFSET_BIT 0x01
586 #define INTEL_TWOSIDE_BIT 0x02
587 #define INTEL_UNFILLED_BIT 0x04
588 #define INTEL_FALLBACK_BIT 0x08
589 #define INTEL_MAX_TRIFUNC 0x10
594 tnl_points_func points
;
596 tnl_triangle_func triangle
;
598 } rast_tab
[INTEL_MAX_TRIFUNC
];
601 #define DO_FALLBACK ((IND & INTEL_FALLBACK_BIT) != 0)
602 #define DO_OFFSET ((IND & INTEL_OFFSET_BIT) != 0)
603 #define DO_UNFILLED ((IND & INTEL_UNFILLED_BIT) != 0)
604 #define DO_TWOSIDE ((IND & INTEL_TWOSIDE_BIT) != 0)
610 #define DO_FULL_QUAD 1
613 #define HAVE_BACK_COLORS 0
614 #define HAVE_HW_FLATSHADE 1
615 #define VERTEX intelVertex
618 /* Only used to pull back colors into vertices (ie, we know color is
621 #define INTEL_COLOR( dst, src ) \
623 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
624 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
625 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
626 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
629 #define INTEL_SPEC( dst, src ) \
631 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
632 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
633 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
637 #define DEPTH_SCALE (ctx->DrawBuffer->Visual.depthBits == 16 ? 1.0 : 2.0)
638 #define UNFILLED_TRI unfilled_tri
639 #define UNFILLED_QUAD unfilled_quad
640 #define VERT_X(_v) _v->v.x
641 #define VERT_Y(_v) _v->v.y
642 #define VERT_Z(_v) _v->v.z
643 #define AREA_IS_CCW( a ) (a > 0)
644 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
646 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
647 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
648 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
649 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
651 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
652 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
653 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
654 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
656 #define LOCAL_VARS(n) \
657 struct intel_context *intel = intel_context(ctx); \
658 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
659 GLuint coloroffset = intel->coloroffset; \
660 GLuint specoffset = intel->specoffset; \
661 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
664 /***********************************************************************
665 * Helpers for rendering unfilled primitives *
666 ***********************************************************************/
668 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
669 [GL_POINTS
] = PRIM3D_POINTLIST
,
670 [GL_LINES
] = PRIM3D_LINELIST
,
671 [GL_LINE_LOOP
] = PRIM3D_LINELIST
,
672 [GL_LINE_STRIP
] = PRIM3D_LINELIST
,
673 [GL_TRIANGLES
] = PRIM3D_TRILIST
,
674 [GL_TRIANGLE_STRIP
] = PRIM3D_TRILIST
,
675 [GL_TRIANGLE_FAN
] = PRIM3D_TRILIST
,
676 [GL_QUADS
] = PRIM3D_TRILIST
,
677 [GL_QUAD_STRIP
] = PRIM3D_TRILIST
,
678 [GL_POLYGON
] = PRIM3D_TRILIST
,
681 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
682 #define RENDER_PRIMITIVE intel->render_primitive
684 #define IND INTEL_FALLBACK_BIT
685 #include "tnl_dd/t_dd_unfilled.h"
688 /***********************************************************************
689 * Generate GL render functions *
690 ***********************************************************************/
694 #include "tnl_dd/t_dd_tritmp.h"
696 #define IND (INTEL_OFFSET_BIT)
697 #define TAG(x) x##_offset
698 #include "tnl_dd/t_dd_tritmp.h"
700 #define IND (INTEL_TWOSIDE_BIT)
701 #define TAG(x) x##_twoside
702 #include "tnl_dd/t_dd_tritmp.h"
704 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
705 #define TAG(x) x##_twoside_offset
706 #include "tnl_dd/t_dd_tritmp.h"
708 #define IND (INTEL_UNFILLED_BIT)
709 #define TAG(x) x##_unfilled
710 #include "tnl_dd/t_dd_tritmp.h"
712 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
713 #define TAG(x) x##_offset_unfilled
714 #include "tnl_dd/t_dd_tritmp.h"
716 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
717 #define TAG(x) x##_twoside_unfilled
718 #include "tnl_dd/t_dd_tritmp.h"
720 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
721 #define TAG(x) x##_twoside_offset_unfilled
722 #include "tnl_dd/t_dd_tritmp.h"
724 #define IND (INTEL_FALLBACK_BIT)
725 #define TAG(x) x##_fallback
726 #include "tnl_dd/t_dd_tritmp.h"
728 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
729 #define TAG(x) x##_offset_fallback
730 #include "tnl_dd/t_dd_tritmp.h"
732 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
733 #define TAG(x) x##_twoside_fallback
734 #include "tnl_dd/t_dd_tritmp.h"
736 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
737 #define TAG(x) x##_twoside_offset_fallback
738 #include "tnl_dd/t_dd_tritmp.h"
740 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
741 #define TAG(x) x##_unfilled_fallback
742 #include "tnl_dd/t_dd_tritmp.h"
744 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
745 #define TAG(x) x##_offset_unfilled_fallback
746 #include "tnl_dd/t_dd_tritmp.h"
748 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
749 #define TAG(x) x##_twoside_unfilled_fallback
750 #include "tnl_dd/t_dd_tritmp.h"
752 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
754 #define TAG(x) x##_twoside_offset_unfilled_fallback
755 #include "tnl_dd/t_dd_tritmp.h"
764 init_twoside_offset();
766 init_offset_unfilled();
767 init_twoside_unfilled();
768 init_twoside_offset_unfilled();
770 init_offset_fallback();
771 init_twoside_fallback();
772 init_twoside_offset_fallback();
773 init_unfilled_fallback();
774 init_offset_unfilled_fallback();
775 init_twoside_unfilled_fallback();
776 init_twoside_offset_unfilled_fallback();
780 /***********************************************************************
781 * Rasterization fallback helpers *
782 ***********************************************************************/
785 /* This code is hit only when a mix of accelerated and unaccelerated
786 * primitives are being drawn, and only for the unaccelerated
790 intel_fallback_tri(struct intel_context
*intel
,
791 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
793 struct gl_context
*ctx
= &intel
->ctx
;
797 fprintf(stderr
, "\n%s\n", __func__
);
799 INTEL_FIREVERTICES(intel
);
801 _swsetup_Translate(ctx
, v0
, &v
[0]);
802 _swsetup_Translate(ctx
, v1
, &v
[1]);
803 _swsetup_Translate(ctx
, v2
, &v
[2]);
804 _swrast_render_start(ctx
);
805 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
806 _swrast_render_finish(ctx
);
811 intel_fallback_line(struct intel_context
*intel
,
812 intelVertex
* v0
, intelVertex
* v1
)
814 struct gl_context
*ctx
= &intel
->ctx
;
818 fprintf(stderr
, "\n%s\n", __func__
);
820 INTEL_FIREVERTICES(intel
);
822 _swsetup_Translate(ctx
, v0
, &v
[0]);
823 _swsetup_Translate(ctx
, v1
, &v
[1]);
824 _swrast_render_start(ctx
);
825 _swrast_Line(ctx
, &v
[0], &v
[1]);
826 _swrast_render_finish(ctx
);
830 intel_fallback_point(struct intel_context
*intel
,
833 struct gl_context
*ctx
= &intel
->ctx
;
837 fprintf(stderr
, "\n%s\n", __func__
);
839 INTEL_FIREVERTICES(intel
);
841 _swsetup_Translate(ctx
, v0
, &v
[0]);
842 _swrast_render_start(ctx
);
843 _swrast_Point(ctx
, &v
[0]);
844 _swrast_render_finish(ctx
);
848 /**********************************************************************/
849 /* Render unclipped begin/end objects */
850 /**********************************************************************/
853 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
854 #define RENDER_POINTS( start, count ) \
855 for ( ; start < count ; start++) POINT( V(ELT(start)) );
856 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
857 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
858 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
859 #define INIT(x) intelRenderPrimitive( ctx, x )
862 struct intel_context *intel = intel_context(ctx); \
863 GLubyte *vertptr = (GLubyte *)intel->verts; \
864 const GLuint vertsize = intel->vertex_size; \
865 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
867 #define RESET_STIPPLE
868 #define RESET_OCCLUSION
869 #define PRESERVE_VB_DEFS
871 #define TAG(x) intel_##x##_verts
872 #include "tnl/t_vb_rendertmp.h"
875 #define TAG(x) intel_##x##_elts
876 #define ELT(x) elt[x]
877 #include "tnl/t_vb_rendertmp.h"
879 /**********************************************************************/
880 /* Render clipped primitives */
881 /**********************************************************************/
886 intelRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
888 struct intel_context
*intel
= intel_context(ctx
);
889 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
890 GLuint prim
= intel
->render_primitive
;
892 /* Render the new vertices as an unclipped polygon.
894 _tnl_RenderClippedPolygon(ctx
, elts
, n
);
896 /* Restore the render primitive
898 if (prim
!= GL_POLYGON
)
899 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
903 intelFastRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
905 struct intel_context
*intel
= intel_context(ctx
);
906 const GLuint vertsize
= intel
->vertex_size
;
907 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
908 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
909 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
912 if (ctx
->Light
.ProvokingVertex
== GL_LAST_VERTEX_CONVENTION
) {
913 for (i
= 2; i
< n
; i
++) {
914 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
915 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
916 COPY_DWORDS(j
, vb
, vertsize
, start
);
919 for (i
= 2; i
< n
; i
++) {
920 COPY_DWORDS(j
, vb
, vertsize
, start
);
921 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
922 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
927 /**********************************************************************/
928 /* Choose render functions */
929 /**********************************************************************/
932 #define DD_TRI_LIGHT_TWOSIDE (1 << 1)
933 #define DD_TRI_UNFILLED (1 << 2)
934 #define DD_TRI_STIPPLE (1 << 4)
935 #define DD_TRI_OFFSET (1 << 5)
936 #define DD_LINE_STIPPLE (1 << 7)
937 #define DD_POINT_ATTEN (1 << 9)
939 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
940 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
943 intelChooseRenderState(struct gl_context
* ctx
)
945 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
946 struct intel_context
*intel
= intel_context(ctx
);
948 ((ctx
->Light
.Enabled
&&
949 ctx
->Light
.Model
.TwoSide
) ? DD_TRI_LIGHT_TWOSIDE
: 0) |
950 ((ctx
->Polygon
.FrontMode
!= GL_FILL
||
951 ctx
->Polygon
.BackMode
!= GL_FILL
) ? DD_TRI_UNFILLED
: 0) |
952 (ctx
->Polygon
.StippleFlag
? DD_TRI_STIPPLE
: 0) |
953 ((ctx
->Polygon
.OffsetPoint
||
954 ctx
->Polygon
.OffsetLine
||
955 ctx
->Polygon
.OffsetFill
) ? DD_TRI_OFFSET
: 0) |
956 (ctx
->Line
.StippleFlag
? DD_LINE_STIPPLE
: 0) |
957 (ctx
->Point
._Attenuated
? DD_POINT_ATTEN
: 0);
958 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
959 bool have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& VARYING_BIT_POS
));
962 if (INTEL_DEBUG
& DEBUG_STATE
)
963 fprintf(stderr
, "\n%s\n", __func__
);
965 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
967 if (flags
& ANY_RASTER_FLAGS
) {
968 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
969 index
|= INTEL_TWOSIDE_BIT
;
970 if (flags
& DD_TRI_OFFSET
)
971 index
|= INTEL_OFFSET_BIT
;
972 if (flags
& DD_TRI_UNFILLED
)
973 index
|= INTEL_UNFILLED_BIT
;
977 intel
->draw_point
= intel_wpos_point
;
978 intel
->draw_line
= intel_wpos_line
;
979 intel
->draw_tri
= intel_wpos_triangle
;
981 /* Make sure these get called:
983 index
|= INTEL_FALLBACK_BIT
;
986 intel
->draw_point
= intel_draw_point
;
987 intel
->draw_line
= intel_draw_line
;
988 intel
->draw_tri
= intel_draw_triangle
;
991 /* Hook in fallbacks for specific primitives.
993 if (flags
& ANY_FALLBACK_FLAGS
) {
994 if (flags
& DD_LINE_STIPPLE
)
995 intel
->draw_line
= intel_fallback_line
;
997 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
998 intel
->draw_tri
= intel_fallback_tri
;
1000 if (flags
& DD_POINT_ATTEN
) {
1002 intel
->draw_point
= intel_atten_point
;
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
= _tnl_RenderClippedLine
;
1029 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1034 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1035 [GL_POINTS
] = GL_POINTS
,
1036 [GL_LINES
] = GL_LINES
,
1037 [GL_LINE_LOOP
] = GL_LINES
,
1038 [GL_LINE_STRIP
] = GL_LINES
,
1039 [GL_TRIANGLES
] = GL_TRIANGLES
,
1040 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
1041 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
1042 [GL_QUADS
] = GL_TRIANGLES
,
1043 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
1044 [GL_POLYGON
] = GL_TRIANGLES
1048 /**********************************************************************/
1049 /* High level hooks for t_vb_render.c */
1050 /**********************************************************************/
1056 intelRunPipeline(struct gl_context
* ctx
)
1058 struct intel_context
*intel
= intel_context(ctx
);
1060 _mesa_lock_context_textures(ctx
);
1063 _mesa_update_state_locked(ctx
);
1065 /* We need to get this done before we start the pipeline, or a
1066 * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
1067 * while the pipeline is running will result in mismatched swrast
1068 * map/unmaps, and later assertion failures.
1070 intel_prepare_render(intel
);
1072 if (intel
->NewGLState
) {
1073 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1074 intel
->vtbl
.update_texture_state(intel
);
1077 if (!intel
->Fallback
) {
1078 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1079 intelChooseRenderState(ctx
);
1082 intel
->NewGLState
= 0;
1085 intel
->tnl_pipeline_running
= true;
1086 _tnl_run_pipeline(ctx
);
1087 intel
->tnl_pipeline_running
= false;
1089 _mesa_unlock_context_textures(ctx
);
1093 intelRenderStart(struct gl_context
* ctx
)
1095 struct intel_context
*intel
= intel_context(ctx
);
1097 intel_check_front_buffer_rendering(intel
);
1098 intel
->vtbl
.render_start(intel_context(ctx
));
1099 intel
->vtbl
.emit_state(intel
);
1103 intelRenderFinish(struct gl_context
* ctx
)
1105 struct intel_context
*intel
= intel_context(ctx
);
1107 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1110 INTEL_FIREVERTICES(intel
);
1116 /* System to flush dma and emit state changes based on the rasterized
1120 intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
, GLuint hwprim
)
1122 struct intel_context
*intel
= intel_context(ctx
);
1125 fprintf(stderr
, "%s %s %x\n", __func__
,
1126 _mesa_enum_to_string(rprim
), hwprim
);
1128 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1130 /* Start a new primitive. Arrange to have it flushed later on.
1132 if (hwprim
!= intel
->prim
.primitive
) {
1133 INTEL_FIREVERTICES(intel
);
1135 intel_set_prim(intel
, hwprim
);
1143 intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
)
1145 struct intel_context
*intel
= intel_context(ctx
);
1146 GLboolean unfilled
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
1147 ctx
->Polygon
.BackMode
!= GL_FILL
);
1150 fprintf(stderr
, "%s %s\n", __func__
, _mesa_enum_to_string(prim
));
1152 /* Let some clipping routines know which primitive they're dealing
1155 intel
->render_primitive
= prim
;
1157 /* Shortcircuit this when called for unfilled triangles. The rasterized
1158 * primitive will always be reset by lower level functions in that case,
1159 * potentially pingponging the state:
1161 if (reduced_prim
[prim
] == GL_TRIANGLES
&& unfilled
)
1164 /* Set some primitive-dependent state and Start? a new primitive.
1166 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1170 /**********************************************************************/
1171 /* Transition to/from hardware rasterization. */
1172 /**********************************************************************/
1174 static char *fallbackStrings
[] = {
1175 [0] = "Draw buffer",
1176 [1] = "Read buffer",
1177 [2] = "Depth buffer",
1178 [3] = "Stencil buffer",
1179 [4] = "User disable",
1180 [5] = "Render mode",
1183 [13] = "Color mask",
1188 [18] = "Smooth polygon",
1189 [19] = "Smooth point",
1190 [20] = "point sprite coord origin",
1191 [21] = "depth/color drawing offset",
1192 [22] = "coord replace(SPRITE POINT ENABLE)",
1197 getFallbackString(GLuint bit
)
1204 return fallbackStrings
[i
];
1210 * Enable/disable a fallback flag.
1211 * \param bit one of INTEL_FALLBACK_x flags.
1214 intelFallback(struct intel_context
*intel
, GLbitfield bit
, bool mode
)
1216 struct gl_context
*ctx
= &intel
->ctx
;
1217 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1218 const GLbitfield oldfallback
= intel
->Fallback
;
1221 intel
->Fallback
|= bit
;
1222 if (oldfallback
== 0) {
1223 assert(!intel
->tnl_pipeline_running
);
1226 if (INTEL_DEBUG
& DEBUG_PERF
)
1227 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1228 bit
, getFallbackString(bit
));
1229 _swsetup_Wakeup(ctx
);
1230 intel
->RenderIndex
= ~0;
1234 intel
->Fallback
&= ~bit
;
1235 if (oldfallback
== bit
) {
1236 assert(!intel
->tnl_pipeline_running
);
1239 if (INTEL_DEBUG
& DEBUG_PERF
)
1240 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1241 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1242 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1243 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1244 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1245 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1246 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1248 _tnl_invalidate_vertex_state(ctx
, ~0);
1249 _tnl_invalidate_vertices(ctx
, ~0);
1250 _tnl_install_attrs(ctx
,
1251 intel
->vertex_attrs
,
1252 intel
->vertex_attr_count
,
1253 intel
->ViewportMatrix
.m
, 0);
1255 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1260 /**********************************************************************/
1261 /* Initialization. */
1262 /**********************************************************************/
1266 intelInitTriFuncs(struct gl_context
* ctx
)
1268 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1269 static int firsttime
= 1;
1276 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1277 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1278 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1279 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1280 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1281 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1282 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1283 tnl
->Driver
.Render
.Interp
= _tnl_interp
;