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_face
== PIPE_FACE_FRONT_AND_BACK
) {
46 key
->clip_mode
= BRW_CLIPMODE_REJECT_ALL
;
50 key
->fill_ccw
= CLIP_CULL
;
51 key
->fill_cw
= CLIP_CULL
;
53 if (!(templ
->cull_face
& PIPE_FACE_FRONT
)) {
55 key
->fill_ccw
= translate_fill(templ
->fill_front
);
57 key
->fill_cw
= translate_fill(templ
->fill_front
);
60 if (!(templ
->cull_face
& PIPE_FACE_BACK
)) {
62 key
->fill_cw
= translate_fill(templ
->fill_back
);
64 key
->fill_ccw
= translate_fill(templ
->fill_back
);
67 if (key
->fill_cw
== CLIP_LINE
||
68 key
->fill_ccw
== CLIP_LINE
||
69 key
->fill_cw
== CLIP_POINT
||
70 key
->fill_ccw
== CLIP_POINT
) {
72 key
->clip_mode
= BRW_CLIPMODE_CLIP_NON_REJECTED
;
75 switch (key
->fill_cw
) {
77 key
->offset_cw
= templ
->offset_point
;
80 key
->offset_cw
= templ
->offset_line
;
83 key
->offset_cw
= templ
->offset_tri
;
87 switch (key
->fill_ccw
) {
89 key
->offset_ccw
= templ
->offset_point
;
92 key
->offset_ccw
= templ
->offset_line
;
95 key
->offset_ccw
= templ
->offset_tri
;
99 if (templ
->light_twoside
&& key
->fill_cw
!= CLIP_CULL
)
100 key
->copy_bfc_cw
= 1;
102 if (templ
->light_twoside
&& key
->fill_ccw
!= CLIP_CULL
)
103 key
->copy_bfc_ccw
= 1;
108 calculate_line_stipple_rast( const struct pipe_rasterizer_state
*templ
,
109 struct brw_line_stipple
*bls
)
111 GLfloat tmp
= 1.0f
/ (templ
->line_stipple_factor
+ 1);
112 GLint tmpi
= tmp
* (1<<13);
114 bls
->header
.opcode
= CMD_LINE_STIPPLE_PATTERN
;
115 bls
->header
.length
= sizeof(*bls
)/4 - 2;
116 bls
->bits0
.pattern
= templ
->line_stipple_pattern
;
117 bls
->bits1
.repeat_count
= templ
->line_stipple_factor
+ 1;
118 bls
->bits1
.inverse_repeat_count
= tmpi
;
121 static void *brw_create_rasterizer_state( struct pipe_context
*pipe
,
122 const struct pipe_rasterizer_state
*templ
)
124 struct brw_context
*brw
= brw_context(pipe
);
125 struct brw_rasterizer_state
*rast
;
127 rast
= CALLOC_STRUCT(brw_rasterizer_state
);
131 rast
->templ
= *templ
;
133 calculate_clip_key_rast( brw
, templ
, rast
, &rast
->clip_key
);
135 if (templ
->line_stipple_enable
)
136 calculate_line_stipple_rast( templ
, &rast
->bls
);
138 /* Caclculate lookup value for WM IZ table.
140 if (templ
->line_smooth
) {
141 if (templ
->fill_front
== PIPE_POLYGON_MODE_LINE
&&
142 templ
->fill_back
== PIPE_POLYGON_MODE_LINE
) {
143 rast
->unfilled_aa_line
= AA_ALWAYS
;
145 else if (templ
->fill_front
== PIPE_POLYGON_MODE_LINE
||
146 templ
->fill_back
== PIPE_POLYGON_MODE_LINE
) {
147 rast
->unfilled_aa_line
= AA_SOMETIMES
;
150 rast
->unfilled_aa_line
= AA_NEVER
;
154 rast
->unfilled_aa_line
= AA_NEVER
;
161 static void brw_bind_rasterizer_state(struct pipe_context
*pipe
,
164 struct brw_context
*brw
= brw_context(pipe
);
165 brw
->curr
.rast
= (const struct brw_rasterizer_state
*)cso
;
166 brw
->state
.dirty
.mesa
|= PIPE_NEW_RAST
;
169 static void brw_delete_rasterizer_state(struct pipe_context
*pipe
,
172 struct brw_context
*brw
= brw_context(pipe
);
173 assert((const void *)cso
!= (const void *)brw
->curr
.rast
);
179 void brw_pipe_rast_init( struct brw_context
*brw
)
181 brw
->base
.create_rasterizer_state
= brw_create_rasterizer_state
;
182 brw
->base
.bind_rasterizer_state
= brw_bind_rasterizer_state
;
183 brw
->base
.delete_rasterizer_state
= brw_delete_rasterizer_state
;
186 void brw_pipe_rast_cleanup( struct brw_context
*brw
)