1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "i915_batch.h"
29 #include "i915_state_inlines.h"
30 #include "i915_context.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"
37 #define FILE_DEBUG_FLAG DEBUG_STATE
39 /* State that we have chosen to store in the DYNAMIC segment of the
40 * i915 indirect state mechanism.
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
46 * Additionally, there seems to be a requirement to re-issue the full
47 * (active) state every time a 4kb boundary is crossed.
50 static INLINE
void set_dynamic_indirect( struct i915_context
*i915
,
57 for (i
= 0; i
< dwords
; i
++)
58 i915
->current
.dynamic
[offset
+ i
] = src
[i
];
60 i915
->hardware_dirty
|= I915_HW_DYNAMIC
;
64 /***********************************************************************
65 * Modes4: stencil masks and logicop
67 static void upload_MODES4( struct i915_context
*i915
)
71 /* I915_NEW_STENCIL */
72 modes4
|= i915
->depth_stencil
->stencil_modes4
;
74 modes4
|= i915
->blend
->modes4
;
76 /* Always, so that we know when state is in-active:
78 set_dynamic_indirect( i915
,
84 const struct i915_tracked_state i915_upload_MODES4
= {
85 I915_NEW_BLEND
| I915_NEW_DEPTH_STENCIL
,
92 /***********************************************************************
95 static void upload_BFO( struct i915_context
*i915
)
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
;
104 set_dynamic_indirect( i915
,
110 const struct i915_tracked_state i915_upload_BFO
= {
111 I915_NEW_DEPTH_STENCIL
,
116 /***********************************************************************
120 static void upload_BLENDCOLOR( struct i915_context
*i915
)
124 memset( bc
, 0, sizeof(bc
) );
126 /* I915_NEW_BLEND {_COLOR}
129 const float *color
= i915
->blend_color
.color
;
131 bc
[0] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
132 bc
[1] = pack_ui32_float4( color
[0],
138 set_dynamic_indirect( i915
,
144 const struct i915_tracked_state i915_upload_BLENDCOLOR
= {
149 /***********************************************************************
153 static void upload_IAB( struct i915_context
*i915
)
155 unsigned iab
= i915
->blend
->iab
;
158 set_dynamic_indirect( i915
,
164 const struct i915_tracked_state i915_upload_IAB
= {
170 /***********************************************************************
175 static void upload_DEPTHSCALE( struct i915_context
*i915
)
177 set_dynamic_indirect( i915
,
178 I915_DYNAMIC_DEPTHSCALE_0
,
179 &(i915
->rasterizer
->ds
[0].u
),
183 const struct i915_tracked_state i915_upload_DEPTHSCALE
= {
190 /***********************************************************************
193 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
194 * Fortunately stipple is usually a repeating pattern.
196 * XXX: does stipple pattern need to be adjusted according to
197 * the window position?
199 * XXX: possibly need workaround for conform paths test.
202 static void upload_STIPPLE( struct i915_context
*i915
)
206 st
[0] = _3DSTATE_STIPPLE
;
209 /* I915_NEW_RASTERIZER
211 st
[1] |= i915
->rasterizer
->st
;
217 const ubyte
*mask
= (const ubyte
*)i915
->poly_stipple
.stipple
;
220 p
[0] = mask
[12] & 0xf;
221 p
[1] = mask
[8] & 0xf;
222 p
[2] = mask
[4] & 0xf;
223 p
[3] = mask
[0] & 0xf;
225 /* Not sure what to do about fallbacks, so for now just dont:
227 st
[1] |= ((p
[0] << 0) |
234 set_dynamic_indirect( i915
,
241 const struct i915_tracked_state i915_upload_STIPPLE
= {
242 I915_NEW_RASTERIZER
| I915_NEW_STIPPLE
,
248 /***********************************************************************
251 static void upload_SCISSOR_ENABLE( struct i915_context
*i915
)
253 set_dynamic_indirect( i915
,
254 I915_DYNAMIC_SC_ENA_0
,
255 &(i915
->rasterizer
->sc
[0]),
259 const struct i915_tracked_state i915_upload_SCISSOR_ENABLE
= {
261 upload_SCISSOR_ENABLE
266 static void upload_SCISSOR_RECT( struct i915_context
*i915
)
268 unsigned x1
= i915
->scissor
.minx
;
269 unsigned y1
= i915
->scissor
.miny
;
270 unsigned x2
= i915
->scissor
.maxx
;
271 unsigned y2
= i915
->scissor
.maxy
;
274 sc
[0] = _3DSTATE_SCISSOR_RECT_0_CMD
;
275 sc
[1] = (y1
<< 16) | (x1
& 0xffff);
276 sc
[2] = (y2
<< 16) | (x2
& 0xffff);
278 set_dynamic_indirect( i915
,
279 I915_DYNAMIC_SC_RECT_0
,
285 const struct i915_tracked_state i915_upload_SCISSOR_RECT
= {
295 static const struct i915_tracked_state
*atoms
[] = {
298 &i915_upload_BLENDCOLOR
,
300 &i915_upload_DEPTHSCALE
,
301 &i915_upload_STIPPLE
,
302 &i915_upload_SCISSOR_ENABLE
,
303 &i915_upload_SCISSOR_RECT
306 /* These will be dynamic indirect state commands, but for now just end
307 * up on the batch buffer with everything else.
309 void i915_update_dynamic( struct i915_context
*i915
)
313 for (i
= 0; i
< Elements(atoms
); i
++)
314 if (i915
->dirty
& atoms
[i
]->dirty
)
315 atoms
[i
]->update( i915
);