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 memset(&c
, 0, sizeof(c
));
146 memcpy(&c
.key
, key
, sizeof(*key
));
149 c
.env_param
= brw
->intel
.ctx
.FragmentProgram
.Parameters
;
152 /* Augment fragment program. Add instructions for pre- and
153 * post-fragment-program tasks such as interpolation and fogging.
157 /* Translate to intermediate representation. Build register usage
162 /* Dead code removal.
168 brw_wm_pass_hal (&c
);
170 /* Register allocation.
172 c
.grf_limit
= BRW_WM_MAX_GRF
/2;
174 /* This is where we start emitting gen4 code:
176 brw_init_compile(&c
.func
);
180 c
.prog_data
.total_grf
= c
.max_wm_grf
;
181 c
.prog_data
.total_scratch
= c
.last_scratch
? c
.last_scratch
+ 0x40 : 0;
189 program
= brw_get_program(&c
.func
, &program_size
);
193 brw
->wm
.prog_gs_offset
= brw_upload_cache( &brw
->cache
[BRW_WM_PROG
],
199 &brw
->wm
.prog_data
);
204 static void brw_wm_populate_key( struct brw_context
*brw
,
205 struct brw_wm_prog_key
*key
)
207 /* BRW_NEW_FRAGMENT_PROGRAM */
208 struct brw_fragment_program
*fp
=
209 (struct brw_fragment_program
*)brw
->fragment_program
;
214 memset(key
, 0, sizeof(*key
));
216 /* Build the index for table lookup
219 if (fp
->program
.UsesKill
||
220 brw
->attribs
.Color
->AlphaEnabled
)
221 lookup
|= IZ_PS_KILL_ALPHATEST_BIT
;
223 if (fp
->program
.Base
.OutputsWritten
& (1<<FRAG_RESULT_DEPR
))
224 lookup
|= IZ_PS_COMPUTES_DEPTH_BIT
;
227 if (brw
->attribs
.Depth
->Test
)
228 lookup
|= IZ_DEPTH_TEST_ENABLE_BIT
;
230 if (brw
->attribs
.Depth
->Test
&&
231 brw
->attribs
.Depth
->Mask
) /* ?? */
232 lookup
|= IZ_DEPTH_WRITE_ENABLE_BIT
;
235 if (brw
->attribs
.Stencil
->Enabled
) {
236 lookup
|= IZ_STENCIL_TEST_ENABLE_BIT
;
238 if (brw
->attribs
.Stencil
->WriteMask
[0] ||
239 (brw
->attribs
.Stencil
->TestTwoSide
&& brw
->attribs
.Stencil
->WriteMask
[1]))
240 lookup
|= IZ_STENCIL_WRITE_ENABLE_BIT
;
243 /* XXX: when should this be disabled?
246 lookup
|= IZ_EARLY_DEPTH_TEST_BIT
;
251 /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
252 if (brw
->attribs
.Line
->SmoothFlag
) {
253 if (brw
->intel
.reduced_primitive
== GL_LINES
) {
256 else if (brw
->intel
.reduced_primitive
== GL_TRIANGLES
) {
257 if (brw
->attribs
.Polygon
->FrontMode
== GL_LINE
) {
258 line_aa
= AA_SOMETIMES
;
260 if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
||
261 (brw
->attribs
.Polygon
->CullFlag
&&
262 brw
->attribs
.Polygon
->CullFaceMode
== GL_BACK
))
265 else if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
) {
266 line_aa
= AA_SOMETIMES
;
268 if ((brw
->attribs
.Polygon
->CullFlag
&&
269 brw
->attribs
.Polygon
->CullFaceMode
== GL_FRONT
))
275 brw_wm_lookup_iz(line_aa
,
280 /* BRW_NEW_WM_INPUT_DIMENSIONS */
281 key
->projtex_mask
= brw
->wm
.input_size_masks
[4-1];
284 key
->flat_shade
= (brw
->attribs
.Light
->ShadeModel
== GL_FLAT
);
287 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
288 const struct gl_texture_unit
*unit
= &brw
->attribs
.Texture
->Unit
[i
];
289 const struct gl_texture_object
*t
= unit
->_Current
;
291 if (unit
->_ReallyEnabled
) {
293 if (t
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
&&
294 t
->Image
[0][t
->BaseLevel
]->_BaseFormat
== GL_DEPTH_COMPONENT
) {
295 key
->shadowtex_mask
|= 1<<i
;
298 if (t
->Image
[0][t
->BaseLevel
]->InternalFormat
== GL_YCBCR_MESA
)
299 key
->yuvtex_mask
|= 1<<i
;
306 key
->program_string_id
= fp
->id
;
311 static void brw_upload_wm_prog( struct brw_context
*brw
)
313 struct brw_wm_prog_key key
;
314 struct brw_fragment_program
*fp
= (struct brw_fragment_program
*)
315 brw
->fragment_program
;
317 brw_wm_populate_key(brw
, &key
);
319 /* Make an early check for the key.
321 if (brw_search_cache(&brw
->cache
[BRW_WM_PROG
],
324 &brw
->wm
.prog_gs_offset
))
327 do_wm_prog(brw
, fp
, &key
);
333 const struct brw_tracked_state brw_wm_prog
= {
335 .mesa
= (_NEW_COLOR
|
342 .brw
= (BRW_NEW_FRAGMENT_PROGRAM
|
343 BRW_NEW_WM_INPUT_DIMENSIONS
|
344 BRW_NEW_REDUCED_PRIMITIVE
),
347 .update
= brw_upload_wm_prog