2 #include "util/u_memory.h"
3 #include "pipe/p_defines.h"
4 #include "brw_context.h"
5 #include "brw_defines.h"
6 #include "brw_pipe_rast.h"
10 static unsigned translate_fill( unsigned fill
)
13 case PIPE_POLYGON_MODE_FILL
:
15 case PIPE_POLYGON_MODE_LINE
:
17 case PIPE_POLYGON_MODE_POINT
:
26 /* Calculates the key for triangle-mode clipping. Non-triangle
27 * clipping keys use much less information and are computed on the
31 calculate_clip_key_rast( const struct brw_context
*brw
,
32 const struct pipe_rasterizer_state
*templ
,
33 const struct brw_rasterizer_state
*rast
,
34 struct brw_clip_prog_key
*key
)
36 memset(key
, 0, sizeof *key
);
38 if (brw
->chipset
.is_igdng
)
39 key
->clip_mode
= BRW_CLIPMODE_KERNEL_CLIP
;
41 key
->clip_mode
= BRW_CLIPMODE_NORMAL
;
43 key
->do_flat_shading
= templ
->flatshade
;
45 if (templ
->cull_mode
== PIPE_WINDING_BOTH
) {
46 key
->clip_mode
= BRW_CLIPMODE_REJECT_ALL
;
50 key
->fill_ccw
= CLIP_CULL
;
51 key
->fill_cw
= CLIP_CULL
;
53 if (!(templ
->cull_mode
& PIPE_WINDING_CCW
)) {
54 key
->fill_ccw
= translate_fill(templ
->fill_ccw
);
57 if (!(templ
->cull_mode
& PIPE_WINDING_CW
)) {
58 key
->fill_cw
= translate_fill(templ
->fill_cw
);
61 if (key
->fill_cw
== CLIP_LINE
||
62 key
->fill_ccw
== CLIP_LINE
||
63 key
->fill_cw
== CLIP_POINT
||
64 key
->fill_ccw
== CLIP_POINT
) {
66 key
->clip_mode
= BRW_CLIPMODE_CLIP_NON_REJECTED
;
69 key
->offset_ccw
= templ
->offset_ccw
;
70 key
->offset_cw
= templ
->offset_cw
;
72 if (templ
->light_twoside
&& key
->fill_cw
!= CLIP_CULL
)
75 if (templ
->light_twoside
&& key
->fill_ccw
!= CLIP_CULL
)
76 key
->copy_bfc_ccw
= 1;
81 calculate_line_stipple_rast( const struct pipe_rasterizer_state
*templ
,
82 struct brw_line_stipple
*bls
)
84 GLfloat tmp
= 1.0f
/ (templ
->line_stipple_factor
+ 1);
85 GLint tmpi
= tmp
* (1<<13);
87 bls
->header
.opcode
= CMD_LINE_STIPPLE_PATTERN
;
88 bls
->header
.length
= sizeof(*bls
)/4 - 2;
89 bls
->bits0
.pattern
= templ
->line_stipple_pattern
;
90 bls
->bits1
.repeat_count
= templ
->line_stipple_factor
+ 1;
91 bls
->bits1
.inverse_repeat_count
= tmpi
;
94 static void *brw_create_rasterizer_state( struct pipe_context
*pipe
,
95 const struct pipe_rasterizer_state
*templ
)
97 struct brw_context
*brw
= brw_context(pipe
);
98 struct brw_rasterizer_state
*rast
;
100 rast
= CALLOC_STRUCT(brw_rasterizer_state
);
104 rast
->templ
= *templ
;
106 calculate_clip_key_rast( brw
, templ
, rast
, &rast
->clip_key
);
108 if (templ
->line_stipple_enable
)
109 calculate_line_stipple_rast( templ
, &rast
->bls
);
111 /* Caclculate lookup value for WM IZ table.
113 if (templ
->line_smooth
) {
114 if (templ
->fill_cw
== PIPE_POLYGON_MODE_LINE
&&
115 templ
->fill_ccw
== PIPE_POLYGON_MODE_LINE
) {
116 rast
->unfilled_aa_line
= AA_ALWAYS
;
118 else if (templ
->fill_cw
== PIPE_POLYGON_MODE_LINE
||
119 templ
->fill_ccw
== PIPE_POLYGON_MODE_LINE
) {
120 rast
->unfilled_aa_line
= AA_SOMETIMES
;
123 rast
->unfilled_aa_line
= AA_NEVER
;
127 rast
->unfilled_aa_line
= AA_NEVER
;
134 static void brw_bind_rasterizer_state(struct pipe_context
*pipe
,
137 struct brw_context
*brw
= brw_context(pipe
);
138 brw
->curr
.rast
= (const struct brw_rasterizer_state
*)cso
;
139 brw
->state
.dirty
.mesa
|= PIPE_NEW_RAST
;
142 static void brw_delete_rasterizer_state(struct pipe_context
*pipe
,
145 struct brw_context
*brw
= brw_context(pipe
);
146 assert((const void *)cso
!= (const void *)brw
->curr
.rast
);
152 void brw_pipe_rast_init( struct brw_context
*brw
)
154 brw
->base
.create_rasterizer_state
= brw_create_rasterizer_state
;
155 brw
->base
.bind_rasterizer_state
= brw_bind_rasterizer_state
;
156 brw
->base
.delete_rasterizer_state
= brw_delete_rasterizer_state
;
159 void brw_pipe_rast_cleanup( struct brw_context
*brw
)