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 "brw_batchbuffer.h"
35 #include "brw_defines.h"
36 #include "brw_context.h"
37 #include "brw_pipe_rast.h"
41 #include "brw_state.h"
43 static enum pipe_error
compile_sf_prog( struct brw_context
*brw
,
44 struct brw_sf_prog_key
*key
,
45 struct brw_winsys_buffer
**bo_out
)
48 struct brw_sf_compile c
;
49 const GLuint
*program
;
52 memset(&c
, 0, sizeof(c
));
54 /* Begin the compilation:
56 brw_init_compile(brw
, &c
.func
);
59 c
.nr_attrs
= c
.key
.nr_attrs
;
60 c
.nr_attr_regs
= (c
.nr_attrs
+1)/2;
61 c
.nr_setup_attrs
= c
.key
.nr_attrs
;
62 c
.nr_setup_regs
= (c
.nr_setup_attrs
+1)/2;
64 c
.prog_data
.urb_read_length
= c
.nr_attr_regs
;
65 c
.prog_data
.urb_entry_size
= c
.nr_setup_regs
* 2;
68 /* Which primitive? Or all three?
70 switch (key
->primitive
) {
73 brw_emit_tri_setup( &c
, GL_TRUE
);
77 brw_emit_line_setup( &c
, GL_TRUE
);
81 if (key
->do_point_sprite
)
82 brw_emit_point_sprite_setup( &c
, GL_TRUE
);
84 brw_emit_point_setup( &c
, GL_TRUE
);
86 case SF_UNFILLED_TRIS
:
88 brw_emit_anyprim_setup( &c
);
92 return PIPE_ERROR_BAD_INPUT
;
97 ret
= brw_get_program(&c
.func
, &program
, &program_size
);
103 ret
= brw_upload_cache( &brw
->cache
, BRW_SF_PROG
,
104 &c
.key
, sizeof(c
.key
),
106 program
, program_size
,
116 /* Calculate interpolants for triangle and line rasterization.
118 static enum pipe_error
upload_sf_prog(struct brw_context
*brw
)
121 struct brw_sf_prog_key key
;
123 memset(&key
, 0, sizeof(key
));
125 /* Populate the key, noting state dependencies:
128 /* XXX: Add one to account for the position input.
130 /* PIPE_NEW_FRAGMENT_SIGNATURE */
131 key
.nr_attrs
= brw
->curr
.fragment_shader
->signature
.nr_inputs
+ 1;
134 /* XXX: this is probably where the mapping between vertex shader
135 * outputs and fragment shader inputs should be handled. Assume
136 * for now 1:1 correspondance.
138 * XXX: scan frag shader inputs to work out linear vs. perspective
139 * interpolation below.
141 * XXX: as long as we're hard-wiring, is eg. position required to
144 //key.linear_attrs = 0;
145 //key.persp_attrs = (1 << key.nr_attrs) - 1;
147 key
.linear_attrs
= (1 << key
.nr_attrs
) - 1;
150 /* BRW_NEW_REDUCED_PRIMITIVE */
151 switch (brw
->reduced_primitive
) {
152 case PIPE_PRIM_TRIANGLES
:
155 if (brw
->curr
.rast
->templ
.fill_cw
!= PIPE_POLYGON_MODE_FILL
||
156 brw
->curr
.rast
->templ
.fill_ccw
!= PIPE_POLYGON_MODE_FILL
)
157 key
.primitive
= SF_UNFILLED_TRIS
;
159 key
.primitive
= SF_TRIANGLES
;
161 case PIPE_PRIM_LINES
:
162 key
.primitive
= SF_LINES
;
164 case PIPE_PRIM_POINTS
:
165 key
.primitive
= SF_POINTS
;
169 key
.do_point_sprite
= brw
->curr
.rast
->templ
.point_sprite
;
170 key
.sprite_origin_lower_left
= 0; /* XXX: ctx->Point.SpriteOrigin - fix rast state */
171 key
.do_flat_shading
= brw
->curr
.rast
->templ
.flatshade
;
172 key
.do_twoside_color
= brw
->curr
.rast
->templ
.light_twoside
;
174 if (key
.do_twoside_color
) {
175 key
.frontface_ccw
= (brw
->curr
.rast
->templ
.front_winding
==
179 if (brw_search_cache(&brw
->cache
, BRW_SF_PROG
,
186 ret
= compile_sf_prog( brw
, &key
, &brw
->sf
.prog_bo
);
194 const struct brw_tracked_state brw_sf_prog
= {
196 .mesa
= (PIPE_NEW_RAST
| PIPE_NEW_FRAGMENT_SIGNATURE
),
197 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
200 .prepare
= upload_sf_prog