16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2003 VMware, Inc.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
28f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/** @file intel_tris.c
29f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie *
30f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * This file contains functions for managing the vertex buffer and emitting
31f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * primitives into it.
32f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie */
33f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
34ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/glheader.h"
35ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/context.h"
36ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h"
37ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h"
38ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/texobj.h"
39ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/state.h"
40ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/dd.h"
41c738ea1191cd1b5a0dc60b0e6d05fd918083e961Paul Berry#include "main/fbobject.h"
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "swrast/swrast.h"
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "swrast_setup/swrast_setup.h"
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_context.h"
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_pipeline.h"
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vertex.h"
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_screen.h"
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_context.h"
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_tris.h"
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_batchbuffer.h"
53beffb4e88c71679ab69776498ee7178b7b8a16c0Michel Dänzer#include "intel_buffers.h"
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_reg.h"
55f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "i830_context.h"
56f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#include "i830_reg.h"
572c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson#include "i915_context.h"
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
59f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void intelRenderPrimitive(struct gl_context * ctx, GLenum prim);
60f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void intelRasterPrimitive(struct gl_context * ctx, GLenum rprim,
616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 GLuint hwprim);
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
63cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airliestatic void
64cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlieintel_flush_inline_primitive(struct intel_context *intel)
65cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie{
668d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   GLuint used = intel->batch.used - intel->prim.start_ptr;
67cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
68cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   assert(intel->prim.primitive != ~0);
69cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
70298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/*    printf("/\n"); */
71cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
728d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   if (used < 2)
73cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie      goto do_discard;
74cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
758d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   intel->batch.map[intel->prim.start_ptr] =
768d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson      _3DPRIMITIVE | intel->prim.primitive | (used - 2);
77cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
78cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   goto finished;
79cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
80cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie do_discard:
818d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   intel->batch.used = intel->prim.start_ptr;
82cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
83cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie finished:
84cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->prim.primitive = ~0;
85cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->prim.start_ptr = 0;
86cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->prim.flush = 0;
87cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie}
88cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
89cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airliestatic void intel_start_inline(struct intel_context *intel, uint32_t prim)
90cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie{
916b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul   BATCH_LOCALS;
92cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
93cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->vtbl.emit_state(intel);
94cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
952e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   intel->no_batch_wrap = true;
96cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
97cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   /* Emit a slot which will be filled with the inline primitive
98cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie    * command later.
99cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie    */
100ac6ce53af7f67d01afd8e33d297f95c21aa3405eChris Wilson   BEGIN_BATCH(1);
101cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
1028d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   intel->prim.start_ptr = intel->batch.used;
103cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->prim.primitive = prim;
104cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->prim.flush = intel_flush_inline_primitive;
105cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
106cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   OUT_BATCH(0);
107cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   ADVANCE_BATCH();
108cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
1092e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   intel->no_batch_wrap = false;
110298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/*    printf(">"); */
111cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie}
112cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
113cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airliestatic void intel_wrap_inline(struct intel_context *intel)
114cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie{
115cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   GLuint prim = intel->prim.primitive;
116cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
117cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel_flush_inline_primitive(intel);
1188d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   intel_batchbuffer_flush(intel);
119cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel_start_inline(intel, prim);  /* ??? */
120cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie}
121cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
122cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airliestatic GLuint *intel_extend_inline(struct intel_context *intel, GLuint dwords)
123cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie{
124cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   GLuint *ptr;
125cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
126cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   assert(intel->prim.flush == intel_flush_inline_primitive);
127cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
1288d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   if (intel_batchbuffer_space(intel) < dwords * sizeof(GLuint))
129cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie      intel_wrap_inline(intel);
130cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
131298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/*    printf("."); */
132cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
133cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   intel->vtbl.assert_not_dirty(intel);
134cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
1358d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   ptr = intel->batch.map + intel->batch.used;
1368d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   intel->batch.used += dwords;
137cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
138cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   return ptr;
139cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie}
140cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
141f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/** Sets the primitive type for a primitive sequence, flushing as needed. */
142f75843a517bd188639e6866db2a7b04de3524e16Dave Airlievoid intel_set_prim(struct intel_context *intel, uint32_t prim)
1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
144cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   /* if we have no VBOs */
145cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
146cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   if (intel->intelScreen->no_vbo) {
147cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie      intel_start_inline(intel, prim);
148cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie      return;
149cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   }
150f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (prim != intel->prim.primitive) {
151f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      INTEL_FIREVERTICES(intel);
152f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel->prim.primitive = prim;
153f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   }
154f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie}
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
156f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/** Returns mapped VB space for the given number of vertices */
157f75843a517bd188639e6866db2a7b04de3524e16Dave Airlieuint32_t *intel_get_prim_space(struct intel_context *intel, unsigned int count)
158f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie{
159f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   uint32_t *addr;
160f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
161cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   if (intel->intelScreen->no_vbo) {
162cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie      return intel_extend_inline(intel, count * intel->vertex_size);
163cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie   }
164cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie
165f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   /* Check for space in the existing VB */
166f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (intel->prim.vb_bo == NULL ||
167f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       (intel->prim.current_offset +
168f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	count * intel->vertex_size * 4) > INTEL_VB_SIZE ||
169f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       (intel->prim.count + count) >= (1 << 16)) {
170f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      /* Flush existing prim if any */
171f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      INTEL_FIREVERTICES(intel);
172a42dac187973cbc17be6c59db89264cbc935ab91Eric Anholt
173f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel_finish_vb(intel);
1747c81124d7c4a4d1da9f48cbf7e82ab1a3a970a7aDave Airlie
175f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      /* Start a new VB */
176f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      if (intel->prim.vb == NULL)
177f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	 intel->prim.vb = malloc(INTEL_VB_SIZE);
17834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt      intel->prim.vb_bo = drm_intel_bo_alloc(intel->bufmgr, "vb",
17934474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt					     INTEL_VB_SIZE, 4);
180f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel->prim.start_offset = 0;
181f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel->prim.current_offset = 0;
182f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   }
1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
184f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   intel->prim.flush = intel_flush_prim;
1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
186f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   addr = (uint32_t *)(intel->prim.vb + intel->prim.current_offset);
187f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   intel->prim.current_offset += intel->vertex_size * 4 * count;
188f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   intel->prim.count += count;
1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
190f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   return addr;
19162d66caeba786f01f6159c980fda79606afe4c61Eric Anholt}
1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
193f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/** Dispatches the accumulated primitive to the batchbuffer. */
194f75843a517bd188639e6866db2a7b04de3524e16Dave Airlievoid intel_flush_prim(struct intel_context *intel)
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
19634474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo *aper_array[2];
19734474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo *vb_bo;
198b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   unsigned int offset, count;
1996b9c1446b35cb33d73bd8ea7aeed8d219d0a9989Brian Paul   BATCH_LOCALS;
200f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
201f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   /* Must be called after an intel_start_prim. */
202f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   assert(intel->prim.primitive != ~0);
203f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
204f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (intel->prim.count == 0)
205f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      return;
206f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
207b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   /* Clear the current prims out of the context state so that a batch flush
208194d039f1efee0e666c2d1b1116fd5adea8cb942Kristian Høgsberg    * flush triggered by emit_state doesn't loop back to flush_prim again.
209f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie    */
210f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   vb_bo = intel->prim.vb_bo;
21134474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo_reference(vb_bo);
212b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   count = intel->prim.count;
213b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   intel->prim.count = 0;
214b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   offset = intel->prim.start_offset;
215b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   intel->prim.start_offset = intel->prim.current_offset;
216415b7c7775dd7240abd2c929ea3335304a790d39Chris Wilson   if (intel->gen < 3)
2172c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      intel->prim.current_offset = intel->prim.start_offset = ALIGN(intel->prim.start_offset, 128);
218b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   intel->prim.flush = NULL;
2198517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vtbl.emit_state(intel);
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2228d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   aper_array[0] = intel->batch.bo;
223f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   aper_array[1] = vb_bo;
224f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (dri_bufmgr_check_aperture_space(aper_array, 2)) {
2258d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson      intel_batchbuffer_flush(intel);
226f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel->vtbl.emit_state(intel);
227f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   }
2287c81124d7c4a4d1da9f48cbf7e82ab1a3a970a7aDave Airlie
229f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   /* Ensure that we don't start a new batch for the following emit, which
230f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie    * depends on the state just emitted. emit_state should be making sure we
231f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie    * have the space for this.
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
2332e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   intel->no_batch_wrap = true;
2347c81124d7c4a4d1da9f48cbf7e82ab1a3a970a7aDave Airlie
235db364a8af0d19e4032ac44635834737017e1051cEric Anholt   if (intel->always_flush_cache) {
236db364a8af0d19e4032ac44635834737017e1051cEric Anholt      intel_batchbuffer_emit_mi_flush(intel);
237db364a8af0d19e4032ac44635834737017e1051cEric Anholt   }
238db364a8af0d19e4032ac44635834737017e1051cEric Anholt
239f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#if 0
240b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt   printf("emitting %d..%d=%d vertices size %d\n", offset,
241cd031749a75883a6fbf8fb7bf989b77a7c705819Dave Airlie	  intel->prim.current_offset, count,
242f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie	  intel->vertex_size * 4);
243f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie#endif
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
245f67748038935e609aa85450b20d550b4813c9429Eric Anholt   if (intel->gen >= 3) {
2462c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      struct i915_context *i915 = i915_context(&intel->ctx);
2472c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      unsigned int cmd = 0, len = 0;
2482c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson
2492c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (vb_bo != i915->current_vb_bo) {
2502c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 cmd |= I1_LOAD_S(0);
2512c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 len++;
2522c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      }
2532c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson
2542c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (intel->vertex_size != i915->current_vertex_size) {
2552c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 cmd |= I1_LOAD_S(1);
2562c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 len++;
2572c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      }
2582c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (len)
2592c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 len++;
2602c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson
2612c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      BEGIN_BATCH(2+len);
2622c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (cmd)
2632c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | cmd | (len - 2));
2642c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (vb_bo != i915->current_vb_bo) {
2652c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
2662c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 i915->current_vb_bo = vb_bo;
2672c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      }
2682c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      if (intel->vertex_size != i915->current_vertex_size) {
2692c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 OUT_BATCH((intel->vertex_size << S1_VERTEX_WIDTH_SHIFT) |
2702c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson		   (intel->vertex_size << S1_VERTEX_PITCH_SHIFT));
2712c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson	 i915->current_vertex_size = intel->vertex_size;
2722c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      }
273f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_BATCH(_3DPRIMITIVE |
274f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		PRIM_INDIRECT |
275f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		PRIM_INDIRECT_SEQUENTIAL |
276f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		intel->prim.primitive |
277b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt		count);
2782c6793fb6bc89df16c23f727bcb072a157ab8d10Chris Wilson      OUT_BATCH(offset / (intel->vertex_size * 4));
279f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      ADVANCE_BATCH();
280f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   } else {
281f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      struct i830_context *i830 = i830_context(&intel->ctx);
282f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
2835203b7227ccb6b618fa42f08434d4a3cf123dca2Kristian Høgsberg      BEGIN_BATCH(5);
284f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
285f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		I1_LOAD_S(0) | I1_LOAD_S(2) | 1);
286f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      /* S0 */
287062a208814ad65d330f403c46d4bed88648f334fIan Romanick      assert((offset & ~S0_VB_OFFSET_MASK_830) == 0);
288f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0,
289b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt		offset | (intel->vertex_size << S0_VB_PITCH_SHIFT_830) |
290f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		S0_VB_ENABLE_830);
2911412ca0be24461cad36de865851484464fac3bfeDave Airlie      /* S2
292f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       * This is somewhat unfortunate -- VB width is tied up with
293f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       * vertex format data that we've already uploaded through
294f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       * _3DSTATE_VFT[01]_CMD.  We may want to replace emits of VFT state with
295f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       * STATE_IMMEDIATE_1 like this to avoid duplication.
296f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie       */
297f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_BATCH((i830->state.Ctx[I830_CTXREG_VF] & VFT0_TEX_COUNT_MASK) >>
298f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		VFT0_TEX_COUNT_SHIFT << S2_TEX_COUNT_SHIFT_830 |
299f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		(i830->state.Ctx[I830_CTXREG_VF2] << 16) |
300f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		intel->vertex_size << S2_VERTEX_0_WIDTH_SHIFT_830);
301f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie
302f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_BATCH(_3DPRIMITIVE |
303f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		PRIM_INDIRECT |
304f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		PRIM_INDIRECT_SEQUENTIAL |
305f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie		intel->prim.primitive |
306b9532f078a2fbf459b0403b6f656711f80ff83c2Eric Anholt		count);
307f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      OUT_BATCH(0); /* Beginning vertex index */
308f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      ADVANCE_BATCH();
309f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   }
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
311db364a8af0d19e4032ac44635834737017e1051cEric Anholt   if (intel->always_flush_cache) {
312db364a8af0d19e4032ac44635834737017e1051cEric Anholt      intel_batchbuffer_emit_mi_flush(intel);
313db364a8af0d19e4032ac44635834737017e1051cEric Anholt   }
314db364a8af0d19e4032ac44635834737017e1051cEric Anholt
3152e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   intel->no_batch_wrap = false;
3168517079cbcbbf31291b05420f3b776df712dfd47Eric Anholt
31734474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo_unreference(vb_bo);
318a42dac187973cbc17be6c59db89264cbc935ab91Eric Anholt}
319a42dac187973cbc17be6c59db89264cbc935ab91Eric Anholt
320f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie/**
321f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * Uploads the locally-accumulated VB into the buffer object.
322f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie *
323f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * This avoids us thrashing the cachelines in and out as the buffer gets
324f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * filled, dispatched, then reused as the hardware completes rendering from it,
325f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * and also lets us clflush less if we dispatch with a partially-filled VB.
326f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie *
327f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * This is called normally from get_space when we're finishing a BO, but also
328f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * at batch flush time so that we don't try accessing the contents of a
329f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie * just-dispatched buffer.
330f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie */
331f75843a517bd188639e6866db2a7b04de3524e16Dave Airlievoid intel_finish_vb(struct intel_context *intel)
332a42dac187973cbc17be6c59db89264cbc935ab91Eric Anholt{
333f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   if (intel->prim.vb_bo == NULL)
334f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      return;
3357c81124d7c4a4d1da9f48cbf7e82ab1a3a970a7aDave Airlie
33634474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo_subdata(intel->prim.vb_bo, 0, intel->prim.start_offset,
33734474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt			intel->prim.vb);
33834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo_unreference(intel->prim.vb_bo);
339f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   intel->prim.vb_bo = NULL;
3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
3436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                    Emit primitives as inline vertices               *
3446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
3456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifdef __i386__
3476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define COPY_DWORDS( j, vb, vertsize, v )			\
3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {								\
3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int __tmp;							\
3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   __asm__ __volatile__( "rep ; movsl"				\
3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			 : "=%c" (j), "=D" (vb), "=S" (__tmp)	\
3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			 : "0" (vertsize),			\
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			 "D" ((long)vb),			\
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell			 "S" ((long)v) );			\
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#else
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define COPY_DWORDS( j, vb, vertsize, v )	\
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {						\
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for ( j = 0 ; j < vertsize ; j++ ) {		\
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      vb[j] = ((GLuint *)v)[j];			\
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }						\
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   vb += vertsize;				\
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_draw_quad(struct intel_context *intel,
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                intelVertexPtr v0,
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                intelVertexPtr v1, intelVertexPtr v2, intelVertexPtr v3)
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint vertsize = intel->vertex_size;
372f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   GLuint *vb = intel_get_prim_space(intel, 6);
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int j;
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v0);
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v1);
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* If smooth shading, draw like a trifan which gives better
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * rasterization.  Otherwise draw as two triangles with provoking
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * vertex in third position as required for flat shading.
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (intel->ctx.Light.ShadeModel == GL_FLAT) {
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      COPY_DWORDS(j, vb, vertsize, v3);
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      COPY_DWORDS(j, vb, vertsize, v1);
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      COPY_DWORDS(j, vb, vertsize, v2);
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      COPY_DWORDS(j, vb, vertsize, v0);
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v2);
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v3);
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_draw_triangle(struct intel_context *intel,
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                    intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint vertsize = intel->vertex_size;
400f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   GLuint *vb = intel_get_prim_space(intel, 3);
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int j;
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v0);
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v1);
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v2);
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_draw_line(struct intel_context *intel,
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                intelVertexPtr v0, intelVertexPtr v1)
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint vertsize = intel->vertex_size;
414f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   GLuint *vb = intel_get_prim_space(intel, 2);
4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int j;
4166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v0);
4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   COPY_DWORDS(j, vb, vertsize, v1);
4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_draw_point(struct intel_context *intel, intelVertexPtr v0)
4246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint vertsize = intel->vertex_size;
426f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   GLuint *vb = intel_get_prim_space(intel, 1);
4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int j;
4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4290febd0ecfd1e2a36381ab7793811b9c7891ed82fVille Syrjälä   COPY_DWORDS(j, vb, vertsize, v0);
4306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
4356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                Fixup for ARB_point_parameters                       *
4366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
4376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
439e81aaeba37f5419323d8f88bc10943c77e25ed14Timothy Arceri * represented in the fragment program info.inputs_read field.
4406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
4416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
4426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_atten_point(struct intel_context *intel, intelVertexPtr v0)
4436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
444f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
4456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLfloat psz[4], col[4], restore_psz, restore_alpha;
4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _tnl_get_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _tnl_get_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
4496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   restore_psz = psz[0];
4516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   restore_alpha = col[3];
4526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (psz[0] >= ctx->Point.Threshold) {
4546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      psz[0] = MIN2(psz[0], ctx->Point.MaxSize);
4556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
4576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLfloat dsize = psz[0] / ctx->Point.Threshold;
4586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      psz[0] = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
4596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      col[3] *= dsize * dsize;
4606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (psz[0] < 1.0)
4636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      psz[0] = 1.0;
4646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (restore_psz != psz[0] || restore_alpha != col[3]) {
4666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
4676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
4686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_point(intel, v0);
4706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      psz[0] = restore_psz;
4726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      col[3] = restore_alpha;
4736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _tnl_set_attr(ctx, v0, _TNL_ATTRIB_POINTSIZE, psz);
4756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _tnl_set_attr(ctx, v0, _TNL_ATTRIB_COLOR0, col);
4766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else
4786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_point(intel, v0);
4796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
4866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                Fixup for I915 WPOS texture coordinate                *
4876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
4886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
489cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholtstatic void
490cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholtintel_emit_fragcoord(struct intel_context *intel, intelVertexPtr v)
491cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt{
492cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   struct gl_context *ctx = &intel->ctx;
493cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   struct gl_framebuffer *fb = ctx->DrawBuffer;
494cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   GLuint offset = intel->wpos_offset;
495cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   float *vertex_position = (float *)v;
496cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   float *fragcoord = (float *)((char *)v + offset);
497cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt
498cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   fragcoord[0] = vertex_position[0];
4996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
500c738ea1191cd1b5a0dc60b0e6d05fd918083e961Paul Berry   if (_mesa_is_user_fbo(fb))
501cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt      fragcoord[1] = vertex_position[1];
502cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   else
503cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt      fragcoord[1] = fb->Height - vertex_position[1];
504cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt
505cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   fragcoord[2] = vertex_position[2];
506cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   fragcoord[3] = vertex_position[3];
507cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt}
5086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_wpos_triangle(struct intel_context *intel,
5116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                    intelVertexPtr v0, intelVertexPtr v1, intelVertexPtr v2)
5126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
513cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v0);
514cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v1);
515cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v2);
5166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel_draw_triangle(intel, v0, v1, v2);
5186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_wpos_line(struct intel_context *intel,
5236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                intelVertexPtr v0, intelVertexPtr v1)
5246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
525cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v0);
526cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v1);
5276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel_draw_line(intel, v0, v1);
5286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
5326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_wpos_point(struct intel_context *intel, intelVertexPtr v0)
5336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
534cb5e0ba2aa97df28a9faeb7ca0d2f0cdfcf4e507Eric Anholt   intel_emit_fragcoord(intel, v0);
5356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel_draw_point(intel, v0);
5366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
5376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
5446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *          Macros for t_dd_tritmp.h to draw basic primitives          *
5456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
5466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TRI( a, b, c )				\
5486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { 						\
5496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (DO_FALLBACK)				\
5506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->draw_tri( intel, a, b, c );	\
5516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else						\
5526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_triangle( intel, a, b, c );	\
5536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
5546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define QUAD( a, b, c, d )			\
5566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { 						\
5576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (DO_FALLBACK) {				\
5586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->draw_tri( intel, a, b, d );	\
5596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->draw_tri( intel, b, c, d );	\
5606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   } else					\
5616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_quad( intel, a, b, c, d );	\
5626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
5636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define LINE( v0, v1 )				\
5656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { 						\
5666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (DO_FALLBACK)				\
5676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->draw_line( intel, v0, v1 );	\
5686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else						\
5696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_line( intel, v0, v1 );		\
5706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
5716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define POINT( v0 )				\
5736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo { 						\
5746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (DO_FALLBACK)				\
5756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->draw_point( intel, v0 );		\
5766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else						\
5776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel_draw_point( intel, v0 );		\
5786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
5796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
5826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *              Build render functions from dd templates               *
5836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
5846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_OFFSET_BIT 	0x01
5866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_TWOSIDE_BIT	0x02
5876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_UNFILLED_BIT	0x04
5886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_FALLBACK_BIT	0x08
5896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_MAX_TRIFUNC	0x10
5906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
5926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic struct
5936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
5946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl_points_func points;
5956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl_line_func line;
5966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl_triangle_func triangle;
5976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl_quad_func quad;
5986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} rast_tab[INTEL_MAX_TRIFUNC];
5996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
60132c55448602f8ed764005e72682f5f3979763321Vinson Lee#define DO_FALLBACK ((IND & INTEL_FALLBACK_BIT) != 0)
60232c55448602f8ed764005e72682f5f3979763321Vinson Lee#define DO_OFFSET   ((IND & INTEL_OFFSET_BIT) != 0)
60332c55448602f8ed764005e72682f5f3979763321Vinson Lee#define DO_UNFILLED ((IND & INTEL_UNFILLED_BIT) != 0)
60432c55448602f8ed764005e72682f5f3979763321Vinson Lee#define DO_TWOSIDE  ((IND & INTEL_TWOSIDE_BIT) != 0)
6056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_FLAT      0
6066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_TRI       1
6076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_QUAD      1
6086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_LINE      1
6096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_POINTS    1
6106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define DO_FULL_QUAD 1
6116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define HAVE_SPEC         1
6136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define HAVE_BACK_COLORS  0
6146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define HAVE_HW_FLATSHADE 1
6156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERTEX            intelVertex
6166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAB               rast_tab
6176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Only used to pull back colors into vertices (ie, we know color is
6196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * floating point).
6206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
6216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_COLOR( dst, src )				\
6226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {							\
6236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]);	\
6246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]);	\
6256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]);	\
6266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]);	\
6276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
6286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_SPEC( dst, src )				\
6306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelldo {							\
6316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]);	\
6326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]);	\
6336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]);	\
6346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} while (0)
6356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
637dba46831b0887a3f76ad011a9653ed9d2fff570eEric Anholt#define DEPTH_SCALE (ctx->DrawBuffer->Visual.depthBits == 16 ? 1.0 : 2.0)
6386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UNFILLED_TRI unfilled_tri
6396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define UNFILLED_QUAD unfilled_quad
6406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_X(_v) _v->v.x
6416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_Y(_v) _v->v.y
6426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_Z(_v) _v->v.z
6436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define AREA_IS_CCW( a ) (a > 0)
6446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
6456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_SET_RGBA( v, c )    if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
6476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
6486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_SAVE_RGBA( idx )    if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
6496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
6506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_SET_SPEC( v, c )    if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
6526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
6536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_SAVE_SPEC( idx )    if (specoffset) spec[idx] = v[idx]->ui[specoffset]
6546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
6556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define LOCAL_VARS(n)							\
65754bd506c0fcfd7dffa31bea22f3c0175ec41b9b0Kristian Høgsberg   struct intel_context *intel = intel_context(ctx);			\
65854bd506c0fcfd7dffa31bea22f3c0175ec41b9b0Kristian Høgsberg   GLuint color[n] = { 0, }, spec[n] = { 0, };				\
65954bd506c0fcfd7dffa31bea22f3c0175ec41b9b0Kristian Høgsberg   GLuint coloroffset = intel->coloroffset;				\
6606b0a07f9ce844a8a96e2583bd37ed8453bf151c6Paul Berry   GLuint specoffset = intel->specoffset;				\
6616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   (void) color; (void) spec; (void) coloroffset; (void) specoffset;
6626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
6656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                Helpers for rendering unfilled primitives            *
6666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
6676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic const GLuint hw_prim[GL_POLYGON + 1] = {
669fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_POINTS] = PRIM3D_POINTLIST,
670fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINES] = PRIM3D_LINELIST,
671fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINE_LOOP] = PRIM3D_LINELIST,
672fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINE_STRIP] = PRIM3D_LINELIST,
673fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLES] = PRIM3D_TRILIST,
674fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLE_STRIP] = PRIM3D_TRILIST,
675fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLE_FAN] = PRIM3D_TRILIST,
676fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_QUADS] = PRIM3D_TRILIST,
677fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_QUAD_STRIP] = PRIM3D_TRILIST,
678fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_POLYGON] = PRIM3D_TRILIST,
6796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
6806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
6826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RENDER_PRIMITIVE intel->render_primitive
6836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x
6846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND INTEL_FALLBACK_BIT
6856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_unfilled.h"
6866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#undef IND
6876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
6896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                      Generate GL render functions                   *
6906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
6916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (0)
6936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x
6946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
6956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
6966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_OFFSET_BIT)
6976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_offset
6986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
6996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT)
7016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside
7026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
7056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_offset
7066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_UNFILLED_BIT)
7096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_unfilled
7106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
7136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_offset_unfilled
7146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
7176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_unfilled
7186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
7216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_offset_unfilled
7226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_FALLBACK_BIT)
7256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_fallback
7266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
7296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_offset_fallback
7306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
7336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_fallback
7346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
7376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_offset_fallback
7386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
7416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_unfilled_fallback
7426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
7456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_offset_unfilled_fallback
7466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
7496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_unfilled_fallback
7506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
7536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	     INTEL_FALLBACK_BIT)
7546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) x##_twoside_offset_unfilled_fallback
7556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl_dd/t_dd_tritmp.h"
7566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
7596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellinit_rast_tab(void)
7606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
7616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init();
7626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_offset();
7636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside();
7646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_offset();
7656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_unfilled();
7666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_offset_unfilled();
7676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_unfilled();
7686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_offset_unfilled();
7696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_fallback();
7706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_offset_fallback();
7716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_fallback();
7726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_offset_fallback();
7736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_unfilled_fallback();
7746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_offset_unfilled_fallback();
7756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_unfilled_fallback();
7766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   init_twoside_offset_unfilled_fallback();
7776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
7786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/***********************************************************************
7816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *                    Rasterization fallback helpers                   *
7826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ***********************************************************************/
7836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* This code is hit only when a mix of accelerated and unaccelerated
7866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * primitives are being drawn, and only for the unaccelerated
7876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * primitives.
7886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
7896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
7906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_fallback_tri(struct intel_context *intel,
7916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                   intelVertex * v0, intelVertex * v1, intelVertex * v2)
7926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
793f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
7946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   SWvertex v[3];
7956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0)
797139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "\n%s\n", __func__);
7986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
7996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   INTEL_FIREVERTICES(intel);
8006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v0, &v[0]);
8026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v1, &v[1]);
8036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v2, &v[2]);
804df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_start(ctx);
8056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);
806df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_finish(ctx);
8076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
8086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
8116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_fallback_line(struct intel_context *intel,
8126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                    intelVertex * v0, intelVertex * v1)
8136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
814f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
8156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   SWvertex v[2];
8166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0)
818139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "\n%s\n", __func__);
8196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   INTEL_FIREVERTICES(intel);
8216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v0, &v[0]);
8236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v1, &v[1]);
824df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_start(ctx);
8256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swrast_Line(ctx, &v[0], &v[1]);
826df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_finish(ctx);
8276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
8286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
8306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellintel_fallback_point(struct intel_context *intel,
8316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell		     intelVertex * v0)
8326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
833f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
8346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   SWvertex v[1];
8356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0)
837139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "\n%s\n", __func__);
8386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   INTEL_FIREVERTICES(intel);
8406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swsetup_Translate(ctx, v0, &v[0]);
842df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_start(ctx);
8436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _swrast_Point(ctx, &v[0]);
844df410863d7c2377cfbabfef907fc318e10c5486eEric Anholt   _swrast_render_finish(ctx);
8456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
8466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
8496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/*               Render unclipped begin/end objects                   */
8506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
8516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define IND 0
8536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
8546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RENDER_POINTS( start, count )	\
8556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for ( ; start < count ; start++) POINT( V(ELT(start)) );
8566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RENDER_LINE( v0, v1 )         LINE( V(v0), V(v1) )
8576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RENDER_TRI(  v0, v1, v2 )     TRI(  V(v0), V(v1), V(v2) )
8586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
8596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INIT(x) intelRenderPrimitive( ctx, x )
8606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#undef LOCAL_VARS
8616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define LOCAL_VARS						\
8626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    struct intel_context *intel = intel_context(ctx);			\
8636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    GLubyte *vertptr = (GLubyte *)intel->verts;			\
8646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    const GLuint vertsize = intel->vertex_size;       	\
8656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts;	\
8666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    (void) elt;
8676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RESET_STIPPLE
8686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define RESET_OCCLUSION
8696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define PRESERVE_VB_DEFS
8706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ELT(x) x
8716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) intel_##x##_verts
8726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vb_rendertmp.h"
8736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#undef ELT
8746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#undef TAG
8756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define TAG(x) intel_##x##_elts
8766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ELT(x) elt[x]
8776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "tnl/t_vb_rendertmp.h"
8786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
8806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/*                   Render clipped primitives                        */
8816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
8826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
886f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
8876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
8886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
8896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
8906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint prim = intel->render_primitive;
8916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Render the new vertices as an unclipped polygon.
8936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
894bcf650496f22961fb66975aba3c8a982dbc72c9eVille Syrjälä   _tnl_RenderClippedPolygon(ctx, elts, n);
8956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
8966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Restore the render primitive
8976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
8986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (prim != GL_POLYGON)
8996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      tnl->Driver.Render.PrimitiveNotify(ctx, prim);
9006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
9016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
903f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelFastRenderClippedPoly(struct gl_context * ctx, const GLuint * elts, GLuint n)
9046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
9056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
9066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   const GLuint vertsize = intel->vertex_size;
907f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie   GLuint *vb = intel_get_prim_space(intel, (n - 2) * 3);
9086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLubyte *vertptr = (GLubyte *) intel->verts;
9096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   const GLuint *start = (const GLuint *) V(elts[0]);
9106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int i, j;
9116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
912303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä   if (ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) {
913303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä      for (i = 2; i < n; i++) {
914303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
915303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, V(elts[i]));
916303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, start);
917303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä      }
918303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä   } else {
919303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä      for (i = 2; i < n; i++) {
920303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, start);
921303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, V(elts[i - 1]));
922303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä         COPY_DWORDS(j, vb, vertsize, V(elts[i]));
923303895655c6ed837e3d867a450f4322404e86a88Ville Syrjälä      }
9246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
9256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
9266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
9286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/*                    Choose render functions                         */
9296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
9306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
932cbbcb0247e6aa8d7adc274a94206ee02f9c70beaBrian Paul#define DD_TRI_LIGHT_TWOSIDE (1 << 1)
933c9bb052e31b7952272e60d28969e90eafb6b3e1fBrian Paul#define DD_TRI_UNFILLED (1 << 2)
934b32fb8ac9e05b78d2bd07fcaf0d5f68525c4aa3bBrian Paul#define DD_TRI_STIPPLE  (1 << 4)
935dfb1474aac97b94b36eed56954cbf2fadd0eddedBrian Paul#define DD_TRI_OFFSET   (1 << 5)
9368ac8ae83609d5d5f28037ccd5b81ce5e40db2d33Brian Paul#define DD_LINE_STIPPLE (1 << 7)
937c6a81448f8d55a510d8e32cf28e1e174bf2574ddBrian Paul#define DD_POINT_ATTEN  (1 << 9)
9386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
93967d3ff760a33f3f98b89d3a6422bb85c199a9963Eric Anholt#define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN)
9406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
9416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
943f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelChooseRenderState(struct gl_context * ctx)
9446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
9456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
9466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
9473350ca223e4319dce79d26652a3f9c1c63aaf9b3Brian Paul   GLuint flags =
948cbbcb0247e6aa8d7adc274a94206ee02f9c70beaBrian Paul      ((ctx->Light.Enabled &&
949cbbcb0247e6aa8d7adc274a94206ee02f9c70beaBrian Paul        ctx->Light.Model.TwoSide) ? DD_TRI_LIGHT_TWOSIDE : 0) |
950c9bb052e31b7952272e60d28969e90eafb6b3e1fBrian Paul      ((ctx->Polygon.FrontMode != GL_FILL ||
951c9bb052e31b7952272e60d28969e90eafb6b3e1fBrian Paul        ctx->Polygon.BackMode != GL_FILL) ? DD_TRI_UNFILLED : 0) |
952b32fb8ac9e05b78d2bd07fcaf0d5f68525c4aa3bBrian Paul      (ctx->Polygon.StippleFlag ? DD_TRI_STIPPLE : 0) |
953dfb1474aac97b94b36eed56954cbf2fadd0eddedBrian Paul      ((ctx->Polygon.OffsetPoint ||
954dfb1474aac97b94b36eed56954cbf2fadd0eddedBrian Paul        ctx->Polygon.OffsetLine ||
955dfb1474aac97b94b36eed56954cbf2fadd0eddedBrian Paul        ctx->Polygon.OffsetFill) ? DD_TRI_OFFSET : 0) |
956c6a81448f8d55a510d8e32cf28e1e174bf2574ddBrian Paul      (ctx->Line.StippleFlag ? DD_LINE_STIPPLE : 0) |
957c6a81448f8d55a510d8e32cf28e1e174bf2574ddBrian Paul      (ctx->Point._Attenuated ? DD_POINT_ATTEN : 0);
9583423488d55b9c483fcdb3996eb89b424c1031d24Timothy Arceri   const struct gl_program *fprog = ctx->FragmentProgram._Current;
959e81aaeba37f5419323d8f88bc10943c77e25ed14Timothy Arceri   bool have_wpos = (fprog && (fprog->info.inputs_read & VARYING_BIT_POS));
9606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint index = 0;
9616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (INTEL_DEBUG & DEBUG_STATE)
963139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "\n%s\n", __func__);
9646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if ((flags & (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)) || have_wpos) {
9666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (flags & ANY_RASTER_FLAGS) {
9686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (flags & DD_TRI_LIGHT_TWOSIDE)
9696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            index |= INTEL_TWOSIDE_BIT;
9706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (flags & DD_TRI_OFFSET)
9716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            index |= INTEL_OFFSET_BIT;
9726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (flags & DD_TRI_UNFILLED)
9736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            index |= INTEL_UNFILLED_BIT;
9746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
9756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (have_wpos) {
9776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_point = intel_wpos_point;
9786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_line = intel_wpos_line;
9796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_tri = intel_wpos_triangle;
9806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         /* Make sure these get called:
9826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          */
9836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         index |= INTEL_FALLBACK_BIT;
9846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
9856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
9866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_point = intel_draw_point;
9876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_line = intel_draw_line;
9886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->draw_tri = intel_draw_triangle;
9896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
9906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Hook in fallbacks for specific primitives.
9926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
9936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (flags & ANY_FALLBACK_FLAGS) {
9946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (flags & DD_LINE_STIPPLE)
9956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            intel->draw_line = intel_fallback_line;
9966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
9976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if ((flags & DD_TRI_STIPPLE) && !intel->hw_stipple)
9986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            intel->draw_tri = intel_fallback_tri;
9996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (flags & DD_POINT_ATTEN) {
10016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    if (0)
10026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       intel->draw_point = intel_atten_point;
10036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    else
10046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       intel->draw_point = intel_fallback_point;
10056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	 }
10066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         index |= INTEL_FALLBACK_BIT;
10086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
10096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
10106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (intel->RenderIndex != index) {
10126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->RenderIndex = index;
10136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      tnl->Driver.Render.Points = rast_tab[index].points;
10156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      tnl->Driver.Render.Line = rast_tab[index].line;
10166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      tnl->Driver.Render.Triangle = rast_tab[index].triangle;
10176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      tnl->Driver.Render.Quad = rast_tab[index].quad;
10186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (index == 0) {
10206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.PrimTabVerts = intel_render_tab_verts;
10216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.PrimTabElts = intel_render_tab_elts;
10226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */
10236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.ClippedPolygon = intelFastRenderClippedPoly;
10246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
10256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
10266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
10276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
1028bcf650496f22961fb66975aba3c8a982dbc72c9eVille Syrjälä         tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine;
10296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.ClippedPolygon = intelRenderClippedPoly;
10306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
10316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
10326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
10336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic const GLenum reduced_prim[GL_POLYGON + 1] = {
1035fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_POINTS] = GL_POINTS,
1036fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINES] = GL_LINES,
1037fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINE_LOOP] = GL_LINES,
1038fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_LINE_STRIP] = GL_LINES,
1039fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLES] = GL_TRIANGLES,
1040fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLE_STRIP] = GL_TRIANGLES,
1041fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_TRIANGLE_FAN] = GL_TRIANGLES,
1042fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_QUADS] = GL_TRIANGLES,
1043fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_QUAD_STRIP] = GL_TRIANGLES,
1044fad5fd3a254c9c37bc25cd356d2bced0dcfe9e26Ville Syrjälä   [GL_POLYGON] = GL_TRIANGLES
10456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
10466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
10496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/*                 High level hooks for t_vb_render.c                 */
10506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
10516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
1056f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRunPipeline(struct gl_context * ctx)
10576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
10586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
10596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _mesa_lock_context_textures(ctx);
10616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (ctx->NewState)
10636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _mesa_update_state_locked(ctx);
10646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10656e6b38860488a0b2b282866f095cea9860503a14Eric Anholt   /* We need to get this done before we start the pipeline, or a
10666e6b38860488a0b2b282866f095cea9860503a14Eric Anholt    * change in the INTEL_FALLBACK() of its intel_draw_buffers() call
10676e6b38860488a0b2b282866f095cea9860503a14Eric Anholt    * while the pipeline is running will result in mismatched swrast
10686e6b38860488a0b2b282866f095cea9860503a14Eric Anholt    * map/unmaps, and later assertion failures.
10696e6b38860488a0b2b282866f095cea9860503a14Eric Anholt    */
10706e6b38860488a0b2b282866f095cea9860503a14Eric Anholt   intel_prepare_render(intel);
10716e6b38860488a0b2b282866f095cea9860503a14Eric Anholt
10726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (intel->NewGLState) {
10736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (intel->NewGLState & _NEW_TEXTURE) {
10746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->vtbl.update_texture_state(intel);
10756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
10766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (!intel->Fallback) {
10786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         if (intel->NewGLState & _INTEL_NEW_RENDERSTATE)
10796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            intelChooseRenderState(ctx);
10806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
10816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->NewGLState = 0;
10836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
10846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10856e6b38860488a0b2b282866f095cea9860503a14Eric Anholt   intel->tnl_pipeline_running = true;
10866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _tnl_run_pipeline(ctx);
10876e6b38860488a0b2b282866f095cea9860503a14Eric Anholt   intel->tnl_pipeline_running = false;
10886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   _mesa_unlock_context_textures(ctx);
10906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
10916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
10926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
1093f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRenderStart(struct gl_context * ctx)
10946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
10956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
10966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1097bcbfda71b03303d3f008a6f3cf8cb7d9667bf8d2Brian Paul   intel_check_front_buffer_rendering(intel);
10986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vtbl.render_start(intel_context(ctx));
10996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vtbl.emit_state(intel);
11006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
11016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
1103f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRenderFinish(struct gl_context * ctx)
11046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
11056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
11066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (intel->RenderIndex & INTEL_FALLBACK_BIT)
11086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      _swrast_flush(ctx);
11096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   INTEL_FIREVERTICES(intel);
11116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
11126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* System to flush dma and emit state changes based on the rasterized
11176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell  * primitive.
11186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell  */
11196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
1120f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRasterPrimitive(struct gl_context * ctx, GLenum rprim, GLuint hwprim)
11216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
11226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
11236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0)
1125139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "%s %s %x\n", __func__,
11262f11e92cef51c88a09bc778e2ceca4ab50cf0017Kenneth Graunke              _mesa_enum_to_string(rprim), hwprim);
11276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->vtbl.reduced_primitive_state(intel, rprim);
11296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Start a new primitive.  Arrange to have it flushed later on.
11316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
11326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (hwprim != intel->prim.primitive) {
11336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      INTEL_FIREVERTICES(intel);
11346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1135f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie      intel_set_prim(intel, hwprim);
11366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
11376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
11386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /*
11416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell  */
11426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic void
1143f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelRenderPrimitive(struct gl_context * ctx, GLenum prim)
11446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
11456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_context *intel = intel_context(ctx);
11463350ca223e4319dce79d26652a3f9c1c63aaf9b3Brian Paul   GLboolean unfilled = (ctx->Polygon.FrontMode != GL_FILL ||
11473350ca223e4319dce79d26652a3f9c1c63aaf9b3Brian Paul                         ctx->Polygon.BackMode != GL_FILL);
11486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (0)
11502f11e92cef51c88a09bc778e2ceca4ab50cf0017Kenneth Graunke      fprintf(stderr, "%s %s\n", __func__, _mesa_enum_to_string(prim));
11516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Let some clipping routines know which primitive they're dealing
11536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * with.
11546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
11556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intel->render_primitive = prim;
11566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11576118bbd0a67773d9247f3252a0643657bbd898a0Ian Romanick   /* Shortcircuit this when called for unfilled triangles.  The rasterized
11586118bbd0a67773d9247f3252a0643657bbd898a0Ian Romanick    * primitive will always be reset by lower level functions in that case,
11596118bbd0a67773d9247f3252a0643657bbd898a0Ian Romanick    * potentially pingponging the state:
11606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
11613350ca223e4319dce79d26652a3f9c1c63aaf9b3Brian Paul   if (reduced_prim[prim] == GL_TRIANGLES && unfilled)
11626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return;
11636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Set some primitive-dependent state and Start? a new primitive.
11656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
11666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   intelRasterPrimitive(ctx, reduced_prim[prim], hw_prim[prim]);
11676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
11686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /**********************************************************************/
11716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /*           Transition to/from hardware rasterization.               */
11726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /**********************************************************************/
11736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic char *fallbackStrings[] = {
11756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [0] = "Draw buffer",
11766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [1] = "Read buffer",
11776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [2] = "Depth buffer",
11786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [3] = "Stencil buffer",
11796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [4] = "User disable",
11806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [5] = "Render mode",
11816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [12] = "Texture",
11836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [13] = "Color mask",
11846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [14] = "Stencil",
11856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [15] = "Stipple",
11866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [16] = "Program",
11876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [17] = "Logic op",
11886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [18] = "Smooth polygon",
11896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   [19] = "Smooth point",
1190b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt   [20] = "point sprite coord origin",
1191b87406e55f029d29594ae76a4b39a4fe1007fe4fEric Anholt   [21] = "depth/color drawing offset",
1192c6532875493ffe7de9c37924c70ebf6d0472e23dYuanhan Liu   [22] = "coord replace(SPRITE POINT ENABLE)",
11936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
11946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
11966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic char *
11976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith WhitwellgetFallbackString(GLuint bit)
11986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
11996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   int i = 0;
12006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   while (bit > 1) {
12016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      i++;
12026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      bit >>= 1;
12036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
12046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return fallbackStrings[i];
12056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
12066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1209ea659f891740fab1943eca219ffbdd5ed3d1906cBrian Paul/**
1210ea659f891740fab1943eca219ffbdd5ed3d1906cBrian Paul * Enable/disable a fallback flag.
1211ea659f891740fab1943eca219ffbdd5ed3d1906cBrian Paul * \param bit  one of INTEL_FALLBACK_x flags.
1212ea659f891740fab1943eca219ffbdd5ed3d1906cBrian Paul */
12136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
12142e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth GraunkeintelFallback(struct intel_context *intel, GLbitfield bit, bool mode)
12156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1216f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
12176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
1218ea659f891740fab1943eca219ffbdd5ed3d1906cBrian Paul   const GLbitfield oldfallback = intel->Fallback;
12196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (mode) {
12216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->Fallback |= bit;
12226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (oldfallback == 0) {
12236e6b38860488a0b2b282866f095cea9860503a14Eric Anholt	 assert(!intel->tnl_pipeline_running);
12246e6b38860488a0b2b282866f095cea9860503a14Eric Anholt
12250bf1ddd60a3660974ad54e410533eeb481949364Vinson Lee         intel_flush(ctx);
122679198063b8adb23536b291081f8df8571926950eEric Anholt         if (INTEL_DEBUG & DEBUG_PERF)
12276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            fprintf(stderr, "ENTER FALLBACK %x: %s\n",
12286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                    bit, getFallbackString(bit));
12296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _swsetup_Wakeup(ctx);
12306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->RenderIndex = ~0;
12316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
12326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
12336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   else {
12346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      intel->Fallback &= ~bit;
12356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (oldfallback == bit) {
12366e6b38860488a0b2b282866f095cea9860503a14Eric Anholt	 assert(!intel->tnl_pipeline_running);
12376e6b38860488a0b2b282866f095cea9860503a14Eric Anholt
12386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _swrast_flush(ctx);
123979198063b8adb23536b291081f8df8571926950eEric Anholt         if (INTEL_DEBUG & DEBUG_PERF)
12406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            fprintf(stderr, "LEAVE FALLBACK %s\n", getFallbackString(bit));
12416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.Start = intelRenderStart;
12426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
12436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.Finish = intelRenderFinish;
12446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
12456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.CopyPV = _tnl_copy_pv;
12466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         tnl->Driver.Render.Interp = _tnl_interp;
12476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _tnl_invalidate_vertex_state(ctx, ~0);
12496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _tnl_invalidate_vertices(ctx, ~0);
12506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         _tnl_install_attrs(ctx,
12516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->vertex_attrs,
12526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->vertex_attr_count,
12536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                            intel->ViewportMatrix.m, 0);
12546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         intel->NewGLState |= _INTEL_NEW_RENDERSTATE;
12566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
12576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
12586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
12596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
12616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/*                            Initialization.                         */
12626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**********************************************************************/
12636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
1266f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergintelInitTriFuncs(struct gl_context * ctx)
12676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
12686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   TNLcontext *tnl = TNL_CONTEXT(ctx);
12696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   static int firsttime = 1;
12706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (firsttime) {
12726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      init_rast_tab();
12736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      firsttime = 0;
12746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
12756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
12766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.RunPipeline = intelRunPipeline;
12776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.Start = intelRenderStart;
12786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.Finish = intelRenderFinish;
12796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.PrimitiveNotify = intelRenderPrimitive;
12806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
12816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.BuildVertices = _tnl_build_vertices;
12826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.CopyPV = _tnl_copy_pv;
12836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   tnl->Driver.Render.Interp = _tnl_interp;
12846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1285