1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /** @file intel_tris.c
30 * This file contains functions for managing the vertex buffer and emitting
34 #include "main/glheader.h"
35 #include "main/context.h"
36 #include "main/macros.h"
37 #include "main/enums.h"
38 #include "main/texobj.h"
39 #include "main/state.h"
42 #include "swrast/swrast.h"
43 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_context.h"
45 #include "tnl/t_pipeline.h"
46 #include "tnl/t_vertex.h"
48 #include "intel_screen.h"
49 #include "intel_context.h"
50 #include "intel_tris.h"
51 #include "intel_batchbuffer.h"
52 #include "intel_buffers.h"
53 #include "intel_reg.h"
54 #include "intel_span.h"
55 #include "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
= GL_TRUE
;
97 /*printf("%s *", __progname);*/
99 /* Emit a slot which will be filled with the inline primitive
104 intel
->prim
.start_ptr
= intel
->batch
.used
;
105 intel
->prim
.primitive
= prim
;
106 intel
->prim
.flush
= intel_flush_inline_primitive
;
111 intel
->no_batch_wrap
= GL_FALSE
;
115 static void intel_wrap_inline(struct intel_context
*intel
)
117 GLuint prim
= intel
->prim
.primitive
;
119 intel_flush_inline_primitive(intel
);
120 intel_batchbuffer_flush(intel
);
121 intel_start_inline(intel
, prim
); /* ??? */
124 static GLuint
*intel_extend_inline(struct intel_context
*intel
, GLuint dwords
)
128 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
130 if (intel_batchbuffer_space(intel
) < dwords
* sizeof(GLuint
))
131 intel_wrap_inline(intel
);
135 intel
->vtbl
.assert_not_dirty(intel
);
137 ptr
= intel
->batch
.map
+ intel
->batch
.used
;
138 intel
->batch
.used
+= dwords
;
143 /** Sets the primitive type for a primitive sequence, flushing as needed. */
144 void intel_set_prim(struct intel_context
*intel
, uint32_t prim
)
146 /* if we have no VBOs */
148 if (intel
->intelScreen
->no_vbo
) {
149 intel_start_inline(intel
, prim
);
152 if (prim
!= intel
->prim
.primitive
) {
153 INTEL_FIREVERTICES(intel
);
154 intel
->prim
.primitive
= prim
;
158 /** Returns mapped VB space for the given number of vertices */
159 uint32_t *intel_get_prim_space(struct intel_context
*intel
, unsigned int count
)
163 if (intel
->intelScreen
->no_vbo
) {
164 return intel_extend_inline(intel
, count
* intel
->vertex_size
);
167 /* Check for space in the existing VB */
168 if (intel
->prim
.vb_bo
== NULL
||
169 (intel
->prim
.current_offset
+
170 count
* intel
->vertex_size
* 4) > INTEL_VB_SIZE
||
171 (intel
->prim
.count
+ count
) >= (1 << 16)) {
172 /* Flush existing prim if any */
173 INTEL_FIREVERTICES(intel
);
175 intel_finish_vb(intel
);
178 if (intel
->prim
.vb
== NULL
)
179 intel
->prim
.vb
= malloc(INTEL_VB_SIZE
);
180 intel
->prim
.vb_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "vb",
182 intel
->prim
.start_offset
= 0;
183 intel
->prim
.current_offset
= 0;
186 intel
->prim
.flush
= intel_flush_prim
;
188 addr
= (uint32_t *)(intel
->prim
.vb
+ intel
->prim
.current_offset
);
189 intel
->prim
.current_offset
+= intel
->vertex_size
* 4 * count
;
190 intel
->prim
.count
+= count
;
195 /** Dispatches the accumulated primitive to the batchbuffer. */
196 void intel_flush_prim(struct intel_context
*intel
)
198 drm_intel_bo
*aper_array
[2];
200 unsigned int offset
, count
;
203 /* Must be called after an intel_start_prim. */
204 assert(intel
->prim
.primitive
!= ~0);
206 if (intel
->prim
.count
== 0)
209 /* Clear the current prims out of the context state so that a batch flush
210 * flush triggered by emit_state doesn't loop back to flush_prim again.
212 vb_bo
= intel
->prim
.vb_bo
;
213 drm_intel_bo_reference(vb_bo
);
214 count
= intel
->prim
.count
;
215 intel
->prim
.count
= 0;
216 offset
= intel
->prim
.start_offset
;
217 intel
->prim
.start_offset
= intel
->prim
.current_offset
;
219 intel
->prim
.current_offset
= intel
->prim
.start_offset
= ALIGN(intel
->prim
.start_offset
, 128);
220 intel
->prim
.flush
= NULL
;
222 intel
->vtbl
.emit_state(intel
);
224 aper_array
[0] = intel
->batch
.bo
;
225 aper_array
[1] = vb_bo
;
226 if (dri_bufmgr_check_aperture_space(aper_array
, 2)) {
227 intel_batchbuffer_flush(intel
);
228 intel
->vtbl
.emit_state(intel
);
231 /* Ensure that we don't start a new batch for the following emit, which
232 * depends on the state just emitted. emit_state should be making sure we
233 * have the space for this.
235 intel
->no_batch_wrap
= GL_TRUE
;
238 printf("emitting %d..%d=%d vertices size %d\n", offset
,
239 intel
->prim
.current_offset
, count
,
240 intel
->vertex_size
* 4);
243 if (intel
->gen
>= 3) {
244 struct i915_context
*i915
= i915_context(&intel
->ctx
);
245 unsigned int cmd
= 0, len
= 0;
247 if (vb_bo
!= i915
->current_vb_bo
) {
252 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
261 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
| cmd
| (len
- 2));
262 if (vb_bo
!= i915
->current_vb_bo
) {
263 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0, 0);
264 i915
->current_vb_bo
= vb_bo
;
266 if (intel
->vertex_size
!= i915
->current_vertex_size
) {
267 OUT_BATCH((intel
->vertex_size
<< S1_VERTEX_WIDTH_SHIFT
) |
268 (intel
->vertex_size
<< S1_VERTEX_PITCH_SHIFT
));
269 i915
->current_vertex_size
= intel
->vertex_size
;
271 OUT_BATCH(_3DPRIMITIVE
|
273 PRIM_INDIRECT_SEQUENTIAL
|
274 intel
->prim
.primitive
|
276 OUT_BATCH(offset
/ (intel
->vertex_size
* 4));
279 struct i830_context
*i830
= i830_context(&intel
->ctx
);
282 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1
|
283 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
285 assert((offset
& ~S0_VB_OFFSET_MASK_830
) == 0);
286 OUT_RELOC(vb_bo
, I915_GEM_DOMAIN_VERTEX
, 0,
287 offset
| (intel
->vertex_size
<< S0_VB_PITCH_SHIFT_830
) |
290 * This is somewhat unfortunate -- VB width is tied up with
291 * vertex format data that we've already uploaded through
292 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
293 * STATE_IMMEDIATE_1 like this to avoid duplication.
295 OUT_BATCH((i830
->state
.Ctx
[I830_CTXREG_VF
] & VFT0_TEX_COUNT_MASK
) >>
296 VFT0_TEX_COUNT_SHIFT
<< S2_TEX_COUNT_SHIFT_830
|
297 (i830
->state
.Ctx
[I830_CTXREG_VF2
] << 16) |
298 intel
->vertex_size
<< S2_VERTEX_0_WIDTH_SHIFT_830
);
300 OUT_BATCH(_3DPRIMITIVE
|
302 PRIM_INDIRECT_SEQUENTIAL
|
303 intel
->prim
.primitive
|
305 OUT_BATCH(0); /* Beginning vertex index */
309 intel
->no_batch_wrap
= GL_FALSE
;
311 drm_intel_bo_unreference(vb_bo
);
315 * Uploads the locally-accumulated VB into the buffer object.
317 * This avoids us thrashing the cachelines in and out as the buffer gets
318 * filled, dispatched, then reused as the hardware completes rendering from it,
319 * and also lets us clflush less if we dispatch with a partially-filled VB.
321 * This is called normally from get_space when we're finishing a BO, but also
322 * at batch flush time so that we don't try accessing the contents of a
323 * just-dispatched buffer.
325 void intel_finish_vb(struct intel_context
*intel
)
327 if (intel
->prim
.vb_bo
== NULL
)
330 drm_intel_bo_subdata(intel
->prim
.vb_bo
, 0, intel
->prim
.start_offset
,
332 drm_intel_bo_unreference(intel
->prim
.vb_bo
);
333 intel
->prim
.vb_bo
= NULL
;
336 /***********************************************************************
337 * Emit primitives as inline vertices *
338 ***********************************************************************/
341 #define COPY_DWORDS( j, vb, vertsize, v ) \
344 __asm__ __volatile__( "rep ; movsl" \
345 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
351 #define COPY_DWORDS( j, vb, vertsize, v ) \
353 for ( j = 0 ; j < vertsize ; j++ ) { \
354 vb[j] = ((GLuint *)v)[j]; \
361 intel_draw_quad(struct intel_context
*intel
,
363 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
365 GLuint vertsize
= intel
->vertex_size
;
366 GLuint
*vb
= intel_get_prim_space(intel
, 6);
369 COPY_DWORDS(j
, vb
, vertsize
, v0
);
370 COPY_DWORDS(j
, vb
, vertsize
, v1
);
372 /* If smooth shading, draw like a trifan which gives better
373 * rasterization. Otherwise draw as two triangles with provoking
374 * vertex in third position as required for flat shading.
376 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
377 COPY_DWORDS(j
, vb
, vertsize
, v3
);
378 COPY_DWORDS(j
, vb
, vertsize
, v1
);
381 COPY_DWORDS(j
, vb
, vertsize
, v2
);
382 COPY_DWORDS(j
, vb
, vertsize
, v0
);
385 COPY_DWORDS(j
, vb
, vertsize
, v2
);
386 COPY_DWORDS(j
, vb
, vertsize
, v3
);
390 intel_draw_triangle(struct intel_context
*intel
,
391 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
393 GLuint vertsize
= intel
->vertex_size
;
394 GLuint
*vb
= intel_get_prim_space(intel
, 3);
397 COPY_DWORDS(j
, vb
, vertsize
, v0
);
398 COPY_DWORDS(j
, vb
, vertsize
, v1
);
399 COPY_DWORDS(j
, vb
, vertsize
, v2
);
404 intel_draw_line(struct intel_context
*intel
,
405 intelVertexPtr v0
, intelVertexPtr v1
)
407 GLuint vertsize
= intel
->vertex_size
;
408 GLuint
*vb
= intel_get_prim_space(intel
, 2);
411 COPY_DWORDS(j
, vb
, vertsize
, v0
);
412 COPY_DWORDS(j
, vb
, vertsize
, v1
);
417 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
419 GLuint vertsize
= intel
->vertex_size
;
420 GLuint
*vb
= intel_get_prim_space(intel
, 1);
423 /* Adjust for sub pixel position -- still required for conform. */
424 *(float *) &vb
[0] = v0
->v
.x
;
425 *(float *) &vb
[1] = v0
->v
.y
;
426 for (j
= 2; j
< vertsize
; j
++)
432 /***********************************************************************
433 * Fixup for ARB_point_parameters *
434 ***********************************************************************/
436 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
437 * represented in the fragment program InputsRead field.
440 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
442 struct gl_context
*ctx
= &intel
->ctx
;
443 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
445 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
446 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
448 restore_psz
= psz
[0];
449 restore_alpha
= col
[3];
451 if (psz
[0] >= ctx
->Point
.Threshold
) {
452 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
455 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
456 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
457 col
[3] *= dsize
* dsize
;
463 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
464 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
465 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
467 intel_draw_point(intel
, v0
);
469 psz
[0] = restore_psz
;
470 col
[3] = restore_alpha
;
472 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
473 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
476 intel_draw_point(intel
, v0
);
483 /***********************************************************************
484 * Fixup for I915 WPOS texture coordinate *
485 ***********************************************************************/
490 intel_wpos_triangle(struct intel_context
*intel
,
491 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
493 const struct gl_framebuffer
*fb
= intel
->ctx
.DrawBuffer
;
494 GLuint offset
= intel
->wpos_offset
;
495 GLuint size
= intel
->wpos_size
;
496 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
497 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
498 GLfloat
*v2_wpos
= (GLfloat
*)((char *)v2
+ offset
);
500 __memcpy(v0_wpos
, v0
, size
);
501 __memcpy(v1_wpos
, v1
, size
);
502 __memcpy(v2_wpos
, v2
, size
);
505 v0_wpos
[1] = -v0_wpos
[1] + fb
->Height
;
506 v1_wpos
[1] = -v1_wpos
[1] + fb
->Height
;
507 v2_wpos
[1] = -v2_wpos
[1] + fb
->Height
;
510 intel_draw_triangle(intel
, v0
, v1
, v2
);
515 intel_wpos_line(struct intel_context
*intel
,
516 intelVertexPtr v0
, intelVertexPtr v1
)
518 const struct gl_framebuffer
*fb
= intel
->ctx
.DrawBuffer
;
519 GLuint offset
= intel
->wpos_offset
;
520 GLuint size
= intel
->wpos_size
;
521 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
522 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
524 __memcpy(v0_wpos
, v0
, size
);
525 __memcpy(v1_wpos
, v1
, size
);
528 v0_wpos
[1] = -v0_wpos
[1] + fb
->Height
;
529 v1_wpos
[1] = -v1_wpos
[1] + fb
->Height
;
532 intel_draw_line(intel
, v0
, v1
);
537 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
539 const struct gl_framebuffer
*fb
= intel
->ctx
.DrawBuffer
;
540 GLuint offset
= intel
->wpos_offset
;
541 GLuint size
= intel
->wpos_size
;
542 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
544 __memcpy(v0_wpos
, v0
, size
);
547 v0_wpos
[1] = -v0_wpos
[1] + fb
->Height
;
549 intel_draw_point(intel
, v0
);
557 /***********************************************************************
558 * Macros for t_dd_tritmp.h to draw basic primitives *
559 ***********************************************************************/
561 #define TRI( a, b, c ) \
564 intel->draw_tri( intel, a, b, c ); \
566 intel_draw_triangle( intel, a, b, c ); \
569 #define QUAD( a, b, c, d ) \
572 intel->draw_tri( intel, a, b, d ); \
573 intel->draw_tri( intel, b, c, d ); \
575 intel_draw_quad( intel, a, b, c, d ); \
578 #define LINE( v0, v1 ) \
581 intel->draw_line( intel, v0, v1 ); \
583 intel_draw_line( intel, v0, v1 ); \
586 #define POINT( v0 ) \
589 intel->draw_point( intel, v0 ); \
591 intel_draw_point( intel, v0 ); \
595 /***********************************************************************
596 * Build render functions from dd templates *
597 ***********************************************************************/
599 #define INTEL_OFFSET_BIT 0x01
600 #define INTEL_TWOSIDE_BIT 0x02
601 #define INTEL_UNFILLED_BIT 0x04
602 #define INTEL_FALLBACK_BIT 0x08
603 #define INTEL_MAX_TRIFUNC 0x10
608 tnl_points_func points
;
610 tnl_triangle_func triangle
;
612 } rast_tab
[INTEL_MAX_TRIFUNC
];
615 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
616 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
617 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
618 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
624 #define DO_FULL_QUAD 1
627 #define HAVE_BACK_COLORS 0
628 #define HAVE_HW_FLATSHADE 1
629 #define VERTEX intelVertex
632 /* Only used to pull back colors into vertices (ie, we know color is
635 #define INTEL_COLOR( dst, src ) \
637 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
638 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
639 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
640 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
643 #define INTEL_SPEC( dst, src ) \
645 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
646 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
647 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
651 #define DEPTH_SCALE intel->polygon_offset_scale
652 #define UNFILLED_TRI unfilled_tri
653 #define UNFILLED_QUAD unfilled_quad
654 #define VERT_X(_v) _v->v.x
655 #define VERT_Y(_v) _v->v.y
656 #define VERT_Z(_v) _v->v.z
657 #define AREA_IS_CCW( a ) (a > 0)
658 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
660 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
661 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
662 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
663 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
665 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
666 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
667 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
668 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
670 #define LOCAL_VARS(n) \
671 struct intel_context *intel = intel_context(ctx); \
672 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
673 GLuint coloroffset = intel->coloroffset; \
674 GLboolean specoffset = intel->specoffset; \
675 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
678 /***********************************************************************
679 * Helpers for rendering unfilled primitives *
680 ***********************************************************************/
682 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
695 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
696 #define RENDER_PRIMITIVE intel->render_primitive
698 #define IND INTEL_FALLBACK_BIT
699 #include "tnl_dd/t_dd_unfilled.h"
702 /***********************************************************************
703 * Generate GL render functions *
704 ***********************************************************************/
708 #include "tnl_dd/t_dd_tritmp.h"
710 #define IND (INTEL_OFFSET_BIT)
711 #define TAG(x) x##_offset
712 #include "tnl_dd/t_dd_tritmp.h"
714 #define IND (INTEL_TWOSIDE_BIT)
715 #define TAG(x) x##_twoside
716 #include "tnl_dd/t_dd_tritmp.h"
718 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
719 #define TAG(x) x##_twoside_offset
720 #include "tnl_dd/t_dd_tritmp.h"
722 #define IND (INTEL_UNFILLED_BIT)
723 #define TAG(x) x##_unfilled
724 #include "tnl_dd/t_dd_tritmp.h"
726 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
727 #define TAG(x) x##_offset_unfilled
728 #include "tnl_dd/t_dd_tritmp.h"
730 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
731 #define TAG(x) x##_twoside_unfilled
732 #include "tnl_dd/t_dd_tritmp.h"
734 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
735 #define TAG(x) x##_twoside_offset_unfilled
736 #include "tnl_dd/t_dd_tritmp.h"
738 #define IND (INTEL_FALLBACK_BIT)
739 #define TAG(x) x##_fallback
740 #include "tnl_dd/t_dd_tritmp.h"
742 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
743 #define TAG(x) x##_offset_fallback
744 #include "tnl_dd/t_dd_tritmp.h"
746 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
747 #define TAG(x) x##_twoside_fallback
748 #include "tnl_dd/t_dd_tritmp.h"
750 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
751 #define TAG(x) x##_twoside_offset_fallback
752 #include "tnl_dd/t_dd_tritmp.h"
754 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
755 #define TAG(x) x##_unfilled_fallback
756 #include "tnl_dd/t_dd_tritmp.h"
758 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
759 #define TAG(x) x##_offset_unfilled_fallback
760 #include "tnl_dd/t_dd_tritmp.h"
762 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
763 #define TAG(x) x##_twoside_unfilled_fallback
764 #include "tnl_dd/t_dd_tritmp.h"
766 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
768 #define TAG(x) x##_twoside_offset_unfilled_fallback
769 #include "tnl_dd/t_dd_tritmp.h"
778 init_twoside_offset();
780 init_offset_unfilled();
781 init_twoside_unfilled();
782 init_twoside_offset_unfilled();
784 init_offset_fallback();
785 init_twoside_fallback();
786 init_twoside_offset_fallback();
787 init_unfilled_fallback();
788 init_offset_unfilled_fallback();
789 init_twoside_unfilled_fallback();
790 init_twoside_offset_unfilled_fallback();
794 /***********************************************************************
795 * Rasterization fallback helpers *
796 ***********************************************************************/
799 /* This code is hit only when a mix of accelerated and unaccelerated
800 * primitives are being drawn, and only for the unaccelerated
804 intel_fallback_tri(struct intel_context
*intel
,
805 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
807 struct gl_context
*ctx
= &intel
->ctx
;
811 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
813 INTEL_FIREVERTICES(intel
);
815 _swsetup_Translate(ctx
, v0
, &v
[0]);
816 _swsetup_Translate(ctx
, v1
, &v
[1]);
817 _swsetup_Translate(ctx
, v2
, &v
[2]);
818 intelSpanRenderStart(ctx
);
819 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
820 intelSpanRenderFinish(ctx
);
825 intel_fallback_line(struct intel_context
*intel
,
826 intelVertex
* v0
, intelVertex
* v1
)
828 struct gl_context
*ctx
= &intel
->ctx
;
832 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
834 INTEL_FIREVERTICES(intel
);
836 _swsetup_Translate(ctx
, v0
, &v
[0]);
837 _swsetup_Translate(ctx
, v1
, &v
[1]);
838 intelSpanRenderStart(ctx
);
839 _swrast_Line(ctx
, &v
[0], &v
[1]);
840 intelSpanRenderFinish(ctx
);
844 intel_fallback_point(struct intel_context
*intel
,
847 struct gl_context
*ctx
= &intel
->ctx
;
851 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
853 INTEL_FIREVERTICES(intel
);
855 _swsetup_Translate(ctx
, v0
, &v
[0]);
856 intelSpanRenderStart(ctx
);
857 _swrast_Point(ctx
, &v
[0]);
858 intelSpanRenderFinish(ctx
);
862 /**********************************************************************/
863 /* Render unclipped begin/end objects */
864 /**********************************************************************/
867 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
868 #define RENDER_POINTS( start, count ) \
869 for ( ; start < count ; start++) POINT( V(ELT(start)) );
870 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
871 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
872 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
873 #define INIT(x) intelRenderPrimitive( ctx, x )
876 struct intel_context *intel = intel_context(ctx); \
877 GLubyte *vertptr = (GLubyte *)intel->verts; \
878 const GLuint vertsize = intel->vertex_size; \
879 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
881 #define RESET_STIPPLE
882 #define RESET_OCCLUSION
883 #define PRESERVE_VB_DEFS
885 #define TAG(x) intel_##x##_verts
886 #include "tnl/t_vb_rendertmp.h"
889 #define TAG(x) intel_##x##_elts
890 #define ELT(x) elt[x]
891 #include "tnl/t_vb_rendertmp.h"
893 /**********************************************************************/
894 /* Render clipped primitives */
895 /**********************************************************************/
900 intelRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
902 struct intel_context
*intel
= intel_context(ctx
);
903 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
904 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
905 GLuint prim
= intel
->render_primitive
;
907 /* Render the new vertices as an unclipped polygon.
910 GLuint
*tmp
= VB
->Elts
;
911 VB
->Elts
= (GLuint
*) elts
;
912 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
913 PRIM_BEGIN
| PRIM_END
);
917 /* Restore the render primitive
919 if (prim
!= GL_POLYGON
)
920 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
924 intelRenderClippedLine(struct gl_context
* ctx
, GLuint ii
, GLuint jj
)
926 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
928 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
932 intelFastRenderClippedPoly(struct gl_context
* ctx
, const GLuint
* elts
, GLuint n
)
934 struct intel_context
*intel
= intel_context(ctx
);
935 const GLuint vertsize
= intel
->vertex_size
;
936 GLuint
*vb
= intel_get_prim_space(intel
, (n
- 2) * 3);
937 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
938 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
941 for (i
= 2; i
< n
; i
++) {
942 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
943 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
944 COPY_DWORDS(j
, vb
, vertsize
, start
);
948 /**********************************************************************/
949 /* Choose render functions */
950 /**********************************************************************/
955 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
956 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
959 intelChooseRenderState(struct gl_context
* ctx
)
961 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
962 struct intel_context
*intel
= intel_context(ctx
);
963 GLuint flags
= ctx
->_TriangleCaps
;
964 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
965 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
968 if (INTEL_DEBUG
& DEBUG_STATE
)
969 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
971 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
973 if (flags
& ANY_RASTER_FLAGS
) {
974 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
975 index
|= INTEL_TWOSIDE_BIT
;
976 if (flags
& DD_TRI_OFFSET
)
977 index
|= INTEL_OFFSET_BIT
;
978 if (flags
& DD_TRI_UNFILLED
)
979 index
|= INTEL_UNFILLED_BIT
;
983 intel
->draw_point
= intel_wpos_point
;
984 intel
->draw_line
= intel_wpos_line
;
985 intel
->draw_tri
= intel_wpos_triangle
;
987 /* Make sure these get called:
989 index
|= INTEL_FALLBACK_BIT
;
992 intel
->draw_point
= intel_draw_point
;
993 intel
->draw_line
= intel_draw_line
;
994 intel
->draw_tri
= intel_draw_triangle
;
997 /* Hook in fallbacks for specific primitives.
999 if (flags
& ANY_FALLBACK_FLAGS
) {
1000 if (flags
& DD_LINE_STIPPLE
)
1001 intel
->draw_line
= intel_fallback_line
;
1003 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
1004 intel
->draw_tri
= intel_fallback_tri
;
1006 if (flags
& DD_TRI_SMOOTH
) {
1007 if (intel
->conformance_mode
> 0)
1008 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 if (flags
& DD_POINT_SMOOTH
) {
1019 if (intel
->conformance_mode
> 0)
1020 intel
->draw_point
= intel_fallback_point
;
1023 index
|= INTEL_FALLBACK_BIT
;
1027 if (intel
->RenderIndex
!= index
) {
1028 intel
->RenderIndex
= index
;
1030 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
1031 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
1032 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
1033 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
1036 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
1037 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
1038 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
1039 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
1042 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
1043 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
1044 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
1045 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
1050 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
1064 /**********************************************************************/
1065 /* High level hooks for t_vb_render.c */
1066 /**********************************************************************/
1072 intelRunPipeline(struct gl_context
* ctx
)
1074 struct intel_context
*intel
= intel_context(ctx
);
1076 _mesa_lock_context_textures(ctx
);
1079 _mesa_update_state_locked(ctx
);
1081 if (intel
->NewGLState
) {
1082 if (intel
->NewGLState
& _NEW_TEXTURE
) {
1083 intel
->vtbl
.update_texture_state(intel
);
1086 if (!intel
->Fallback
) {
1087 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
1088 intelChooseRenderState(ctx
);
1091 intel
->NewGLState
= 0;
1094 intel_map_vertex_shader_textures(ctx
);
1095 _tnl_run_pipeline(ctx
);
1096 intel_unmap_vertex_shader_textures(ctx
);
1098 _mesa_unlock_context_textures(ctx
);
1102 intelRenderStart(struct gl_context
* ctx
)
1104 struct intel_context
*intel
= intel_context(ctx
);
1106 intel_check_front_buffer_rendering(intel
);
1107 intel
->vtbl
.render_start(intel_context(ctx
));
1108 intel
->vtbl
.emit_state(intel
);
1112 intelRenderFinish(struct gl_context
* ctx
)
1114 struct intel_context
*intel
= intel_context(ctx
);
1116 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
1119 INTEL_FIREVERTICES(intel
);
1125 /* System to flush dma and emit state changes based on the rasterized
1129 intelRasterPrimitive(struct gl_context
* ctx
, GLenum rprim
, GLuint hwprim
)
1131 struct intel_context
*intel
= intel_context(ctx
);
1134 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
1135 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
1137 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
1139 /* Start a new primitive. Arrange to have it flushed later on.
1141 if (hwprim
!= intel
->prim
.primitive
) {
1142 INTEL_FIREVERTICES(intel
);
1144 intel_set_prim(intel
, hwprim
);
1152 intelRenderPrimitive(struct gl_context
* ctx
, GLenum prim
)
1154 struct intel_context
*intel
= intel_context(ctx
);
1157 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
1159 /* Let some clipping routines know which primitive they're dealing
1162 intel
->render_primitive
= prim
;
1164 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
1165 * triangles. The rasterized primitive will always be reset by
1166 * lower level functions in that case, potentially pingponging the
1169 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
1170 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
1173 /* Set some primitive-dependent state and Start? a new primitive.
1175 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
1179 /**********************************************************************/
1180 /* Transition to/from hardware rasterization. */
1181 /**********************************************************************/
1183 static char *fallbackStrings
[] = {
1184 [0] = "Draw buffer",
1185 [1] = "Read buffer",
1186 [2] = "Depth buffer",
1187 [3] = "Stencil buffer",
1188 [4] = "User disable",
1189 [5] = "Render mode",
1192 [13] = "Color mask",
1197 [18] = "Smooth polygon",
1198 [19] = "Smooth point",
1199 [20] = "point sprite coord origin",
1200 [21] = "depth/color drawing offset",
1205 getFallbackString(GLuint bit
)
1212 return fallbackStrings
[i
];
1218 * Enable/disable a fallback flag.
1219 * \param bit one of INTEL_FALLBACK_x flags.
1222 intelFallback(struct intel_context
*intel
, GLbitfield bit
, GLboolean mode
)
1224 struct gl_context
*ctx
= &intel
->ctx
;
1225 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1226 const GLbitfield oldfallback
= intel
->Fallback
;
1229 intel
->Fallback
|= bit
;
1230 if (oldfallback
== 0) {
1232 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1233 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1234 bit
, getFallbackString(bit
));
1235 _swsetup_Wakeup(ctx
);
1236 intel
->RenderIndex
= ~0;
1240 intel
->Fallback
&= ~bit
;
1241 if (oldfallback
== bit
) {
1243 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1244 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1245 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1246 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1247 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1248 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1249 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1250 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1252 _tnl_invalidate_vertex_state(ctx
, ~0);
1253 _tnl_invalidate_vertices(ctx
, ~0);
1254 _tnl_install_attrs(ctx
,
1255 intel
->vertex_attrs
,
1256 intel
->vertex_attr_count
,
1257 intel
->ViewportMatrix
.m
, 0);
1259 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1270 /**********************************************************************/
1271 /* Initialization. */
1272 /**********************************************************************/
1276 intelInitTriFuncs(struct gl_context
* ctx
)
1278 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1279 static int firsttime
= 1;
1286 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1287 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1288 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1289 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1290 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1291 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1292 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1293 tnl
->Driver
.Render
.Interp
= _tnl_interp
;