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 GLuint
brw_wm_nr_args( GLuint opcode
)
97 GLuint
brw_wm_is_scalar_result( GLuint opcode
)
119 static void brw_wm_pass_hal (struct brw_wm_compile
*c
)
121 static void (*hal_wm_pass
) (struct brw_wm_compile
*c
);
122 static GLboolean hal_tried
;
126 hal_wm_pass
= brw_hal_find_symbol ("intel_hal_wm_pass");
133 static void do_wm_prog( struct brw_context
*brw
,
134 struct brw_fragment_program
*fp
,
135 struct brw_wm_prog_key
*key
)
137 struct brw_wm_compile
*c
;
138 const GLuint
*program
;
141 c
= brw
->wm
.compile_data
;
143 brw
->wm
.compile_data
= calloc(1, sizeof(*brw
->wm
.compile_data
));
144 c
= brw
->wm
.compile_data
;
146 memset(c
, 0, sizeof(*brw
->wm
.compile_data
));
148 memcpy(&c
->key
, key
, sizeof(*key
));
151 c
->env_param
= brw
->intel
.ctx
.FragmentProgram
.Parameters
;
154 /* Augment fragment program. Add instructions for pre- and
155 * post-fragment-program tasks such as interpolation and fogging.
159 /* Translate to intermediate representation. Build register usage
164 /* Dead code removal.
172 /* Register allocation.
174 c
->grf_limit
= BRW_WM_MAX_GRF
/2;
176 /* This is where we start emitting gen4 code:
178 brw_init_compile(&c
->func
);
182 c
->prog_data
.total_grf
= c
->max_wm_grf
;
183 if (c
->last_scratch
) {
184 c
->prog_data
.total_scratch
=
185 c
->last_scratch
+ 0x40;
187 c
->prog_data
.total_scratch
= 0;
196 program
= brw_get_program(&c
->func
, &program_size
);
200 brw
->wm
.prog_gs_offset
= brw_upload_cache( &brw
->cache
[BRW_WM_PROG
],
206 &brw
->wm
.prog_data
);
211 static void brw_wm_populate_key( struct brw_context
*brw
,
212 struct brw_wm_prog_key
*key
)
214 /* BRW_NEW_FRAGMENT_PROGRAM */
215 struct brw_fragment_program
*fp
=
216 (struct brw_fragment_program
*)brw
->fragment_program
;
221 memset(key
, 0, sizeof(*key
));
223 /* Build the index for table lookup
226 if (fp
->program
.UsesKill
||
227 brw
->attribs
.Color
->AlphaEnabled
)
228 lookup
|= IZ_PS_KILL_ALPHATEST_BIT
;
230 if (fp
->program
.Base
.OutputsWritten
& (1<<FRAG_RESULT_DEPR
))
231 lookup
|= IZ_PS_COMPUTES_DEPTH_BIT
;
234 if (brw
->attribs
.Depth
->Test
)
235 lookup
|= IZ_DEPTH_TEST_ENABLE_BIT
;
237 if (brw
->attribs
.Depth
->Test
&&
238 brw
->attribs
.Depth
->Mask
) /* ?? */
239 lookup
|= IZ_DEPTH_WRITE_ENABLE_BIT
;
242 if (brw
->attribs
.Stencil
->Enabled
) {
243 lookup
|= IZ_STENCIL_TEST_ENABLE_BIT
;
245 if (brw
->attribs
.Stencil
->WriteMask
[0] ||
246 (brw
->attribs
.Stencil
->TestTwoSide
&& brw
->attribs
.Stencil
->WriteMask
[1]))
247 lookup
|= IZ_STENCIL_WRITE_ENABLE_BIT
;
250 /* XXX: when should this be disabled?
253 lookup
|= IZ_EARLY_DEPTH_TEST_BIT
;
258 /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
259 if (brw
->attribs
.Line
->SmoothFlag
) {
260 if (brw
->intel
.reduced_primitive
== GL_LINES
) {
263 else if (brw
->intel
.reduced_primitive
== GL_TRIANGLES
) {
264 if (brw
->attribs
.Polygon
->FrontMode
== GL_LINE
) {
265 line_aa
= AA_SOMETIMES
;
267 if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
||
268 (brw
->attribs
.Polygon
->CullFlag
&&
269 brw
->attribs
.Polygon
->CullFaceMode
== GL_BACK
))
272 else if (brw
->attribs
.Polygon
->BackMode
== GL_LINE
) {
273 line_aa
= AA_SOMETIMES
;
275 if ((brw
->attribs
.Polygon
->CullFlag
&&
276 brw
->attribs
.Polygon
->CullFaceMode
== GL_FRONT
))
282 brw_wm_lookup_iz(line_aa
,
287 /* BRW_NEW_WM_INPUT_DIMENSIONS */
288 key
->projtex_mask
= brw
->wm
.input_size_masks
[4-1];
291 key
->flat_shade
= (brw
->attribs
.Light
->ShadeModel
== GL_FLAT
);
294 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
295 const struct gl_texture_unit
*unit
= &brw
->attribs
.Texture
->Unit
[i
];
296 const struct gl_texture_object
*t
= unit
->_Current
;
298 if (unit
->_ReallyEnabled
) {
300 if (t
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
&&
301 t
->Image
[0][t
->BaseLevel
]->_BaseFormat
== GL_DEPTH_COMPONENT
) {
302 key
->shadowtex_mask
|= 1<<i
;
305 if (t
->Image
[0][t
->BaseLevel
]->InternalFormat
== GL_YCBCR_MESA
)
306 key
->yuvtex_mask
|= 1<<i
;
313 key
->program_string_id
= fp
->id
;
318 static void brw_upload_wm_prog( struct brw_context
*brw
)
320 struct brw_wm_prog_key key
;
321 struct brw_fragment_program
*fp
= (struct brw_fragment_program
*)
322 brw
->fragment_program
;
324 brw_wm_populate_key(brw
, &key
);
326 /* Make an early check for the key.
328 if (brw_search_cache(&brw
->cache
[BRW_WM_PROG
],
331 &brw
->wm
.prog_gs_offset
))
334 do_wm_prog(brw
, fp
, &key
);
340 const struct brw_tracked_state brw_wm_prog
= {
342 .mesa
= (_NEW_COLOR
|
349 .brw
= (BRW_NEW_FRAGMENT_PROGRAM
|
350 BRW_NEW_WM_INPUT_DIMENSIONS
|
351 BRW_NEW_REDUCED_PRIMITIVE
),
354 .update
= brw_upload_wm_prog