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