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"
34 #include "util/u_memory.h"
35 #include "util/u_pack_color.h"
38 /* State that we have chosen to store in the DYNAMIC segment of the
39 * i915 indirect state mechanism.
41 * Can't cache these in the way we do the static state, as there is no
42 * start/size in the command packet, instead an 'end' value that gets
45 * Additionally, there seems to be a requirement to re-issue the full
46 * (active) state every time a 4kb boundary is crossed.
49 static INLINE
void set_dynamic(struct i915_context
*i915
,
53 if (i915
->current
.dynamic
[offset
] == state
)
56 i915
->current
.dynamic
[offset
] = state
;
57 i915
->dynamic_dirty
|= 1 << offset
;
58 i915
->hardware_dirty
|= I915_HW_DYNAMIC
;
63 static INLINE
void set_dynamic_array(struct i915_context
*i915
,
70 if (!memcmp(src
, &i915
->current
.dynamic
[offset
], dwords
* 4))
73 for (i
= 0; i
< dwords
; i
++) {
74 i915
->current
.dynamic
[offset
+ i
] = src
[i
];
75 i915
->dynamic_dirty
|= 1 << (offset
+ i
);
78 i915
->hardware_dirty
|= I915_HW_DYNAMIC
;
83 /***********************************************************************
84 * Modes4: stencil masks and logicop
86 static void upload_MODES4(struct i915_context
*i915
)
92 modes4
|= i915
->depth_stencil
->stencil_modes4
;
96 modes4
|= i915
->blend
->modes4
;
98 set_dynamic(i915
, I915_DYNAMIC_MODES4
, modes4
);
101 const struct i915_tracked_state i915_upload_MODES4
= {
104 I915_NEW_BLEND
| I915_NEW_DEPTH_STENCIL
109 /***********************************************************************
111 static void upload_BFO(struct i915_context
*i915
)
114 bfo
[0] = i915
->depth_stencil
->bfo
[0];
115 bfo
[1] = i915
->depth_stencil
->bfo
[1];
116 /* I don't get it only allowed to set a ref mask when the enable bit is set? */
117 if (bfo
[0] & BFO_ENABLE_STENCIL_REF
) {
118 bfo
[0] |= i915
->stencil_ref
.ref_value
[1] << BFO_STENCIL_REF_SHIFT
;
121 set_dynamic_array(i915
, I915_DYNAMIC_BFO_0
, bfo
, 2);
124 const struct i915_tracked_state i915_upload_BFO
= {
127 I915_NEW_DEPTH_STENCIL
132 /***********************************************************************
134 static void upload_BLENDCOLOR(struct i915_context
*i915
)
138 memset(bc
, 0, sizeof(bc
));
143 const float *color
= i915
->blend_color
.color
;
145 bc
[0] = _3DSTATE_CONST_BLEND_COLOR_CMD
;
146 bc
[1] = pack_ui32_float4(color
[0],
152 set_dynamic_array(i915
, I915_DYNAMIC_BC_0
, bc
, 2);
155 const struct i915_tracked_state i915_upload_BLENDCOLOR
= {
163 /***********************************************************************
165 static void upload_IAB(struct i915_context
*i915
)
167 unsigned iab
= i915
->blend
->iab
;
169 set_dynamic(i915
, I915_DYNAMIC_IAB
, iab
);
172 const struct i915_tracked_state i915_upload_IAB
= {
180 /***********************************************************************
182 static void upload_DEPTHSCALE(struct i915_context
*i915
)
184 set_dynamic_array(i915
, I915_DYNAMIC_DEPTHSCALE_0
,
185 &i915
->rasterizer
->ds
[0].u
, 2);
188 const struct i915_tracked_state i915_upload_DEPTHSCALE
= {
196 /***********************************************************************
199 static void upload_SCISSOR_ENABLE( struct i915_context
*i915
)
201 set_dynamic(i915
, I915_DYNAMIC_SC_ENA_0
, i915
->rasterizer
->sc
[0]);
204 const struct i915_tracked_state i915_upload_SCISSOR_ENABLE
= {
206 upload_SCISSOR_ENABLE
,
212 /***********************************************************************
215 static void upload_SCISSOR_RECT(struct i915_context
*i915
)
217 unsigned x1
= i915
->scissor
.minx
;
218 unsigned y1
= i915
->scissor
.miny
;
219 unsigned x2
= i915
->scissor
.maxx
- 1;
220 unsigned y2
= i915
->scissor
.maxy
- 1;
223 sc
[0] = _3DSTATE_SCISSOR_RECT_0_CMD
;
224 sc
[1] = (y1
<< 16) | (x1
& 0xffff);
225 sc
[2] = (y2
<< 16) | (x2
& 0xffff);
227 set_dynamic_array(i915
, I915_DYNAMIC_SC_RECT_0
, sc
, 3);
230 const struct i915_tracked_state i915_upload_SCISSOR_RECT
= {
238 /***********************************************************************
240 static const struct i915_tracked_state
*atoms
[] = {
243 &i915_upload_BLENDCOLOR
,
245 &i915_upload_DEPTHSCALE
,
246 &i915_upload_SCISSOR_ENABLE
,
247 &i915_upload_SCISSOR_RECT
250 /* These will be dynamic indirect state commands, but for now just end
251 * up on the batch buffer with everything else.
253 static void update_dynamic(struct i915_context
*i915
)
257 for (i
= 0; i
< Elements(atoms
); i
++)
258 if (i915
->dirty
& atoms
[i
]->dirty
)
259 atoms
[i
]->update(i915
);
262 struct i915_tracked_state i915_hw_dynamic
= {
265 ~0 /* all state atoms, becuase we do internal checking */