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>
32 #include "brw_defines.h"
33 #include "brw_context.h"
36 #include "brw_state.h"
39 #define FRONT_UNFILLED_BIT 0x1
40 #define BACK_UNFILLED_BIT 0x2
43 static void compile_clip_prog( struct brw_context
*brw
,
44 struct brw_clip_prog_key
*key
)
46 struct brw_clip_compile c
;
47 const unsigned *program
;
48 unsigned program_size
;
52 memset(&c
, 0, sizeof(c
));
54 /* Begin the compilation:
56 brw_init_compile(&c
.func
);
58 c
.func
.single_program_flow
= 1;
63 /* Need to locate the two positions present in vertex + header.
64 * These are currently hardcoded:
66 c
.header_position_offset
= ATTR_SIZE
;
68 for (i
= 0, delta
= REG_SIZE
; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++)
69 if (c
.key
.attrs
& (1<<i
)) {
74 c
.nr_attrs
= brw_count_bits(c
.key
.attrs
);
75 c
.nr_regs
= (c
.nr_attrs
+ 1) / 2 + 1; /* are vertices packed, or reg-aligned? */
76 c
.nr_bytes
= c
.nr_regs
* REG_SIZE
;
78 c
.prog_data
.clip_mode
= c
.key
.clip_mode
; /* XXX */
80 /* For some reason the thread is spawned with only 4 channels
83 brw_set_mask_control(&c
.func
, BRW_MASK_DISABLE
);
86 /* Would ideally have the option of producing a program which could
89 switch (key
->primitive
) {
90 case PIPE_PRIM_TRIANGLES
:
93 brw_emit_unfilled_clip( &c
);
96 brw_emit_tri_clip( &c
);
99 brw_emit_line_clip( &c
);
101 case PIPE_PRIM_POINTS
:
102 brw_emit_point_clip( &c
);
113 program
= brw_get_program(&c
.func
, &program_size
);
117 brw
->clip
.prog_gs_offset
= brw_upload_cache( &brw
->cache
[BRW_CLIP_PROG
],
123 &brw
->clip
.prog_data
);
127 static boolean
search_cache( struct brw_context
*brw
,
128 struct brw_clip_prog_key
*key
)
130 return brw_search_cache(&brw
->cache
[BRW_CLIP_PROG
],
132 &brw
->clip
.prog_data
,
133 &brw
->clip
.prog_gs_offset
);
139 /* Calculate interpolants for triangle and line rasterization.
141 static void upload_clip_prog(struct brw_context
*brw
)
143 struct brw_clip_prog_key key
;
145 memset(&key
, 0, sizeof(key
));
149 /* BRW_NEW_REDUCED_PRIMITIVE */
150 key
.primitive
= brw
->reduced_primitive
;
151 /* CACHE_NEW_VS_PROG */
152 key
.attrs
= brw
->vs
.prog_data
->outputs_written
;
154 key
.do_flat_shading
= (brw
->attribs
.Raster
->flatshade
);
156 key
.nr_userclip
= brw
->attribs
.Clip
.nr
; /* XXX */
159 key
.clip_mode
= BRW_CLIPMODE_NORMAL
;
161 if (key
.primitive
== PIPE_PRIM_TRIANGLES
) {
162 if (brw
->attribs
.Raster
->cull_mode
== PIPE_WINDING_BOTH
)
163 key
.clip_mode
= BRW_CLIPMODE_REJECT_ALL
;
165 if (brw
->attribs
.Raster
->fill_cw
!= PIPE_POLYGON_MODE_FILL
||
166 brw
->attribs
.Raster
->fill_ccw
!= PIPE_POLYGON_MODE_FILL
)
169 /* Most cases the fixed function units will handle. Cases where
170 * one or more polygon faces are unfilled will require help:
172 if (key
.do_unfilled
) {
173 key
.clip_mode
= BRW_CLIPMODE_CLIP_NON_REJECTED
;
175 if (brw
->attribs
.Raster
->offset_cw
||
176 brw
->attribs
.Raster
->offset_ccw
) {
177 key
.offset_units
= brw
->attribs
.Raster
->offset_units
;
178 key
.offset_factor
= brw
->attribs
.Raster
->offset_scale
;
180 key
.fill_ccw
= brw
->attribs
.Raster
->fill_ccw
;
181 key
.fill_cw
= brw
->attribs
.Raster
->fill_cw
;
182 key
.offset_ccw
= brw
->attribs
.Raster
->offset_ccw
;
183 key
.offset_cw
= brw
->attribs
.Raster
->offset_cw
;
184 if (brw
->attribs
.Raster
->light_twoside
&&
185 key
.fill_cw
!= CLIP_CULL
)
191 key
.clip_mode
= BRW_CLIPMODE_ACCEPT_ALL
;
194 if (!search_cache(brw
, &key
))
195 compile_clip_prog( brw
, &key
);
198 const struct brw_tracked_state brw_clip_prog
= {
200 .brw
= (BRW_NEW_RASTERIZER
|
202 BRW_NEW_REDUCED_PRIMITIVE
),
203 .cache
= CACHE_NEW_VS_PROG
205 .update
= upload_clip_prog