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 **************************************************************************/
33 #include "i915_batch.h"
34 #include "i915_state_inlines.h"
35 #include "i915_context.h"
37 #include "i915_state.h"
39 #define FILE_DEBUG_FLAG DEBUG_STATE
41 /* State that we have chosen to store in the DYNAMIC segment of the
42 * i915 indirect state mechanism.
44 * Can't cache these in the way we do the static state, as there is no
45 * start/size in the command packet, instead an 'end' value that gets
48 * Additionally, there seems to be a requirement to re-issue the full
49 * (active) state every time a 4kb boundary is crossed.
52 static inline void set_dynamic_indirect( struct i915_context
*i915
,
59 for (i
= 0; i
< dwords
; i
++)
60 i915
->current
.dynamic
[offset
+ i
] = src
[i
];
62 i915
->hardware_dirty
|= I915_HW_DYNAMIC
;
66 /***********************************************************************
67 * Modes4: stencil masks and logicop
69 static void upload_MODES4( struct i915_context
*i915
)
73 /* I915_NEW_STENCIL */
75 GLint testmask
= i915
->stencil
.value_mask
[0] & 0xff;
76 GLint writemask
= i915
->stencil
.write_mask
[0] & 0xff;
78 modes4
|= (_3DSTATE_MODES_4_CMD
|
79 ENABLE_STENCIL_TEST_MASK
|
80 STENCIL_TEST_MASK(testmask
) |
81 ENABLE_STENCIL_WRITE_MASK
|
82 STENCIL_WRITE_MASK(writemask
));
87 modes4
|= (_3DSTATE_MODES_4_CMD
|
88 ENABLE_LOGIC_OP_FUNC
|
89 LOGIC_OP_FUNC(i915_translate_logic_op(i915
->blend
.logicop_func
)));
92 /* Always, so that we know when state is in-active:
94 set_dynamic_indirect( i915
,
100 const struct i915_tracked_state i915_upload_MODES4
= {
101 .dirty
= I915_NEW_BLEND
| I915_NEW_STENCIL
,
102 .update
= upload_MODES4
108 /***********************************************************************
111 static void upload_BFO( struct i915_context
*i915
)
115 memset( bf
, 0, sizeof(bf
) );
119 if (i915
->stencil
.back_enabled
) {
120 GLint test
= i915_translate_compare_func(i915
->stencil
.back_func
);
121 GLint fop
= i915_translate_stencil_op(i915
->stencil
.back_fail_op
);
122 GLint dfop
= i915_translate_stencil_op(i915
->stencil
.back_zfail_op
);
123 GLint dpop
= i915_translate_stencil_op(i915
->stencil
.back_zpass_op
);
124 GLint ref
= i915
->stencil
.ref_value
[1] & 0xff;
125 GLint tmask
= i915
->stencil
.value_mask
[1] & 0xff;
126 GLint wmask
= i915
->stencil
.write_mask
[1] & 0xff;
128 bf
[0] = (_3DSTATE_BACKFACE_STENCIL_OPS
|
129 BFO_ENABLE_STENCIL_FUNCS
|
130 BFO_ENABLE_STENCIL_TWO_SIDE
|
131 BFO_ENABLE_STENCIL_REF
|
132 BFO_STENCIL_TWO_SIDE
|
133 (ref
<< BFO_STENCIL_REF_SHIFT
) |
134 (test
<< BFO_STENCIL_TEST_SHIFT
) |
135 (fop
<< BFO_STENCIL_FAIL_SHIFT
) |
136 (dfop
<< BFO_STENCIL_PASS_Z_FAIL_SHIFT
) |
137 (dpop
<< BFO_STENCIL_PASS_Z_PASS_SHIFT
));
139 bf
[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS
|
140 BFM_ENABLE_STENCIL_TEST_MASK
|
141 BFM_ENABLE_STENCIL_WRITE_MASK
|
142 (tmask
<< BFM_STENCIL_TEST_MASK_SHIFT
) |
143 (wmask
<< BFM_STENCIL_WRITE_MASK_SHIFT
));
146 /* This actually disables two-side stencil: The bit set is a
147 * modify-enable bit to indicate we are changing the two-side
148 * setting. Then there is a symbolic zero to show that we are
149 * setting the flag to zero/off.
151 bf
[0] = (_3DSTATE_BACKFACE_STENCIL_OPS
|
152 BFO_ENABLE_STENCIL_TWO_SIDE
|
157 set_dynamic_indirect( i915
,
163 const struct i915_tracked_state i915_upload_BFO
= {
164 .dirty
= I915_NEW_STENCIL
,
169 /***********************************************************************
173 static void upload_BLENDCOLOR( struct i915_context
*i915
)
177 memset( bc
, 0, sizeof(bc
) );
179 /* I915_NEW_BLEND {_COLOR}
182 const GLfloat
*color
= i915
->blend_color
.color
;
185 UNCLAMPED_FLOAT_TO_UBYTE(r
, color
[RCOMP
]);
186 UNCLAMPED_FLOAT_TO_UBYTE(g
, color
[GCOMP
]);
187 UNCLAMPED_FLOAT_TO_UBYTE(b
, color
[BCOMP
]);
188 UNCLAMPED_FLOAT_TO_UBYTE(a
, color
[ACOMP
]);
190 bc
[0] = (_3DSTATE_CONST_BLEND_COLOR_CMD
);
191 bc
[1] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
194 set_dynamic_indirect( i915
,
200 const struct i915_tracked_state i915_upload_BLENDCOLOR
= {
201 .dirty
= I915_NEW_BLEND
,
202 .update
= upload_BLENDCOLOR
205 /***********************************************************************
209 static void upload_IAB( struct i915_context
*i915
)
214 GLuint eqRGB
= i915
->blend
.rgb_func
;
215 GLuint srcRGB
= i915
->blend
.rgb_src_factor
;
216 GLuint dstRGB
= i915
->blend
.rgb_dst_factor
;
218 GLuint eqA
= i915
->blend
.alpha_func
;
219 GLuint srcA
= i915
->blend
.alpha_src_factor
;
220 GLuint dstA
= i915
->blend
.alpha_dst_factor
;
222 if (eqA
== GL_MIN
|| eqA
== GL_MAX
) {
223 srcA
= dstA
= GL_ONE
;
226 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
) {
227 srcRGB
= dstRGB
= GL_ONE
;
230 if (srcA
!= srcRGB
||
234 iab
= (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
238 IAB_MODIFY_SRC_FACTOR
|
239 IAB_MODIFY_DST_FACTOR
|
240 SRC_ABLND_FACT(i915_translate_blend_factor(srcA
)) |
241 DST_ABLND_FACT(i915_translate_blend_factor(dstA
)) |
242 (i915_translate_blend_func(eqA
) << IAB_FUNC_SHIFT
));
245 iab
= (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
252 set_dynamic_indirect( i915
,
258 const struct i915_tracked_state i915_upload_IAB
= {
259 .dirty
= I915_NEW_BLEND
,
264 /***********************************************************************
269 static void upload_DEPTHSCALE( struct i915_context
*i915
)
271 union { GLfloat f
; GLuint u
; } ds
[2];
273 memset( ds
, 0, sizeof(ds
) );
277 ds
[0].u
= _3DSTATE_DEPTH_OFFSET_SCALE
;
278 ds
[1].f
= i915
->setup
.offset_scale
;
280 set_dynamic_indirect( i915
,
281 I915_DYNAMIC_DEPTHSCALE_0
,
286 const struct i915_tracked_state i915_upload_DEPTHSCALE
= {
287 .dirty
= I915_NEW_SETUP
,
288 .update
= upload_DEPTHSCALE
293 /***********************************************************************
296 * The i915 supports a 4x4 stipple natively, GL wants 32x32.
297 * Fortunately stipple is usually a repeating pattern.
299 * XXX: does stipple pattern need to be adjusted according to
300 * the window position?
302 * XXX: possibly need workaround for conform paths test.
305 static void upload_STIPPLE( struct i915_context
*i915
)
309 st
[0] = _3DSTATE_STIPPLE
;
314 if (i915
->setup
.poly_stipple_enable
) {
322 const GLubyte
*mask
= (const GLubyte
*)i915
->poly_stipple
.stipple
;
325 p
[0] = mask
[12] & 0xf;
326 p
[1] = mask
[8] & 0xf;
327 p
[2] = mask
[4] & 0xf;
328 p
[3] = mask
[0] & 0xf;
330 /* Not sure what to do about fallbacks, so for now just dont:
332 st
[1] |= ((p
[0] << 0) |
339 set_dynamic_indirect( i915
,
346 const struct i915_tracked_state i915_upload_STIPPLE
= {
347 .dirty
= I915_NEW_SETUP
| I915_NEW_STIPPLE
,
348 .update
= upload_STIPPLE
353 /***********************************************************************
356 static void upload_SCISSOR_ENABLE( struct i915_context
*i915
)
360 if (i915
->setup
.scissor
)
361 sc
[0] = _3DSTATE_SCISSOR_ENABLE_CMD
| ENABLE_SCISSOR_RECT
;
363 sc
[0] = _3DSTATE_SCISSOR_ENABLE_CMD
| DISABLE_SCISSOR_RECT
;
365 set_dynamic_indirect( i915
,
366 I915_DYNAMIC_SC_ENA_0
,
371 const struct i915_tracked_state i915_upload_SCISSOR_ENABLE
= {
372 .dirty
= I915_NEW_SETUP
,
373 .update
= upload_SCISSOR_ENABLE
378 static void upload_SCISSOR_RECT( struct i915_context
*i915
)
380 unsigned x1
= i915
->scissor
.minx
;
381 unsigned y1
= i915
->scissor
.miny
;
382 unsigned x2
= i915
->scissor
.maxx
;
383 unsigned y2
= i915
->scissor
.maxy
;
386 sc
[0] = _3DSTATE_SCISSOR_RECT_0_CMD
;
387 sc
[1] = (y1
<< 16) | (x1
& 0xffff);
388 sc
[2] = (y2
<< 16) | (x2
& 0xffff);
390 set_dynamic_indirect( i915
,
391 I915_DYNAMIC_SC_RECT_0
,
397 const struct i915_tracked_state i915_upload_SCISSOR_RECT
= {
398 .dirty
= I915_NEW_SCISSOR
,
399 .update
= upload_SCISSOR_RECT
407 static const struct i915_tracked_state
*atoms
[] = {
410 &i915_upload_BLENDCOLOR
,
412 &i915_upload_DEPTHSCALE
,
413 &i915_upload_STIPPLE
,
414 &i915_upload_SCISSOR_ENABLE
,
415 &i915_upload_SCISSOR_RECT
418 /* These will be dynamic indirect state commands, but for now just end
419 * up on the batch buffer with everything else.
421 void i915_update_dynamic( struct i915_context
*i915
)
425 for (i
= 0; i
< Elements(atoms
); i
++)
426 if (i915
->dirty
& atoms
[i
]->dirty
)
427 atoms
[i
]->update( i915
);