Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_sf.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
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:
13
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.
17
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.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "glheader.h"
34 #include "macros.h"
35 #include "enums.h"
36
37 #include "intel_batchbuffer.h"
38
39 #include "brw_defines.h"
40 #include "brw_context.h"
41 #include "brw_eu.h"
42 #include "brw_util.h"
43 #include "brw_sf.h"
44 #include "brw_state.h"
45
46 #define DO_SETUP_BITS ((1<<FRAG_ATTRIB_MAX)-1)
47
48 static void compile_sf_prog( struct brw_context *brw,
49 struct brw_sf_prog_key *key )
50 {
51 struct brw_sf_compile c;
52 const GLuint *program;
53 GLuint program_size;
54 GLuint i, idx;
55
56 memset(&c, 0, sizeof(c));
57
58 /* Begin the compilation:
59 */
60 brw_init_compile(&c.func);
61
62 c.key = *key;
63 c.nr_attrs = brw_count_bits(c.key.attrs);
64 c.nr_attr_regs = (c.nr_attrs+1)/2;
65 c.nr_setup_attrs = brw_count_bits(c.key.attrs & DO_SETUP_BITS);
66 c.nr_setup_regs = (c.nr_setup_attrs+1)/2;
67
68 c.prog_data.urb_read_length = c.nr_attr_regs;
69 c.prog_data.urb_entry_size = c.nr_setup_regs * 2;
70
71 /* Construct map from attribute number to position in the vertex.
72 */
73 for (i = idx = 0; i < VERT_RESULT_MAX; i++)
74 if (c.key.attrs & (1<<i)) {
75 c.attr_to_idx[i] = idx;
76 c.idx_to_attr[idx] = i;
77 idx++;
78 }
79
80 /* Which primitive? Or all three?
81 */
82 switch (key->primitive) {
83 case SF_TRIANGLES:
84 c.nr_verts = 3;
85 brw_emit_tri_setup( &c );
86 break;
87 case SF_LINES:
88 c.nr_verts = 2;
89 brw_emit_line_setup( &c );
90 break;
91 case SF_POINTS:
92 c.nr_verts = 1;
93 brw_emit_point_setup( &c );
94 break;
95 case SF_UNFILLED_TRIS:
96 c.nr_verts = 3;
97 brw_emit_anyprim_setup( &c );
98 break;
99 default:
100 assert(0);
101 return;
102 }
103
104
105 /* get the program
106 */
107 program = brw_get_program(&c.func, &program_size);
108
109 /* Upload
110 */
111 brw->sf.prog_gs_offset = brw_upload_cache( &brw->cache[BRW_SF_PROG],
112 &c.key,
113 sizeof(c.key),
114 program,
115 program_size,
116 &c.prog_data,
117 &brw->sf.prog_data );
118 }
119
120
121 static GLboolean search_cache( struct brw_context *brw,
122 struct brw_sf_prog_key *key )
123 {
124 return brw_search_cache(&brw->cache[BRW_SF_PROG],
125 key, sizeof(*key),
126 &brw->sf.prog_data,
127 &brw->sf.prog_gs_offset);
128 }
129
130
131 /* Calculate interpolants for triangle and line rasterization.
132 */
133 static void upload_sf_prog( struct brw_context *brw )
134 {
135 struct brw_sf_prog_key key;
136
137 memset(&key, 0, sizeof(key));
138
139 /* Populate the key, noting state dependencies:
140 */
141 /* CACHE_NEW_VS_PROG */
142 key.attrs = brw->vs.prog_data->outputs_written;
143
144 /* BRW_NEW_REDUCED_PRIMITIVE */
145 switch (brw->intel.reduced_primitive) {
146 case GL_TRIANGLES:
147 /* NOTE: We just use the edgeflag attribute as an indicator that
148 * unfilled triangles are active. We don't actually do the
149 * edgeflag testing here, it is already done in the clip
150 * program.
151 */
152 if (key.attrs & (1<<VERT_RESULT_EDGE))
153 key.primitive = SF_UNFILLED_TRIS;
154 else
155 key.primitive = SF_TRIANGLES;
156 break;
157 case GL_LINES:
158 key.primitive = SF_LINES;
159 break;
160 case GL_POINTS:
161 key.primitive = SF_POINTS;
162 break;
163 }
164
165
166 /* _NEW_LIGHT */
167 key.do_flat_shading = (brw->attribs.Light->ShadeModel == GL_FLAT);
168 key.do_twoside_color = (brw->attribs.Light->Enabled && brw->attribs.Light->Model.TwoSide);
169
170 /* _NEW_POLYGON */
171 if (key.do_twoside_color)
172 key.frontface_ccw = (brw->attribs.Polygon->FrontFace == GL_CCW);
173
174
175 if (!search_cache(brw, &key))
176 compile_sf_prog( brw, &key );
177 }
178
179
180 const struct brw_tracked_state brw_sf_prog = {
181 .dirty = {
182 .mesa = (_NEW_LIGHT|_NEW_POLYGON),
183 .brw = (BRW_NEW_REDUCED_PRIMITIVE),
184 .cache = CACHE_NEW_VS_PROG
185 },
186 .update = upload_sf_prog
187 };
188