Merge branch 'nouveau-gallium-0.1' into darktama-gallium-0.1
[mesa.git] / src / mesa / pipe / i915simple / i915_state.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31
32 #include "pipe/draw/draw_context.h"
33 #include "pipe/p_winsys.h"
34 #include "pipe/p_util.h"
35
36 #include "i915_context.h"
37 #include "i915_reg.h"
38 #include "i915_state.h"
39 #include "i915_state_inlines.h"
40
41
42 /* The i915 (and related graphics cores) do not support GL_CLAMP. The
43 * Intel drivers for "other operating systems" implement GL_CLAMP as
44 * GL_CLAMP_TO_EDGE, so the same is done here.
45 */
46 static unsigned
47 translate_wrap_mode(unsigned wrap)
48 {
49 switch (wrap) {
50 case PIPE_TEX_WRAP_REPEAT:
51 return TEXCOORDMODE_WRAP;
52 case PIPE_TEX_WRAP_CLAMP:
53 return TEXCOORDMODE_CLAMP_EDGE; /* not quite correct */
54 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
55 return TEXCOORDMODE_CLAMP_EDGE;
56 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
57 return TEXCOORDMODE_CLAMP_BORDER;
58 // case PIPE_TEX_WRAP_MIRRORED_REPEAT:
59 // return TEXCOORDMODE_MIRROR;
60 default:
61 return TEXCOORDMODE_WRAP;
62 }
63 }
64
65 static unsigned translate_img_filter( unsigned filter )
66 {
67 switch (filter) {
68 case PIPE_TEX_FILTER_NEAREST:
69 return FILTER_NEAREST;
70 case PIPE_TEX_FILTER_LINEAR:
71 return FILTER_LINEAR;
72 default:
73 assert(0);
74 return FILTER_NEAREST;
75 }
76 }
77
78 static unsigned translate_mip_filter( unsigned filter )
79 {
80 switch (filter) {
81 case PIPE_TEX_MIPFILTER_NONE:
82 return MIPFILTER_NONE;
83 case PIPE_TEX_MIPFILTER_NEAREST:
84 return MIPFILTER_NEAREST;
85 case PIPE_TEX_FILTER_LINEAR:
86 return MIPFILTER_LINEAR;
87 default:
88 assert(0);
89 return MIPFILTER_NONE;
90 }
91 }
92
93
94 /* None of this state is actually used for anything yet.
95 */
96 static void *
97 i915_create_blend_state(struct pipe_context *pipe,
98 const struct pipe_blend_state *blend)
99 {
100 struct i915_blend_state *cso_data = CALLOC_STRUCT( i915_blend_state );
101
102 {
103 unsigned eqRGB = blend->rgb_func;
104 unsigned srcRGB = blend->rgb_src_factor;
105 unsigned dstRGB = blend->rgb_dst_factor;
106
107 unsigned eqA = blend->alpha_func;
108 unsigned srcA = blend->alpha_src_factor;
109 unsigned dstA = blend->alpha_dst_factor;
110
111 /* Special handling for MIN/MAX filter modes handled at
112 * state_tracker level.
113 */
114
115 if (srcA != srcRGB ||
116 dstA != dstRGB ||
117 eqA != eqRGB) {
118
119 cso_data->iab = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD |
120 IAB_MODIFY_ENABLE |
121 IAB_ENABLE |
122 IAB_MODIFY_FUNC |
123 IAB_MODIFY_SRC_FACTOR |
124 IAB_MODIFY_DST_FACTOR |
125 SRC_ABLND_FACT(i915_translate_blend_factor(srcA)) |
126 DST_ABLND_FACT(i915_translate_blend_factor(dstA)) |
127 (i915_translate_blend_func(eqA) << IAB_FUNC_SHIFT));
128 }
129 else {
130 cso_data->iab = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD |
131 IAB_MODIFY_ENABLE |
132 0);
133 }
134 }
135
136 cso_data->modes4 |= (_3DSTATE_MODES_4_CMD |
137 ENABLE_LOGIC_OP_FUNC |
138 LOGIC_OP_FUNC(i915_translate_logic_op(blend->logicop_func)));
139
140 if (blend->logicop_enable)
141 cso_data->LIS5 |= S5_LOGICOP_ENABLE;
142
143 if (blend->dither)
144 cso_data->LIS5 |= S5_COLOR_DITHER_ENABLE;
145
146 if ((blend->colormask & PIPE_MASK_R) == 0)
147 cso_data->LIS5 |= S5_WRITEDISABLE_RED;
148
149 if ((blend->colormask & PIPE_MASK_G) == 0)
150 cso_data->LIS5 |= S5_WRITEDISABLE_GREEN;
151
152 if ((blend->colormask & PIPE_MASK_B) == 0)
153 cso_data->LIS5 |= S5_WRITEDISABLE_BLUE;
154
155 if ((blend->colormask & PIPE_MASK_A) == 0)
156 cso_data->LIS5 |= S5_WRITEDISABLE_ALPHA;
157
158 if (blend->blend_enable) {
159 unsigned funcRGB = blend->rgb_func;
160 unsigned srcRGB = blend->rgb_src_factor;
161 unsigned dstRGB = blend->rgb_dst_factor;
162
163 cso_data->LIS6 |= (S6_CBUF_BLEND_ENABLE |
164 SRC_BLND_FACT(i915_translate_blend_factor(srcRGB)) |
165 DST_BLND_FACT(i915_translate_blend_factor(dstRGB)) |
166 (i915_translate_blend_func(funcRGB) << S6_CBUF_BLEND_FUNC_SHIFT));
167 }
168
169 return cso_data;
170 }
171
172 static void i915_bind_blend_state(struct pipe_context *pipe,
173 void *blend)
174 {
175 struct i915_context *i915 = i915_context(pipe);
176
177 i915->blend = (struct i915_blend_state*)blend;
178
179 i915->dirty |= I915_NEW_BLEND;
180 }
181
182
183 static void i915_delete_blend_state(struct pipe_context *pipe, void *blend)
184 {
185 FREE(blend);
186 }
187
188 static void i915_set_blend_color( struct pipe_context *pipe,
189 const struct pipe_blend_color *blend_color )
190 {
191 struct i915_context *i915 = i915_context(pipe);
192
193 i915->blend_color = *blend_color;
194
195 i915->dirty |= I915_NEW_BLEND;
196 }
197
198 static void *
199 i915_create_sampler_state(struct pipe_context *pipe,
200 const struct pipe_sampler_state *sampler)
201 {
202 struct i915_sampler_state *cso = CALLOC_STRUCT( i915_sampler_state );
203 const unsigned ws = sampler->wrap_s;
204 const unsigned wt = sampler->wrap_t;
205 const unsigned wr = sampler->wrap_r;
206 unsigned minFilt, magFilt;
207 unsigned mipFilt;
208
209 cso->templ = sampler;
210
211 mipFilt = translate_mip_filter(sampler->min_mip_filter);
212 if (sampler->max_anisotropy > 1.0) {
213 minFilt = FILTER_ANISOTROPIC;
214 magFilt = FILTER_ANISOTROPIC;
215 if (sampler->max_anisotropy > 2.0) {
216 cso->state[0] |= SS2_MAX_ANISO_4;
217 }
218 }
219 else {
220 minFilt = translate_img_filter( sampler->min_img_filter );
221 magFilt = translate_img_filter( sampler->mag_img_filter );
222 }
223
224 {
225 int b = (int) (sampler->lod_bias * 16.0);
226 b = CLAMP(b, -256, 255);
227 cso->state[0] |= ((b << SS2_LOD_BIAS_SHIFT) & SS2_LOD_BIAS_MASK);
228 }
229
230 /* Shadow:
231 */
232 if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE)
233 {
234 cso->state[0] |= (SS2_SHADOW_ENABLE |
235 i915_translate_compare_func(sampler->compare_func));
236
237 minFilt = FILTER_4X4_FLAT;
238 magFilt = FILTER_4X4_FLAT;
239 }
240
241 cso->state[0] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
242 (mipFilt << SS2_MIP_FILTER_SHIFT) |
243 (magFilt << SS2_MAG_FILTER_SHIFT));
244
245 cso->state[1] |=
246 ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
247 (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
248 (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
249
250 if (sampler->normalized_coords)
251 cso->state[1] |= SS3_NORMALIZED_COORDS;
252
253 {
254 ubyte r = float_to_ubyte(sampler->border_color[0]);
255 ubyte g = float_to_ubyte(sampler->border_color[1]);
256 ubyte b = float_to_ubyte(sampler->border_color[2]);
257 ubyte a = float_to_ubyte(sampler->border_color[3]);
258 cso->state[2] = I915PACKCOLOR8888(r, g, b, a);
259 }
260 return cso;
261 }
262
263 static void i915_bind_sampler_state(struct pipe_context *pipe,
264 unsigned unit, void *sampler)
265 {
266 struct i915_context *i915 = i915_context(pipe);
267
268 assert(unit < PIPE_MAX_SAMPLERS);
269 i915->sampler[unit] = (const struct i915_sampler_state*)sampler;
270
271 i915->dirty |= I915_NEW_SAMPLER;
272 }
273
274 static void i915_delete_sampler_state(struct pipe_context *pipe,
275 void *sampler)
276 {
277 FREE(sampler);
278 }
279
280
281 /** XXX move someday? Or consolidate all these simple state setters
282 * into one file.
283 */
284
285 static void *
286 i915_create_depth_stencil_state(struct pipe_context *pipe,
287 const struct pipe_depth_stencil_state *depth_stencil)
288 {
289 struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state );
290
291 {
292 int testmask = depth_stencil->stencil.value_mask[0] & 0xff;
293 int writemask = depth_stencil->stencil.write_mask[0] & 0xff;
294
295 cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD |
296 ENABLE_STENCIL_TEST_MASK |
297 STENCIL_TEST_MASK(testmask) |
298 ENABLE_STENCIL_WRITE_MASK |
299 STENCIL_WRITE_MASK(writemask));
300 }
301
302 if (depth_stencil->stencil.front_enabled) {
303 int test = i915_translate_compare_func(depth_stencil->stencil.front_func);
304 int fop = i915_translate_stencil_op(depth_stencil->stencil.front_fail_op);
305 int dfop = i915_translate_stencil_op(depth_stencil->stencil.front_zfail_op);
306 int dpop = i915_translate_stencil_op(depth_stencil->stencil.front_zpass_op);
307 int ref = depth_stencil->stencil.ref_value[0] & 0xff;
308
309 cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE |
310 S5_STENCIL_WRITE_ENABLE |
311 (ref << S5_STENCIL_REF_SHIFT) |
312 (test << S5_STENCIL_TEST_FUNC_SHIFT) |
313 (fop << S5_STENCIL_FAIL_SHIFT) |
314 (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) |
315 (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT));
316 }
317
318 if (depth_stencil->stencil.back_enabled) {
319 int test = i915_translate_compare_func(depth_stencil->stencil.back_func);
320 int fop = i915_translate_stencil_op(depth_stencil->stencil.back_fail_op);
321 int dfop = i915_translate_stencil_op(depth_stencil->stencil.back_zfail_op);
322 int dpop = i915_translate_stencil_op(depth_stencil->stencil.back_zpass_op);
323 int ref = depth_stencil->stencil.ref_value[1] & 0xff;
324 int tmask = depth_stencil->stencil.value_mask[1] & 0xff;
325 int wmask = depth_stencil->stencil.write_mask[1] & 0xff;
326
327 cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS |
328 BFO_ENABLE_STENCIL_FUNCS |
329 BFO_ENABLE_STENCIL_TWO_SIDE |
330 BFO_ENABLE_STENCIL_REF |
331 BFO_STENCIL_TWO_SIDE |
332 (ref << BFO_STENCIL_REF_SHIFT) |
333 (test << BFO_STENCIL_TEST_SHIFT) |
334 (fop << BFO_STENCIL_FAIL_SHIFT) |
335 (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) |
336 (dpop << BFO_STENCIL_PASS_Z_PASS_SHIFT));
337
338 cso->bfo[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS |
339 BFM_ENABLE_STENCIL_TEST_MASK |
340 BFM_ENABLE_STENCIL_WRITE_MASK |
341 (tmask << BFM_STENCIL_TEST_MASK_SHIFT) |
342 (wmask << BFM_STENCIL_WRITE_MASK_SHIFT));
343 }
344 else {
345 /* This actually disables two-side stencil: The bit set is a
346 * modify-enable bit to indicate we are changing the two-side
347 * setting. Then there is a symbolic zero to show that we are
348 * setting the flag to zero/off.
349 */
350 cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS |
351 BFO_ENABLE_STENCIL_TWO_SIDE |
352 0);
353 cso->bfo[1] = 0;
354 }
355
356 if (depth_stencil->depth.enabled) {
357 int func = i915_translate_compare_func(depth_stencil->depth.func);
358
359 cso->depth_LIS6 |= (S6_DEPTH_TEST_ENABLE |
360 (func << S6_DEPTH_TEST_FUNC_SHIFT));
361
362 if (depth_stencil->depth.writemask)
363 cso->depth_LIS6 |= S6_DEPTH_WRITE_ENABLE;
364 }
365
366 return cso;
367 }
368
369 static void i915_bind_depth_stencil_state(struct pipe_context *pipe,
370 void *depth_stencil)
371 {
372 struct i915_context *i915 = i915_context(pipe);
373
374 i915->depth_stencil = (const struct i915_depth_stencil_state *)depth_stencil;
375
376 i915->dirty |= I915_NEW_DEPTH_STENCIL;
377 }
378
379 static void i915_delete_depth_stencil_state(struct pipe_context *pipe,
380 void *depth_stencil)
381 {
382 FREE(depth_stencil);
383 }
384
385
386 static void *
387 i915_create_alpha_test_state(struct pipe_context *pipe,
388 const struct pipe_alpha_test_state *alpha_test)
389 {
390 struct i915_alpha_test_state *cso = CALLOC_STRUCT( i915_alpha_test_state );
391
392 if (alpha_test->enabled) {
393 int test = i915_translate_compare_func(alpha_test->func);
394 ubyte refByte = float_to_ubyte(alpha_test->ref);
395
396 cso->LIS6 |= (S6_ALPHA_TEST_ENABLE |
397 (test << S6_ALPHA_TEST_FUNC_SHIFT) |
398 (((unsigned) refByte) << S6_ALPHA_REF_SHIFT));
399 }
400 return cso;
401 }
402
403 static void i915_bind_alpha_test_state(struct pipe_context *pipe,
404 void *alpha)
405 {
406 struct i915_context *i915 = i915_context(pipe);
407
408 i915->alpha_test = (const struct i915_alpha_test_state*)alpha;
409
410 i915->dirty |= I915_NEW_ALPHA_TEST;
411 }
412
413 static void i915_delete_alpha_test_state(struct pipe_context *pipe,
414 void *alpha)
415 {
416 FREE(alpha);
417 }
418
419 static void i915_set_scissor_state( struct pipe_context *pipe,
420 const struct pipe_scissor_state *scissor )
421 {
422 struct i915_context *i915 = i915_context(pipe);
423
424 memcpy( &i915->scissor, scissor, sizeof(*scissor) );
425 i915->dirty |= I915_NEW_SCISSOR;
426 }
427
428
429 static void i915_set_polygon_stipple( struct pipe_context *pipe,
430 const struct pipe_poly_stipple *stipple )
431 {
432 }
433
434 static void i915_set_sampler_units(struct pipe_context *pipe,
435 uint numSamplers, const uint *units)
436 {
437 struct i915_context *i915 = i915_context(pipe);
438 uint i;
439 for (i = 0; i < numSamplers; i++)
440 i915->sampler_units[i] = units[i];
441 }
442
443 static void * i915_create_fs_state(struct pipe_context *pipe,
444 const struct pipe_shader_state *templ)
445 {
446 return 0;
447 }
448
449 static void i915_bind_fs_state(struct pipe_context *pipe, void *fs)
450 {
451 struct i915_context *i915 = i915_context(pipe);
452
453 i915->fs = (struct pipe_shader_state *)fs;
454
455 i915->dirty |= I915_NEW_FS;
456 }
457
458 static void i915_delete_fs_state(struct pipe_context *pipe, void *shader)
459 {
460 /*do nothing*/
461 }
462
463 static void *
464 i915_create_vs_state(struct pipe_context *pipe,
465 const struct pipe_shader_state *templ)
466 {
467 struct i915_context *i915 = i915_context(pipe);
468
469 /* just pass-through to draw module */
470 return draw_create_vertex_shader(i915->draw, templ);
471 }
472
473 static void i915_bind_vs_state(struct pipe_context *pipe, void *vs)
474 {
475 struct i915_context *i915 = i915_context(pipe);
476
477 /* just pass-through to draw module */
478 draw_bind_vertex_shader(i915->draw, vs);
479 }
480
481 static void i915_delete_vs_state(struct pipe_context *pipe, void *shader)
482 {
483 struct i915_context *i915 = i915_context(pipe);
484
485 /* just pass-through to draw module */
486 draw_delete_vertex_shader(i915->draw, shader);
487 }
488
489 static void i915_set_constant_buffer(struct pipe_context *pipe,
490 uint shader, uint index,
491 const struct pipe_constant_buffer *buf)
492 {
493 struct i915_context *i915 = i915_context(pipe);
494 struct pipe_winsys *ws = pipe->winsys;
495
496 assert(shader < PIPE_SHADER_TYPES);
497 assert(index == 0);
498
499 /* Make a copy of shader constants.
500 * During fragment program translation we may add additional
501 * constants to the array.
502 *
503 * We want to consider the situation where some user constants
504 * (ex: a material color) may change frequently but the shader program
505 * stays the same. In that case we should only be updating the first
506 * N constants, leaving any extras from shader translation alone.
507 */
508 {
509 void *mapped;
510 if (buf->size &&
511 (mapped = ws->buffer_map(ws, buf->buffer, PIPE_BUFFER_FLAG_READ))) {
512 memcpy(i915->current.constants[shader], mapped, buf->size);
513 ws->buffer_unmap(ws, buf->buffer);
514 i915->current.num_user_constants[shader]
515 = buf->size / (4 * sizeof(float));
516 }
517 else {
518 i915->current.num_user_constants[shader] = 0;
519 }
520 }
521
522 i915->dirty |= I915_NEW_CONSTANTS;
523 }
524
525
526 static void i915_set_texture_state(struct pipe_context *pipe,
527 unsigned unit,
528 struct pipe_texture *texture)
529 {
530 struct i915_context *i915 = i915_context(pipe);
531
532 i915->texture[unit] = (struct i915_texture*)texture; /* ptr, not struct */
533
534 i915->dirty |= I915_NEW_TEXTURE;
535 }
536
537
538
539 static void i915_set_framebuffer_state(struct pipe_context *pipe,
540 const struct pipe_framebuffer_state *fb)
541 {
542 struct i915_context *i915 = i915_context(pipe);
543
544 i915->framebuffer = *fb; /* struct copy */
545
546 i915->dirty |= I915_NEW_FRAMEBUFFER;
547 }
548
549
550 static void
551 i915_set_feedback_state(struct pipe_context *pipe,
552 const struct pipe_feedback_state *feedback)
553 {
554 struct i915_context *i915 = i915_context(pipe);
555 i915->feedback = *feedback;
556 draw_set_feedback_state(i915->draw, feedback);
557 }
558
559
560 static void
561 i915_set_feedback_buffer(struct pipe_context *pipe,
562 unsigned index,
563 const struct pipe_feedback_buffer *feedback)
564 {
565 struct i915_context *i915 = i915_context(pipe);
566
567 assert(index < PIPE_MAX_FEEDBACK_ATTRIBS);
568
569 /* Need to be careful with referencing */
570 pipe->winsys->buffer_reference(pipe->winsys,
571 &i915->feedback_buffer[index].buffer,
572 feedback->buffer);
573 i915->feedback_buffer[index].size = feedback->size;
574 i915->feedback_buffer[index].start_offset = feedback->start_offset;
575 }
576
577
578
579 static void i915_set_clear_color_state(struct pipe_context *pipe,
580 const struct pipe_clear_color_state *clear)
581 {
582 struct i915_context *i915 = i915_context(pipe);
583
584 i915->clear_color = *clear; /* struct copy */
585 }
586
587
588
589 static void i915_set_clip_state( struct pipe_context *pipe,
590 const struct pipe_clip_state *clip )
591 {
592 struct i915_context *i915 = i915_context(pipe);
593
594 draw_set_clip_state(i915->draw, clip);
595
596 i915->dirty |= I915_NEW_CLIP;
597 }
598
599
600
601 /* Called when driver state tracker notices changes to the viewport
602 * matrix:
603 */
604 static void i915_set_viewport_state( struct pipe_context *pipe,
605 const struct pipe_viewport_state *viewport )
606 {
607 struct i915_context *i915 = i915_context(pipe);
608
609 i915->viewport = *viewport; /* struct copy */
610
611 /* pass the viewport info to the draw module */
612 draw_set_viewport_state(i915->draw, &i915->viewport);
613
614 i915->dirty |= I915_NEW_VIEWPORT;
615 }
616
617
618 static void *
619 i915_create_rasterizer_state(struct pipe_context *pipe,
620 const struct pipe_rasterizer_state *rasterizer)
621 {
622 struct i915_rasterizer_state *cso = CALLOC_STRUCT( i915_rasterizer_state );
623
624 cso->templ = rasterizer;
625 cso->color_interp = rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
626 cso->light_twoside = rasterizer->light_twoside;
627 cso->ds[0].u = _3DSTATE_DEPTH_OFFSET_SCALE;
628 cso->ds[1].f = rasterizer->offset_scale;
629 if (rasterizer->poly_stipple_enable) {
630 cso->st |= ST1_ENABLE;
631 }
632
633 if (rasterizer->scissor)
634 cso->sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT;
635 else
636 cso->sc[0] = _3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT;
637
638 switch (rasterizer->cull_mode) {
639 case PIPE_WINDING_NONE:
640 cso->LIS4 |= S4_CULLMODE_NONE;
641 break;
642 case PIPE_WINDING_CW:
643 cso->LIS4 |= S4_CULLMODE_CW;
644 break;
645 case PIPE_WINDING_CCW:
646 cso->LIS4 |= S4_CULLMODE_CCW;
647 break;
648 case PIPE_WINDING_BOTH:
649 cso->LIS4 |= S4_CULLMODE_BOTH;
650 break;
651 }
652
653 {
654 int line_width = CLAMP((int)(rasterizer->line_width * 2), 1, 0xf);
655
656 cso->LIS4 |= line_width << S4_LINE_WIDTH_SHIFT;
657
658 if (rasterizer->line_smooth)
659 cso->LIS4 |= S4_LINE_ANTIALIAS_ENABLE;
660 }
661
662 {
663 int point_size = CLAMP((int) rasterizer->point_size, 1, 0xff);
664
665 cso->LIS4 |= point_size << S4_POINT_WIDTH_SHIFT;
666 }
667
668 if (rasterizer->flatshade) {
669 cso->LIS4 |= (S4_FLATSHADE_ALPHA |
670 S4_FLATSHADE_COLOR |
671 S4_FLATSHADE_SPECULAR);
672 }
673
674 cso->LIS7 = fui( rasterizer->offset_units );
675
676
677 return cso;
678 }
679
680 static void i915_bind_rasterizer_state( struct pipe_context *pipe,
681 void *setup )
682 {
683 struct i915_context *i915 = i915_context(pipe);
684
685 i915->rasterizer = (struct i915_rasterizer_state *)setup;
686
687 /* pass-through to draw module */
688 draw_set_rasterizer_state(i915->draw, i915->rasterizer->templ);
689
690 i915->dirty |= I915_NEW_RASTERIZER;
691 }
692
693 static void i915_delete_rasterizer_state(struct pipe_context *pipe,
694 void *setup)
695 {
696 FREE(setup);
697 }
698
699 static void i915_set_vertex_buffer( struct pipe_context *pipe,
700 unsigned index,
701 const struct pipe_vertex_buffer *buffer )
702 {
703 struct i915_context *i915 = i915_context(pipe);
704 i915->vertex_buffer[index] = *buffer;
705 /* pass-through to draw module */
706 draw_set_vertex_buffer(i915->draw, index, buffer);
707 }
708
709 static void i915_set_vertex_element( struct pipe_context *pipe,
710 unsigned index,
711 const struct pipe_vertex_element *element)
712 {
713 struct i915_context *i915 = i915_context(pipe);
714 /* pass-through to draw module */
715 draw_set_vertex_element(i915->draw, index, element);
716 }
717
718
719
720 void
721 i915_init_state_functions( struct i915_context *i915 )
722 {
723 i915->pipe.create_alpha_test_state = i915_create_alpha_test_state;
724 i915->pipe.bind_alpha_test_state = i915_bind_alpha_test_state;
725 i915->pipe.delete_alpha_test_state = i915_delete_alpha_test_state;
726
727 i915->pipe.create_blend_state = i915_create_blend_state;
728 i915->pipe.bind_blend_state = i915_bind_blend_state;
729 i915->pipe.delete_blend_state = i915_delete_blend_state;
730
731 i915->pipe.create_sampler_state = i915_create_sampler_state;
732 i915->pipe.bind_sampler_state = i915_bind_sampler_state;
733 i915->pipe.delete_sampler_state = i915_delete_sampler_state;
734
735 i915->pipe.create_depth_stencil_state = i915_create_depth_stencil_state;
736 i915->pipe.bind_depth_stencil_state = i915_bind_depth_stencil_state;
737 i915->pipe.delete_depth_stencil_state = i915_delete_depth_stencil_state;
738
739 i915->pipe.create_rasterizer_state = i915_create_rasterizer_state;
740 i915->pipe.bind_rasterizer_state = i915_bind_rasterizer_state;
741 i915->pipe.delete_rasterizer_state = i915_delete_rasterizer_state;
742 i915->pipe.create_fs_state = i915_create_fs_state;
743 i915->pipe.bind_fs_state = i915_bind_fs_state;
744 i915->pipe.delete_fs_state = i915_delete_fs_state;
745 i915->pipe.create_vs_state = i915_create_vs_state;
746 i915->pipe.bind_vs_state = i915_bind_vs_state;
747 i915->pipe.delete_vs_state = i915_delete_vs_state;
748
749 i915->pipe.set_blend_color = i915_set_blend_color;
750 i915->pipe.set_clip_state = i915_set_clip_state;
751 i915->pipe.set_clear_color_state = i915_set_clear_color_state;
752 i915->pipe.set_constant_buffer = i915_set_constant_buffer;
753 i915->pipe.set_framebuffer_state = i915_set_framebuffer_state;
754 i915->pipe.set_feedback_state = i915_set_feedback_state;
755 i915->pipe.set_feedback_buffer = i915_set_feedback_buffer;
756
757 i915->pipe.set_polygon_stipple = i915_set_polygon_stipple;
758 i915->pipe.set_sampler_units = i915_set_sampler_units;
759 i915->pipe.set_scissor_state = i915_set_scissor_state;
760 i915->pipe.set_texture_state = i915_set_texture_state;
761 i915->pipe.set_viewport_state = i915_set_viewport_state;
762 i915->pipe.set_vertex_buffer = i915_set_vertex_buffer;
763 i915->pipe.set_vertex_element = i915_set_vertex_element;
764 }