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