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