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 "pipe/p_state.h"
34 #include "util/u_math.h"
36 #include "brw_screen.h"
37 #include "brw_batchbuffer.h"
38 #include "brw_defines.h"
39 #include "brw_context.h"
42 #include "brw_state.h"
43 #include "brw_pipe_rast.h"
47 #define FRONT_UNFILLED_BIT 0x1
48 #define BACK_UNFILLED_BIT 0x2
51 static enum pipe_error
52 compile_clip_prog( struct brw_context
*brw
,
53 struct brw_clip_prog_key
*key
,
54 struct brw_winsys_buffer
**bo_out
)
57 struct brw_clip_compile c
;
58 const GLuint
*program
;
62 memset(&c
, 0, sizeof(c
));
64 /* Begin the compilation:
66 brw_init_compile(brw
, &c
.func
);
68 c
.func
.single_program_flow
= 1;
70 c
.chipset
= brw
->chipset
;
72 c
.need_ff_sync
= c
.chipset
.is_igdng
;
74 /* Need to locate the two positions present in vertex + header.
75 * These are currently hardcoded:
77 c
.header_position_offset
= ATTR_SIZE
;
79 if (c
.chipset
.is_igdng
)
84 /* XXX: c.nr_attrs is very redundant:
86 c
.nr_attrs
= c
.key
.nr_attrs
;
88 c
.offset_hpos
= delta
+ c
.key
.output_hpos
* ATTR_SIZE
;
90 if (c
.key
.output_color0
)
91 c
.offset_color0
= delta
+ c
.key
.output_color0
* ATTR_SIZE
;
93 if (c
.key
.output_color1
)
94 c
.offset_color1
= delta
+ c
.key
.output_color1
* ATTR_SIZE
;
96 if (c
.key
.output_bfc0
)
97 c
.offset_bfc0
= delta
+ c
.key
.output_bfc0
* ATTR_SIZE
;
99 if (c
.key
.output_bfc1
)
100 c
.offset_bfc1
= delta
+ c
.key
.output_bfc1
* ATTR_SIZE
;
102 if (c
.key
.output_edgeflag
)
103 c
.offset_edgeflag
= delta
+ c
.key
.output_edgeflag
* ATTR_SIZE
;
105 if (BRW_IS_IGDNG(brw
))
106 c
.nr_regs
= (c
.nr_attrs
+ 1) / 2 + 3; /* are vertices packed, or reg-aligned? */
108 c
.nr_regs
= (c
.nr_attrs
+ 1) / 2 + 1; /* are vertices packed, or reg-aligned? */
110 c
.nr_bytes
= c
.nr_regs
* REG_SIZE
;
112 c
.prog_data
.clip_mode
= c
.key
.clip_mode
; /* XXX */
114 /* For some reason the thread is spawned with only 4 channels
117 brw_set_mask_control(&c
.func
, BRW_MASK_DISABLE
);
120 /* Would ideally have the option of producing a program which could
123 switch (key
->primitive
) {
124 case PIPE_PRIM_TRIANGLES
:
125 if (key
->do_unfilled
)
126 brw_emit_unfilled_clip( &c
);
128 brw_emit_tri_clip( &c
);
130 case PIPE_PRIM_LINES
:
131 brw_emit_line_clip( &c
);
133 case PIPE_PRIM_POINTS
:
134 brw_emit_point_clip( &c
);
138 return PIPE_ERROR_BAD_INPUT
;
145 ret
= brw_get_program(&c
.func
, &program
, &program_size
);
151 ret
= brw_upload_cache( &brw
->cache
,
153 &c
.key
, sizeof(c
.key
),
155 program
, program_size
,
157 &brw
->clip
.prog_data
,
165 /* Calculate interpolants for triangle and line rasterization.
167 static enum pipe_error
168 upload_clip_prog(struct brw_context
*brw
)
170 const struct brw_vertex_shader
*vs
= brw
->curr
.vertex_shader
;
171 struct brw_clip_prog_key key
;
174 /* Populate the key, starting from the almost-complete version from
179 key
= brw
->curr
.rast
->clip_key
;
181 /* BRW_NEW_REDUCED_PRIMITIVE */
182 key
.primitive
= brw
->reduced_primitive
;
184 /* XXX: if edgeflag is moved to a proper TGSI vs output, can remove
185 * dependency on CACHE_NEW_VS_PROG
187 /* CACHE_NEW_VS_PROG */
188 key
.nr_attrs
= brw
->vs
.prog_data
->nr_outputs
;
189 key
.output_edgeflag
= brw
->vs
.prog_data
->output_edgeflag
;
192 key
.output_hpos
= vs
->output_hpos
;
193 key
.output_color0
= vs
->output_color0
;
194 key
.output_color1
= vs
->output_color1
;
195 key
.output_bfc0
= vs
->output_bfc0
;
196 key
.output_bfc1
= vs
->output_bfc1
;
199 key
.nr_userclip
= brw
->curr
.ucp
.nr
;
203 if (brw_search_cache(&brw
->cache
, BRW_CLIP_PROG
,
206 &brw
->clip
.prog_data
,
210 /* Compile new program:
212 ret
= compile_clip_prog( brw
, &key
, &brw
->clip
.prog_bo
);
220 const struct brw_tracked_state brw_clip_prog
= {
222 .mesa
= (PIPE_NEW_RAST
|
224 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
225 .cache
= CACHE_NEW_VS_PROG
227 .prepare
= upload_clip_prog