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 /* Adjust for sub pixel position -- still required for conform. */
430 *(float *) &vb
[0] = v0
->v
.x
;
431 *(float *) &vb
[1] = v0
->v
.y
;
432 for (j
= 2; j
< vertsize
; j
++)
438 /***********************************************************************
439 * Fixup for ARB_point_parameters *
440 ***********************************************************************/
442 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
443 * represented in the fragment program InputsRead field.
446 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
448 struct gl_context
*ctx
= &intel
->ctx
;
449 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
451 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
452 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
454 restore_psz
= psz
[0];
455 restore_alpha
= col
[3];
457 if (psz
[0] >= ctx
->Point
.Threshold
) {
458 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
461 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
462 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
463 col
[3] *= dsize
* dsize
;
469 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
470 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
471 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
473 intel_draw_point(intel
, v0
);
475 psz
[0] = restore_psz
;
476 col
[3] = restore_alpha
;
478 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
479 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
482 intel_draw_point(intel
, v0
);
489 /***********************************************************************
490 * Fixup for I915 WPOS texture coordinate *
491 ***********************************************************************/
494 intel_emit_fragcoord(struct intel_context
*intel
, intelVertexPtr v
)
496 struct gl_context
*ctx
= &intel
->ctx
;
497 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
498 GLuint offset
= intel
->wpos_offset
;
499 float *vertex_position
= (float *)v
;
500 float *fragcoord
= (float *)((char *)v
+ offset
);
502 fragcoord
[0] = vertex_position
[0];
504 if (_mesa_is_user_fbo(fb
))
505 fragcoord
[1] = vertex_position
[1];
507 fragcoord
[1] = fb
->Height
- vertex_position
[1];
509 fragcoord
[2] = vertex_position
[2];
510 fragcoord
[3] = vertex_position
[3];
514 intel_wpos_triangle(struct intel_context
*intel
,
515 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
517 intel_emit_fragcoord(intel
, v0
);
518 intel_emit_fragcoord(intel
, v1
);
519 intel_emit_fragcoord(intel
, v2
);
521 intel_draw_triangle(intel
, v0
, v1
, v2
);
526 intel_wpos_line(struct intel_context
*intel
,
527 intelVertexPtr v0
, intelVertexPtr v1
)
529 intel_emit_fragcoord(intel
, v0
);
530 intel_emit_fragcoord(intel
, v1
);
531 intel_draw_line(intel
, v0
, v1
);
536 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
538 intel_emit_fragcoord(intel
, v0
);
539 intel_draw_point(intel
, v0
);
547 /***********************************************************************
548 * Macros for t_dd_tritmp.h to draw basic primitives *
549 ***********************************************************************/
551 #define TRI( a, b, c ) \
554 intel->draw_tri( intel, a, b, c ); \
556 intel_draw_triangle( intel, a, b, c ); \
559 #define QUAD( a, b, c, d ) \
562 intel->draw_tri( intel, a, b, d ); \
563 intel->draw_tri( intel, b, c, d ); \
565 intel_draw_quad( intel, a, b, c, d ); \
568 #define LINE( v0, v1 ) \
571 intel->draw_line( intel, v0, v1 ); \
573 intel_draw_line( intel, v0, v1 ); \
576 #define POINT( v0 ) \
579 intel->draw_point( intel, v0 ); \
581 intel_draw_point( intel, v0 ); \
585 /***********************************************************************
586 * Build render functions from dd templates *
587 ***********************************************************************/
589 #define INTEL_OFFSET_BIT 0x01
590 #define INTEL_TWOSIDE_BIT 0x02
591 #define INTEL_UNFILLED_BIT 0x04
592 #define INTEL_FALLBACK_BIT 0x08
593 #define INTEL_MAX_TRIFUNC 0x10
598 tnl_points_func points
;
600 tnl_triangle_func triangle
;
602 } rast_tab
[INTEL_MAX_TRIFUNC
];
605 #define DO_FALLBACK ((IND & INTEL_FALLBACK_BIT) != 0)
606 #define DO_OFFSET ((IND & INTEL_OFFSET_BIT) != 0)
607 #define DO_UNFILLED ((IND & INTEL_UNFILLED_BIT) != 0)
608 #define DO_TWOSIDE ((IND & INTEL_TWOSIDE_BIT) != 0)
614 #define DO_FULL_QUAD 1
617 #define HAVE_BACK_COLORS 0
618 #define HAVE_HW_FLATSHADE 1
619 #define VERTEX intelVertex
622 /* Only used to pull back colors into vertices (ie, we know color is
625 #define INTEL_COLOR( dst, src ) \
627 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
628 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
629 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
630 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
633 #define INTEL_SPEC( dst, src ) \
635 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
636 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
637 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
641 #define DEPTH_SCALE (ctx->DrawBuffer->Visual.depthBits == 16 ? 1.0 : 2.0)
642 #define UNFILLED_TRI unfilled_tri
643 #define UNFILLED_QUAD unfilled_quad
644 #define VERT_X(_v) _v->v.x
645 #define VERT_Y(_v) _v->v.y
646 #define VERT_Z(_v) _v->v.z
647 #define AREA_IS_CCW( a ) (a > 0)
648 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
650 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
651 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
652 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
653 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
655 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
656 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
657 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
658 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
660 #define LOCAL_VARS(n) \
661 struct intel_context *intel = intel_context(ctx); \
662 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
663 GLuint coloroffset = intel->coloroffset; \
664 GLuint specoffset = intel->specoffset; \
665 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
668 /***********************************************************************
669 * Helpers for rendering unfilled primitives *
670 ***********************************************************************/
672 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
673 [GL_POINTS
] = PRIM3D_POINTLIST
,
674 [GL_LINES
] = PRIM3D_LINELIST
,
675 [GL_LINE_LOOP
] = PRIM3D_LINELIST
,
676 [GL_LINE_STRIP
] = PRIM3D_LINELIST
,
677 [GL_TRIANGLES
] = PRIM3D_TRILIST
,
678 [GL_TRIANGLE_STRIP
] = PRIM3D_TRILIST
,
679 [GL_TRIANGLE_FAN
] = PRIM3D_TRILIST
,
680 [GL_QUADS
] = PRIM3D_TRILIST
,
681 [GL_QUAD_STRIP
] = PRIM3D_TRILIST
,
682 [GL_POLYGON
] = PRIM3D_TRILIST
,
685 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
686 #define RENDER_PRIMITIVE intel->render_primitive
688 #define IND INTEL_FALLBACK_BIT
689 #include "tnl_dd/t_dd_unfilled.h"
692 /***********************************************************************
693 * Generate GL render functions *
694 ***********************************************************************/
698 #include "tnl_dd/t_dd_tritmp.h"
700 #define IND (INTEL_OFFSET_BIT)
701 #define TAG(x) x##_offset
702 #include "tnl_dd/t_dd_tritmp.h"
704 #define IND (INTEL_TWOSIDE_BIT)
705 #define TAG(x) x##_twoside
706 #include "tnl_dd/t_dd_tritmp.h"
708 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
709 #define TAG(x) x##_twoside_offset
710 #include "tnl_dd/t_dd_tritmp.h"
712 #define IND (INTEL_UNFILLED_BIT)
713 #define TAG(x) x##_unfilled
714 #include "tnl_dd/t_dd_tritmp.h"
716 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
717 #define TAG(x) x##_offset_unfilled
718 #include "tnl_dd/t_dd_tritmp.h"
720 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
721 #define TAG(x) x##_twoside_unfilled
722 #include "tnl_dd/t_dd_tritmp.h"
724 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
725 #define TAG(x) x##_twoside_offset_unfilled
726 #include "tnl_dd/t_dd_tritmp.h"
728 #define IND (INTEL_FALLBACK_BIT)
729 #define TAG(x) x##_fallback
730 #include "tnl_dd/t_dd_tritmp.h"
732 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
733 #define TAG(x) x##_offset_fallback
734 #include "tnl_dd/t_dd_tritmp.h"
736 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
737 #define TAG(x) x##_twoside_fallback
738 #include "tnl_dd/t_dd_tritmp.h"
740 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
741 #define TAG(x) x##_twoside_offset_fallback
742 #include "tnl_dd/t_dd_tritmp.h"
744 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
745 #define TAG(x) x##_unfilled_fallback
746 #include "tnl_dd/t_dd_tritmp.h"
748 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
749 #define TAG(x) x##_offset_unfilled_fallback
750 #include "tnl_dd/t_dd_tritmp.h"
752 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
753 #define TAG(x) x##_twoside_unfilled_fallback
754 #include "tnl_dd/t_dd_tritmp.h"
756 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
758 #define TAG(x) x##_twoside_offset_unfilled_fallback
759 #include "tnl_dd/t_dd_tritmp.h"
768 init_twoside_offset();
770 init_offset_unfilled();
771 init_twoside_unfilled();
772 init_twoside_offset_unfilled();
774 init_offset_fallback();
775 init_twoside_fallback();
776 init_twoside_offset_fallback();
777 init_unfilled_fallback();
778 init_offset_unfilled_fallback();
779 init_twoside_unfilled_fallback();
780 init_twoside_offset_unfilled_fallback();
784 /***********************************************************************
785 * Rasterization fallback helpers *
786 ***********************************************************************/
789 /* This code is hit only when a mix of accelerated and unaccelerated
790 * primitives are being drawn, and only for the unaccelerated
794 intel_fallback_tri(struct intel_context
*intel
,
795 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
797 struct gl_context
*ctx
= &intel
->ctx
;
801 fprintf(stderr
, "\n%s\n", __func__
);
803 INTEL_FIREVERTICES(intel
);
805 _swsetup_Translate(ctx
, v0
, &v
[0]);
806 _swsetup_Translate(ctx
, v1
, &v
[1]);
807 _swsetup_Translate(ctx
, v2
, &v
[2]);
808 _swrast_render_start(ctx
);
809 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
810 _swrast_render_finish(ctx
);
815 intel_fallback_line(struct intel_context
*intel
,
816 intelVertex
* v0
, intelVertex
* v1
)
818 struct gl_context
*ctx
= &intel
->ctx
;
822 fprintf(stderr
, "\n%s\n", __func__
);
824 INTEL_FIREVERTICES(intel
);
826 _swsetup_Translate(ctx
, v0
, &v
[0]);
827 _swsetup_Translate(ctx
, v1
, &v
[1]);
828 _swrast_render_start(ctx
);
829 _swrast_Line(ctx
, &v
[0], &v
[1]);
830 _swrast_render_finish(ctx
);
834 intel_fallback_point(struct intel_context
*intel
,
837 struct gl_context
*ctx
= &intel
->ctx
;
841 fprintf(stderr
, "\n%s\n", __func__
);
843 INTEL_FIREVERTICES(intel
);
845 _swsetup_Translate(ctx
, v0
, &v
[0]);
846 _swrast_render_start(ctx
);
847 _swrast_Point(ctx
, &v
[0]);
848 _swrast_render_finish(ctx
);
852 /**********************************************************************/
853 /* Render unclipped begin/end objects */
854 /**********************************************************************/
857 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
858 #define RENDER_POINTS( start, count ) \
859 for ( ; start < count ; start++) POINT( V(ELT(start)) );
860 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
861 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
862 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
863 #define INIT(x) intelRenderPrimitive( ctx, x )
866 struct intel_context *intel = intel_context(ctx); \
867 GLubyte *vertptr = (GLubyte *)intel->verts; \
868 const GLuint vertsize = intel->vertex_size; \
869 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
871 #define RESET_STIPPLE
872 #define RESET_OCCLUSION
873 #define PRESERVE_VB_DEFS
875 #define TAG(x) intel_##x##_verts
876 #include "tnl/t_vb_rendertmp.h"
879 #define TAG(x) intel_##x##_elts
880 #define ELT(x) elt[x]
881 #include "tnl/t_vb_rendertmp.h"
883 /**********************************************************************/
884 /* Render clipped primitives */
885 /**********************************************************************/
890 intelRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
892 struct intel_context
*intel
= intel_context(ctx
);
893 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
894 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
895 GLuint prim
= intel
->render_primitive
;
897 /* Render the new vertices as an unclipped polygon.
900 GLuint
*tmp
= VB
->Elts
;
901 VB
->Elts
= (GLuint
*) elts
;
902 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
903 PRIM_BEGIN
| PRIM_END
);
907 /* Restore the render primitive
909 if (prim
!= GL_POLYGON
)
910 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
914 intelRenderClippedLine(struct gl_context
* ctx
, GLuint ii
, GLuint jj
)
916 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
918 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
922 intelFastRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
924 struct intel_context
*intel
= intel_context(ctx
);
925 const GLuint vertsize
= intel
->vertex_size
;
926 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
927 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
928 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
931 for (i
= 2; i
< n
; i
++) {
932 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
933 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
934 COPY_DWORDS(j
, vb
, vertsize
, start
);
938 /**********************************************************************/
939 /* Choose render functions */
940 /**********************************************************************/
943 #define DD_TRI_LIGHT_TWOSIDE (1 << 1)
944 #define DD_TRI_UNFILLED (1 << 2)
945 #define DD_TRI_STIPPLE (1 << 4)
946 #define DD_TRI_OFFSET (1 << 5)
947 #define DD_LINE_STIPPLE (1 << 7)
948 #define DD_POINT_ATTEN (1 << 9)
950 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
951 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
954 intelChooseRenderState(struct gl_context
* ctx
)
956 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
957 struct intel_context
*intel
= intel_context(ctx
);
959 ((ctx
->Light
.Enabled
&&
960 ctx
->Light
.Model
.TwoSide
) ? DD_TRI_LIGHT_TWOSIDE
: 0) |
961 ((ctx
->Polygon
.FrontMode
!= GL_FILL
||
962 ctx
->Polygon
.BackMode
!= GL_FILL
) ? DD_TRI_UNFILLED
: 0) |
963 (ctx
->Polygon
.StippleFlag
? DD_TRI_STIPPLE
: 0) |
964 ((ctx
->Polygon
.OffsetPoint
||
965 ctx
->Polygon
.OffsetLine
||
966 ctx
->Polygon
.OffsetFill
) ? DD_TRI_OFFSET
: 0) |
967 (ctx
->Line
.StippleFlag
? DD_LINE_STIPPLE
: 0) |
968 (ctx
->Point
._Attenuated
? DD_POINT_ATTEN
: 0);
969 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
970 bool have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& VARYING_BIT_POS
));
973 if (INTEL_DEBUG
& DEBUG_STATE
)
974 fprintf(stderr
, "\n%s\n", __func__
);
976 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
978 if (flags
& ANY_RASTER_FLAGS
) {
979 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
980 index
|= INTEL_TWOSIDE_BIT
;
981 if (flags
& DD_TRI_OFFSET
)
982 index
|= INTEL_OFFSET_BIT
;
983 if (flags
& DD_TRI_UNFILLED
)
984 index
|= INTEL_UNFILLED_BIT
;
988 intel
->draw_point
= intel_wpos_point
;
989 intel
->draw_line
= intel_wpos_line
;
990 intel
->draw_tri
= intel_wpos_triangle
;
992 /* Make sure these get called:
994 index
|= INTEL_FALLBACK_BIT
;
997 intel
->draw_point
= intel_draw_point
;
998 intel
->draw_line
= intel_draw_line
;
999 intel
->draw_tri
= intel_draw_triangle
;
1002 /* Hook in fallbacks for specific primitives.
1004 if (flags
& ANY_FALLBACK_FLAGS
) {
1005 if (flags
& DD_LINE_STIPPLE
)
1006 intel
->draw_line
= intel_fallback_line
;
1008 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
1009 intel
->draw_tri
= intel_fallback_tri
;
1011 if (flags
& DD_POINT_ATTEN
) {
1013 intel
->draw_point
= intel_atten_point
;
1015 intel
->draw_point
= intel_fallback_point
;
1018 index
|= INTEL_FALLBACK_BIT
;
1022 if (intel
->RenderIndex
!= index
) {
1023 intel
->RenderIndex
= index
;
1025 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
1026 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
1027 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
1028 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
1031 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
1032 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
1033 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
1034 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
1037 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
1038 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
1039 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
1040 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1045 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1046 [GL_POINTS
] = GL_POINTS
,
1047 [GL_LINES
] = GL_LINES
,
1048 [GL_LINE_LOOP
] = GL_LINES
,
1049 [GL_LINE_STRIP
] = GL_LINES
,
1050 [GL_TRIANGLES
] = GL_TRIANGLES
,
1051 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
1052 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
1053 [GL_QUADS
] = GL_TRIANGLES
,
1054 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
1055 [GL_POLYGON
] = GL_TRIANGLES
1059 /**********************************************************************/
1060 /* High level hooks for t_vb_render.c */
1061 /**********************************************************************/
1067 intelRunPipeline(struct gl_context
* ctx
)
1069 struct intel_context
*intel
= intel_context(ctx
);
1071 _mesa_lock_context_textures(ctx
);
1074 _mesa_update_state_locked(ctx
);
1076 /* We need to get this done before we start the pipeline, or a
1077 * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
1078 * while the pipeline is running will result in mismatched swrast
1079 * map/unmaps, and later assertion failures.
1081 intel_prepare_render(intel
);
1083 if (intel
->NewGLState
) {
1084 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1085 intel
->vtbl
.update_texture_state(intel
);
1088 if (!intel
->Fallback
) {
1089 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1090 intelChooseRenderState(ctx
);
1093 intel
->NewGLState
= 0;
1096 intel
->tnl_pipeline_running
= true;
1097 _tnl_run_pipeline(ctx
);
1098 intel
->tnl_pipeline_running
= false;
1100 _mesa_unlock_context_textures(ctx
);
1104 intelRenderStart(struct gl_context
* ctx
)
1106 struct intel_context
*intel
= intel_context(ctx
);
1108 intel_check_front_buffer_rendering(intel
);
1109 intel
->vtbl
.render_start(intel_context(ctx
));
1110 intel
->vtbl
.emit_state(intel
);
1114 intelRenderFinish(struct gl_context
* ctx
)
1116 struct intel_context
*intel
= intel_context(ctx
);
1118 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1121 INTEL_FIREVERTICES(intel
);
1127 /* System to flush dma and emit state changes based on the rasterized
1131 intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
, GLuint hwprim
)
1133 struct intel_context
*intel
= intel_context(ctx
);
1136 fprintf(stderr
, "%s %s %x\n", __func__
,
1137 _mesa_enum_to_string(rprim
), hwprim
);
1139 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1141 /* Start a new primitive. Arrange to have it flushed later on.
1143 if (hwprim
!= intel
->prim
.primitive
) {
1144 INTEL_FIREVERTICES(intel
);
1146 intel_set_prim(intel
, hwprim
);
1154 intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
)
1156 struct intel_context
*intel
= intel_context(ctx
);
1157 GLboolean unfilled
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
1158 ctx
->Polygon
.BackMode
!= GL_FILL
);
1161 fprintf(stderr
, "%s %s\n", __func__
, _mesa_enum_to_string(prim
));
1163 /* Let some clipping routines know which primitive they're dealing
1166 intel
->render_primitive
= prim
;
1168 /* Shortcircuit this when called for unfilled triangles. The rasterized
1169 * primitive will always be reset by lower level functions in that case,
1170 * potentially pingponging the state:
1172 if (reduced_prim
[prim
] == GL_TRIANGLES
&& unfilled
)
1175 /* Set some primitive-dependent state and Start? a new primitive.
1177 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1181 /**********************************************************************/
1182 /* Transition to/from hardware rasterization. */
1183 /**********************************************************************/
1185 static char *fallbackStrings
[] = {
1186 [0] = "Draw buffer",
1187 [1] = "Read buffer",
1188 [2] = "Depth buffer",
1189 [3] = "Stencil buffer",
1190 [4] = "User disable",
1191 [5] = "Render mode",
1194 [13] = "Color mask",
1199 [18] = "Smooth polygon",
1200 [19] = "Smooth point",
1201 [20] = "point sprite coord origin",
1202 [21] = "depth/color drawing offset",
1203 [22] = "coord replace(SPRITE POINT ENABLE)",
1208 getFallbackString(GLuint bit
)
1215 return fallbackStrings
[i
];
1221 * Enable/disable a fallback flag.
1222 * \param bit one of INTEL_FALLBACK_x flags.
1225 intelFallback(struct intel_context
*intel
, GLbitfield bit
, bool mode
)
1227 struct gl_context
*ctx
= &intel
->ctx
;
1228 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1229 const GLbitfield oldfallback
= intel
->Fallback
;
1232 intel
->Fallback
|= bit
;
1233 if (oldfallback
== 0) {
1234 assert(!intel
->tnl_pipeline_running
);
1237 if (INTEL_DEBUG
& DEBUG_PERF
)
1238 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1239 bit
, getFallbackString(bit
));
1240 _swsetup_Wakeup(ctx
);
1241 intel
->RenderIndex
= ~0;
1245 intel
->Fallback
&= ~bit
;
1246 if (oldfallback
== bit
) {
1247 assert(!intel
->tnl_pipeline_running
);
1250 if (INTEL_DEBUG
& DEBUG_PERF
)
1251 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1252 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1253 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1254 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1255 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1256 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1257 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1259 _tnl_invalidate_vertex_state(ctx
, ~0);
1260 _tnl_invalidate_vertices(ctx
, ~0);
1261 _tnl_install_attrs(ctx
,
1262 intel
->vertex_attrs
,
1263 intel
->vertex_attr_count
,
1264 intel
->ViewportMatrix
.m
, 0);
1266 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1271 /**********************************************************************/
1272 /* Initialization. */
1273 /**********************************************************************/
1277 intelInitTriFuncs(struct gl_context
* ctx
)
1279 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1280 static int firsttime
= 1;
1287 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1288 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1289 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1290 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1291 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1292 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1293 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1294 tnl
->Driver
.Render
.Interp
= _tnl_interp
;