1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
32 #include "draw/draw_context.h"
33 #include "pipe/internal/p_winsys_screen.h"
34 #include "pipe/p_inlines.h"
35 #include "util/u_math.h"
36 #include "util/u_memory.h"
37 #include "tgsi/tgsi_parse.h"
39 #include "i915_context.h"
41 #include "i915_state.h"
42 #include "i915_state_inlines.h"
45 /* The i915 (and related graphics cores) do not support GL_CLAMP. The
46 * Intel drivers for "other operating systems" implement GL_CLAMP as
47 * GL_CLAMP_TO_EDGE, so the same is done here.
50 translate_wrap_mode(unsigned wrap
)
53 case PIPE_TEX_WRAP_REPEAT
:
54 return TEXCOORDMODE_WRAP
;
55 case PIPE_TEX_WRAP_CLAMP
:
56 return TEXCOORDMODE_CLAMP_EDGE
; /* not quite correct */
57 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
58 return TEXCOORDMODE_CLAMP_EDGE
;
59 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
60 return TEXCOORDMODE_CLAMP_BORDER
;
62 case PIPE_TEX_WRAP_MIRRORED_REPEAT:
63 return TEXCOORDMODE_MIRROR;
66 return TEXCOORDMODE_WRAP
;
70 static unsigned translate_img_filter( unsigned filter
)
73 case PIPE_TEX_FILTER_NEAREST
:
74 return FILTER_NEAREST
;
75 case PIPE_TEX_FILTER_LINEAR
:
77 case PIPE_TEX_FILTER_ANISO
:
78 return FILTER_ANISOTROPIC
;
81 return FILTER_NEAREST
;
85 static unsigned translate_mip_filter( unsigned filter
)
88 case PIPE_TEX_MIPFILTER_NONE
:
89 return MIPFILTER_NONE
;
90 case PIPE_TEX_MIPFILTER_NEAREST
:
91 return MIPFILTER_NEAREST
;
92 case PIPE_TEX_MIPFILTER_LINEAR
:
93 return MIPFILTER_LINEAR
;
96 return MIPFILTER_NONE
;
101 /* None of this state is actually used for anything yet.
104 i915_create_blend_state(struct pipe_context
*pipe
,
105 const struct pipe_blend_state
*blend
)
107 struct i915_blend_state
*cso_data
= CALLOC_STRUCT( i915_blend_state
);
110 unsigned eqRGB
= blend
->rgb_func
;
111 unsigned srcRGB
= blend
->rgb_src_factor
;
112 unsigned dstRGB
= blend
->rgb_dst_factor
;
114 unsigned eqA
= blend
->alpha_func
;
115 unsigned srcA
= blend
->alpha_src_factor
;
116 unsigned dstA
= blend
->alpha_dst_factor
;
118 /* Special handling for MIN/MAX filter modes handled at
119 * state_tracker level.
122 if (srcA
!= srcRGB
||
126 cso_data
->iab
= (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
130 IAB_MODIFY_SRC_FACTOR
|
131 IAB_MODIFY_DST_FACTOR
|
132 SRC_ABLND_FACT(i915_translate_blend_factor(srcA
)) |
133 DST_ABLND_FACT(i915_translate_blend_factor(dstA
)) |
134 (i915_translate_blend_func(eqA
) << IAB_FUNC_SHIFT
));
137 cso_data
->iab
= (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
143 cso_data
->modes4
|= (_3DSTATE_MODES_4_CMD
|
144 ENABLE_LOGIC_OP_FUNC
|
145 LOGIC_OP_FUNC(i915_translate_logic_op(blend
->logicop_func
)));
147 if (blend
->logicop_enable
)
148 cso_data
->LIS5
|= S5_LOGICOP_ENABLE
;
151 cso_data
->LIS5
|= S5_COLOR_DITHER_ENABLE
;
153 if ((blend
->colormask
& PIPE_MASK_R
) == 0)
154 cso_data
->LIS5
|= S5_WRITEDISABLE_RED
;
156 if ((blend
->colormask
& PIPE_MASK_G
) == 0)
157 cso_data
->LIS5
|= S5_WRITEDISABLE_GREEN
;
159 if ((blend
->colormask
& PIPE_MASK_B
) == 0)
160 cso_data
->LIS5
|= S5_WRITEDISABLE_BLUE
;
162 if ((blend
->colormask
& PIPE_MASK_A
) == 0)
163 cso_data
->LIS5
|= S5_WRITEDISABLE_ALPHA
;
165 if (blend
->blend_enable
) {
166 unsigned funcRGB
= blend
->rgb_func
;
167 unsigned srcRGB
= blend
->rgb_src_factor
;
168 unsigned dstRGB
= blend
->rgb_dst_factor
;
170 cso_data
->LIS6
|= (S6_CBUF_BLEND_ENABLE
|
171 SRC_BLND_FACT(i915_translate_blend_factor(srcRGB
)) |
172 DST_BLND_FACT(i915_translate_blend_factor(dstRGB
)) |
173 (i915_translate_blend_func(funcRGB
) << S6_CBUF_BLEND_FUNC_SHIFT
));
179 static void i915_bind_blend_state(struct pipe_context
*pipe
,
182 struct i915_context
*i915
= i915_context(pipe
);
183 draw_flush(i915
->draw
);
185 i915
->blend
= (struct i915_blend_state
*)blend
;
187 i915
->dirty
|= I915_NEW_BLEND
;
191 static void i915_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
196 static void i915_set_blend_color( struct pipe_context
*pipe
,
197 const struct pipe_blend_color
*blend_color
)
199 struct i915_context
*i915
= i915_context(pipe
);
200 draw_flush(i915
->draw
);
202 i915
->blend_color
= *blend_color
;
204 i915
->dirty
|= I915_NEW_BLEND
;
208 i915_create_sampler_state(struct pipe_context
*pipe
,
209 const struct pipe_sampler_state
*sampler
)
211 struct i915_sampler_state
*cso
= CALLOC_STRUCT( i915_sampler_state
);
212 const unsigned ws
= sampler
->wrap_s
;
213 const unsigned wt
= sampler
->wrap_t
;
214 const unsigned wr
= sampler
->wrap_r
;
215 unsigned minFilt
, magFilt
;
218 cso
->templ
= sampler
;
220 mipFilt
= translate_mip_filter(sampler
->min_mip_filter
);
221 minFilt
= translate_img_filter( sampler
->min_img_filter
);
222 magFilt
= translate_img_filter( sampler
->mag_img_filter
);
224 if (sampler
->max_anisotropy
> 2.0) {
225 cso
->state
[0] |= SS2_MAX_ANISO_4
;
229 int b
= (int) (sampler
->lod_bias
* 16.0);
230 b
= CLAMP(b
, -256, 255);
231 cso
->state
[0] |= ((b
<< SS2_LOD_BIAS_SHIFT
) & SS2_LOD_BIAS_MASK
);
236 if (sampler
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
238 cso
->state
[0] |= (SS2_SHADOW_ENABLE
|
239 i915_translate_compare_func(sampler
->compare_func
));
241 minFilt
= FILTER_4X4_FLAT
;
242 magFilt
= FILTER_4X4_FLAT
;
245 cso
->state
[0] |= ((minFilt
<< SS2_MIN_FILTER_SHIFT
) |
246 (mipFilt
<< SS2_MIP_FILTER_SHIFT
) |
247 (magFilt
<< SS2_MAG_FILTER_SHIFT
));
250 ((translate_wrap_mode(ws
) << SS3_TCX_ADDR_MODE_SHIFT
) |
251 (translate_wrap_mode(wt
) << SS3_TCY_ADDR_MODE_SHIFT
) |
252 (translate_wrap_mode(wr
) << SS3_TCZ_ADDR_MODE_SHIFT
));
254 if (sampler
->normalized_coords
)
255 cso
->state
[1] |= SS3_NORMALIZED_COORDS
;
258 int minlod
= (int) (16.0 * sampler
->min_lod
);
259 int maxlod
= (int) (16.0 * sampler
->max_lod
);
260 minlod
= CLAMP(minlod
, 0, 16 * 11);
261 maxlod
= CLAMP(maxlod
, 0, 16 * 11);
266 cso
->minlod
= minlod
;
267 cso
->maxlod
= maxlod
;
271 ubyte r
= float_to_ubyte(sampler
->border_color
[0]);
272 ubyte g
= float_to_ubyte(sampler
->border_color
[1]);
273 ubyte b
= float_to_ubyte(sampler
->border_color
[2]);
274 ubyte a
= float_to_ubyte(sampler
->border_color
[3]);
275 cso
->state
[2] = I915PACKCOLOR8888(r
, g
, b
, a
);
280 static void i915_bind_sampler_states(struct pipe_context
*pipe
,
281 unsigned num
, void **sampler
)
283 struct i915_context
*i915
= i915_context(pipe
);
286 assert(num
<= PIPE_MAX_SAMPLERS
);
288 /* Check for no-op */
289 if (num
== i915
->num_samplers
&&
290 !memcmp(i915
->sampler
, sampler
, num
* sizeof(void *)))
293 draw_flush(i915
->draw
);
295 for (i
= 0; i
< num
; ++i
)
296 i915
->sampler
[i
] = sampler
[i
];
297 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; ++i
)
298 i915
->sampler
[i
] = NULL
;
300 i915
->num_samplers
= num
;
302 i915
->dirty
|= I915_NEW_SAMPLER
;
305 static void i915_delete_sampler_state(struct pipe_context
*pipe
,
312 /** XXX move someday? Or consolidate all these simple state setters
317 i915_create_depth_stencil_state(struct pipe_context
*pipe
,
318 const struct pipe_depth_stencil_alpha_state
*depth_stencil
)
320 struct i915_depth_stencil_state
*cso
= CALLOC_STRUCT( i915_depth_stencil_state
);
323 int testmask
= depth_stencil
->stencil
[0].valuemask
& 0xff;
324 int writemask
= depth_stencil
->stencil
[0].writemask
& 0xff;
326 cso
->stencil_modes4
|= (_3DSTATE_MODES_4_CMD
|
327 ENABLE_STENCIL_TEST_MASK
|
328 STENCIL_TEST_MASK(testmask
) |
329 ENABLE_STENCIL_WRITE_MASK
|
330 STENCIL_WRITE_MASK(writemask
));
333 if (depth_stencil
->stencil
[0].enabled
) {
334 int test
= i915_translate_compare_func(depth_stencil
->stencil
[0].func
);
335 int fop
= i915_translate_stencil_op(depth_stencil
->stencil
[0].fail_op
);
336 int dfop
= i915_translate_stencil_op(depth_stencil
->stencil
[0].zfail_op
);
337 int dpop
= i915_translate_stencil_op(depth_stencil
->stencil
[0].zpass_op
);
338 int ref
= depth_stencil
->stencil
[0].ref_value
& 0xff;
340 cso
->stencil_LIS5
|= (S5_STENCIL_TEST_ENABLE
|
341 S5_STENCIL_WRITE_ENABLE
|
342 (ref
<< S5_STENCIL_REF_SHIFT
) |
343 (test
<< S5_STENCIL_TEST_FUNC_SHIFT
) |
344 (fop
<< S5_STENCIL_FAIL_SHIFT
) |
345 (dfop
<< S5_STENCIL_PASS_Z_FAIL_SHIFT
) |
346 (dpop
<< S5_STENCIL_PASS_Z_PASS_SHIFT
));
349 if (depth_stencil
->stencil
[1].enabled
) {
350 int test
= i915_translate_compare_func(depth_stencil
->stencil
[1].func
);
351 int fop
= i915_translate_stencil_op(depth_stencil
->stencil
[1].fail_op
);
352 int dfop
= i915_translate_stencil_op(depth_stencil
->stencil
[1].zfail_op
);
353 int dpop
= i915_translate_stencil_op(depth_stencil
->stencil
[1].zpass_op
);
354 int ref
= depth_stencil
->stencil
[1].ref_value
& 0xff;
355 int tmask
= depth_stencil
->stencil
[1].valuemask
& 0xff;
356 int wmask
= depth_stencil
->stencil
[1].writemask
& 0xff;
358 cso
->bfo
[0] = (_3DSTATE_BACKFACE_STENCIL_OPS
|
359 BFO_ENABLE_STENCIL_FUNCS
|
360 BFO_ENABLE_STENCIL_TWO_SIDE
|
361 BFO_ENABLE_STENCIL_REF
|
362 BFO_STENCIL_TWO_SIDE
|
363 (ref
<< BFO_STENCIL_REF_SHIFT
) |
364 (test
<< BFO_STENCIL_TEST_SHIFT
) |
365 (fop
<< BFO_STENCIL_FAIL_SHIFT
) |
366 (dfop
<< BFO_STENCIL_PASS_Z_FAIL_SHIFT
) |
367 (dpop
<< BFO_STENCIL_PASS_Z_PASS_SHIFT
));
369 cso
->bfo
[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS
|
370 BFM_ENABLE_STENCIL_TEST_MASK
|
371 BFM_ENABLE_STENCIL_WRITE_MASK
|
372 (tmask
<< BFM_STENCIL_TEST_MASK_SHIFT
) |
373 (wmask
<< BFM_STENCIL_WRITE_MASK_SHIFT
));
376 /* This actually disables two-side stencil: The bit set is a
377 * modify-enable bit to indicate we are changing the two-side
378 * setting. Then there is a symbolic zero to show that we are
379 * setting the flag to zero/off.
381 cso
->bfo
[0] = (_3DSTATE_BACKFACE_STENCIL_OPS
|
382 BFO_ENABLE_STENCIL_TWO_SIDE
|
387 if (depth_stencil
->depth
.enabled
) {
388 int func
= i915_translate_compare_func(depth_stencil
->depth
.func
);
390 cso
->depth_LIS6
|= (S6_DEPTH_TEST_ENABLE
|
391 (func
<< S6_DEPTH_TEST_FUNC_SHIFT
));
393 if (depth_stencil
->depth
.writemask
)
394 cso
->depth_LIS6
|= S6_DEPTH_WRITE_ENABLE
;
397 if (depth_stencil
->alpha
.enabled
) {
398 int test
= i915_translate_compare_func(depth_stencil
->alpha
.func
);
399 ubyte refByte
= float_to_ubyte(depth_stencil
->alpha
.ref_value
);
401 cso
->depth_LIS6
|= (S6_ALPHA_TEST_ENABLE
|
402 (test
<< S6_ALPHA_TEST_FUNC_SHIFT
) |
403 (((unsigned) refByte
) << S6_ALPHA_REF_SHIFT
));
409 static void i915_bind_depth_stencil_state(struct pipe_context
*pipe
,
412 struct i915_context
*i915
= i915_context(pipe
);
413 draw_flush(i915
->draw
);
415 i915
->depth_stencil
= (const struct i915_depth_stencil_state
*)depth_stencil
;
417 i915
->dirty
|= I915_NEW_DEPTH_STENCIL
;
420 static void i915_delete_depth_stencil_state(struct pipe_context
*pipe
,
427 static void i915_set_scissor_state( struct pipe_context
*pipe
,
428 const struct pipe_scissor_state
*scissor
)
430 struct i915_context
*i915
= i915_context(pipe
);
431 draw_flush(i915
->draw
);
433 memcpy( &i915
->scissor
, scissor
, sizeof(*scissor
) );
434 i915
->dirty
|= I915_NEW_SCISSOR
;
438 static void i915_set_polygon_stipple( struct pipe_context
*pipe
,
439 const struct pipe_poly_stipple
*stipple
)
446 i915_create_fs_state(struct pipe_context
*pipe
,
447 const struct pipe_shader_state
*templ
)
449 struct i915_context
*i915
= i915_context(pipe
);
450 struct i915_fragment_shader
*ifs
= CALLOC_STRUCT(i915_fragment_shader
);
454 ifs
->state
.tokens
= tgsi_dup_tokens(templ
->tokens
);
456 tgsi_scan_shader(templ
->tokens
, &ifs
->info
);
458 /* The shader's compiled to i915 instructions here */
459 i915_translate_fragment_program(i915
, ifs
);
465 i915_bind_fs_state(struct pipe_context
*pipe
, void *shader
)
467 struct i915_context
*i915
= i915_context(pipe
);
468 draw_flush(i915
->draw
);
470 i915
->fs
= (struct i915_fragment_shader
*) shader
;
472 i915
->dirty
|= I915_NEW_FS
;
476 void i915_delete_fs_state(struct pipe_context
*pipe
, void *shader
)
478 struct i915_fragment_shader
*ifs
= (struct i915_fragment_shader
*) shader
;
482 ifs
->program_len
= 0;
484 FREE((struct tgsi_token
*)ifs
->state
.tokens
);
491 i915_create_vs_state(struct pipe_context
*pipe
,
492 const struct pipe_shader_state
*templ
)
494 struct i915_context
*i915
= i915_context(pipe
);
496 /* just pass-through to draw module */
497 return draw_create_vertex_shader(i915
->draw
, templ
);
500 static void i915_bind_vs_state(struct pipe_context
*pipe
, void *shader
)
502 struct i915_context
*i915
= i915_context(pipe
);
504 /* just pass-through to draw module */
505 draw_bind_vertex_shader(i915
->draw
, (struct draw_vertex_shader
*) shader
);
507 i915
->dirty
|= I915_NEW_VS
;
510 static void i915_delete_vs_state(struct pipe_context
*pipe
, void *shader
)
512 struct i915_context
*i915
= i915_context(pipe
);
514 /* just pass-through to draw module */
515 draw_delete_vertex_shader(i915
->draw
, (struct draw_vertex_shader
*) shader
);
518 static void i915_set_constant_buffer(struct pipe_context
*pipe
,
519 uint shader
, uint index
,
520 const struct pipe_constant_buffer
*buf
)
522 struct i915_context
*i915
= i915_context(pipe
);
523 struct pipe_screen
*screen
= pipe
->screen
;
524 draw_flush(i915
->draw
);
526 assert(shader
< PIPE_SHADER_TYPES
);
529 /* Make a copy of shader constants.
530 * During fragment program translation we may add additional
531 * constants to the array.
533 * We want to consider the situation where some user constants
534 * (ex: a material color) may change frequently but the shader program
535 * stays the same. In that case we should only be updating the first
536 * N constants, leaving any extras from shader translation alone.
540 if (buf
->buffer
&& buf
->buffer
->size
&&
541 (mapped
= pipe_buffer_map(screen
, buf
->buffer
,
542 PIPE_BUFFER_USAGE_CPU_READ
))) {
543 memcpy(i915
->current
.constants
[shader
], mapped
, buf
->buffer
->size
);
544 pipe_buffer_unmap(screen
, buf
->buffer
);
545 i915
->current
.num_user_constants
[shader
]
546 = buf
->buffer
->size
/ (4 * sizeof(float));
549 i915
->current
.num_user_constants
[shader
] = 0;
553 i915
->dirty
|= I915_NEW_CONSTANTS
;
557 static void i915_set_sampler_textures(struct pipe_context
*pipe
,
559 struct pipe_texture
**texture
)
561 struct i915_context
*i915
= i915_context(pipe
);
564 assert(num
<= PIPE_MAX_SAMPLERS
);
566 /* Check for no-op */
567 if (num
== i915
->num_textures
&&
568 !memcmp(i915
->texture
, texture
, num
* sizeof(struct pipe_texture
*)))
571 /* Fixes wrong texture in texobj with VBUF */
572 draw_flush(i915
->draw
);
574 for (i
= 0; i
< num
; i
++)
575 pipe_texture_reference((struct pipe_texture
**) &i915
->texture
[i
],
578 for (i
= num
; i
< i915
->num_textures
; i
++)
579 pipe_texture_reference((struct pipe_texture
**) &i915
->texture
[i
],
582 i915
->num_textures
= num
;
584 i915
->dirty
|= I915_NEW_TEXTURE
;
589 static void i915_set_framebuffer_state(struct pipe_context
*pipe
,
590 const struct pipe_framebuffer_state
*fb
)
592 struct i915_context
*i915
= i915_context(pipe
);
595 draw_flush(i915
->draw
);
597 i915
->framebuffer
.width
= fb
->width
;
598 i915
->framebuffer
.height
= fb
->height
;
599 i915
->framebuffer
.nr_cbufs
= fb
->nr_cbufs
;
600 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
601 pipe_surface_reference(&i915
->framebuffer
.cbufs
[i
], fb
->cbufs
[i
]);
603 pipe_surface_reference(&i915
->framebuffer
.zsbuf
, fb
->zsbuf
);
605 i915
->dirty
|= I915_NEW_FRAMEBUFFER
;
610 static void i915_set_clip_state( struct pipe_context
*pipe
,
611 const struct pipe_clip_state
*clip
)
613 struct i915_context
*i915
= i915_context(pipe
);
614 draw_flush(i915
->draw
);
616 draw_set_clip_state(i915
->draw
, clip
);
618 i915
->dirty
|= I915_NEW_CLIP
;
623 /* Called when driver state tracker notices changes to the viewport
626 static void i915_set_viewport_state( struct pipe_context
*pipe
,
627 const struct pipe_viewport_state
*viewport
)
629 struct i915_context
*i915
= i915_context(pipe
);
631 i915
->viewport
= *viewport
; /* struct copy */
633 /* pass the viewport info to the draw module */
634 draw_set_viewport_state(i915
->draw
, &i915
->viewport
);
636 i915
->dirty
|= I915_NEW_VIEWPORT
;
641 i915_create_rasterizer_state(struct pipe_context
*pipe
,
642 const struct pipe_rasterizer_state
*rasterizer
)
644 struct i915_rasterizer_state
*cso
= CALLOC_STRUCT( i915_rasterizer_state
);
646 cso
->templ
= rasterizer
;
647 cso
->color_interp
= rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
648 cso
->light_twoside
= rasterizer
->light_twoside
;
649 cso
->ds
[0].u
= _3DSTATE_DEPTH_OFFSET_SCALE
;
650 cso
->ds
[1].f
= rasterizer
->offset_scale
;
651 if (rasterizer
->poly_stipple_enable
) {
652 cso
->st
|= ST1_ENABLE
;
655 if (rasterizer
->scissor
)
656 cso
->sc
[0] = _3DSTATE_SCISSOR_ENABLE_CMD
| ENABLE_SCISSOR_RECT
;
658 cso
->sc
[0] = _3DSTATE_SCISSOR_ENABLE_CMD
| DISABLE_SCISSOR_RECT
;
660 switch (rasterizer
->cull_mode
) {
661 case PIPE_WINDING_NONE
:
662 cso
->LIS4
|= S4_CULLMODE_NONE
;
664 case PIPE_WINDING_CW
:
665 cso
->LIS4
|= S4_CULLMODE_CW
;
667 case PIPE_WINDING_CCW
:
668 cso
->LIS4
|= S4_CULLMODE_CCW
;
670 case PIPE_WINDING_BOTH
:
671 cso
->LIS4
|= S4_CULLMODE_BOTH
;
676 int line_width
= CLAMP((int)(rasterizer
->line_width
* 2), 1, 0xf);
678 cso
->LIS4
|= line_width
<< S4_LINE_WIDTH_SHIFT
;
680 if (rasterizer
->line_smooth
)
681 cso
->LIS4
|= S4_LINE_ANTIALIAS_ENABLE
;
685 int point_size
= CLAMP((int) rasterizer
->point_size
, 1, 0xff);
687 cso
->LIS4
|= point_size
<< S4_POINT_WIDTH_SHIFT
;
690 if (rasterizer
->flatshade
) {
691 cso
->LIS4
|= (S4_FLATSHADE_ALPHA
|
693 S4_FLATSHADE_SPECULAR
);
696 cso
->LIS7
= fui( rasterizer
->offset_units
);
702 static void i915_bind_rasterizer_state( struct pipe_context
*pipe
,
705 struct i915_context
*i915
= i915_context(pipe
);
707 i915
->rasterizer
= (struct i915_rasterizer_state
*)raster
;
709 /* pass-through to draw module */
710 draw_set_rasterizer_state(i915
->draw
,
711 (i915
->rasterizer
? i915
->rasterizer
->templ
: NULL
));
713 i915
->dirty
|= I915_NEW_RASTERIZER
;
716 static void i915_delete_rasterizer_state(struct pipe_context
*pipe
,
722 static void i915_set_vertex_buffers(struct pipe_context
*pipe
,
724 const struct pipe_vertex_buffer
*buffers
)
726 struct i915_context
*i915
= i915_context(pipe
);
727 /* Because we change state before the draw_set_vertex_buffers call
728 * we need a flush here, just to be sure.
730 draw_flush(i915
->draw
);
732 memcpy(i915
->vertex_buffer
, buffers
, count
* sizeof(buffers
[0]));
733 i915
->num_vertex_buffers
= count
;
735 /* pass-through to draw module */
736 draw_set_vertex_buffers(i915
->draw
, count
, buffers
);
739 static void i915_set_vertex_elements(struct pipe_context
*pipe
,
741 const struct pipe_vertex_element
*elements
)
743 struct i915_context
*i915
= i915_context(pipe
);
744 /* Because we change state before the draw_set_vertex_buffers call
745 * we need a flush here, just to be sure.
747 draw_flush(i915
->draw
);
749 i915
->num_vertex_elements
= count
;
750 /* pass-through to draw module */
751 draw_set_vertex_elements(i915
->draw
, count
, elements
);
756 i915_init_state_functions( struct i915_context
*i915
)
758 i915
->base
.create_blend_state
= i915_create_blend_state
;
759 i915
->base
.bind_blend_state
= i915_bind_blend_state
;
760 i915
->base
.delete_blend_state
= i915_delete_blend_state
;
762 i915
->base
.create_sampler_state
= i915_create_sampler_state
;
763 i915
->base
.bind_fragment_sampler_states
= i915_bind_sampler_states
;
764 i915
->base
.delete_sampler_state
= i915_delete_sampler_state
;
766 i915
->base
.create_depth_stencil_alpha_state
= i915_create_depth_stencil_state
;
767 i915
->base
.bind_depth_stencil_alpha_state
= i915_bind_depth_stencil_state
;
768 i915
->base
.delete_depth_stencil_alpha_state
= i915_delete_depth_stencil_state
;
770 i915
->base
.create_rasterizer_state
= i915_create_rasterizer_state
;
771 i915
->base
.bind_rasterizer_state
= i915_bind_rasterizer_state
;
772 i915
->base
.delete_rasterizer_state
= i915_delete_rasterizer_state
;
773 i915
->base
.create_fs_state
= i915_create_fs_state
;
774 i915
->base
.bind_fs_state
= i915_bind_fs_state
;
775 i915
->base
.delete_fs_state
= i915_delete_fs_state
;
776 i915
->base
.create_vs_state
= i915_create_vs_state
;
777 i915
->base
.bind_vs_state
= i915_bind_vs_state
;
778 i915
->base
.delete_vs_state
= i915_delete_vs_state
;
780 i915
->base
.set_blend_color
= i915_set_blend_color
;
781 i915
->base
.set_clip_state
= i915_set_clip_state
;
782 i915
->base
.set_constant_buffer
= i915_set_constant_buffer
;
783 i915
->base
.set_framebuffer_state
= i915_set_framebuffer_state
;
785 i915
->base
.set_polygon_stipple
= i915_set_polygon_stipple
;
786 i915
->base
.set_scissor_state
= i915_set_scissor_state
;
787 i915
->base
.set_fragment_sampler_textures
= i915_set_sampler_textures
;
788 i915
->base
.set_viewport_state
= i915_set_viewport_state
;
789 i915
->base
.set_vertex_buffers
= i915_set_vertex_buffers
;
790 i915
->base
.set_vertex_elements
= i915_set_vertex_elements
;