1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /** @file intel_tris.c
29 *
30 * This file contains functions for managing the vertex buffer and emitting
31 * primitives into it.
32 */
33
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"
40 #include "main/dd.h"
41 #include "main/fbobject.h"
42
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"
48
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"
56 #include "i830_reg.h"
57 #include "i915_context.h"
58
59 static void intelRenderPrimitive(struct gl_context * ctx, GLenum prim);
60 static void intelRasterPrimitive(struct gl_context * ctx, GLenum rprim,
61 GLuint hwprim);
62
63 static void
intel_flush_inline_primitive(struct intel_context * intel)64 intel_flush_inline_primitive(struct intel_context *intel)
65 {
66 GLuint used = intel->batch.used - intel->prim.start_ptr;
67
68 assert(intel->prim.primitive != ~0);
69
70 /* printf("/\n"); */
71
72 if (used < 2)
73 goto do_discard;
74
75 intel->batch.map[intel->prim.start_ptr] =
76 _3DPRIMITIVE | intel->prim.primitive | (used - 2);
77
78 goto finished;
79
80 do_discard:
81 intel->batch.used = intel->prim.start_ptr;
82
83 finished:
84 intel->prim.primitive = ~0;
85 intel->prim.start_ptr = 0;
86 intel->prim.flush = 0;
87 }
88
intel_start_inline(struct intel_context * intel,uint32_t prim)89 static void intel_start_inline(struct intel_context *intel, uint32_t prim)
90 {
91 BATCH_LOCALS;
92
93 intel->vtbl.emit_state(intel);
94
95 intel->no_batch_wrap = true;
96
97 /* Emit a slot which will be filled with the inline primitive
98 * command later.
99 */
100 BEGIN_BATCH(1);
101
102 intel->prim.start_ptr = intel->batch.used;
103 intel->prim.primitive = prim;
104 intel->prim.flush = intel_flush_inline_primitive;
105
106 OUT_BATCH(0);
107 ADVANCE_BATCH();
108
109 intel->no_batch_wrap = false;
110 /* printf(">"); */
111 }
112
intel_wrap_inline(struct intel_context * intel)113 static void intel_wrap_inline(struct intel_context *intel)
114 {
115 GLuint prim = intel->prim.primitive;
116
117 intel_flush_inline_primitive(intel);
118 intel_batchbuffer_flush(intel);
119 intel_start_inline(intel, prim); /* ??? */
120 }
121
intel_extend_inline(struct intel_context * intel,GLuint dwords)122 static GLuint *intel_extend_inline(struct intel_context *intel, GLuint dwords)
123 {
124 GLuint *ptr;
125
126 assert(intel->prim.flush == intel_flush_inline_primitive);
127
128 if (intel_batchbuffer_space(intel) < dwords * sizeof(GLuint))
129 intel_wrap_inline(intel);
130
131 /* printf("."); */
132
133 intel->vtbl.assert_not_dirty(intel);
134
135 ptr = intel->batch.map + intel->batch.used;
136 intel->batch.used += dwords;
137
138 return ptr;
139 }
140
141 /** Sets the primitive type for a primitive sequence, flushing as needed. */
intel_set_prim(struct intel_context * intel,uint32_t prim)142 void intel_set_prim(struct intel_context *intel, uint32_t prim)
143 {
144 /* if we have no VBOs */
145
146 if (intel->intelScreen->no_vbo) {
147 intel_start_inline(intel, prim);
148 return;
149 }
150 if (prim != intel->prim.primitive) {
151 INTEL_FIREVERTICES(intel);
152 intel->prim.primitive = prim;
153 }
154 }
155
156 /** Returns mapped VB space for the given number of vertices */
intel_get_prim_space(struct intel_context * intel,unsigned int count)157 uint32_t *intel_get_prim_space(struct intel_context *intel, unsigned int count)
158 {
159 uint32_t *addr;
160
161 if (intel->intelScreen->no_vbo) {
162 return intel_extend_inline(intel, count * intel->vertex_size);
163 }
164
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);
172
173 intel_finish_vb(intel);
174
175 /* Start a new VB */
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",
179 INTEL_VB_SIZE, 4);
180 intel->prim.start_offset = 0;
181 intel->prim.current_offset = 0;
182 }
183
184 intel->prim.flush = intel_flush_prim;
185
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;
189
190 return addr;
191 }
192
193 /** Dispatches the accumulated primitive to the batchbuffer. */
intel_flush_prim(struct intel_context * intel)194 void intel_flush_prim(struct intel_context *intel)
195 {
196 drm_intel_bo *aper_array[2];
197 drm_intel_bo *vb_bo;
198 unsigned int offset, count;
199 BATCH_LOCALS;
200
201 /* Must be called after an intel_start_prim. */
202 assert(intel->prim.primitive != ~0);
203
204 if (intel->prim.count == 0)
205 return;
206
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.
209 */
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;
216 if (intel->gen < 3)
217 intel->prim.current_offset = intel->prim.start_offset = ALIGN(intel->prim.start_offset, 128);
218 intel->prim.flush = NULL;
219
220 intel->vtbl.emit_state(intel);
221
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);
227 }
228
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.
232 */
233 intel->no_batch_wrap = true;
234
235 if (intel->always_flush_cache) {
236 intel_batchbuffer_emit_mi_flush(intel);
237 }
238
239 #if 0
240 printf("emitting %d..%d=%d vertices size %d\n", offset,
241 intel->prim.current_offset, count,
242 intel->vertex_size * 4);
243 #endif
244
245 if (intel->gen >= 3) {
246 struct i915_context *i915 = i915_context(&intel->ctx);
247 unsigned int cmd = 0, len = 0;
248
249 if (vb_bo != i915->current_vb_bo) {
250 cmd |= I1_LOAD_S(0);
251 len++;
252 }
253
254 if (intel->vertex_size != i915->current_vertex_size) {
255 cmd |= I1_LOAD_S(1);
256 len++;
257 }
258 if (len)
259 len++;
260
261 BEGIN_BATCH(2+len);
262 if (cmd)
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;
267 }
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;
272 }
273 OUT_BATCH(_3DPRIMITIVE |
274 PRIM_INDIRECT |
275 PRIM_INDIRECT_SEQUENTIAL |
276 intel->prim.primitive |
277 count);
278 OUT_BATCH(offset / (intel->vertex_size * 4));
279 ADVANCE_BATCH();
280 } else {
281 struct i830_context *i830 = i830_context(&intel->ctx);
282
283 BEGIN_BATCH(5);
284 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
285 I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
286 /* S0 */
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) |
290 S0_VB_ENABLE_830);
291 /* S2
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.
296 */
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);
301
302 OUT_BATCH(_3DPRIMITIVE |
303 PRIM_INDIRECT |
304 PRIM_INDIRECT_SEQUENTIAL |
305 intel->prim.primitive |
306 count);
307 OUT_BATCH(0); /* Beginning vertex index */
308 ADVANCE_BATCH();
309 }
310
311 if (intel->always_flush_cache) {
312 intel_batchbuffer_emit_mi_flush(intel);
313 }
314
315 intel->no_batch_wrap = false;
316
317 drm_intel_bo_unreference(vb_bo);
318 }
319
320 /**
321 * Uploads the locally-accumulated VB into the buffer object.
322 *
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.
326 *
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.
330 */
intel_finish_vb(struct intel_context * intel)331 void intel_finish_vb(struct intel_context *intel)
332 {
333 if (intel->prim.vb_bo == NULL)
334 return;
335
336 drm_intel_bo_subdata(intel->prim.vb_bo, 0, intel->prim.start_offset,
337 intel->prim.vb);
338 drm_intel_bo_unreference(intel->prim.vb_bo);
339 intel->prim.vb_bo = NULL;
340 }
341
342 /***********************************************************************
343 * Emit primitives as inline vertices *
344 ***********************************************************************/
345
346 #ifdef __i386__
347 #define COPY_DWORDS( j, vb, vertsize, v ) \
348 do { \
349 int __tmp; \
350 __asm__ __volatile__( "rep ; movsl" \
351 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
352 : "0" (vertsize), \
353 "D" ((long)vb), \
354 "S" ((long)v) ); \
355 } while (0)
356 #else
357 #define COPY_DWORDS( j, vb, vertsize, v ) \
358 do { \
359 for ( j = 0 ; j < vertsize ; j++ ) { \
360 vb[j] = ((GLuint *)v)[j]; \
361 } \
362 vb += vertsize; \
363 } while (0)
364 #endif
365
366 static void
intel_draw_quad(struct intel_context * intel,intelVertexPtr v0,intelVertexPtr v1,intelVertexPtr v2,intelVertexPtr v3)367 intel_draw_quad(struct intel_context *intel,
368 intelVertexPtr v0,
369 intelVertexPtr v1, intelVertexPtr v2, intelVertexPtr v3)
370 {
371 GLuint vertsize = intel->vertex_size;
372 GLuint *vb = intel_get_prim_space(intel, 6);
373 int j;
374
375 COPY_DWORDS(j, vb, vertsize, v0);
376 COPY_DWORDS(j, vb, vertsize, v1);
377
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.
381 */
382 if (intel->ctx.Light.ShadeModel == GL_FLAT) {
383 COPY_DWORDS(j, vb, vertsize, v3);
384 COPY_DWORDS(j, vb, vertsize, v1);
385 }
386 else {
387 COPY_DWORDS(j, vb, vertsize, v2);
388 COPY_DWORDS(j, vb, vertsize, v0);
389 }
390
391 COPY_DWORDS(j, vb, vertsize, v2);
392 COPY_DWORDS(j, vb, vertsize, v3);
393 }
394
395 static void
intel_draw_triangle(struct intel_context * intel,intelVertexPtr v0,intelVertexPtr v1,intelVertexPtr v2)396 intel_draw_triangle(struct intel_context *intel,
397 intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
398 {
399 GLuint vertsize = intel->vertex_size;
400 GLuint *vb = intel_get_prim_space(intel, 3);
401 int j;
402
403 COPY_DWORDS(j, vb, vertsize, v0);
404 COPY_DWORDS(j, vb, vertsize, v1);
405 COPY_DWORDS(j, vb, vertsize, v2);
406 }
407
408
409 static void
intel_draw_line(struct intel_context * intel,intelVertexPtr v0,intelVertexPtr v1)410 intel_draw_line(struct intel_context *intel,
411 intelVertexPtr v0, intelVertexPtr v1)
412 {
413 GLuint vertsize = intel->vertex_size;
414 GLuint *vb = intel_get_prim_space(intel, 2);
415 int j;
416
417 COPY_DWORDS(j, vb, vertsize, v0);
418 COPY_DWORDS(j, vb, vertsize, v1);
419 }
420
421
422 static void
intel_draw_point(struct intel_context * intel,intelVertexPtr v0)423 intel_draw_point(struct intel_context *intel, intelVertexPtr v0)
424 {
425 GLuint vertsize = intel->vertex_size;
426 GLuint *vb = intel_get_prim_space(intel, 1);
427 int j;
428
429 COPY_DWORDS(j, vb, vertsize, v0);
430 }
431
432
433
434 /***********************************************************************
435 * Fixup for ARB_point_parameters *
436 ***********************************************************************/
437
438 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
439 * represented in the fragment program info.inputs_read field.
440 */
441 static void
intel_atten_point(struct intel_context * intel,intelVertexPtr v0)442 intel_atten_point(struct intel_context *intel, intelVertexPtr v0)
443 {
444 struct gl_context *ctx = &intel->ctx;
445 GLfloat psz[4], col[4], restore_psz, restore_alpha;
446
447 _tnl_get_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
448 _tnl_get_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
449
450 restore_psz = psz[0];
451 restore_alpha = col[3];
452
453 if (psz[0] >= ctx->Point.Threshold) {
454 psz[0] = MIN2(psz[0], ctx->Point.MaxSize);
455 }
456 else {
457 GLfloat dsize = psz[0] / ctx->Point.Threshold;
458 psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
459 col[3] *= dsize * dsize;
460 }
461
462 if (psz[0] < 1.0)
463 psz[0] = 1.0;
464
465 if (restore_psz != psz[0] || restore_alpha != col[3]) {
466 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
467 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
468
469 intel_draw_point(intel, v0);
470
471 psz[0] = restore_psz;
472 col[3] = restore_alpha;
473
474 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
475 _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
476 }
477 else
478 intel_draw_point(intel, v0);
479 }
480
481
482
483
484
485 /***********************************************************************
486 * Fixup for I915 WPOS texture coordinate *
487 ***********************************************************************/
488
489 static void
intel_emit_fragcoord(struct intel_context * intel,intelVertexPtr v)490 intel_emit_fragcoord(struct intel_context *intel, intelVertexPtr v)
491 {
492 struct gl_context *ctx = &intel->ctx;
493 struct gl_framebuffer *fb = ctx->DrawBuffer;
494 GLuint offset = intel->wpos_offset;
495 float *vertex_position = (float *)v;
496 float *fragcoord = (float *)((char *)v + offset);
497
498 fragcoord[0] = vertex_position[0];
499
500 if (_mesa_is_user_fbo(fb))
501 fragcoord[1] = vertex_position[1];
502 else
503 fragcoord[1] = fb->Height - vertex_position[1];
504
505 fragcoord[2] = vertex_position[2];
506 fragcoord[3] = vertex_position[3];
507 }
508
509 static void
intel_wpos_triangle(struct intel_context * intel,intelVertexPtr v0,intelVertexPtr v1,intelVertexPtr v2)510 intel_wpos_triangle(struct intel_context *intel,
511 intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
512 {
513 intel_emit_fragcoord(intel, v0);
514 intel_emit_fragcoord(intel, v1);
515 intel_emit_fragcoord(intel, v2);
516
517 intel_draw_triangle(intel, v0, v1, v2);
518 }
519
520
521 static void
intel_wpos_line(struct intel_context * intel,intelVertexPtr v0,intelVertexPtr v1)522 intel_wpos_line(struct intel_context *intel,
523 intelVertexPtr v0, intelVertexPtr v1)
524 {
525 intel_emit_fragcoord(intel, v0);
526 intel_emit_fragcoord(intel, v1);
527 intel_draw_line(intel, v0, v1);
528 }
529
530
531 static void
intel_wpos_point(struct intel_context * intel,intelVertexPtr v0)532 intel_wpos_point(struct intel_context *intel, intelVertexPtr v0)
533 {
534 intel_emit_fragcoord(intel, v0);
535 intel_draw_point(intel, v0);
536 }
537
538
539
540
541
542
543 /***********************************************************************
544 * Macros for t_dd_tritmp.h to draw basic primitives *
545 ***********************************************************************/
546
547 #define TRI( a, b, c ) \
548 do { \
549 if (DO_FALLBACK) \
550 intel->draw_tri( intel, a, b, c ); \
551 else \
552 intel_draw_triangle( intel, a, b, c ); \
553 } while (0)
554
555 #define QUAD( a, b, c, d ) \
556 do { \
557 if (DO_FALLBACK) { \
558 intel->draw_tri( intel, a, b, d ); \
559 intel->draw_tri( intel, b, c, d ); \
560 } else \
561 intel_draw_quad( intel, a, b, c, d ); \
562 } while (0)
563
564 #define LINE( v0, v1 ) \
565 do { \
566 if (DO_FALLBACK) \
567 intel->draw_line( intel, v0, v1 ); \
568 else \
569 intel_draw_line( intel, v0, v1 ); \
570 } while (0)
571
572 #define POINT( v0 ) \
573 do { \
574 if (DO_FALLBACK) \
575 intel->draw_point( intel, v0 ); \
576 else \
577 intel_draw_point( intel, v0 ); \
578 } while (0)
579
580
581 /***********************************************************************
582 * Build render functions from dd templates *
583 ***********************************************************************/
584
585 #define INTEL_OFFSET_BIT 0x01
586 #define INTEL_TWOSIDE_BIT 0x02
587 #define INTEL_UNFILLED_BIT 0x04
588 #define INTEL_FALLBACK_BIT 0x08
589 #define INTEL_MAX_TRIFUNC 0x10
590
591
592 static struct
593 {
594 tnl_points_func points;
595 tnl_line_func line;
596 tnl_triangle_func triangle;
597 tnl_quad_func quad;
598 } rast_tab[INTEL_MAX_TRIFUNC];
599
600
601 #define DO_FALLBACK ((IND & INTEL_FALLBACK_BIT) != 0)
602 #define DO_OFFSET ((IND & INTEL_OFFSET_BIT) != 0)
603 #define DO_UNFILLED ((IND & INTEL_UNFILLED_BIT) != 0)
604 #define DO_TWOSIDE ((IND & INTEL_TWOSIDE_BIT) != 0)
605 #define DO_FLAT 0
606 #define DO_TRI 1
607 #define DO_QUAD 1
608 #define DO_LINE 1
609 #define DO_POINTS 1
610 #define DO_FULL_QUAD 1
611
612 #define HAVE_SPEC 1
613 #define HAVE_BACK_COLORS 0
614 #define HAVE_HW_FLATSHADE 1
615 #define VERTEX intelVertex
616 #define TAB rast_tab
617
618 /* Only used to pull back colors into vertices (ie, we know color is
619 * floating point).
620 */
621 #define INTEL_COLOR( dst, src ) \
622 do { \
623 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
624 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
625 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
626 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
627 } while (0)
628
629 #define INTEL_SPEC( dst, src ) \
630 do { \
631 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
632 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
633 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
634 } while (0)
635
636
637 #define DEPTH_SCALE (ctx->DrawBuffer->Visual.depthBits == 16 ? 1.0 : 2.0)
638 #define UNFILLED_TRI unfilled_tri
639 #define UNFILLED_QUAD unfilled_quad
640 #define VERT_X(_v) _v->v.x
641 #define VERT_Y(_v) _v->v.y
642 #define VERT_Z(_v) _v->v.z
643 #define AREA_IS_CCW( a ) (a > 0)
644 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
645
646 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
647 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
648 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
649 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
650
651 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
652 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
653 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
654 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
655
656 #define LOCAL_VARS(n) \
657 struct intel_context *intel = intel_context(ctx); \
658 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
659 GLuint coloroffset = intel->coloroffset; \
660 GLuint specoffset = intel->specoffset; \
661 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
662
663
664 /***********************************************************************
665 * Helpers for rendering unfilled primitives *
666 ***********************************************************************/
667
668 static const GLuint hw_prim[GL_POLYGON + 1] = {
669 [GL_POINTS] = PRIM3D_POINTLIST,
670 [GL_LINES] = PRIM3D_LINELIST,
671 [GL_LINE_LOOP] = PRIM3D_LINELIST,
672 [GL_LINE_STRIP] = PRIM3D_LINELIST,
673 [GL_TRIANGLES] = PRIM3D_TRILIST,
674 [GL_TRIANGLE_STRIP] = PRIM3D_TRILIST,
675 [GL_TRIANGLE_FAN] = PRIM3D_TRILIST,
676 [GL_QUADS] = PRIM3D_TRILIST,
677 [GL_QUAD_STRIP] = PRIM3D_TRILIST,
678 [GL_POLYGON] = PRIM3D_TRILIST,
679 };
680
681 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
682 #define RENDER_PRIMITIVE intel->render_primitive
683 #define TAG(x) x
684 #define IND INTEL_FALLBACK_BIT
685 #include "tnl_dd/t_dd_unfilled.h"
686 #undef IND
687
688 /***********************************************************************
689 * Generate GL render functions *
690 ***********************************************************************/
691
692 #define IND (0)
693 #define TAG(x) x
694 #include "tnl_dd/t_dd_tritmp.h"
695
696 #define IND (INTEL_OFFSET_BIT)
697 #define TAG(x) x##_offset
698 #include "tnl_dd/t_dd_tritmp.h"
699
700 #define IND (INTEL_TWOSIDE_BIT)
701 #define TAG(x) x##_twoside
702 #include "tnl_dd/t_dd_tritmp.h"
703
704 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
705 #define TAG(x) x##_twoside_offset
706 #include "tnl_dd/t_dd_tritmp.h"
707
708 #define IND (INTEL_UNFILLED_BIT)
709 #define TAG(x) x##_unfilled
710 #include "tnl_dd/t_dd_tritmp.h"
711
712 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
713 #define TAG(x) x##_offset_unfilled
714 #include "tnl_dd/t_dd_tritmp.h"
715
716 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
717 #define TAG(x) x##_twoside_unfilled
718 #include "tnl_dd/t_dd_tritmp.h"
719
720 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
721 #define TAG(x) x##_twoside_offset_unfilled
722 #include "tnl_dd/t_dd_tritmp.h"
723
724 #define IND (INTEL_FALLBACK_BIT)
725 #define TAG(x) x##_fallback
726 #include "tnl_dd/t_dd_tritmp.h"
727
728 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
729 #define TAG(x) x##_offset_fallback
730 #include "tnl_dd/t_dd_tritmp.h"
731
732 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
733 #define TAG(x) x##_twoside_fallback
734 #include "tnl_dd/t_dd_tritmp.h"
735
736 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
737 #define TAG(x) x##_twoside_offset_fallback
738 #include "tnl_dd/t_dd_tritmp.h"
739
740 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
741 #define TAG(x) x##_unfilled_fallback
742 #include "tnl_dd/t_dd_tritmp.h"
743
744 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
745 #define TAG(x) x##_offset_unfilled_fallback
746 #include "tnl_dd/t_dd_tritmp.h"
747
748 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
749 #define TAG(x) x##_twoside_unfilled_fallback
750 #include "tnl_dd/t_dd_tritmp.h"
751
752 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
753 INTEL_FALLBACK_BIT)
754 #define TAG(x) x##_twoside_offset_unfilled_fallback
755 #include "tnl_dd/t_dd_tritmp.h"
756
757
758 static void
init_rast_tab(void)759 init_rast_tab(void)
760 {
761 init();
762 init_offset();
763 init_twoside();
764 init_twoside_offset();
765 init_unfilled();
766 init_offset_unfilled();
767 init_twoside_unfilled();
768 init_twoside_offset_unfilled();
769 init_fallback();
770 init_offset_fallback();
771 init_twoside_fallback();
772 init_twoside_offset_fallback();
773 init_unfilled_fallback();
774 init_offset_unfilled_fallback();
775 init_twoside_unfilled_fallback();
776 init_twoside_offset_unfilled_fallback();
777 }
778
779
780 /***********************************************************************
781 * Rasterization fallback helpers *
782 ***********************************************************************/
783
784
785 /* This code is hit only when a mix of accelerated and unaccelerated
786 * primitives are being drawn, and only for the unaccelerated
787 * primitives.
788 */
789 static void
intel_fallback_tri(struct intel_context * intel,intelVertex * v0,intelVertex * v1,intelVertex * v2)790 intel_fallback_tri(struct intel_context *intel,
791 intelVertex * v0, intelVertex * v1, intelVertex * v2)
792 {
793 struct gl_context *ctx = &intel->ctx;
794 SWvertex v[3];
795
796 if (0)
797 fprintf(stderr, "\n%s\n", __func__);
798
799 INTEL_FIREVERTICES(intel);
800
801 _swsetup_Translate(ctx, v0, &v[0]);
802 _swsetup_Translate(ctx, v1, &v[1]);
803 _swsetup_Translate(ctx, v2, &v[2]);
804 _swrast_render_start(ctx);
805 _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
806 _swrast_render_finish(ctx);
807 }
808
809
810 static void
intel_fallback_line(struct intel_context * intel,intelVertex * v0,intelVertex * v1)811 intel_fallback_line(struct intel_context *intel,
812 intelVertex * v0, intelVertex * v1)
813 {
814 struct gl_context *ctx = &intel->ctx;
815 SWvertex v[2];
816
817 if (0)
818 fprintf(stderr, "\n%s\n", __func__);
819
820 INTEL_FIREVERTICES(intel);
821
822 _swsetup_Translate(ctx, v0, &v[0]);
823 _swsetup_Translate(ctx, v1, &v[1]);
824 _swrast_render_start(ctx);
825 _swrast_Line(ctx, &v[0], &v[1]);
826 _swrast_render_finish(ctx);
827 }
828
829 static void
intel_fallback_point(struct intel_context * intel,intelVertex * v0)830 intel_fallback_point(struct intel_context *intel,
831 intelVertex * v0)
832 {
833 struct gl_context *ctx = &intel->ctx;
834 SWvertex v[1];
835
836 if (0)
837 fprintf(stderr, "\n%s\n", __func__);
838
839 INTEL_FIREVERTICES(intel);
840
841 _swsetup_Translate(ctx, v0, &v[0]);
842 _swrast_render_start(ctx);
843 _swrast_Point(ctx, &v[0]);
844 _swrast_render_finish(ctx);
845 }
846
847
848 /**********************************************************************/
849 /* Render unclipped begin/end objects */
850 /**********************************************************************/
851
852 #define IND 0
853 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
854 #define RENDER_POINTS( start, count ) \
855 for ( ; start < count ; start++) POINT( V(ELT(start)) );
856 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
857 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
858 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
859 #define INIT(x) intelRenderPrimitive( ctx, x )
860 #undef LOCAL_VARS
861 #define LOCAL_VARS \
862 struct intel_context *intel = intel_context(ctx); \
863 GLubyte *vertptr = (GLubyte *)intel->verts; \
864 const GLuint vertsize = intel->vertex_size; \
865 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
866 (void) elt;
867 #define RESET_STIPPLE
868 #define RESET_OCCLUSION
869 #define PRESERVE_VB_DEFS
870 #define ELT(x) x
871 #define TAG(x) intel_##x##_verts
872 #include "tnl/t_vb_rendertmp.h"
873 #undef ELT
874 #undef TAG
875 #define TAG(x) intel_##x##_elts
876 #define ELT(x) elt[x]
877 #include "tnl/t_vb_rendertmp.h"
878
879 /**********************************************************************/
880 /* Render clipped primitives */
881 /**********************************************************************/
882
883
884
885 static void
intelRenderClippedPoly(struct gl_context * ctx,const GLuint * elts,GLuint n)886 intelRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
887 {
888 struct intel_context *intel = intel_context(ctx);
889 TNLcontext *tnl = TNL_CONTEXT(ctx);
890 GLuint prim = intel->render_primitive;
891
892 /* Render the new vertices as an unclipped polygon.
893 */
894 _tnl_RenderClippedPolygon(ctx, elts, n);
895
896 /* Restore the render primitive
897 */
898 if (prim != GL_POLYGON)
899 tnl->Driver.Render.PrimitiveNotify(ctx, prim);
900 }
901
902 static void
intelFastRenderClippedPoly(struct gl_context * ctx,const GLuint * elts,GLuint n)903 intelFastRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
904 {
905 struct intel_context *intel = intel_context(ctx);
906 const GLuint vertsize = intel->vertex_size;
907 GLuint *vb = intel_get_prim_space(intel, (n - 2) * 3);
908 GLubyte *vertptr = (GLubyte *) intel->verts;
909 const GLuint *start = (const GLuint *) V(elts[0]);
910 int i, j;
911
912 if (ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) {
913 for (i = 2; i < n; i++) {
914 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
915 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
916 COPY_DWORDS(j, vb, vertsize, start);
917 }
918 } else {
919 for (i = 2; i < n; i++) {
920 COPY_DWORDS(j, vb, vertsize, start);
921 COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
922 COPY_DWORDS(j, vb, vertsize, V(elts[i]));
923 }
924 }
925 }
926
927 /**********************************************************************/
928 /* Choose render functions */
929 /**********************************************************************/
930
931
932 #define DD_TRI_LIGHT_TWOSIDE (1 << 1)
933 #define DD_TRI_UNFILLED (1 << 2)
934 #define DD_TRI_STIPPLE (1 << 4)
935 #define DD_TRI_OFFSET (1 << 5)
936 #define DD_LINE_STIPPLE (1 << 7)
937 #define DD_POINT_ATTEN (1 << 9)
938
939 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
940 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
941
942 void
intelChooseRenderState(struct gl_context * ctx)943 intelChooseRenderState(struct gl_context * ctx)
944 {
945 TNLcontext *tnl = TNL_CONTEXT(ctx);
946 struct intel_context *intel = intel_context(ctx);
947 GLuint flags =
948 ((ctx->Light.Enabled &&
949 ctx->Light.Model.TwoSide) ? DD_TRI_LIGHT_TWOSIDE : 0) |
950 ((ctx->Polygon.FrontMode != GL_FILL ||
951 ctx->Polygon.BackMode != GL_FILL) ? DD_TRI_UNFILLED : 0) |
952 (ctx->Polygon.StippleFlag ? DD_TRI_STIPPLE : 0) |
953 ((ctx->Polygon.OffsetPoint ||
954 ctx->Polygon.OffsetLine ||
955 ctx->Polygon.OffsetFill) ? DD_TRI_OFFSET : 0) |
956 (ctx->Line.StippleFlag ? DD_LINE_STIPPLE : 0) |
957 (ctx->Point._Attenuated ? DD_POINT_ATTEN : 0);
958 const struct gl_program *fprog = ctx->FragmentProgram._Current;
959 bool have_wpos = (fprog && (fprog->info.inputs_read & VARYING_BIT_POS));
960 GLuint index = 0;
961
962 if (INTEL_DEBUG & DEBUG_STATE)
963 fprintf(stderr, "\n%s\n", __func__);
964
965 if ((flags & (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)) || have_wpos) {
966
967 if (flags & ANY_RASTER_FLAGS) {
968 if (flags & DD_TRI_LIGHT_TWOSIDE)
969 index |= INTEL_TWOSIDE_BIT;
970 if (flags & DD_TRI_OFFSET)
971 index |= INTEL_OFFSET_BIT;
972 if (flags & DD_TRI_UNFILLED)
973 index |= INTEL_UNFILLED_BIT;
974 }
975
976 if (have_wpos) {
977 intel->draw_point = intel_wpos_point;
978 intel->draw_line = intel_wpos_line;
979 intel->draw_tri = intel_wpos_triangle;
980
981 /* Make sure these get called:
982 */
983 index |= INTEL_FALLBACK_BIT;
984 }
985 else {
986 intel->draw_point = intel_draw_point;
987 intel->draw_line = intel_draw_line;
988 intel->draw_tri = intel_draw_triangle;
989 }
990
991 /* Hook in fallbacks for specific primitives.
992 */
993 if (flags & ANY_FALLBACK_FLAGS) {
994 if (flags & DD_LINE_STIPPLE)
995 intel->draw_line = intel_fallback_line;
996
997 if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple)
998 intel->draw_tri = intel_fallback_tri;
999
1000 if (flags & DD_POINT_ATTEN) {
1001 if (0)
1002 intel->draw_point = intel_atten_point;
1003 else
1004 intel->draw_point = intel_fallback_point;
1005 }
1006
1007 index |= INTEL_FALLBACK_BIT;
1008 }
1009 }
1010
1011 if (intel->RenderIndex != index) {
1012 intel->RenderIndex = index;
1013
1014 tnl->Driver.Render.Points = rast_tab[index].points;
1015 tnl->Driver.Render.Line = rast_tab[index].line;
1016 tnl->Driver.Render.Triangle = rast_tab[index].triangle;
1017 tnl->Driver.Render.Quad = rast_tab[index].quad;
1018
1019 if (index == 0) {
1020 tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts;
1021 tnl->Driver.Render.PrimTabElts = intel_render_tab_elts;
1022 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
1023 tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly;
1024 }
1025 else {
1026 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
1027 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
1028 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
1029 tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly;
1030 }
1031 }
1032 }
1033
1034 static const GLenum reduced_prim[GL_POLYGON + 1] = {
1035 [GL_POINTS] = GL_POINTS,
1036 [GL_LINES] = GL_LINES,
1037 [GL_LINE_LOOP] = GL_LINES,
1038 [GL_LINE_STRIP] = GL_LINES,
1039 [GL_TRIANGLES] = GL_TRIANGLES,
1040 [GL_TRIANGLE_STRIP] = GL_TRIANGLES,
1041 [GL_TRIANGLE_FAN] = GL_TRIANGLES,
1042 [GL_QUADS] = GL_TRIANGLES,
1043 [GL_QUAD_STRIP] = GL_TRIANGLES,
1044 [GL_POLYGON] = GL_TRIANGLES
1045 };
1046
1047
1048 /**********************************************************************/
1049 /* High level hooks for t_vb_render.c */
1050 /**********************************************************************/
1051
1052
1053
1054
1055 static void
intelRunPipeline(struct gl_context * ctx)1056 intelRunPipeline(struct gl_context * ctx)
1057 {
1058 struct intel_context *intel = intel_context(ctx);
1059
1060 _mesa_lock_context_textures(ctx);
1061
1062 if (ctx->NewState)
1063 _mesa_update_state_locked(ctx);
1064
1065 /* We need to get this done before we start the pipeline, or a
1066 * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
1067 * while the pipeline is running will result in mismatched swrast
1068 * map/unmaps, and later assertion failures.
1069 */
1070 intel_prepare_render(intel);
1071
1072 if (intel->NewGLState) {
1073 if (intel->NewGLState & _NEW_TEXTURE) {
1074 intel->vtbl.update_texture_state(intel);
1075 }
1076
1077 if (!intel->Fallback) {
1078 if (intel->NewGLState & _INTEL_NEW_RENDERSTATE)
1079 intelChooseRenderState(ctx);
1080 }
1081
1082 intel->NewGLState = 0;
1083 }
1084
1085 intel->tnl_pipeline_running = true;
1086 _tnl_run_pipeline(ctx);
1087 intel->tnl_pipeline_running = false;
1088
1089 _mesa_unlock_context_textures(ctx);
1090 }
1091
1092 static void
intelRenderStart(struct gl_context * ctx)1093 intelRenderStart(struct gl_context * ctx)
1094 {
1095 struct intel_context *intel = intel_context(ctx);
1096
1097 intel_check_front_buffer_rendering(intel);
1098 intel->vtbl.render_start(intel_context(ctx));
1099 intel->vtbl.emit_state(intel);
1100 }
1101
1102 static void
intelRenderFinish(struct gl_context * ctx)1103 intelRenderFinish(struct gl_context * ctx)
1104 {
1105 struct intel_context *intel = intel_context(ctx);
1106
1107 if (intel->RenderIndex & INTEL_FALLBACK_BIT)
1108 _swrast_flush(ctx);
1109
1110 INTEL_FIREVERTICES(intel);
1111 }
1112
1113
1114
1115
1116 /* System to flush dma and emit state changes based on the rasterized
1117 * primitive.
1118 */
1119 static void
intelRasterPrimitive(struct gl_context * ctx,GLenum rprim,GLuint hwprim)1120 intelRasterPrimitive(struct gl_context * ctx, GLenum rprim, GLuint hwprim)
1121 {
1122 struct intel_context *intel = intel_context(ctx);
1123
1124 if (0)
1125 fprintf(stderr, "%s %s %x\n", __func__,
1126 _mesa_enum_to_string(rprim), hwprim);
1127
1128 intel->vtbl.reduced_primitive_state(intel, rprim);
1129
1130 /* Start a new primitive. Arrange to have it flushed later on.
1131 */
1132 if (hwprim != intel->prim.primitive) {
1133 INTEL_FIREVERTICES(intel);
1134
1135 intel_set_prim(intel, hwprim);
1136 }
1137 }
1138
1139
1140 /*
1141 */
1142 static void
intelRenderPrimitive(struct gl_context * ctx,GLenum prim)1143 intelRenderPrimitive(struct gl_context * ctx, GLenum prim)
1144 {
1145 struct intel_context *intel = intel_context(ctx);
1146 GLboolean unfilled = (ctx->Polygon.FrontMode != GL_FILL ||
1147 ctx->Polygon.BackMode != GL_FILL);
1148
1149 if (0)
1150 fprintf(stderr, "%s %s\n", __func__, _mesa_enum_to_string(prim));
1151
1152 /* Let some clipping routines know which primitive they're dealing
1153 * with.
1154 */
1155 intel->render_primitive = prim;
1156
1157 /* Shortcircuit this when called for unfilled triangles. The rasterized
1158 * primitive will always be reset by lower level functions in that case,
1159 * potentially pingponging the state:
1160 */
1161 if (reduced_prim[prim] == GL_TRIANGLES && unfilled)
1162 return;
1163
1164 /* Set some primitive-dependent state and Start? a new primitive.
1165 */
1166 intelRasterPrimitive(ctx, reduced_prim[prim], hw_prim[prim]);
1167 }
1168
1169
1170 /**********************************************************************/
1171 /* Transition to/from hardware rasterization. */
1172 /**********************************************************************/
1173
1174 static char *fallbackStrings[] = {
1175 [0] = "Draw buffer",
1176 [1] = "Read buffer",
1177 [2] = "Depth buffer",
1178 [3] = "Stencil buffer",
1179 [4] = "User disable",
1180 [5] = "Render mode",
1181
1182 [12] = "Texture",
1183 [13] = "Color mask",
1184 [14] = "Stencil",
1185 [15] = "Stipple",
1186 [16] = "Program",
1187 [17] = "Logic op",
1188 [18] = "Smooth polygon",
1189 [19] = "Smooth point",
1190 [20] = "point sprite coord origin",
1191 [21] = "depth/color drawing offset",
1192 [22] = "coord replace(SPRITE POINT ENABLE)",
1193 };
1194
1195
1196 static char *
getFallbackString(GLuint bit)1197 getFallbackString(GLuint bit)
1198 {
1199 int i = 0;
1200 while (bit > 1) {
1201 i++;
1202 bit >>= 1;
1203 }
1204 return fallbackStrings[i];
1205 }
1206
1207
1208
1209 /**
1210 * Enable/disable a fallback flag.
1211 * \param bit one of INTEL_FALLBACK_x flags.
1212 */
1213 void
intelFallback(struct intel_context * intel,GLbitfield bit,bool mode)1214 intelFallback(struct intel_context *intel, GLbitfield bit, bool mode)
1215 {
1216 struct gl_context *ctx = &intel->ctx;
1217 TNLcontext *tnl = TNL_CONTEXT(ctx);
1218 const GLbitfield oldfallback = intel->Fallback;
1219
1220 if (mode) {
1221 intel->Fallback |= bit;
1222 if (oldfallback == 0) {
1223 assert(!intel->tnl_pipeline_running);
1224
1225 intel_flush(ctx);
1226 if (INTEL_DEBUG & DEBUG_PERF)
1227 fprintf(stderr, "ENTER FALLBACK %x: %s\n",
1228 bit, getFallbackString(bit));
1229 _swsetup_Wakeup(ctx);
1230 intel->RenderIndex = ~0;
1231 }
1232 }
1233 else {
1234 intel->Fallback &= ~bit;
1235 if (oldfallback == bit) {
1236 assert(!intel->tnl_pipeline_running);
1237
1238 _swrast_flush(ctx);
1239 if (INTEL_DEBUG & DEBUG_PERF)
1240 fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString(bit));
1241 tnl->Driver.Render.Start = intelRenderStart;
1242 tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
1243 tnl->Driver.Render.Finish = intelRenderFinish;
1244 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
1245 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
1246 tnl->Driver.Render.Interp = _tnl_interp;
1247
1248 _tnl_invalidate_vertex_state(ctx, ~0);
1249 _tnl_invalidate_vertices(ctx, ~0);
1250 _tnl_install_attrs(ctx,
1251 intel->vertex_attrs,
1252 intel->vertex_attr_count,
1253 intel->ViewportMatrix.m, 0);
1254
1255 intel->NewGLState |= _INTEL_NEW_RENDERSTATE;
1256 }
1257 }
1258 }
1259
1260 /**********************************************************************/
1261 /* Initialization. */
1262 /**********************************************************************/
1263
1264
1265 void
intelInitTriFuncs(struct gl_context * ctx)1266 intelInitTriFuncs(struct gl_context * ctx)
1267 {
1268 TNLcontext *tnl = TNL_CONTEXT(ctx);
1269 static int firsttime = 1;
1270
1271 if (firsttime) {
1272 init_rast_tab();
1273 firsttime = 0;
1274 }
1275
1276 tnl->Driver.RunPipeline = intelRunPipeline;
1277 tnl->Driver.Render.Start = intelRenderStart;
1278 tnl->Driver.Render.Finish = intelRenderFinish;
1279 tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
1280 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
1281 tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
1282 tnl->Driver.Render.CopyPV = _tnl_copy_pv;
1283 tnl->Driver.Render.Interp = _tnl_interp;
1284 }
1285