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"
37 #include "brw_state.h"
38 #include "util/u_memory.h"
42 static void do_wm_prog( struct brw_context
*brw
,
43 struct brw_fragment_program
*fp
,
44 struct brw_wm_prog_key
*key
)
46 struct brw_wm_compile
*c
= CALLOC_STRUCT(brw_wm_compile
);
47 const unsigned *program
;
48 unsigned program_size
;
53 c
->delta_xy
[0] = brw_null_reg();
54 c
->delta_xy
[1] = brw_null_reg();
55 c
->pixel_xy
[0] = brw_null_reg();
56 c
->pixel_xy
[1] = brw_null_reg();
57 c
->pixel_w
= brw_null_reg();
60 debug_printf("XXXXXXXX FP\n");
66 program
= brw_get_program(&c
->func
, &program_size
);
70 brw
->wm
.prog_gs_offset
= brw_upload_cache( &brw
->cache
[BRW_WM_PROG
],
83 static void brw_wm_populate_key( struct brw_context
*brw
,
84 struct brw_wm_prog_key
*key
)
86 /* BRW_NEW_FRAGMENT_PROGRAM */
87 struct brw_fragment_program
*fp
=
88 (struct brw_fragment_program
*)brw
->attribs
.FragmentProgram
;
92 memset(key
, 0, sizeof(*key
));
94 /* Build the index for table lookup
96 /* BRW_NEW_DEPTH_STENCIL */
97 if (fp
->info
.uses_kill
||
98 brw
->attribs
.DepthStencil
->alpha
.enabled
)
99 lookup
|= IZ_PS_KILL_ALPHATEST_BIT
;
101 if (fp
->info
.writes_z
)
102 lookup
|= IZ_PS_COMPUTES_DEPTH_BIT
;
104 if (brw
->attribs
.DepthStencil
->depth
.enabled
)
105 lookup
|= IZ_DEPTH_TEST_ENABLE_BIT
;
107 if (brw
->attribs
.DepthStencil
->depth
.enabled
&&
108 brw
->attribs
.DepthStencil
->depth
.writemask
) /* ?? */
109 lookup
|= IZ_DEPTH_WRITE_ENABLE_BIT
;
111 if (brw
->attribs
.DepthStencil
->stencil
[0].enabled
) {
112 lookup
|= IZ_STENCIL_TEST_ENABLE_BIT
;
114 if (brw
->attribs
.DepthStencil
->stencil
[0].writemask
||
115 brw
->attribs
.DepthStencil
->stencil
[1].writemask
)
116 lookup
|= IZ_STENCIL_WRITE_ENABLE_BIT
;
119 /* XXX: when should this be disabled?
122 lookup
|= IZ_EARLY_DEPTH_TEST_BIT
;
127 /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
128 if (brw
->attribs
.Raster
->line_smooth
) {
129 if (brw
->reduced_primitive
== PIPE_PRIM_LINES
) {
132 else if (brw
->reduced_primitive
== PIPE_PRIM_TRIANGLES
) {
133 if (brw
->attribs
.Raster
->fill_ccw
== PIPE_POLYGON_MODE_LINE
) {
134 line_aa
= AA_SOMETIMES
;
136 if (brw
->attribs
.Raster
->fill_cw
== PIPE_POLYGON_MODE_LINE
||
137 (brw
->attribs
.Raster
->cull_mode
== PIPE_WINDING_CW
))
140 else if (brw
->attribs
.Raster
->fill_cw
== PIPE_POLYGON_MODE_LINE
) {
141 line_aa
= AA_SOMETIMES
;
143 if (brw
->attribs
.Raster
->cull_mode
== PIPE_WINDING_CCW
)
149 brw_wm_lookup_iz(line_aa
,
157 * Not doing any of this at the moment:
159 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
160 const struct pipe_sampler_state
*unit
= brw
->attribs
.Samplers
[i
];
164 if (unit
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
) {
165 key
->shadowtex_mask
|= 1<<i
;
167 if (t
->Image
[0][t
->BaseLevel
]->InternalFormat
== GL_YCBCR_MESA
)
168 key
->yuvtex_mask
|= 1<<i
;
176 key
->program_string_id
= fp
->id
;
181 static void brw_upload_wm_prog( struct brw_context
*brw
)
183 struct brw_wm_prog_key key
;
184 struct brw_fragment_program
*fp
= (struct brw_fragment_program
*)
185 brw
->attribs
.FragmentProgram
;
187 brw_wm_populate_key(brw
, &key
);
189 /* Make an early check for the key.
191 if (brw_search_cache(&brw
->cache
[BRW_WM_PROG
],
194 &brw
->wm
.prog_gs_offset
))
197 do_wm_prog(brw
, fp
, &key
);
201 const struct brw_tracked_state brw_wm_prog
= {
204 BRW_NEW_REDUCED_PRIMITIVE
),
207 .update
= brw_upload_wm_prog