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:
127 /* CACHE_NEW_VS_PROG */
128 key
.nr_attrs
= brw
->curr
.vertex_shader
->info
.file_max
[TGSI_FILE_OUTPUT
] + 1;
131 /* XXX: this is probably where the mapping between vertex shader
132 * outputs and fragment shader inputs should be handled. Assume
133 * for now 1:1 correspondance.
135 * XXX: scan frag shader inputs to work out linear vs. perspective
136 * interpolation below.
138 * XXX: as long as we're hard-wiring, is eg. position required to
141 //key.linear_attrs = 0;
142 //key.persp_attrs = (1 << key.nr_attrs) - 1;
144 key
.linear_attrs
= (1 << key
.nr_attrs
) - 1;
147 /* BRW_NEW_REDUCED_PRIMITIVE */
148 switch (brw
->reduced_primitive
) {
149 case PIPE_PRIM_TRIANGLES
:
152 if (brw
->curr
.rast
->templ
.fill_cw
!= PIPE_POLYGON_MODE_FILL
||
153 brw
->curr
.rast
->templ
.fill_ccw
!= PIPE_POLYGON_MODE_FILL
)
154 key
.primitive
= SF_UNFILLED_TRIS
;
156 key
.primitive
= SF_TRIANGLES
;
158 case PIPE_PRIM_LINES
:
159 key
.primitive
= SF_LINES
;
161 case PIPE_PRIM_POINTS
:
162 key
.primitive
= SF_POINTS
;
166 key
.do_point_sprite
= brw
->curr
.rast
->templ
.point_sprite
;
167 key
.sprite_origin_lower_left
= 0; /* XXX: ctx->Point.SpriteOrigin - fix rast state */
168 key
.do_flat_shading
= brw
->curr
.rast
->templ
.flatshade
;
169 key
.do_twoside_color
= brw
->curr
.rast
->templ
.light_twoside
;
171 if (key
.do_twoside_color
) {
172 key
.frontface_ccw
= (brw
->curr
.rast
->templ
.front_winding
==
176 if (brw_search_cache(&brw
->cache
, BRW_SF_PROG
,
183 ret
= compile_sf_prog( brw
, &key
, &brw
->sf
.prog_bo
);
191 const struct brw_tracked_state brw_sf_prog
= {
193 .mesa
= (PIPE_NEW_RAST
| PIPE_NEW_VERTEX_SHADER
),
194 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
197 .prepare
= upload_sf_prog