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 "pipe/p_util.h"
35 #define FILE_DEBUG_FLAG DEBUG_STATE
37 /* State that we have chosen to store in the DYNAMIC segment of the
38 * i915 indirect state mechanism.
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
44 * Additionally, there seems to be a requirement to re-issue the full
45 * (active) state every time a 4kb boundary is crossed.
48 static INLINE
void set_dynamic_indirect( struct i915_context
*i915
,
55 for (i
= 0; i
< dwords
; i
++)
56 i915
->current
.dynamic
[offset
+ i
] = src
[i
];
58 i915
->hardware_dirty
|= I915_HW_DYNAMIC
;
62 /***********************************************************************
63 * Modes4: stencil masks and logicop
65 static void upload_MODES4( struct i915_context
*i915
)
69 /* I915_NEW_STENCIL */
70 modes4
|= i915
->depth_stencil
->stencil_modes4
;
72 modes4
|= i915
->blend
->modes4
;
74 /* Always, so that we know when state is in-active:
76 set_dynamic_indirect( i915
,
82 const struct i915_tracked_state i915_upload_MODES4
= {
83 I915_NEW_BLEND
| I915_NEW_DEPTH_STENCIL
,
90 /***********************************************************************
93 static void upload_BFO( struct i915_context
*i915
)
95 set_dynamic_indirect( i915
,
97 &(i915
->depth_stencil
->bfo
[0]),
101 const struct i915_tracked_state i915_upload_BFO
= {
102 I915_NEW_DEPTH_STENCIL
,
107 /***********************************************************************
111 static void upload_BLENDCOLOR( struct i915_context
*i915
)
115 memset( bc
, 0, sizeof(bc
) );
117 /* I915_NEW_BLEND {_COLOR}
120 const float *color
= i915
->blend_color
.color
;
122 bc
[0] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
123 bc
[1] = pack_ui32_float4( color
[0],
129 set_dynamic_indirect( i915
,
135 const struct i915_tracked_state i915_upload_BLENDCOLOR
= {
140 /***********************************************************************
144 static void upload_IAB( struct i915_context
*i915
)
146 unsigned iab
= i915
->blend
->iab
;
149 set_dynamic_indirect( i915
,
155 const struct i915_tracked_state i915_upload_IAB
= {
161 /***********************************************************************
166 static void upload_DEPTHSCALE( struct i915_context
*i915
)
168 set_dynamic_indirect( i915
,
169 I915_DYNAMIC_DEPTHSCALE_0
,
170 &(i915
->rasterizer
->ds
[0].u
),
174 const struct i915_tracked_state i915_upload_DEPTHSCALE
= {
181 /***********************************************************************
184 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
185 * Fortunately stipple is usually a repeating pattern.
187 * XXX: does stipple pattern need to be adjusted according to
188 * the window position?
190 * XXX: possibly need workaround for conform paths test.
193 static void upload_STIPPLE( struct i915_context
*i915
)
197 st
[0] = _3DSTATE_STIPPLE
;
200 /* I915_NEW_RASTERIZER
202 st
[1] |= i915
->rasterizer
->st
;
208 const ubyte
*mask
= (const ubyte
*)i915
->poly_stipple
.stipple
;
211 p
[0] = mask
[12] & 0xf;
212 p
[1] = mask
[8] & 0xf;
213 p
[2] = mask
[4] & 0xf;
214 p
[3] = mask
[0] & 0xf;
216 /* Not sure what to do about fallbacks, so for now just dont:
218 st
[1] |= ((p
[0] << 0) |
225 set_dynamic_indirect( i915
,
232 const struct i915_tracked_state i915_upload_STIPPLE
= {
233 I915_NEW_RASTERIZER
| I915_NEW_STIPPLE
,
239 /***********************************************************************
242 static void upload_SCISSOR_ENABLE( struct i915_context
*i915
)
244 set_dynamic_indirect( i915
,
245 I915_DYNAMIC_SC_ENA_0
,
246 &(i915
->rasterizer
->sc
[0]),
250 const struct i915_tracked_state i915_upload_SCISSOR_ENABLE
= {
252 upload_SCISSOR_ENABLE
257 static void upload_SCISSOR_RECT( struct i915_context
*i915
)
259 unsigned x1
= i915
->scissor
.minx
;
260 unsigned y1
= i915
->scissor
.miny
;
261 unsigned x2
= i915
->scissor
.maxx
;
262 unsigned y2
= i915
->scissor
.maxy
;
265 sc
[0] = _3DSTATE_SCISSOR_RECT_0_CMD
;
266 sc
[1] = (y1
<< 16) | (x1
& 0xffff);
267 sc
[2] = (y2
<< 16) | (x2
& 0xffff);
269 set_dynamic_indirect( i915
,
270 I915_DYNAMIC_SC_RECT_0
,
276 const struct i915_tracked_state i915_upload_SCISSOR_RECT
= {
286 static const struct i915_tracked_state
*atoms
[] = {
289 &i915_upload_BLENDCOLOR
,
291 &i915_upload_DEPTHSCALE
,
292 &i915_upload_STIPPLE
,
293 &i915_upload_SCISSOR_ENABLE
,
294 &i915_upload_SCISSOR_RECT
297 /* These will be dynamic indirect state commands, but for now just end
298 * up on the batch buffer with everything else.
300 void i915_update_dynamic( struct i915_context
*i915
)
304 for (i
= 0; i
< Elements(atoms
); i
++)
305 if (i915
->dirty
& atoms
[i
]->dirty
)
306 atoms
[i
]->update( i915
);