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"
58 static void intelRenderPrimitive(struct gl_context * ctx, GLenum prim);
59 static void intelRasterPrimitive(struct gl_context * ctx, GLenum rprim,
63 intel_flush_inline_primitive(struct intel_context *intel)
65 GLuint used = intel->batch->ptr - intel->prim.start_ptr;
67 assert(intel->prim.primitive != ~0);
74 *(int *) intel->prim.start_ptr = (_3DPRIMITIVE |
75 intel->prim.primitive | (used / 4 - 2));
80 intel->batch->ptr -= used;
83 intel->prim.primitive = ~0;
84 intel->prim.start_ptr = 0;
85 intel->prim.flush = 0;
88 static void intel_start_inline(struct intel_context *intel, uint32_t prim)
92 intel->vtbl.emit_state(intel);
94 intel->no_batch_wrap = GL_TRUE;
96 /*printf("%s *", __progname);*/
98 /* Emit a slot which will be filled with the inline primitive
103 assert((intel->batch->dirty_state & (1<<1)) == 0);
105 intel->prim.start_ptr = intel->batch->ptr;
106 intel->prim.primitive = prim;
107 intel->prim.flush = intel_flush_inline_primitive;
112 intel->no_batch_wrap = GL_FALSE;
116 static void intel_wrap_inline(struct intel_context *intel)
118 GLuint prim = intel->prim.primitive;
120 intel_flush_inline_primitive(intel);
121 intel_batchbuffer_flush(intel->batch);
122 intel_start_inline(intel, prim); /* ??? */
125 static GLuint *intel_extend_inline(struct intel_context *intel, GLuint dwords)
127 GLuint sz = dwords * sizeof(GLuint);
130 assert(intel->prim.flush == intel_flush_inline_primitive);
132 if (intel_batchbuffer_space(intel->batch) < sz)
133 intel_wrap_inline(intel);
137 intel->vtbl.assert_not_dirty(intel);
139 ptr = (GLuint *) intel->batch->ptr;
140 intel->batch->ptr += sz;
145 /** Sets the primitive type for a primitive sequence, flushing as needed. */
146 void intel_set_prim(struct intel_context *intel, uint32_t prim)
148 /* if we have no VBOs */
150 if (intel->intelScreen->no_vbo) {
151 intel_start_inline(intel, prim);
154 if (prim != intel->prim.primitive) {
155 INTEL_FIREVERTICES(intel);
156 intel->prim.primitive = prim;
160 /** Returns mapped VB space for the given number of vertices */
161 uint32_t *intel_get_prim_space(struct intel_context *intel, unsigned int count)
165 if (intel->intelScreen->no_vbo) {
166 return intel_extend_inline(intel, count * intel->vertex_size);
169 /* Check for space in the existing VB */
170 if (intel->prim.vb_bo == NULL ||
171 (intel->prim.current_offset +
172 count * intel->vertex_size * 4) > INTEL_VB_SIZE ||
173 (intel->prim.count + count) >= (1 << 16)) {
174 /* Flush existing prim if any */
175 INTEL_FIREVERTICES(intel);
177 intel_finish_vb(intel);
180 if (intel->prim.vb == NULL)
181 intel->prim.vb = malloc(INTEL_VB_SIZE);
182 intel->prim.vb_bo = drm_intel_bo_alloc(intel->bufmgr, "vb",
184 intel->prim.start_offset = 0;
185 intel->prim.current_offset = 0;
188 intel->prim.flush = intel_flush_prim;
190 addr = (uint32_t *)(intel->prim.vb + intel->prim.current_offset);
191 intel->prim.current_offset += intel->vertex_size * 4 * count;
192 intel->prim.count += count;
197 /** Dispatches the accumulated primitive to the batchbuffer. */
198 void intel_flush_prim(struct intel_context *intel)
200 drm_intel_bo *aper_array[2];
202 unsigned int offset, count;
205 /* Must be called after an intel_start_prim. */
206 assert(intel->prim.primitive != ~0);
208 if (intel->prim.count == 0)
211 /* Clear the current prims out of the context state so that a batch flush
212 * flush triggered by emit_state doesn't loop back to flush_prim again.
214 vb_bo = intel->prim.vb_bo;
215 drm_intel_bo_reference(vb_bo);
216 count = intel->prim.count;
217 intel->prim.count = 0;
218 offset = intel->prim.start_offset;
219 intel->prim.start_offset = intel->prim.current_offset;
221 intel->prim.start_offset = ALIGN(intel->prim.start_offset, 128);
222 intel->prim.flush = NULL;
224 intel->vtbl.emit_state(intel);
226 aper_array[0] = intel->batch->buf;
227 aper_array[1] = vb_bo;
228 if (dri_bufmgr_check_aperture_space(aper_array, 2)) {
229 intel_batchbuffer_flush(intel->batch);
230 intel->vtbl.emit_state(intel);
233 /* Ensure that we don't start a new batch for the following emit, which
234 * depends on the state just emitted. emit_state should be making sure we
235 * have the space for this.
237 intel->no_batch_wrap = GL_TRUE;
239 /* Check that we actually emitted the state into this batch, using the
240 * UPLOAD_CTX bit as the signal.
242 assert((intel->batch->dirty_state & (1<<1)) == 0);
245 printf("emitting %d..%d=%d vertices size %d\n", offset,
246 intel->prim.current_offset, count,
247 intel->vertex_size * 4);
250 if (intel->gen >= 3) {
252 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
253 I1_LOAD_S(0) | I1_LOAD_S(1) | 1);
254 assert((offset & ~S0_VB_OFFSET_MASK) == 0);
255 OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, offset);
256 OUT_BATCH((intel->vertex_size << S1_VERTEX_WIDTH_SHIFT) |
257 (intel->vertex_size << S1_VERTEX_PITCH_SHIFT));
259 OUT_BATCH(_3DPRIMITIVE |
261 PRIM_INDIRECT_SEQUENTIAL |
262 intel->prim.primitive |
264 OUT_BATCH(0); /* Beginning vertex index */
267 struct i830_context *i830 = i830_context(&intel->ctx);
270 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
271 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
273 assert((offset & ~S0_VB_OFFSET_MASK_830) == 0);
274 OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0,
275 offset | (intel->vertex_size << S0_VB_PITCH_SHIFT_830) |
278 * This is somewhat unfortunate -- VB width is tied up with
279 * vertex format data that we've already uploaded through
280 * _3DSTATE_VFT[01]_CMD. We may want to replace emits of VFT state with
281 * STATE_IMMEDIATE_1 like this to avoid duplication.
283 OUT_BATCH((i830->state.Ctx[I830_CTXREG_VF] & VFT0_TEX_COUNT_MASK) >>
284 VFT0_TEX_COUNT_SHIFT << S2_TEX_COUNT_SHIFT_830 |
285 (i830->state.Ctx[I830_CTXREG_VF2] << 16) |
286 intel->vertex_size << S2_VERTEX_0_WIDTH_SHIFT_830);
288 OUT_BATCH(_3DPRIMITIVE |
290 PRIM_INDIRECT_SEQUENTIAL |
291 intel->prim.primitive |
293 OUT_BATCH(0); /* Beginning vertex index */
297 intel->no_batch_wrap = GL_FALSE;
299 drm_intel_bo_unreference(vb_bo);
303 * Uploads the locally-accumulated VB into the buffer object.
305 * This avoids us thrashing the cachelines in and out as the buffer gets
306 * filled, dispatched, then reused as the hardware completes rendering from it,
307 * and also lets us clflush less if we dispatch with a partially-filled VB.
309 * This is called normally from get_space when we're finishing a BO, but also
310 * at batch flush time so that we don't try accessing the contents of a
311 * just-dispatched buffer.
313 void intel_finish_vb(struct intel_context *intel)
315 if (intel->prim.vb_bo == NULL)
318 drm_intel_bo_subdata(intel->prim.vb_bo, 0, intel->prim.start_offset,
320 drm_intel_bo_unreference(intel->prim.vb_bo);
321 intel->prim.vb_bo = NULL;
324 /***********************************************************************
325 * Emit primitives as inline vertices *
326 ***********************************************************************/
329 #define COPY_DWORDS( j, vb, vertsize, v ) \
332 __asm__ __volatile__( "rep ; movsl" \
333 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
339 #define COPY_DWORDS( j, vb, vertsize, v ) \
341 for ( j = 0 ; j < vertsize ; j++ ) { \
342 vb[j] = ((GLuint *)v)[j]; \
349 intel_draw_quad(struct intel_context *intel,
351 intelVertexPtr v1, intelVertexPtr v2, intelVertexPtr v3)
353 GLuint vertsize = intel->vertex_size;
354 GLuint *vb = intel_get_prim_space(intel, 6);
357 COPY_DWORDS(j, vb, vertsize, v0);
358 COPY_DWORDS(j, vb, vertsize, v1);
360 /* If smooth shading, draw like a trifan which gives better
361 * rasterization. Otherwise draw as two triangles with provoking
362 * vertex in third position as required for flat shading.
364 if (intel->ctx.Light.ShadeModel == GL_FLAT) {
365 COPY_DWORDS(j, vb, vertsize, v3);
366 COPY_DWORDS(j, vb, vertsize, v1);
369 COPY_DWORDS(j, vb, vertsize, v2);
370 COPY_DWORDS(j, vb, vertsize, v0);
373 COPY_DWORDS(j, vb, vertsize, v2);
374 COPY_DWORDS(j, vb, vertsize, v3);
378 intel_draw_triangle(struct intel_context *intel,
379 intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
381 GLuint vertsize = intel->vertex_size;
382 GLuint *vb = intel_get_prim_space(intel, 3);
385 COPY_DWORDS(j, vb, vertsize, v0);
386 COPY_DWORDS(j, vb, vertsize, v1);
387 COPY_DWORDS(j, vb, vertsize, v2);
392 intel_draw_line(struct intel_context *intel,
393 intelVertexPtr v0, intelVertexPtr v1)
395 GLuint vertsize = intel->vertex_size;
396 GLuint *vb = intel_get_prim_space(intel, 2);
399 COPY_DWORDS(j, vb, vertsize, v0);
400 COPY_DWORDS(j, vb, vertsize, v1);
405 intel_draw_point(struct intel_context *intel, intelVertexPtr v0)
407 GLuint vertsize = intel->vertex_size;
408 GLuint *vb = intel_get_prim_space(intel, 1);
411 /* Adjust for sub pixel position -- still required for conform. */
412 *(float *) &vb[0] = v0->v.x;
413 *(float *) &vb[1] = v0->v.y;
414 for (j = 2; j < vertsize; j++)
420 /***********************************************************************
421 * Fixup for ARB_point_parameters *
422 ***********************************************************************/
424 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
425 * represented in the fragment program InputsRead field.
428 intel_atten_point(struct intel_context *intel, intelVertexPtr v0)
430 struct gl_context *ctx = &intel->ctx;
431 GLfloat psz[4], col[4], restore_psz, restore_alpha;
433 _tnl_get_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
434 _tnl_get_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
436 restore_psz = psz[0];
437 restore_alpha = col[3];
439 if (psz[0] >= ctx->Point.Threshold) {
440 psz[0] = MIN2(psz[0], ctx->Point.MaxSize);
443 GLfloat dsize = psz[0] / ctx->Point.Threshold;
444 psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
445 col[3] *= dsize * dsize;
451 if (restore_psz != psz[0] || restore_alpha != col[3]) {
452 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
453 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
455 intel_draw_point(intel, v0);
457 psz[0] = restore_psz;
458 col[3] = restore_alpha;
460 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
461 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
464 intel_draw_point(intel, v0);
471 /***********************************************************************
472 * Fixup for I915 WPOS texture coordinate *
473 ***********************************************************************/
478 intel_wpos_triangle(struct intel_context *intel,
479 intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
481 GLuint offset = intel->wpos_offset;
482 GLuint size = intel->wpos_size;
483 GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
484 GLfloat *v1_wpos = (GLfloat *)((char *)v1 + offset);
485 GLfloat *v2_wpos = (GLfloat *)((char *)v2 + offset);
487 __memcpy(v0_wpos, v0, size);
488 __memcpy(v1_wpos, v1, size);
489 __memcpy(v2_wpos, v2, size);
491 v0_wpos[1] = -v0_wpos[1] + intel->ctx.DrawBuffer->Height;
492 v1_wpos[1] = -v1_wpos[1] + intel->ctx.DrawBuffer->Height;
493 v2_wpos[1] = -v2_wpos[1] + intel->ctx.DrawBuffer->Height;
496 intel_draw_triangle(intel, v0, v1, v2);
501 intel_wpos_line(struct intel_context *intel,
502 intelVertexPtr v0, intelVertexPtr v1)
504 GLuint offset = intel->wpos_offset;
505 GLuint size = intel->wpos_size;
506 GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
507 GLfloat *v1_wpos = (GLfloat *)((char *)v1 + offset);
509 __memcpy(v0_wpos, v0, size);
510 __memcpy(v1_wpos, v1, size);
512 v0_wpos[1] = -v0_wpos[1] + intel->ctx.DrawBuffer->Height;
513 v1_wpos[1] = -v1_wpos[1] + intel->ctx.DrawBuffer->Height;
515 intel_draw_line(intel, v0, v1);
520 intel_wpos_point(struct intel_context *intel, intelVertexPtr v0)
522 GLuint offset = intel->wpos_offset;
523 GLuint size = intel->wpos_size;
524 GLfloat *v0_wpos = (GLfloat *)((char *)v0 + offset);
526 __memcpy(v0_wpos, v0, size);
527 v0_wpos[1] = -v0_wpos[1] + intel->ctx.DrawBuffer->Height;
529 intel_draw_point(intel, v0);
537 /***********************************************************************
538 * Macros for t_dd_tritmp.h to draw basic primitives *
539 ***********************************************************************/
541 #define TRI( a, b, c ) \
544 intel->draw_tri( intel, a, b, c ); \
546 intel_draw_triangle( intel, a, b, c ); \
549 #define QUAD( a, b, c, d ) \
552 intel->draw_tri( intel, a, b, d ); \
553 intel->draw_tri( intel, b, c, d ); \
555 intel_draw_quad( intel, a, b, c, d ); \
558 #define LINE( v0, v1 ) \
561 intel->draw_line( intel, v0, v1 ); \
563 intel_draw_line( intel, v0, v1 ); \
566 #define POINT( v0 ) \
569 intel->draw_point( intel, v0 ); \
571 intel_draw_point( intel, v0 ); \
575 /***********************************************************************
576 * Build render functions from dd templates *
577 ***********************************************************************/
579 #define INTEL_OFFSET_BIT 0x01
580 #define INTEL_TWOSIDE_BIT 0x02
581 #define INTEL_UNFILLED_BIT 0x04
582 #define INTEL_FALLBACK_BIT 0x08
583 #define INTEL_MAX_TRIFUNC 0x10
588 tnl_points_func points;
590 tnl_triangle_func triangle;
592 } rast_tab[INTEL_MAX_TRIFUNC];
595 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
596 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
597 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
598 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
604 #define DO_FULL_QUAD 1
607 #define HAVE_BACK_COLORS 0
608 #define HAVE_HW_FLATSHADE 1
609 #define VERTEX intelVertex
612 /* Only used to pull back colors into vertices (ie, we know color is
615 #define INTEL_COLOR( dst, src ) \
617 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
618 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
619 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
620 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
623 #define INTEL_SPEC( dst, src ) \
625 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
626 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
627 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
631 #define DEPTH_SCALE intel->polygon_offset_scale
632 #define UNFILLED_TRI unfilled_tri
633 #define UNFILLED_QUAD unfilled_quad
634 #define VERT_X(_v) _v->v.x
635 #define VERT_Y(_v) _v->v.y
636 #define VERT_Z(_v) _v->v.z
637 #define AREA_IS_CCW( a ) (a > 0)
638 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
640 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
641 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
642 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
643 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
645 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
646 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
647 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
648 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
650 #define LOCAL_VARS(n) \
651 struct intel_context *intel = intel_context(ctx); \
652 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
653 GLuint coloroffset = intel->coloroffset; \
654 GLboolean specoffset = intel->specoffset; \
655 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
658 /***********************************************************************
659 * Helpers for rendering unfilled primitives *
660 ***********************************************************************/
662 static const GLuint hw_prim[GL_POLYGON + 1] = {
675 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
676 #define RENDER_PRIMITIVE intel->render_primitive
678 #define IND INTEL_FALLBACK_BIT
679 #include "tnl_dd/t_dd_unfilled.h"
682 /***********************************************************************
683 * Generate GL render functions *
684 ***********************************************************************/
688 #include "tnl_dd/t_dd_tritmp.h"
690 #define IND (INTEL_OFFSET_BIT)
691 #define TAG(x) x##_offset
692 #include "tnl_dd/t_dd_tritmp.h"
694 #define IND (INTEL_TWOSIDE_BIT)
695 #define TAG(x) x##_twoside
696 #include "tnl_dd/t_dd_tritmp.h"
698 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
699 #define TAG(x) x##_twoside_offset
700 #include "tnl_dd/t_dd_tritmp.h"
702 #define IND (INTEL_UNFILLED_BIT)
703 #define TAG(x) x##_unfilled
704 #include "tnl_dd/t_dd_tritmp.h"
706 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
707 #define TAG(x) x##_offset_unfilled
708 #include "tnl_dd/t_dd_tritmp.h"
710 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
711 #define TAG(x) x##_twoside_unfilled
712 #include "tnl_dd/t_dd_tritmp.h"
714 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
715 #define TAG(x) x##_twoside_offset_unfilled
716 #include "tnl_dd/t_dd_tritmp.h"
718 #define IND (INTEL_FALLBACK_BIT)
719 #define TAG(x) x##_fallback
720 #include "tnl_dd/t_dd_tritmp.h"
722 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
723 #define TAG(x) x##_offset_fallback
724 #include "tnl_dd/t_dd_tritmp.h"
726 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
727 #define TAG(x) x##_twoside_fallback
728 #include "tnl_dd/t_dd_tritmp.h"
730 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
731 #define TAG(x) x##_twoside_offset_fallback
732 #include "tnl_dd/t_dd_tritmp.h"
734 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
735 #define TAG(x) x##_unfilled_fallback
736 #include "tnl_dd/t_dd_tritmp.h"
738 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
739 #define TAG(x) x##_offset_unfilled_fallback
740 #include "tnl_dd/t_dd_tritmp.h"
742 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
743 #define TAG(x) x##_twoside_unfilled_fallback
744 #include "tnl_dd/t_dd_tritmp.h"
746 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
748 #define TAG(x) x##_twoside_offset_unfilled_fallback
749 #include "tnl_dd/t_dd_tritmp.h"
758 init_twoside_offset();
760 init_offset_unfilled();
761 init_twoside_unfilled();
762 init_twoside_offset_unfilled();
764 init_offset_fallback();
765 init_twoside_fallback();
766 init_twoside_offset_fallback();
767 init_unfilled_fallback();
768 init_offset_unfilled_fallback();
769 init_twoside_unfilled_fallback();
770 init_twoside_offset_unfilled_fallback();
774 /***********************************************************************
775 * Rasterization fallback helpers *
776 ***********************************************************************/
779 /* This code is hit only when a mix of accelerated and unaccelerated
780 * primitives are being drawn, and only for the unaccelerated
784 intel_fallback_tri(struct intel_context *intel,
785 intelVertex * v0, intelVertex * v1, intelVertex * v2)
787 struct gl_context *ctx = &intel->ctx;
791 fprintf(stderr, "\n%s\n", __FUNCTION__);
793 INTEL_FIREVERTICES(intel);
795 _swsetup_Translate(ctx, v0, &v[0]);
796 _swsetup_Translate(ctx, v1, &v[1]);
797 _swsetup_Translate(ctx, v2, &v[2]);
798 intelSpanRenderStart(ctx);
799 _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
800 intelSpanRenderFinish(ctx);
805 intel_fallback_line(struct intel_context *intel,
806 intelVertex * v0, intelVertex * v1)
808 struct gl_context *ctx = &intel->ctx;
812 fprintf(stderr, "\n%s\n", __FUNCTION__);
814 INTEL_FIREVERTICES(intel);
816 _swsetup_Translate(ctx, v0, &v[0]);
817 _swsetup_Translate(ctx, v1, &v[1]);
818 intelSpanRenderStart(ctx);
819 _swrast_Line(ctx, &v[0], &v[1]);
820 intelSpanRenderFinish(ctx);
824 intel_fallback_point(struct intel_context *intel,
827 struct gl_context *ctx = &intel->ctx;
831 fprintf(stderr, "\n%s\n", __FUNCTION__);
833 INTEL_FIREVERTICES(intel);
835 _swsetup_Translate(ctx, v0, &v[0]);
836 intelSpanRenderStart(ctx);
837 _swrast_Point(ctx, &v[0]);
838 intelSpanRenderFinish(ctx);
842 /**********************************************************************/
843 /* Render unclipped begin/end objects */
844 /**********************************************************************/
847 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
848 #define RENDER_POINTS( start, count ) \
849 for ( ; start < count ; start++) POINT( V(ELT(start)) );
850 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
851 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
852 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
853 #define INIT(x) intelRenderPrimitive( ctx, x )
856 struct intel_context *intel = intel_context(ctx); \
857 GLubyte *vertptr = (GLubyte *)intel->verts; \
858 const GLuint vertsize = intel->vertex_size; \
859 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
861 #define RESET_STIPPLE
862 #define RESET_OCCLUSION
863 #define PRESERVE_VB_DEFS
865 #define TAG(x) intel_##x##_verts
866 #include "tnl/t_vb_rendertmp.h"
869 #define TAG(x) intel_##x##_elts
870 #define ELT(x) elt[x]
871 #include "tnl/t_vb_rendertmp.h"
873 /**********************************************************************/
874 /* Render clipped primitives */
875 /**********************************************************************/
880 intelRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
882 struct intel_context *intel = intel_context(ctx);
883 TNLcontext *tnl = TNL_CONTEXT(ctx);
884 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
885 GLuint prim = intel->render_primitive;
887 /* Render the new vertices as an unclipped polygon.
890 GLuint *tmp = VB->Elts;
891 VB->Elts = (GLuint *) elts;
892 tnl->Driver.Render.PrimTabElts[GL_POLYGON] (ctx, 0, n,
893 PRIM_BEGIN | PRIM_END);
897 /* Restore the render primitive
899 if (prim != GL_POLYGON)
900 tnl->Driver.Render.PrimitiveNotify(ctx, prim);
904 intelRenderClippedLine(struct gl_context * ctx, GLuint ii, GLuint jj)
906 TNLcontext *tnl = TNL_CONTEXT(ctx);
908 tnl->Driver.Render.Line(ctx, ii, jj);
912 intelFastRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
914 struct intel_context *intel = intel_context(ctx);
915 const GLuint vertsize = intel->vertex_size;
916 GLuint *vb = intel_get_prim_space(intel, (n - 2) * 3);
917 GLubyte *vertptr = (GLubyte *) intel->verts;
918 const GLuint *start = (const GLuint *) V(elts[0]);
921 for (i = 2; i < n; i++) {
922 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
923 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
924 COPY_DWORDS(j, vb, vertsize, start);
928 /**********************************************************************/
929 /* Choose render functions */
930 /**********************************************************************/
935 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
936 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
939 intelChooseRenderState(struct gl_context * ctx)
941 TNLcontext *tnl = TNL_CONTEXT(ctx);
942 struct intel_context *intel = intel_context(ctx);
943 GLuint flags = ctx->_TriangleCaps;
944 const struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
945 GLboolean have_wpos = (fprog && (fprog->Base.InputsRead & FRAG_BIT_WPOS));
948 if (INTEL_DEBUG & DEBUG_STATE)
949 fprintf(stderr, "\n%s\n", __FUNCTION__);
951 if ((flags & (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)) || have_wpos) {
953 if (flags & ANY_RASTER_FLAGS) {
954 if (flags & DD_TRI_LIGHT_TWOSIDE)
955 index |= INTEL_TWOSIDE_BIT;
956 if (flags & DD_TRI_OFFSET)
957 index |= INTEL_OFFSET_BIT;
958 if (flags & DD_TRI_UNFILLED)
959 index |= INTEL_UNFILLED_BIT;
963 intel->draw_point = intel_wpos_point;
964 intel->draw_line = intel_wpos_line;
965 intel->draw_tri = intel_wpos_triangle;
967 /* Make sure these get called:
969 index |= INTEL_FALLBACK_BIT;
972 intel->draw_point = intel_draw_point;
973 intel->draw_line = intel_draw_line;
974 intel->draw_tri = intel_draw_triangle;
977 /* Hook in fallbacks for specific primitives.
979 if (flags & ANY_FALLBACK_FLAGS) {
980 if (flags & DD_LINE_STIPPLE)
981 intel->draw_line = intel_fallback_line;
983 if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple)
984 intel->draw_tri = intel_fallback_tri;
986 if (flags & DD_TRI_SMOOTH) {
987 if (intel->conformance_mode > 0)
988 intel->draw_tri = intel_fallback_tri;
991 if (flags & DD_POINT_ATTEN) {
993 intel->draw_point = intel_atten_point;
995 intel->draw_point = intel_fallback_point;
998 if (flags & DD_POINT_SMOOTH) {
999 if (intel->conformance_mode > 0)
1000 intel->draw_point = intel_fallback_point;
1003 index |= INTEL_FALLBACK_BIT;
1007 if (intel->RenderIndex != index) {
1008 intel->RenderIndex = index;
1010 tnl->Driver.Render.Points = rast_tab[index].points;
1011 tnl->Driver.Render.Line = rast_tab[index].line;
1012 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
1013 tnl->Driver.Render.Quad = rast_tab[index].quad;
1016 tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts;
1017 tnl->Driver.Render.PrimTabElts = intel_render_tab_elts;
1018 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
1019 tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly;
1022 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
1023 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
1024 tnl->Driver.Render.ClippedLine = intelRenderClippedLine;
1025 tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly;
1030 static const GLenum reduced_prim[GL_POLYGON + 1] = {
1044 /**********************************************************************/
1045 /* High level hooks for t_vb_render.c */
1046 /**********************************************************************/
1052 intelRunPipeline(struct gl_context * ctx)
1054 struct intel_context *intel = intel_context(ctx);
1056 _mesa_lock_context_textures(ctx);
1059 _mesa_update_state_locked(ctx);
1061 if (intel->NewGLState) {
1062 if (intel->NewGLState & _NEW_TEXTURE) {
1063 intel->vtbl.update_texture_state(intel);
1066 if (!intel->Fallback) {
1067 if (intel->NewGLState & _INTEL_NEW_RENDERSTATE)
1068 intelChooseRenderState(ctx);
1071 intel->NewGLState = 0;
1074 intel_map_vertex_shader_textures(ctx);
1075 _tnl_run_pipeline(ctx);
1076 intel_unmap_vertex_shader_textures(ctx);
1078 _mesa_unlock_context_textures(ctx);
1082 intelRenderStart(struct gl_context * ctx)
1084 struct intel_context *intel = intel_context(ctx);
1086 intel_check_front_buffer_rendering(intel);
1087 intel->vtbl.render_start(intel_context(ctx));
1088 intel->vtbl.emit_state(intel);
1092 intelRenderFinish(struct gl_context * ctx)
1094 struct intel_context *intel = intel_context(ctx);
1096 if (intel->RenderIndex & INTEL_FALLBACK_BIT)
1099 INTEL_FIREVERTICES(intel);
1105 /* System to flush dma and emit state changes based on the rasterized
1109 intelRasterPrimitive(struct gl_context * ctx, GLenum rprim, GLuint hwprim)
1111 struct intel_context *intel = intel_context(ctx);
1114 fprintf(stderr, "%s %s %x\n", __FUNCTION__,
1115 _mesa_lookup_enum_by_nr(rprim), hwprim);
1117 intel->vtbl.reduced_primitive_state(intel, rprim);
1119 /* Start a new primitive. Arrange to have it flushed later on.
1121 if (hwprim != intel->prim.primitive) {
1122 INTEL_FIREVERTICES(intel);
1124 intel_set_prim(intel, hwprim);
1132 intelRenderPrimitive(struct gl_context * ctx, GLenum prim)
1134 struct intel_context *intel = intel_context(ctx);
1137 fprintf(stderr, "%s %s\n", __FUNCTION__, _mesa_lookup_enum_by_nr(prim));
1139 /* Let some clipping routines know which primitive they're dealing
1142 intel->render_primitive = prim;
1144 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
1145 * triangles. The rasterized primitive will always be reset by
1146 * lower level functions in that case, potentially pingponging the
1149 if (reduced_prim[prim] == GL_TRIANGLES &&
1150 (ctx->_TriangleCaps & DD_TRI_UNFILLED))
1153 /* Set some primitive-dependent state and Start? a new primitive.
1155 intelRasterPrimitive(ctx, reduced_prim[prim], hw_prim[prim]);
1159 /**********************************************************************/
1160 /* Transition to/from hardware rasterization. */
1161 /**********************************************************************/
1163 static char *fallbackStrings[] = {
1164 [0] = "Draw buffer",
1165 [1] = "Read buffer",
1166 [2] = "Depth buffer",
1167 [3] = "Stencil buffer",
1168 [4] = "User disable",
1169 [5] = "Render mode",
1172 [13] = "Color mask",
1177 [18] = "Smooth polygon",
1178 [19] = "Smooth point",
1179 [20] = "point sprite coord origin",
1180 [21] = "depth/color drawing offset",
1185 getFallbackString(GLuint bit)
1192 return fallbackStrings[i];
1198 * Enable/disable a fallback flag.
1199 * \param bit one of INTEL_FALLBACK_x flags.
1202 intelFallback(struct intel_context *intel, GLbitfield bit, GLboolean mode)
1204 struct gl_context *ctx = &intel->ctx;
1205 TNLcontext *tnl = TNL_CONTEXT(ctx);
1206 const GLbitfield oldfallback = intel->Fallback;
1209 intel->Fallback |= bit;
1210 if (oldfallback == 0) {
1212 if (INTEL_DEBUG & DEBUG_FALLBACKS)
1213 fprintf(stderr, "ENTER FALLBACK %x: %s\n",
1214 bit, getFallbackString(bit));
1215 _swsetup_Wakeup(ctx);
1216 intel->RenderIndex = ~0;
1220 intel->Fallback &= ~bit;
1221 if (oldfallback == bit) {
1223 if (INTEL_DEBUG & DEBUG_FALLBACKS)
1224 fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString(bit));
1225 tnl->Driver.Render.Start = intelRenderStart;
1226 tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
1227 tnl->Driver.Render.Finish = intelRenderFinish;
1228 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
1229 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
1230 tnl->Driver.Render.Interp = _tnl_interp;
1232 _tnl_invalidate_vertex_state(ctx, ~0);
1233 _tnl_invalidate_vertices(ctx, ~0);
1234 _tnl_install_attrs(ctx,
1235 intel->vertex_attrs,
1236 intel->vertex_attr_count,
1237 intel->ViewportMatrix.m, 0);
1239 intel->NewGLState |= _INTEL_NEW_RENDERSTATE;
1250 /**********************************************************************/
1251 /* Initialization. */
1252 /**********************************************************************/
1256 intelInitTriFuncs(struct gl_context * ctx)
1258 TNLcontext *tnl = TNL_CONTEXT(ctx);
1259 static int firsttime = 1;
1266 tnl->Driver.RunPipeline = intelRunPipeline;
1267 tnl->Driver.Render.Start = intelRenderStart;
1268 tnl->Driver.Render.Finish = intelRenderFinish;
1269 tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
1270 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1271 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
1272 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
1273 tnl->Driver.Render.Interp = _tnl_interp;