summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/i965/brw_pipe_rast.c
blob: 2117e91a9e453bd99b0a100a5e625f753b64d55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

#include "util/u_memory.h"
#include "pipe/p_defines.h"
#include "brw_context.h"
#include "brw_defines.h"
#include "brw_pipe_rast.h"
#include "brw_wm.h"


static unsigned translate_fill( unsigned fill )
{
   switch (fill) {
   case PIPE_POLYGON_MODE_FILL:
      return CLIP_FILL;
   case PIPE_POLYGON_MODE_LINE:
      return CLIP_LINE;
   case PIPE_POLYGON_MODE_POINT:
      return CLIP_POINT;
   default:
      assert(0);
      return CLIP_FILL;
   }
}


/* Calculates the key for triangle-mode clipping.  Non-triangle
 * clipping keys use much less information and are computed on the
 * fly.
 */
static void
calculate_clip_key_rast( const struct brw_context *brw,
			 const struct pipe_rasterizer_state *templ,
			 const struct brw_rasterizer_state *rast,
			 struct brw_clip_prog_key *key)
{
   memset(key, 0, sizeof *key);

   if (brw->chipset.is_igdng)
       key->clip_mode = BRW_CLIPMODE_KERNEL_CLIP;
   else
       key->clip_mode = BRW_CLIPMODE_NORMAL;

   key->do_flat_shading = templ->flatshade;

   if (templ->cull_mode == PIPE_WINDING_BOTH) {
      key->clip_mode = BRW_CLIPMODE_REJECT_ALL;
      return;
   }

   key->fill_ccw = CLIP_CULL;
   key->fill_cw = CLIP_CULL;

   if (!(templ->cull_mode & PIPE_WINDING_CCW)) {
      key->fill_ccw = translate_fill(templ->fill_ccw);
   }

   if (!(templ->cull_mode & PIPE_WINDING_CW)) {
      key->fill_cw = translate_fill(templ->fill_cw);
   }

   if (key->fill_cw == CLIP_LINE ||
       key->fill_ccw == CLIP_LINE ||
       key->fill_cw == CLIP_POINT ||
       key->fill_ccw == CLIP_POINT) {
      key->do_unfilled = 1;
      key->clip_mode = BRW_CLIPMODE_CLIP_NON_REJECTED;
   }

   key->offset_ccw = templ->offset_ccw;
   key->offset_cw = templ->offset_cw;

   if (templ->light_twoside && key->fill_cw != CLIP_CULL) 
      key->copy_bfc_cw = 1;
   
   if (templ->light_twoside && key->fill_ccw != CLIP_CULL) 
      key->copy_bfc_ccw = 1;
}


static void
calculate_line_stipple_rast( const struct pipe_rasterizer_state *templ,
			     struct brw_line_stipple *bls )
{
   GLfloat tmp = 1.0f / (templ->line_stipple_factor + 1);
   GLint tmpi = tmp * (1<<13);

   bls->header.opcode = CMD_LINE_STIPPLE_PATTERN;
   bls->header.length = sizeof(*bls)/4 - 2;
   bls->bits0.pattern = templ->line_stipple_pattern;
   bls->bits1.repeat_count = templ->line_stipple_factor + 1;
   bls->bits1.inverse_repeat_count = tmpi;
}

static void *brw_create_rasterizer_state( struct pipe_context *pipe,
					  const struct pipe_rasterizer_state *templ )
{
   struct brw_context *brw = brw_context(pipe);
   struct brw_rasterizer_state *rast;

   rast = CALLOC_STRUCT(brw_rasterizer_state);
   if (rast == NULL)
      return NULL;

   rast->templ = *templ;

   calculate_clip_key_rast( brw, templ, rast, &rast->clip_key );
   
   if (templ->line_stipple_enable)
      calculate_line_stipple_rast( templ, &rast->bls );

   /* Caclculate lookup value for WM IZ table.
    */
   if (templ->line_smooth) {
      if (templ->fill_cw == PIPE_POLYGON_MODE_LINE &&
	  templ->fill_ccw == PIPE_POLYGON_MODE_LINE) {
	 rast->unfilled_aa_line = AA_ALWAYS;
      }
      else if (templ->fill_cw == PIPE_POLYGON_MODE_LINE ||
	       templ->fill_ccw == PIPE_POLYGON_MODE_LINE) {
	 rast->unfilled_aa_line = AA_SOMETIMES;
      }
      else {
	 rast->unfilled_aa_line = AA_NEVER;
      }
   }
   else {
      rast->unfilled_aa_line = AA_NEVER;
   }

   return (void *)rast;
}


static void brw_bind_rasterizer_state(struct pipe_context *pipe,
				 void *cso)
{
   struct brw_context *brw = brw_context(pipe);
   brw->curr.rast = (const struct brw_rasterizer_state *)cso;
   brw->state.dirty.mesa |= PIPE_NEW_RAST;
}

static void brw_delete_rasterizer_state(struct pipe_context *pipe,
				  void *cso)
{
   struct brw_context *brw = brw_context(pipe);
   assert((const void *)cso != (const void *)brw->curr.rast);
   FREE(cso);
}



void brw_pipe_rast_init( struct brw_context *brw )
{
   brw->base.create_rasterizer_state = brw_create_rasterizer_state;
   brw->base.bind_rasterizer_state = brw_bind_rasterizer_state;
   brw->base.delete_rasterizer_state = brw_delete_rasterizer_state;
}

void brw_pipe_rast_cleanup( struct brw_context *brw )
{
}