2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "brw_context.h"
36 #include "brw_state.h"
40 #include "program_instruction.h"
41 #include "arbprogparse.h"
44 GLuint
brw_wm_nr_args( GLuint opcode
)
101 GLuint
brw_wm_is_scalar_result( GLuint opcode
)
123 static void brw_wm_pass_hal (struct brw_wm_compile
*c
)
125 static void (*hal_wm_pass
) (struct brw_wm_compile
*c
);
126 static GLboolean hal_tried
;
130 hal_wm_pass
= brw_hal_find_symbol ("intel_hal_wm_pass");
137 static void do_wm_prog( struct brw_context
*brw
,
138 struct brw_fragment_program
*fp
,
139 struct brw_wm_prog_key
*key
)
141 struct brw_wm_compile
*c
;
142 const GLuint
*program
;
145 c
= brw
->wm
.compile_data
;
147 brw
->wm
.compile_data
= calloc(1, sizeof(*brw
->wm
.compile_data
));
148 c
= brw
->wm
.compile_data
;
150 memset(c
, 0, sizeof(*brw
->wm
.compile_data
));
152 memcpy(&c
->key
, key
, sizeof(*key
));
155 c
->env_param
= brw
->intel
.ctx
.FragmentProgram
.Parameters
;
158 /* Augment fragment program. Add instructions for pre- and
159 * post-fragment-program tasks such as interpolation and fogging.
163 /* Translate to intermediate representation. Build register usage
168 /* Dead code removal.
176 /* Register allocation.
178 c
->grf_limit
= BRW_WM_MAX_GRF
/2;
180 /* This is where we start emitting gen4 code:
182 brw_init_compile(&c
->func
);
186 c
->prog_data
.total_grf
= c
->max_wm_grf
;
187 if (c
->last_scratch
) {
188 c
->prog_data
.total_scratch
=
189 c
->last_scratch
+ 0x40;
191 c
->prog_data
.total_scratch
= 0;
200 program
= brw_get_program(&c
->func
, &program_size
);
204 brw
->wm
.prog_gs_offset
= brw_upload_cache( &brw
->cache
[BRW_WM_PROG
],
210 &brw
->wm
.prog_data
);
215 static void brw_wm_populate_key( struct brw_context
*brw
,
216 struct brw_wm_prog_key
*key
)
218 /* BRW_NEW_FRAGMENT_PROGRAM */
219 struct brw_fragment_program
*fp
=
220 (struct brw_fragment_program
*)brw
->fragment_program
;
225 memset(key
, 0, sizeof(*key
));
227 /* Build the index for table lookup
230 if (fp
->program
.UsesKill
||
231 brw
->attribs
.Color
->AlphaEnabled
)
232 lookup
|= IZ_PS_KILL_ALPHATEST_BIT
;
234 if (fp
->program
.Base
.OutputsWritten
& (1<<FRAG_RESULT_DEPR
))
235 lookup
|= IZ_PS_COMPUTES_DEPTH_BIT
;
238 if (brw
->attribs
.Depth
->Test
)
239 lookup
|= IZ_DEPTH_TEST_ENABLE_BIT
;
241 if (brw
->attribs
.Depth
->Test
&&
242 brw
->attribs
.Depth
->Mask
) /* ?? */
243 lookup
|= IZ_DEPTH_WRITE_ENABLE_BIT
;
246 if (brw
->attribs
.Stencil
->Enabled
) {
247 lookup
|= IZ_STENCIL_TEST_ENABLE_BIT
;
249 if (brw
->attribs
.Stencil
->WriteMask
[0] ||
250 (brw
->attribs
.Stencil
->TestTwoSide
&& brw
->attribs
.Stencil
->WriteMask
[1]))
251 lookup
|= IZ_STENCIL_WRITE_ENABLE_BIT
;
254 /* XXX: when should this be disabled?
257 lookup
|= IZ_EARLY_DEPTH_TEST_BIT
;
262 /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
263 if (brw
->attribs
.Line
->SmoothFlag
) {
264 if (brw
->intel
.reduced_primitive
== GL_LINES
) {
267 else if (brw
->intel
.reduced_primitive
== GL_TRIANGLES
) {
268 if (brw
->attribs
.Polygon
->FrontMode
== GL_LINE
) {
269 line_aa
= AA_SOMETIMES
;
271 if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
||
272 (brw
->attribs
.Polygon
->CullFlag
&&
273 brw
->attribs
.Polygon
->CullFaceMode
== GL_BACK
))
276 else if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
) {
277 line_aa
= AA_SOMETIMES
;
279 if ((brw
->attribs
.Polygon
->CullFlag
&&
280 brw
->attribs
.Polygon
->CullFaceMode
== GL_FRONT
))
286 brw_wm_lookup_iz(line_aa
,
291 /* BRW_NEW_WM_INPUT_DIMENSIONS */
292 key
->projtex_mask
= brw
->wm
.input_size_masks
[4-1];
295 key
->flat_shade
= (brw
->attribs
.Light
->ShadeModel
== GL_FLAT
);
298 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
299 const struct gl_texture_unit
*unit
= &brw
->attribs
.Texture
->Unit
[i
];
300 const struct gl_texture_object
*t
= unit
->_Current
;
302 if (unit
->_ReallyEnabled
) {
304 if (t
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
&&
305 t
->Image
[0][t
->BaseLevel
]->_BaseFormat
== GL_DEPTH_COMPONENT
) {
306 key
->shadowtex_mask
|= 1<<i
;
309 if (t
->Image
[0][t
->BaseLevel
]->InternalFormat
== GL_YCBCR_MESA
)
310 key
->yuvtex_mask
|= 1<<i
;
317 key
->program_string_id
= fp
->id
;
322 static void brw_upload_wm_prog( struct brw_context
*brw
)
324 struct brw_wm_prog_key key
;
325 struct brw_fragment_program
*fp
= (struct brw_fragment_program
*)
326 brw
->fragment_program
;
328 brw_wm_populate_key(brw
, &key
);
330 /* Make an early check for the key.
332 if (brw_search_cache(&brw
->cache
[BRW_WM_PROG
],
335 &brw
->wm
.prog_gs_offset
))
338 do_wm_prog(brw
, fp
, &key
);
344 const struct brw_tracked_state brw_wm_prog
= {
346 .mesa
= (_NEW_COLOR
|
353 .brw
= (BRW_NEW_FRAGMENT_PROGRAM
|
354 BRW_NEW_WM_INPUT_DIMENSIONS
|
355 BRW_NEW_REDUCED_PRIMITIVE
),
358 .update
= brw_upload_wm_prog