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