llvmpipe: move rasterizer to screen instead of setup context
[profile/ivi/mesa.git] / src / gallium / drivers / i915 / i915_state_dynamic.c
1 /**************************************************************************
2  *
3  * Copyright 2003 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 #include "i915_batch.h"
29 #include "i915_state_inlines.h"
30 #include "i915_context.h"
31 #include "i915_reg.h"
32 #include "i915_state.h"
33
34 #include "util/u_memory.h"
35 #include "util/u_pack_color.h"
36
37
38 /* State that we have chosen to store in the DYNAMIC segment of the
39  * i915 indirect state mechanism.
40  *
41  * Can't cache these in the way we do the static state, as there is no
42  * start/size in the command packet, instead an 'end' value that gets
43  * incremented.
44  *
45  * Additionally, there seems to be a requirement to re-issue the full
46  * (active) state every time a 4kb boundary is crossed.
47  */
48
49 static INLINE void set_dynamic_indirect(struct i915_context *i915,
50                                         unsigned offset,
51                                         const unsigned *src,
52                                         unsigned dwords)
53 {
54    unsigned i;
55
56    if (!memcmp(src, &i915->current.dynamic[offset], dwords * 4))
57       return;
58
59    for (i = 0; i < dwords; i++)
60       i915->current.dynamic[offset + i] = src[i];
61
62    i915->hardware_dirty |= I915_HW_DYNAMIC;
63 }
64
65
66
67 /***********************************************************************
68  * Modes4: stencil masks and logicop
69  */
70 static void upload_MODES4(struct i915_context *i915)
71 {
72    unsigned modes4 = 0;
73
74    /* I915_NEW_STENCIL
75     */
76    modes4 |= i915->depth_stencil->stencil_modes4;
77
78    /* I915_NEW_BLEND
79      */
80    modes4 |= i915->blend->modes4;
81
82    /* Always, so that we know when state is in-active:
83     */
84    set_dynamic_indirect(i915,
85                         I915_DYNAMIC_MODES4,
86                         &modes4,
87                         1);
88 }
89
90 const struct i915_tracked_state i915_upload_MODES4 = {
91    "MODES4",
92    upload_MODES4,
93    I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL
94 };
95
96
97
98 /***********************************************************************
99  */
100 static void upload_BFO(struct i915_context *i915)
101 {
102    unsigned bfo[2];
103    bfo[0] = i915->depth_stencil->bfo[0];
104    bfo[1] = i915->depth_stencil->bfo[1];
105    /* I don't get it only allowed to set a ref mask when the enable bit is set? */
106    if (bfo[0] & BFO_ENABLE_STENCIL_REF) {
107       bfo[0] |= i915->stencil_ref.ref_value[1] << BFO_STENCIL_REF_SHIFT;
108    }
109
110    set_dynamic_indirect(i915,
111                         I915_DYNAMIC_BFO_0,
112                         &(bfo[0]),
113                         2);
114 }
115
116 const struct i915_tracked_state i915_upload_BFO = {
117    "BFO",
118    upload_BFO,
119    I915_NEW_DEPTH_STENCIL
120 };
121
122
123
124 /***********************************************************************
125  */
126 static void upload_BLENDCOLOR(struct i915_context *i915)
127 {
128    unsigned bc[2];
129
130    memset(bc, 0, sizeof(bc));
131
132    /* I915_NEW_BLEND
133     */
134    {
135       const float *color = i915->blend_color.color;
136
137       bc[0] = _3DSTATE_CONST_BLEND_COLOR_CMD;
138       bc[1] = pack_ui32_float4(color[0],
139                                color[1],
140                                color[2],
141                                color[3]);
142    }
143
144    set_dynamic_indirect(i915,
145                         I915_DYNAMIC_BC_0,
146                         bc,
147                         2);
148 }
149
150 const struct i915_tracked_state i915_upload_BLENDCOLOR = {
151    "BLENDCOLOR",
152    upload_BLENDCOLOR,
153    I915_NEW_BLEND
154 };
155
156
157
158 /***********************************************************************
159  */
160 static void upload_IAB(struct i915_context *i915)
161 {
162    unsigned iab = i915->blend->iab;
163
164    set_dynamic_indirect(i915,
165                         I915_DYNAMIC_IAB,
166                         &iab,
167                         1);
168 }
169
170 const struct i915_tracked_state i915_upload_IAB = {
171    "IAB",
172    upload_IAB,
173    I915_NEW_BLEND
174 };
175
176
177
178 /***********************************************************************
179  */
180 static void upload_DEPTHSCALE(struct i915_context *i915)
181 {
182    set_dynamic_indirect(i915,
183                         I915_DYNAMIC_DEPTHSCALE_0,
184                         &(i915->rasterizer->ds[0].u),
185                         2);
186 }
187
188 const struct i915_tracked_state i915_upload_DEPTHSCALE = {
189    "DEPTHSCALE",
190    upload_DEPTHSCALE,
191    I915_NEW_RASTERIZER
192 };
193
194
195
196 /***********************************************************************
197  * Polygon stipple
198  *
199  * The i915 supports a 4x4 stipple natively, GL wants 32x32.
200  * Fortunately stipple is usually a repeating pattern.
201  *
202  * XXX: does stipple pattern need to be adjusted according to
203  * the window position?
204  *
205  * XXX: possibly need workaround for conform paths test.
206  */
207 static void upload_STIPPLE(struct i915_context *i915)
208 {
209    unsigned st[2];
210
211    st[0] = _3DSTATE_STIPPLE;
212    st[1] = 0;
213
214    /* I915_NEW_RASTERIZER
215     */
216    st[1] |= i915->rasterizer->st;
217
218    /* I915_NEW_STIPPLE
219     */
220    {
221       const ubyte *mask = (const ubyte *)i915->poly_stipple.stipple;
222       ubyte p[4];
223
224       p[0] = mask[12] & 0xf;
225       p[1] = mask[8] & 0xf;
226       p[2] = mask[4] & 0xf;
227       p[3] = mask[0] & 0xf;
228
229       /* Not sure what to do about fallbacks, so for now just dont:
230        */
231       st[1] |= ((p[0] << 0) |
232                 (p[1] << 4) |
233                 (p[2] << 8) |
234                 (p[3] << 12));
235    }
236
237    set_dynamic_indirect(i915,
238                         I915_DYNAMIC_STP_0,
239                         &st[0],
240                         2);
241 }
242
243 const struct i915_tracked_state i915_upload_STIPPLE = {
244    "STIPPLE",
245    upload_STIPPLE,
246    I915_NEW_RASTERIZER | I915_NEW_STIPPLE
247 };
248
249
250
251 /***********************************************************************
252  * Scissor enable
253  */
254 static void upload_SCISSOR_ENABLE( struct i915_context *i915 )
255 {
256    set_dynamic_indirect(i915,
257                         I915_DYNAMIC_SC_ENA_0,
258                         &(i915->rasterizer->sc[0]),
259                         1);
260 }
261
262 const struct i915_tracked_state i915_upload_SCISSOR_ENABLE = {
263    "SCISSOR ENABLE",
264    upload_SCISSOR_ENABLE,
265    I915_NEW_RASTERIZER
266 };
267
268
269
270 /***********************************************************************
271  * Scissor rect
272  */
273 static void upload_SCISSOR_RECT(struct i915_context *i915)
274 {
275    unsigned x1 = i915->scissor.minx;
276    unsigned y1 = i915->scissor.miny;
277    unsigned x2 = i915->scissor.maxx;
278    unsigned y2 = i915->scissor.maxy;
279    unsigned sc[3];
280
281    sc[0] = _3DSTATE_SCISSOR_RECT_0_CMD;
282    sc[1] = (y1 << 16) | (x1 & 0xffff);
283    sc[2] = (y2 << 16) | (x2 & 0xffff);
284
285    set_dynamic_indirect(i915,
286                         I915_DYNAMIC_SC_RECT_0,
287                         &sc[0],
288                         3);
289 }
290
291 const struct i915_tracked_state i915_upload_SCISSOR_RECT = {
292    "SCISSOR RECT",
293    upload_SCISSOR_RECT,
294    I915_NEW_SCISSOR
295 };
296
297
298
299 /***********************************************************************
300  */
301 static const struct i915_tracked_state *atoms[] = {
302    &i915_upload_MODES4,
303    &i915_upload_BFO,
304    &i915_upload_BLENDCOLOR,
305    &i915_upload_IAB,
306    &i915_upload_DEPTHSCALE,
307    &i915_upload_STIPPLE,
308    &i915_upload_SCISSOR_ENABLE,
309    &i915_upload_SCISSOR_RECT
310 };
311
312 /* These will be dynamic indirect state commands, but for now just end
313  * up on the batch buffer with everything else.
314  */
315 static void update_dynamic(struct i915_context *i915)
316 {
317    int i;
318
319    for (i = 0; i < Elements(atoms); i++)
320       if (i915->dirty & atoms[i]->dirty)
321          atoms[i]->update(i915);
322 }
323
324 struct i915_tracked_state i915_hw_dynamic = {
325    "dynamic",
326    update_dynamic,
327    ~0 /* all state atoms, becuase we do internal checking */
328 };