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"
40 #include "brw_state.h"
42 static enum pipe_error
compile_sf_prog( struct brw_context
*brw
,
43 struct brw_sf_prog_key
*key
,
44 struct brw_winsys_buffer
**bo_out
)
47 struct brw_sf_compile c
;
48 const GLuint
*program
;
51 memset(&c
, 0, sizeof(c
));
53 /* Begin the compilation:
55 brw_init_compile(brw
, &c
.func
);
58 c
.nr_attrs
= c
.key
.nr_attrs
;
59 c
.nr_attr_regs
= (c
.nr_attrs
+1)/2;
60 c
.nr_setup_attrs
= c
.key
.nr_attrs
;
61 c
.nr_setup_regs
= (c
.nr_setup_attrs
+1)/2;
63 c
.prog_data
.urb_read_length
= c
.nr_attr_regs
;
64 c
.prog_data
.urb_entry_size
= c
.nr_setup_regs
* 2;
66 /* Special case when there are no attributes to setup.
68 * XXX: should be able to set nr_setup_attrs to nr_attrs-1 -- but
71 if (c
.nr_attrs
- 1 == 0) {
73 brw_emit_null_setup( &c
);
76 /* Which primitive? Or all three?
78 switch (key
->primitive
) {
81 brw_emit_tri_setup( &c
, GL_TRUE
);
85 brw_emit_line_setup( &c
, GL_TRUE
);
89 if (key
->do_point_sprite
)
90 brw_emit_point_sprite_setup( &c
, GL_TRUE
);
92 brw_emit_point_setup( &c
, GL_TRUE
);
94 case SF_UNFILLED_TRIS
:
96 brw_emit_anyprim_setup( &c
);
100 return PIPE_ERROR_BAD_INPUT
;
106 ret
= brw_get_program(&c
.func
, &program
, &program_size
);
112 ret
= brw_upload_cache( &brw
->cache
, BRW_SF_PROG
,
113 &c
.key
, sizeof(c
.key
),
115 program
, program_size
,
125 /* Calculate interpolants for triangle and line rasterization.
127 static enum pipe_error
upload_sf_prog(struct brw_context
*brw
)
129 const struct brw_fs_signature
*sig
= &brw
->curr
.fragment_shader
->signature
;
130 const struct pipe_rasterizer_state
*rast
= &brw
->curr
.rast
->templ
;
131 struct brw_sf_prog_key key
;
135 memset(&key
, 0, sizeof(key
));
137 /* Populate the key, noting state dependencies:
140 /* XXX: Add one to account for the position input.
142 /* PIPE_NEW_FRAGMENT_SIGNATURE */
143 key
.nr_attrs
= sig
->nr_inputs
+ 1;
146 /* XXX: why is position required to be linear? why do we care
149 key
.linear_attrs
= 1; /* position -- but why? */
151 for (i
= 0; i
< sig
->nr_inputs
; i
++) {
152 switch (sig
->input
[i
].interp
) {
153 case TGSI_INTERPOLATE_CONSTANT
:
155 case TGSI_INTERPOLATE_LINEAR
:
156 key
.linear_attrs
|= 1 << (i
+1);
158 case TGSI_INTERPOLATE_PERSPECTIVE
:
159 key
.persp_attrs
|= 1 << (i
+1);
164 /* BRW_NEW_REDUCED_PRIMITIVE */
165 switch (brw
->reduced_primitive
) {
166 case PIPE_PRIM_TRIANGLES
:
169 if (rast
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
170 rast
->fill_back
!= PIPE_POLYGON_MODE_FILL
)
171 key
.primitive
= SF_UNFILLED_TRIS
;
173 key
.primitive
= SF_TRIANGLES
;
175 case PIPE_PRIM_LINES
:
176 key
.primitive
= SF_LINES
;
178 case PIPE_PRIM_POINTS
:
179 key
.primitive
= SF_POINTS
;
183 key
.do_point_sprite
= rast
->sprite_coord_enable
? 1 : 0;
184 key
.sprite_origin_lower_left
= (rast
->sprite_coord_mode
== PIPE_SPRITE_COORD_LOWER_LEFT
);
185 key
.point_coord_replace_attrs
= rast
->sprite_coord_enable
;
186 key
.do_flat_shading
= rast
->flatshade
;
187 key
.do_twoside_color
= rast
->light_twoside
;
189 if (key
.do_twoside_color
) {
190 key
.frontface_ccw
= rast
->front_ccw
;
193 if (brw_search_cache(&brw
->cache
, BRW_SF_PROG
,
200 ret
= compile_sf_prog( brw
, &key
, &brw
->sf
.prog_bo
);
208 const struct brw_tracked_state brw_sf_prog
= {
210 .mesa
= (PIPE_NEW_RAST
| PIPE_NEW_FRAGMENT_SIGNATURE
),
211 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
214 .prepare
= upload_sf_prog