5c7c0c32d6a97e40bc4c52724a5d6fe572a00390
[mesa.git] / src / mesa / drivers / dri / i915 / i915_state.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/enums.h"
33 #include "main/dd.h"
34 #include "main/state.h"
35 #include "tnl/tnl.h"
36 #include "tnl/t_context.h"
37
38 #include "texmem.h"
39
40 #include "drivers/common/driverfuncs.h"
41
42 #include "intel_fbo.h"
43 #include "intel_screen.h"
44 #include "intel_batchbuffer.h"
45 #include "intel_buffers.h"
46
47 #include "i915_context.h"
48 #include "i915_reg.h"
49
50 #define FILE_DEBUG_FLAG DEBUG_STATE
51
52 void
53 i915_update_stencil(struct gl_context * ctx)
54 {
55 struct i915_context *i915 = I915_CONTEXT(ctx);
56 GLuint front_ref, front_writemask, front_mask;
57 GLenum front_func, front_fail, front_pass_z_fail, front_pass_z_pass;
58 GLuint back_ref, back_writemask, back_mask;
59 GLenum back_func, back_fail, back_pass_z_fail, back_pass_z_pass;
60 GLuint dirty = 0;
61
62 /* The 915 considers CW to be "front" for two-sided stencil, so choose
63 * appropriately.
64 */
65 /* _NEW_POLYGON | _NEW_STENCIL */
66 if (ctx->Polygon.FrontFace == GL_CW) {
67 front_ref = ctx->Stencil.Ref[0];
68 front_mask = ctx->Stencil.ValueMask[0];
69 front_writemask = ctx->Stencil.WriteMask[0];
70 front_func = ctx->Stencil.Function[0];
71 front_fail = ctx->Stencil.FailFunc[0];
72 front_pass_z_fail = ctx->Stencil.ZFailFunc[0];
73 front_pass_z_pass = ctx->Stencil.ZPassFunc[0];
74 back_ref = ctx->Stencil.Ref[ctx->Stencil._BackFace];
75 back_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace];
76 back_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace];
77 back_func = ctx->Stencil.Function[ctx->Stencil._BackFace];
78 back_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace];
79 back_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace];
80 back_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace];
81 } else {
82 front_ref = ctx->Stencil.Ref[ctx->Stencil._BackFace];
83 front_mask = ctx->Stencil.ValueMask[ctx->Stencil._BackFace];
84 front_writemask = ctx->Stencil.WriteMask[ctx->Stencil._BackFace];
85 front_func = ctx->Stencil.Function[ctx->Stencil._BackFace];
86 front_fail = ctx->Stencil.FailFunc[ctx->Stencil._BackFace];
87 front_pass_z_fail = ctx->Stencil.ZFailFunc[ctx->Stencil._BackFace];
88 front_pass_z_pass = ctx->Stencil.ZPassFunc[ctx->Stencil._BackFace];
89 back_ref = ctx->Stencil.Ref[0];
90 back_mask = ctx->Stencil.ValueMask[0];
91 back_writemask = ctx->Stencil.WriteMask[0];
92 back_func = ctx->Stencil.Function[0];
93 back_fail = ctx->Stencil.FailFunc[0];
94 back_pass_z_fail = ctx->Stencil.ZFailFunc[0];
95 back_pass_z_pass = ctx->Stencil.ZPassFunc[0];
96 }
97 #define set_ctx_bits(reg, mask, set) do{ \
98 GLuint dw = i915->state.Ctx[reg]; \
99 dw &= ~(mask); \
100 dw |= (set); \
101 dirty |= dw != i915->state.Ctx[reg]; \
102 i915->state.Ctx[reg] = dw; \
103 } while(0)
104
105 /* Set front state. */
106 set_ctx_bits(I915_CTXREG_STATE4,
107 MODE4_ENABLE_STENCIL_TEST_MASK |
108 MODE4_ENABLE_STENCIL_WRITE_MASK,
109 ENABLE_STENCIL_TEST_MASK |
110 ENABLE_STENCIL_WRITE_MASK |
111 STENCIL_TEST_MASK(front_mask) |
112 STENCIL_WRITE_MASK(front_writemask));
113
114 set_ctx_bits(I915_CTXREG_LIS5,
115 S5_STENCIL_REF_MASK |
116 S5_STENCIL_TEST_FUNC_MASK |
117 S5_STENCIL_FAIL_MASK |
118 S5_STENCIL_PASS_Z_FAIL_MASK |
119 S5_STENCIL_PASS_Z_PASS_MASK,
120 (front_ref << S5_STENCIL_REF_SHIFT) |
121 (intel_translate_compare_func(front_func) << S5_STENCIL_TEST_FUNC_SHIFT) |
122 (intel_translate_stencil_op(front_fail) << S5_STENCIL_FAIL_SHIFT) |
123 (intel_translate_stencil_op(front_pass_z_fail) <<
124 S5_STENCIL_PASS_Z_FAIL_SHIFT) |
125 (intel_translate_stencil_op(front_pass_z_pass) <<
126 S5_STENCIL_PASS_Z_PASS_SHIFT));
127
128 /* Set back state if different from front. */
129 if (ctx->Stencil._TestTwoSide) {
130 set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS,
131 BFO_STENCIL_REF_MASK |
132 BFO_STENCIL_TEST_MASK |
133 BFO_STENCIL_FAIL_MASK |
134 BFO_STENCIL_PASS_Z_FAIL_MASK |
135 BFO_STENCIL_PASS_Z_PASS_MASK,
136 BFO_STENCIL_TWO_SIDE |
137 (back_ref << BFO_STENCIL_REF_SHIFT) |
138 (intel_translate_compare_func(back_func) << BFO_STENCIL_TEST_SHIFT) |
139 (intel_translate_stencil_op(back_fail) << BFO_STENCIL_FAIL_SHIFT) |
140 (intel_translate_stencil_op(back_pass_z_fail) <<
141 BFO_STENCIL_PASS_Z_FAIL_SHIFT) |
142 (intel_translate_stencil_op(back_pass_z_pass) <<
143 BFO_STENCIL_PASS_Z_PASS_SHIFT));
144
145 set_ctx_bits(I915_CTXREG_BF_STENCIL_MASKS,
146 BFM_STENCIL_TEST_MASK_MASK |
147 BFM_STENCIL_WRITE_MASK_MASK,
148 BFM_STENCIL_TEST_MASK(back_mask) |
149 BFM_STENCIL_WRITE_MASK(back_writemask));
150 } else {
151 set_ctx_bits(I915_CTXREG_BF_STENCIL_OPS,
152 BFO_STENCIL_TWO_SIDE, 0);
153 }
154
155 #undef set_ctx_bits
156
157 if (dirty)
158 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
159 }
160
161 static void
162 i915StencilFuncSeparate(struct gl_context * ctx, GLenum face, GLenum func, GLint ref,
163 GLuint mask)
164 {
165 }
166
167 static void
168 i915StencilMaskSeparate(struct gl_context * ctx, GLenum face, GLuint mask)
169 {
170 }
171
172 static void
173 i915StencilOpSeparate(struct gl_context * ctx, GLenum face, GLenum fail, GLenum zfail,
174 GLenum zpass)
175 {
176 }
177
178 static void
179 i915AlphaFunc(struct gl_context * ctx, GLenum func, GLfloat ref)
180 {
181 struct i915_context *i915 = I915_CONTEXT(ctx);
182 int test = intel_translate_compare_func(func);
183 GLubyte refByte;
184 GLuint dw;
185
186 UNCLAMPED_FLOAT_TO_UBYTE(refByte, ref);
187
188 dw = i915->state.Ctx[I915_CTXREG_LIS6];
189 dw &= ~(S6_ALPHA_TEST_FUNC_MASK | S6_ALPHA_REF_MASK);
190 dw |= ((test << S6_ALPHA_TEST_FUNC_SHIFT) |
191 (((GLuint) refByte) << S6_ALPHA_REF_SHIFT));
192 if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
193 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
194 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
195 }
196 }
197
198 /* This function makes sure that the proper enables are
199 * set for LogicOp, Independant Alpha Blend, and Blending.
200 * It needs to be called from numerous places where we
201 * could change the LogicOp or Independant Alpha Blend without subsequent
202 * calls to glEnable.
203 */
204 static void
205 i915EvalLogicOpBlendState(struct gl_context * ctx)
206 {
207 struct i915_context *i915 = I915_CONTEXT(ctx);
208 GLuint dw0, dw1;
209
210 dw0 = i915->state.Ctx[I915_CTXREG_LIS5];
211 dw1 = i915->state.Ctx[I915_CTXREG_LIS6];
212
213 if (_mesa_rgba_logicop_enabled(ctx)) {
214 dw0 |= S5_LOGICOP_ENABLE;
215 dw1 &= ~S6_CBUF_BLEND_ENABLE;
216 }
217 else {
218 dw0 &= ~S5_LOGICOP_ENABLE;
219
220 if (ctx->Color.BlendEnabled) {
221 dw1 |= S6_CBUF_BLEND_ENABLE;
222 }
223 else {
224 dw1 &= ~S6_CBUF_BLEND_ENABLE;
225 }
226 }
227 if (dw0 != i915->state.Ctx[I915_CTXREG_LIS5] ||
228 dw1 != i915->state.Ctx[I915_CTXREG_LIS6]) {
229 i915->state.Ctx[I915_CTXREG_LIS5] = dw0;
230 i915->state.Ctx[I915_CTXREG_LIS6] = dw1;
231
232 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
233 }
234 }
235
236 static void
237 i915BlendColor(struct gl_context * ctx, const GLfloat color[4])
238 {
239 struct i915_context *i915 = I915_CONTEXT(ctx);
240 GLubyte r, g, b, a;
241 GLuint dw;
242
243 DBG("%s\n", __FUNCTION__);
244
245 UNCLAMPED_FLOAT_TO_UBYTE(r, color[RCOMP]);
246 UNCLAMPED_FLOAT_TO_UBYTE(g, color[GCOMP]);
247 UNCLAMPED_FLOAT_TO_UBYTE(b, color[BCOMP]);
248 UNCLAMPED_FLOAT_TO_UBYTE(a, color[ACOMP]);
249
250 dw = (a << 24) | (r << 16) | (g << 8) | b;
251 if (dw != i915->state.Blend[I915_BLENDREG_BLENDCOLOR1]) {
252 i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = dw;
253 I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
254 }
255 }
256
257
258 #define DST_BLND_FACT(f) ((f)<<S6_CBUF_DST_BLEND_FACT_SHIFT)
259 #define SRC_BLND_FACT(f) ((f)<<S6_CBUF_SRC_BLEND_FACT_SHIFT)
260 #define DST_ABLND_FACT(f) ((f)<<IAB_DST_FACTOR_SHIFT)
261 #define SRC_ABLND_FACT(f) ((f)<<IAB_SRC_FACTOR_SHIFT)
262
263
264
265 static GLuint
266 translate_blend_equation(GLenum mode)
267 {
268 switch (mode) {
269 case GL_FUNC_ADD:
270 return BLENDFUNC_ADD;
271 case GL_MIN:
272 return BLENDFUNC_MIN;
273 case GL_MAX:
274 return BLENDFUNC_MAX;
275 case GL_FUNC_SUBTRACT:
276 return BLENDFUNC_SUBTRACT;
277 case GL_FUNC_REVERSE_SUBTRACT:
278 return BLENDFUNC_REVERSE_SUBTRACT;
279 default:
280 return 0;
281 }
282 }
283
284 static void
285 i915UpdateBlendState(struct gl_context * ctx)
286 {
287 struct i915_context *i915 = I915_CONTEXT(ctx);
288 GLuint iab = (i915->state.Blend[I915_BLENDREG_IAB] &
289 ~(IAB_SRC_FACTOR_MASK |
290 IAB_DST_FACTOR_MASK |
291 (BLENDFUNC_MASK << IAB_FUNC_SHIFT) | IAB_ENABLE));
292
293 GLuint lis6 = (i915->state.Ctx[I915_CTXREG_LIS6] &
294 ~(S6_CBUF_SRC_BLEND_FACT_MASK |
295 S6_CBUF_DST_BLEND_FACT_MASK | S6_CBUF_BLEND_FUNC_MASK));
296
297 GLuint eqRGB = ctx->Color.Blend[0].EquationRGB;
298 GLuint eqA = ctx->Color.Blend[0].EquationA;
299 GLuint srcRGB = ctx->Color.Blend[0].SrcRGB;
300 GLuint dstRGB = ctx->Color.Blend[0].DstRGB;
301 GLuint srcA = ctx->Color.Blend[0].SrcA;
302 GLuint dstA = ctx->Color.Blend[0].DstA;
303
304 if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
305 srcRGB = dstRGB = GL_ONE;
306 }
307
308 if (eqA == GL_MIN || eqA == GL_MAX) {
309 srcA = dstA = GL_ONE;
310 }
311
312 lis6 |= SRC_BLND_FACT(intel_translate_blend_factor(srcRGB));
313 lis6 |= DST_BLND_FACT(intel_translate_blend_factor(dstRGB));
314 lis6 |= translate_blend_equation(eqRGB) << S6_CBUF_BLEND_FUNC_SHIFT;
315
316 iab |= SRC_ABLND_FACT(intel_translate_blend_factor(srcA));
317 iab |= DST_ABLND_FACT(intel_translate_blend_factor(dstA));
318 iab |= translate_blend_equation(eqA) << IAB_FUNC_SHIFT;
319
320 if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB)
321 iab |= IAB_ENABLE;
322
323 if (iab != i915->state.Blend[I915_BLENDREG_IAB]) {
324 i915->state.Blend[I915_BLENDREG_IAB] = iab;
325 I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
326 }
327 if (lis6 != i915->state.Ctx[I915_CTXREG_LIS6]) {
328 i915->state.Ctx[I915_CTXREG_LIS6] = lis6;
329 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
330 }
331
332 /* This will catch a logicop blend equation */
333 i915EvalLogicOpBlendState(ctx);
334 }
335
336
337 static void
338 i915BlendFuncSeparate(struct gl_context * ctx, GLenum srcRGB,
339 GLenum dstRGB, GLenum srcA, GLenum dstA)
340 {
341 i915UpdateBlendState(ctx);
342 }
343
344
345 static void
346 i915BlendEquationSeparate(struct gl_context * ctx, GLenum eqRGB, GLenum eqA)
347 {
348 i915UpdateBlendState(ctx);
349 }
350
351
352 static void
353 i915DepthFunc(struct gl_context * ctx, GLenum func)
354 {
355 struct i915_context *i915 = I915_CONTEXT(ctx);
356 int test = intel_translate_compare_func(func);
357 GLuint dw;
358
359 DBG("%s\n", __FUNCTION__);
360
361 dw = i915->state.Ctx[I915_CTXREG_LIS6];
362 dw &= ~S6_DEPTH_TEST_FUNC_MASK;
363 dw |= test << S6_DEPTH_TEST_FUNC_SHIFT;
364 if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
365 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
366 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
367 }
368 }
369
370 static void
371 i915DepthMask(struct gl_context * ctx, GLboolean flag)
372 {
373 struct i915_context *i915 = I915_CONTEXT(ctx);
374 GLuint dw;
375
376 DBG("%s flag (%d)\n", __FUNCTION__, flag);
377
378 dw = i915->state.Ctx[I915_CTXREG_LIS6];
379 if (flag && ctx->Depth.Test)
380 dw |= S6_DEPTH_WRITE_ENABLE;
381 else
382 dw &= ~S6_DEPTH_WRITE_ENABLE;
383 if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
384 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
385 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
386 }
387 }
388
389
390
391 /**
392 * Update the viewport transformation matrix. Depends on:
393 * - viewport pos/size
394 * - depthrange
395 * - window pos/size or FBO size
396 */
397 void
398 intelCalcViewport(struct gl_context * ctx)
399 {
400 struct intel_context *intel = intel_context(ctx);
401 const GLfloat *v = ctx->Viewport._WindowMap.m;
402 const GLfloat depthScale = 1.0F / ctx->DrawBuffer->_DepthMaxF;
403 GLfloat *m = intel->ViewportMatrix.m;
404 GLfloat yScale, yBias;
405
406 if (ctx->DrawBuffer->Name) {
407 /* User created FBO */
408 /* y=0=bottom */
409 yScale = 1.0;
410 yBias = 0.0;
411 }
412 else {
413 /* window buffer, y=0=top */
414 yScale = -1.0;
415 yBias = ctx->DrawBuffer->Height;
416 }
417
418 m[MAT_SX] = v[MAT_SX];
419 m[MAT_TX] = v[MAT_TX];
420
421 m[MAT_SY] = v[MAT_SY] * yScale;
422 m[MAT_TY] = v[MAT_TY] * yScale + yBias;
423
424 m[MAT_SZ] = v[MAT_SZ] * depthScale;
425 m[MAT_TZ] = v[MAT_TZ] * depthScale;
426 }
427
428
429 /** Called from ctx->Driver.Viewport() */
430 static void
431 i915Viewport(struct gl_context * ctx,
432 GLint x, GLint y, GLsizei width, GLsizei height)
433 {
434 intelCalcViewport(ctx);
435 }
436
437
438 /** Called from ctx->Driver.DepthRange() */
439 static void
440 i915DepthRange(struct gl_context * ctx, GLclampd nearval, GLclampd farval)
441 {
442 intelCalcViewport(ctx);
443 }
444
445
446 /* =============================================================
447 * Polygon stipple
448 *
449 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
450 * Fortunately stipple is usually a repeating pattern.
451 */
452 static void
453 i915PolygonStipple(struct gl_context * ctx, const GLubyte * mask)
454 {
455 struct i915_context *i915 = I915_CONTEXT(ctx);
456 const GLubyte *m;
457 GLubyte p[4];
458 int i, j, k;
459 int active = (ctx->Polygon.StippleFlag &&
460 i915->intel.reduced_primitive == GL_TRIANGLES);
461 GLuint newMask;
462
463 if (active) {
464 I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
465 i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE;
466 }
467
468 /* Use the already unpacked stipple data from the context rather than the
469 * uninterpreted mask passed in.
470 */
471 mask = (const GLubyte *)ctx->PolygonStipple;
472 m = mask;
473
474 p[0] = mask[12] & 0xf;
475 p[0] |= p[0] << 4;
476 p[1] = mask[8] & 0xf;
477 p[1] |= p[1] << 4;
478 p[2] = mask[4] & 0xf;
479 p[2] |= p[2] << 4;
480 p[3] = mask[0] & 0xf;
481 p[3] |= p[3] << 4;
482
483 for (k = 0; k < 8; k++)
484 for (j = 3; j >= 0; j--)
485 for (i = 0; i < 4; i++, m++)
486 if (*m != p[j]) {
487 i915->intel.hw_stipple = 0;
488 return;
489 }
490
491 newMask = (((p[0] & 0xf) << 0) |
492 ((p[1] & 0xf) << 4) |
493 ((p[2] & 0xf) << 8) | ((p[3] & 0xf) << 12));
494
495
496 if (newMask == 0xffff || newMask == 0x0) {
497 /* this is needed to make conform pass */
498 i915->intel.hw_stipple = 0;
499 return;
500 }
501
502 i915->state.Stipple[I915_STPREG_ST1] &= ~0xffff;
503 i915->state.Stipple[I915_STPREG_ST1] |= newMask;
504 i915->intel.hw_stipple = 1;
505
506 if (active)
507 i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE;
508 }
509
510
511 /* =============================================================
512 * Hardware clipping
513 */
514 static void
515 i915Scissor(struct gl_context * ctx, GLint x, GLint y, GLsizei w, GLsizei h)
516 {
517 struct i915_context *i915 = I915_CONTEXT(ctx);
518 int x1, y1, x2, y2;
519
520 if (!ctx->DrawBuffer)
521 return;
522
523 DBG("%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h);
524
525 if (ctx->DrawBuffer->Name == 0) {
526 x1 = x;
527 y1 = ctx->DrawBuffer->Height - (y + h);
528 x2 = x + w - 1;
529 y2 = y1 + h - 1;
530 DBG("%s %d..%d,%d..%d (inverted)\n", __FUNCTION__, x1, x2, y1, y2);
531 }
532 else {
533 /* FBO - not inverted
534 */
535 x1 = x;
536 y1 = y;
537 x2 = x + w - 1;
538 y2 = y + h - 1;
539 DBG("%s %d..%d,%d..%d (not inverted)\n", __FUNCTION__, x1, x2, y1, y2);
540 }
541
542 x1 = CLAMP(x1, 0, ctx->DrawBuffer->Width - 1);
543 y1 = CLAMP(y1, 0, ctx->DrawBuffer->Height - 1);
544 x2 = CLAMP(x2, 0, ctx->DrawBuffer->Width - 1);
545 y2 = CLAMP(y2, 0, ctx->DrawBuffer->Height - 1);
546
547 DBG("%s %d..%d,%d..%d (clamped)\n", __FUNCTION__, x1, x2, y1, y2);
548
549 I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS);
550 i915->state.Buffer[I915_DESTREG_SR1] = (y1 << 16) | (x1 & 0xffff);
551 i915->state.Buffer[I915_DESTREG_SR2] = (y2 << 16) | (x2 & 0xffff);
552 }
553
554 static void
555 i915LogicOp(struct gl_context * ctx, GLenum opcode)
556 {
557 struct i915_context *i915 = I915_CONTEXT(ctx);
558 int tmp = intel_translate_logic_op(opcode);
559
560 DBG("%s\n", __FUNCTION__);
561
562 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
563 i915->state.Ctx[I915_CTXREG_STATE4] &= ~LOGICOP_MASK;
564 i915->state.Ctx[I915_CTXREG_STATE4] |= LOGIC_OP_FUNC(tmp);
565 }
566
567
568
569 static void
570 i915CullFaceFrontFace(struct gl_context * ctx, GLenum unused)
571 {
572 struct i915_context *i915 = I915_CONTEXT(ctx);
573 GLuint mode, dw;
574
575 DBG("%s %d\n", __FUNCTION__,
576 ctx->DrawBuffer ? ctx->DrawBuffer->Name : 0);
577
578 if (!ctx->Polygon.CullFlag) {
579 mode = S4_CULLMODE_NONE;
580 }
581 else if (ctx->Polygon.CullFaceMode != GL_FRONT_AND_BACK) {
582 mode = S4_CULLMODE_CW;
583
584 if (ctx->DrawBuffer && ctx->DrawBuffer->Name != 0)
585 mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
586 if (ctx->Polygon.CullFaceMode == GL_FRONT)
587 mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
588 if (ctx->Polygon.FrontFace != GL_CCW)
589 mode ^= (S4_CULLMODE_CW ^ S4_CULLMODE_CCW);
590 }
591 else {
592 mode = S4_CULLMODE_BOTH;
593 }
594
595 dw = i915->state.Ctx[I915_CTXREG_LIS4];
596 dw &= ~S4_CULLMODE_MASK;
597 dw |= mode;
598 if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
599 i915->state.Ctx[I915_CTXREG_LIS4] = dw;
600 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
601 }
602 }
603
604 static void
605 i915LineWidth(struct gl_context * ctx, GLfloat widthf)
606 {
607 struct i915_context *i915 = I915_CONTEXT(ctx);
608 int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_LINE_WIDTH_MASK;
609 int width;
610
611 DBG("%s\n", __FUNCTION__);
612
613 width = (int) (widthf * 2);
614 width = CLAMP(width, 1, 0xf);
615 lis4 |= width << S4_LINE_WIDTH_SHIFT;
616
617 if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
618 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
619 i915->state.Ctx[I915_CTXREG_LIS4] = lis4;
620 }
621 }
622
623 static void
624 i915PointSize(struct gl_context * ctx, GLfloat size)
625 {
626 struct i915_context *i915 = I915_CONTEXT(ctx);
627 int lis4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_POINT_WIDTH_MASK;
628 GLint point_size = (int) round(size);
629
630 DBG("%s\n", __FUNCTION__);
631
632 point_size = CLAMP(point_size, 1, 255);
633 lis4 |= point_size << S4_POINT_WIDTH_SHIFT;
634
635 if (lis4 != i915->state.Ctx[I915_CTXREG_LIS4]) {
636 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
637 i915->state.Ctx[I915_CTXREG_LIS4] = lis4;
638 }
639 }
640
641
642 static void
643 i915PointParameterfv(struct gl_context * ctx, GLenum pname, const GLfloat *params)
644 {
645 struct i915_context *i915 = I915_CONTEXT(ctx);
646
647 switch (pname) {
648 case GL_POINT_SPRITE_COORD_ORIGIN:
649 /* This could be supported, but it would require modifying the fragment
650 * program to invert the y component of the texture coordinate by
651 * inserting a 'SUB tc.y, {1.0}.xxxx, tc' instruction.
652 */
653 FALLBACK(&i915->intel, I915_FALLBACK_POINT_SPRITE_COORD_ORIGIN,
654 (params[0] != GL_UPPER_LEFT));
655 break;
656 }
657 }
658
659
660 /* =============================================================
661 * Color masks
662 */
663
664 static void
665 i915ColorMask(struct gl_context * ctx,
666 GLboolean r, GLboolean g, GLboolean b, GLboolean a)
667 {
668 struct i915_context *i915 = I915_CONTEXT(ctx);
669 GLuint tmp = i915->state.Ctx[I915_CTXREG_LIS5] & ~S5_WRITEDISABLE_MASK;
670
671 DBG("%s r(%d) g(%d) b(%d) a(%d)\n", __FUNCTION__, r, g, b,
672 a);
673
674 if (!r)
675 tmp |= S5_WRITEDISABLE_RED;
676 if (!g)
677 tmp |= S5_WRITEDISABLE_GREEN;
678 if (!b)
679 tmp |= S5_WRITEDISABLE_BLUE;
680 if (!a)
681 tmp |= S5_WRITEDISABLE_ALPHA;
682
683 if (tmp != i915->state.Ctx[I915_CTXREG_LIS5]) {
684 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
685 i915->state.Ctx[I915_CTXREG_LIS5] = tmp;
686 }
687 }
688
689 static void
690 update_specular(struct gl_context * ctx)
691 {
692 /* A hack to trigger the rebuild of the fragment program.
693 */
694 intel_context(ctx)->NewGLState |= _NEW_TEXTURE;
695 }
696
697 static void
698 i915LightModelfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
699 {
700 DBG("%s\n", __FUNCTION__);
701
702 if (pname == GL_LIGHT_MODEL_COLOR_CONTROL) {
703 update_specular(ctx);
704 }
705 }
706
707 static void
708 i915ShadeModel(struct gl_context * ctx, GLenum mode)
709 {
710 struct i915_context *i915 = I915_CONTEXT(ctx);
711 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
712
713 if (mode == GL_SMOOTH) {
714 i915->state.Ctx[I915_CTXREG_LIS4] &= ~(S4_FLATSHADE_ALPHA |
715 S4_FLATSHADE_COLOR |
716 S4_FLATSHADE_SPECULAR);
717 }
718 else {
719 i915->state.Ctx[I915_CTXREG_LIS4] |= (S4_FLATSHADE_ALPHA |
720 S4_FLATSHADE_COLOR |
721 S4_FLATSHADE_SPECULAR);
722 }
723 }
724
725 /* =============================================================
726 * Fog
727 */
728 void
729 i915_update_fog(struct gl_context * ctx)
730 {
731 struct i915_context *i915 = I915_CONTEXT(ctx);
732 GLenum mode;
733 GLboolean enabled;
734 GLboolean try_pixel_fog;
735 GLuint dw;
736
737 if (ctx->FragmentProgram._Current) {
738 /* Pull in static fog state from program */
739 mode = GL_NONE;
740 enabled = GL_FALSE;
741 try_pixel_fog = 0;
742 }
743 else {
744 enabled = ctx->Fog.Enabled;
745 mode = ctx->Fog.Mode;
746 #if 0
747 /* XXX - DISABLED -- Need ortho fallback */
748 try_pixel_fog = (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT
749 && ctx->Hint.Fog == GL_NICEST);
750 #else
751 try_pixel_fog = 0;
752 #endif
753 }
754
755 if (!enabled) {
756 i915->vertex_fog = I915_FOG_NONE;
757 }
758 else if (try_pixel_fog) {
759 I915_STATECHANGE(i915, I915_UPLOAD_FOG);
760 i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_FOGFUNC_MASK;
761 i915->vertex_fog = I915_FOG_PIXEL;
762
763 switch (mode) {
764 case GL_LINEAR:
765 if (ctx->Fog.End <= ctx->Fog.Start) {
766 /* XXX - this won't work with fragment programs. Need to
767 * either fallback or append fog instructions to end of
768 * program in the case of linear fog.
769 */
770 printf("vertex fog!\n");
771 i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_VERTEX;
772 i915->vertex_fog = I915_FOG_VERTEX;
773 }
774 else {
775 GLfloat c2 = 1.0 / (ctx->Fog.End - ctx->Fog.Start);
776 GLfloat c1 = ctx->Fog.End * c2;
777
778 i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_C1_MASK;
779 i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_LINEAR;
780 i915->state.Fog[I915_FOGREG_MODE1] |=
781 ((GLuint) (c1 * FMC1_C1_ONE)) & FMC1_C1_MASK;
782
783 if (i915->state.Fog[I915_FOGREG_MODE1] & FMC1_FOGINDEX_Z) {
784 i915->state.Fog[I915_FOGREG_MODE2]
785 = (GLuint) (c2 * FMC2_C2_ONE);
786 }
787 else {
788 fi_type fi;
789 fi.f = c2;
790 i915->state.Fog[I915_FOGREG_MODE2] = fi.i;
791 }
792 }
793 break;
794 case GL_EXP:
795 i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_EXP;
796 break;
797 case GL_EXP2:
798 i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_PIXEL_EXP2;
799 break;
800 default:
801 break;
802 }
803 }
804 else { /* if (i915->vertex_fog != I915_FOG_VERTEX) */
805 I915_STATECHANGE(i915, I915_UPLOAD_FOG);
806 i915->state.Fog[I915_FOGREG_MODE1] &= ~FMC1_FOGFUNC_MASK;
807 i915->state.Fog[I915_FOGREG_MODE1] |= FMC1_FOGFUNC_VERTEX;
808 i915->vertex_fog = I915_FOG_VERTEX;
809 }
810
811 I915_ACTIVESTATE(i915, I915_UPLOAD_FOG, enabled);
812 dw = i915->state.Ctx[I915_CTXREG_LIS5];
813 if (enabled)
814 dw |= S5_FOG_ENABLE;
815 else
816 dw &= ~S5_FOG_ENABLE;
817 if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) {
818 i915->state.Ctx[I915_CTXREG_LIS5] = dw;
819 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
820 }
821
822 /* Always enable pixel fog. Vertex fog using fog coord will conflict
823 * with fog code appended onto fragment program.
824 */
825 _tnl_allow_vertex_fog( ctx, 0 );
826 _tnl_allow_pixel_fog( ctx, 1 );
827 }
828
829 static void
830 i915Fogfv(struct gl_context * ctx, GLenum pname, const GLfloat * param)
831 {
832 struct i915_context *i915 = I915_CONTEXT(ctx);
833
834 switch (pname) {
835 case GL_FOG_COORDINATE_SOURCE_EXT:
836 case GL_FOG_MODE:
837 case GL_FOG_START:
838 case GL_FOG_END:
839 break;
840
841 case GL_FOG_DENSITY:
842 I915_STATECHANGE(i915, I915_UPLOAD_FOG);
843
844 if (i915->state.Fog[I915_FOGREG_MODE1] & FMC1_FOGINDEX_Z) {
845 i915->state.Fog[I915_FOGREG_MODE3] =
846 (GLuint) (ctx->Fog.Density * FMC3_D_ONE);
847 }
848 else {
849 fi_type fi;
850 fi.f = ctx->Fog.Density;
851 i915->state.Fog[I915_FOGREG_MODE3] = fi.i;
852 }
853 break;
854
855 case GL_FOG_COLOR:
856 I915_STATECHANGE(i915, I915_UPLOAD_FOG);
857 i915->state.Fog[I915_FOGREG_COLOR] =
858 (_3DSTATE_FOG_COLOR_CMD |
859 ((GLubyte) (ctx->Fog.Color[0] * 255.0F) << 16) |
860 ((GLubyte) (ctx->Fog.Color[1] * 255.0F) << 8) |
861 ((GLubyte) (ctx->Fog.Color[2] * 255.0F) << 0));
862 break;
863
864 default:
865 break;
866 }
867 }
868
869 static void
870 i915Hint(struct gl_context * ctx, GLenum target, GLenum state)
871 {
872 switch (target) {
873 case GL_FOG_HINT:
874 break;
875 default:
876 break;
877 }
878 }
879
880 /* =============================================================
881 */
882
883 static void
884 i915Enable(struct gl_context * ctx, GLenum cap, GLboolean state)
885 {
886 struct i915_context *i915 = I915_CONTEXT(ctx);
887 GLuint dw;
888
889 switch (cap) {
890 case GL_TEXTURE_2D:
891 break;
892
893 case GL_LIGHTING:
894 case GL_COLOR_SUM:
895 update_specular(ctx);
896 break;
897
898 case GL_ALPHA_TEST:
899 dw = i915->state.Ctx[I915_CTXREG_LIS6];
900 if (state)
901 dw |= S6_ALPHA_TEST_ENABLE;
902 else
903 dw &= ~S6_ALPHA_TEST_ENABLE;
904 if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
905 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
906 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
907 }
908 break;
909
910 case GL_BLEND:
911 i915EvalLogicOpBlendState(ctx);
912 break;
913
914 case GL_COLOR_LOGIC_OP:
915 i915EvalLogicOpBlendState(ctx);
916
917 /* Logicop doesn't seem to work at 16bpp:
918 */
919 if (ctx->Visual.rgbBits == 16)
920 FALLBACK(&i915->intel, I915_FALLBACK_LOGICOP, state);
921 break;
922
923 case GL_FRAGMENT_PROGRAM_ARB:
924 break;
925
926 case GL_DITHER:
927 dw = i915->state.Ctx[I915_CTXREG_LIS5];
928 if (state)
929 dw |= S5_COLOR_DITHER_ENABLE;
930 else
931 dw &= ~S5_COLOR_DITHER_ENABLE;
932 if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) {
933 i915->state.Ctx[I915_CTXREG_LIS5] = dw;
934 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
935 }
936 break;
937
938 case GL_DEPTH_TEST:
939 dw = i915->state.Ctx[I915_CTXREG_LIS6];
940 if (state)
941 dw |= S6_DEPTH_TEST_ENABLE;
942 else
943 dw &= ~S6_DEPTH_TEST_ENABLE;
944 if (dw != i915->state.Ctx[I915_CTXREG_LIS6]) {
945 i915->state.Ctx[I915_CTXREG_LIS6] = dw;
946 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
947 }
948
949 i915DepthMask(ctx, ctx->Depth.Mask);
950 break;
951
952 case GL_SCISSOR_TEST:
953 I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS);
954 if (state)
955 i915->state.Buffer[I915_DESTREG_SENABLE] =
956 (_3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT);
957 else
958 i915->state.Buffer[I915_DESTREG_SENABLE] =
959 (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
960 break;
961
962 case GL_LINE_SMOOTH:
963 dw = i915->state.Ctx[I915_CTXREG_LIS4];
964 if (state)
965 dw |= S4_LINE_ANTIALIAS_ENABLE;
966 else
967 dw &= ~S4_LINE_ANTIALIAS_ENABLE;
968 if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
969 i915->state.Ctx[I915_CTXREG_LIS4] = dw;
970 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
971 }
972 break;
973
974 case GL_FOG:
975 break;
976
977 case GL_CULL_FACE:
978 i915CullFaceFrontFace(ctx, 0);
979 break;
980
981 case GL_STENCIL_TEST:
982 {
983 GLboolean hw_stencil = GL_FALSE;
984 if (ctx->DrawBuffer) {
985 struct intel_renderbuffer *irbStencil
986 = intel_get_renderbuffer(ctx->DrawBuffer, BUFFER_STENCIL);
987 hw_stencil = (irbStencil && irbStencil->region);
988 }
989 if (hw_stencil) {
990 dw = i915->state.Ctx[I915_CTXREG_LIS5];
991 if (state)
992 dw |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE);
993 else
994 dw &= ~(S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE);
995 if (dw != i915->state.Ctx[I915_CTXREG_LIS5]) {
996 i915->state.Ctx[I915_CTXREG_LIS5] = dw;
997 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
998 }
999 }
1000 else {
1001 FALLBACK(&i915->intel, I915_FALLBACK_STENCIL, state);
1002 }
1003 }
1004 break;
1005
1006 case GL_POLYGON_STIPPLE:
1007 /* The stipple command worked on my 855GM box, but not my 845G.
1008 * I'll do more testing later to find out exactly which hardware
1009 * supports it. Disabled for now.
1010 */
1011 if (i915->intel.hw_stipple &&
1012 i915->intel.reduced_primitive == GL_TRIANGLES) {
1013 I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
1014 if (state)
1015 i915->state.Stipple[I915_STPREG_ST1] |= ST1_ENABLE;
1016 else
1017 i915->state.Stipple[I915_STPREG_ST1] &= ~ST1_ENABLE;
1018 }
1019 break;
1020
1021 case GL_POLYGON_SMOOTH:
1022 break;
1023
1024 case GL_POINT_SPRITE:
1025 /* This state change is handled in i915_reduced_primitive_state because
1026 * the hardware bit should only be set when rendering points.
1027 */
1028 dw = i915->state.Ctx[I915_CTXREG_LIS4];
1029 if (state)
1030 dw |= S4_SPRITE_POINT_ENABLE;
1031 else
1032 dw &= ~S4_SPRITE_POINT_ENABLE;
1033 if (dw != i915->state.Ctx[I915_CTXREG_LIS4]) {
1034 i915->state.Ctx[I915_CTXREG_LIS4] = dw;
1035 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
1036 }
1037 break;
1038
1039 case GL_POINT_SMOOTH:
1040 break;
1041
1042 default:
1043 ;
1044 }
1045 }
1046
1047
1048 static void
1049 i915_init_packets(struct i915_context *i915)
1050 {
1051 /* Zero all state */
1052 memset(&i915->state, 0, sizeof(i915->state));
1053
1054
1055 {
1056 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
1057 I915_STATECHANGE(i915, I915_UPLOAD_BLEND);
1058 /* Probably don't want to upload all this stuff every time one
1059 * piece changes.
1060 */
1061 i915->state.Ctx[I915_CTXREG_LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
1062 I1_LOAD_S(2) |
1063 I1_LOAD_S(4) |
1064 I1_LOAD_S(5) | I1_LOAD_S(6) | (3));
1065 i915->state.Ctx[I915_CTXREG_LIS2] = 0;
1066 i915->state.Ctx[I915_CTXREG_LIS4] = 0;
1067 i915->state.Ctx[I915_CTXREG_LIS5] = 0;
1068
1069 if (i915->intel.ctx.Visual.rgbBits == 16)
1070 i915->state.Ctx[I915_CTXREG_LIS5] |= S5_COLOR_DITHER_ENABLE;
1071
1072
1073 i915->state.Ctx[I915_CTXREG_LIS6] = (S6_COLOR_WRITE_ENABLE |
1074 (2 << S6_TRISTRIP_PV_SHIFT));
1075
1076 i915->state.Ctx[I915_CTXREG_STATE4] = (_3DSTATE_MODES_4_CMD |
1077 ENABLE_LOGIC_OP_FUNC |
1078 LOGIC_OP_FUNC(LOGICOP_COPY) |
1079 ENABLE_STENCIL_TEST_MASK |
1080 STENCIL_TEST_MASK(0xff) |
1081 ENABLE_STENCIL_WRITE_MASK |
1082 STENCIL_WRITE_MASK(0xff));
1083
1084 i915->state.Blend[I915_BLENDREG_IAB] =
1085 (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | IAB_MODIFY_ENABLE |
1086 IAB_MODIFY_FUNC | IAB_MODIFY_SRC_FACTOR | IAB_MODIFY_DST_FACTOR);
1087
1088 i915->state.Blend[I915_BLENDREG_BLENDCOLOR0] =
1089 _3DSTATE_CONST_BLEND_COLOR_CMD;
1090 i915->state.Blend[I915_BLENDREG_BLENDCOLOR1] = 0;
1091
1092 i915->state.Ctx[I915_CTXREG_BF_STENCIL_MASKS] =
1093 _3DSTATE_BACKFACE_STENCIL_MASKS |
1094 BFM_ENABLE_STENCIL_TEST_MASK |
1095 BFM_ENABLE_STENCIL_WRITE_MASK |
1096 (0xff << BFM_STENCIL_WRITE_MASK_SHIFT) |
1097 (0xff << BFM_STENCIL_TEST_MASK_SHIFT);
1098 i915->state.Ctx[I915_CTXREG_BF_STENCIL_OPS] =
1099 _3DSTATE_BACKFACE_STENCIL_OPS |
1100 BFO_ENABLE_STENCIL_REF |
1101 BFO_ENABLE_STENCIL_FUNCS |
1102 BFO_ENABLE_STENCIL_TWO_SIDE;
1103 }
1104
1105 {
1106 I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
1107 i915->state.Stipple[I915_STPREG_ST0] = _3DSTATE_STIPPLE;
1108 }
1109
1110
1111 {
1112 I915_STATECHANGE(i915, I915_UPLOAD_FOG);
1113 i915->state.Fog[I915_FOGREG_MODE0] = _3DSTATE_FOG_MODE_CMD;
1114 i915->state.Fog[I915_FOGREG_MODE1] = (FMC1_FOGFUNC_MODIFY_ENABLE |
1115 FMC1_FOGFUNC_VERTEX |
1116 FMC1_FOGINDEX_MODIFY_ENABLE |
1117 FMC1_FOGINDEX_W |
1118 FMC1_C1_C2_MODIFY_ENABLE |
1119 FMC1_DENSITY_MODIFY_ENABLE);
1120 i915->state.Fog[I915_FOGREG_COLOR] = _3DSTATE_FOG_COLOR_CMD;
1121 }
1122
1123 {
1124 i915->state.Buffer[I915_DESTREG_DV0] = _3DSTATE_DST_BUF_VARS_CMD;
1125
1126 /* scissor */
1127 i915->state.Buffer[I915_DESTREG_SENABLE] =
1128 (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
1129 i915->state.Buffer[I915_DESTREG_SR0] = _3DSTATE_SCISSOR_RECT_0_CMD;
1130 i915->state.Buffer[I915_DESTREG_SR1] = 0;
1131 i915->state.Buffer[I915_DESTREG_SR2] = 0;
1132 }
1133
1134 i915->state.RasterRules[I915_RASTER_RULES] = _3DSTATE_RASTER_RULES_CMD |
1135 ENABLE_POINT_RASTER_RULE |
1136 OGL_POINT_RASTER_RULE |
1137 ENABLE_LINE_STRIP_PROVOKE_VRTX |
1138 ENABLE_TRI_FAN_PROVOKE_VRTX |
1139 LINE_STRIP_PROVOKE_VRTX(1) |
1140 TRI_FAN_PROVOKE_VRTX(2) | ENABLE_TEXKILL_3D_4D | TEXKILL_4D;
1141
1142 #if 0
1143 {
1144 I915_STATECHANGE(i915, I915_UPLOAD_DEFAULTS);
1145 i915->state.Default[I915_DEFREG_C0] = _3DSTATE_DEFAULT_DIFFUSE;
1146 i915->state.Default[I915_DEFREG_C1] = 0;
1147 i915->state.Default[I915_DEFREG_S0] = _3DSTATE_DEFAULT_SPECULAR;
1148 i915->state.Default[I915_DEFREG_S1] = 0;
1149 i915->state.Default[I915_DEFREG_Z0] = _3DSTATE_DEFAULT_Z;
1150 i915->state.Default[I915_DEFREG_Z1] = 0;
1151 }
1152 #endif
1153
1154
1155 /* These will be emitted every at the head of every buffer, unless
1156 * we get hardware contexts working.
1157 */
1158 i915->state.active = (I915_UPLOAD_PROGRAM |
1159 I915_UPLOAD_STIPPLE |
1160 I915_UPLOAD_CTX |
1161 I915_UPLOAD_BLEND |
1162 I915_UPLOAD_BUFFERS |
1163 I915_UPLOAD_INVARIENT |
1164 I915_UPLOAD_RASTER_RULES);
1165 }
1166
1167 void
1168 i915_update_provoking_vertex(struct gl_context * ctx)
1169 {
1170 struct i915_context *i915 = I915_CONTEXT(ctx);
1171
1172 I915_STATECHANGE(i915, I915_UPLOAD_CTX);
1173 i915->state.Ctx[I915_CTXREG_LIS6] &= ~(S6_TRISTRIP_PV_MASK);
1174
1175 I915_STATECHANGE(i915, I915_UPLOAD_RASTER_RULES);
1176 i915->state.RasterRules[I915_RASTER_RULES] &= ~(LINE_STRIP_PROVOKE_VRTX_MASK |
1177 TRI_FAN_PROVOKE_VRTX_MASK);
1178
1179 /* _NEW_LIGHT */
1180 if (ctx->Light.ProvokingVertex == GL_LAST_VERTEX_CONVENTION) {
1181 i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(1) |
1182 TRI_FAN_PROVOKE_VRTX(2));
1183 i915->state.Ctx[I915_CTXREG_LIS6] |= (2 << S6_TRISTRIP_PV_SHIFT);
1184 } else {
1185 i915->state.RasterRules[I915_RASTER_RULES] |= (LINE_STRIP_PROVOKE_VRTX(0) |
1186 TRI_FAN_PROVOKE_VRTX(1));
1187 i915->state.Ctx[I915_CTXREG_LIS6] |= (0 << S6_TRISTRIP_PV_SHIFT);
1188 }
1189 }
1190
1191 void
1192 i915InitStateFunctions(struct dd_function_table *functions)
1193 {
1194 functions->AlphaFunc = i915AlphaFunc;
1195 functions->BlendColor = i915BlendColor;
1196 functions->BlendEquationSeparate = i915BlendEquationSeparate;
1197 functions->BlendFuncSeparate = i915BlendFuncSeparate;
1198 functions->ColorMask = i915ColorMask;
1199 functions->CullFace = i915CullFaceFrontFace;
1200 functions->DepthFunc = i915DepthFunc;
1201 functions->DepthMask = i915DepthMask;
1202 functions->Enable = i915Enable;
1203 functions->Fogfv = i915Fogfv;
1204 functions->FrontFace = i915CullFaceFrontFace;
1205 functions->Hint = i915Hint;
1206 functions->LightModelfv = i915LightModelfv;
1207 functions->LineWidth = i915LineWidth;
1208 functions->LogicOpcode = i915LogicOp;
1209 functions->PointSize = i915PointSize;
1210 functions->PointParameterfv = i915PointParameterfv;
1211 functions->PolygonStipple = i915PolygonStipple;
1212 functions->Scissor = i915Scissor;
1213 functions->ShadeModel = i915ShadeModel;
1214 functions->StencilFuncSeparate = i915StencilFuncSeparate;
1215 functions->StencilMaskSeparate = i915StencilMaskSeparate;
1216 functions->StencilOpSeparate = i915StencilOpSeparate;
1217 functions->DepthRange = i915DepthRange;
1218 functions->Viewport = i915Viewport;
1219 }
1220
1221
1222 void
1223 i915InitState(struct i915_context *i915)
1224 {
1225 struct gl_context *ctx = &i915->intel.ctx;
1226
1227 i915_init_packets(i915);
1228
1229 _mesa_init_driver_state(ctx);
1230 }