i965g: more files compiling
[mesa.git] / src / gallium / drivers / i965 / brw_gs.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 #include "brw_batchbuffer.h"
33
34 #include "brw_defines.h"
35 #include "brw_context.h"
36 #include "brw_eu.h"
37 #include "brw_util.h"
38 #include "brw_state.h"
39 #include "brw_gs.h"
40
41
42
43 static void compile_gs_prog( struct brw_context *brw,
44 struct brw_gs_prog_key *key )
45 {
46 struct brw_gs_compile c;
47 const GLuint *program;
48 GLuint program_size;
49
50 memset(&c, 0, sizeof(c));
51
52 c.key = *key;
53 c.need_ff_sync = BRW_IS_IGDNG(brw);
54 /* Need to locate the two positions present in vertex + header.
55 * These are currently hardcoded:
56 */
57 c.nr_attrs = util_count_bits(c.key.attrs);
58
59 if (BRW_IS_IGDNG(brw))
60 c.nr_regs = (c.nr_attrs + 1) / 2 + 3; /* are vertices packed, or reg-aligned? */
61 else
62 c.nr_regs = (c.nr_attrs + 1) / 2 + 1; /* are vertices packed, or reg-aligned? */
63
64 c.nr_bytes = c.nr_regs * REG_SIZE;
65
66
67 /* Begin the compilation:
68 */
69 brw_init_compile(brw, &c.func);
70
71 c.func.single_program_flow = 1;
72
73 /* For some reason the thread is spawned with only 4 channels
74 * unmasked.
75 */
76 brw_set_mask_control(&c.func, BRW_MASK_DISABLE);
77
78
79 /* Note that primitives which don't require a GS program have
80 * already been weeded out by this stage:
81 */
82 switch (key->primitive) {
83 case GL_QUADS:
84 brw_gs_quads( &c );
85 break;
86 case GL_QUAD_STRIP:
87 brw_gs_quad_strip( &c );
88 break;
89 case GL_LINE_LOOP:
90 brw_gs_lines( &c );
91 break;
92 case GL_LINES:
93 if (key->hint_gs_always)
94 brw_gs_lines( &c );
95 else {
96 return;
97 }
98 break;
99 case GL_TRIANGLES:
100 if (key->hint_gs_always)
101 brw_gs_tris( &c );
102 else {
103 return;
104 }
105 break;
106 case GL_POINTS:
107 if (key->hint_gs_always)
108 brw_gs_points( &c );
109 else {
110 return;
111 }
112 break;
113 default:
114 return;
115 }
116
117 /* get the program
118 */
119 program = brw_get_program(&c.func, &program_size);
120
121 /* Upload
122 */
123 brw->sws->bo_unreference(brw->gs.prog_bo);
124 brw->gs.prog_bo = brw_upload_cache( &brw->cache, BRW_GS_PROG,
125 &c.key, sizeof(c.key),
126 NULL, 0,
127 program, program_size,
128 &c.prog_data,
129 &brw->gs.prog_data );
130 }
131
132 static const GLenum gs_prim[GL_POLYGON+1] = {
133 GL_POINTS,
134 GL_LINES,
135 GL_LINE_LOOP,
136 GL_LINES,
137 GL_TRIANGLES,
138 GL_TRIANGLES,
139 GL_TRIANGLES,
140 GL_QUADS,
141 GL_QUAD_STRIP,
142 GL_TRIANGLES
143 };
144
145 static void populate_key( struct brw_context *brw,
146 struct brw_gs_prog_key *key )
147 {
148 memset(key, 0, sizeof(*key));
149
150 /* CACHE_NEW_VS_PROG */
151 key->attrs = brw->vs.prog_data->outputs_written;
152
153 /* BRW_NEW_PRIMITIVE */
154 key->primitive = gs_prim[brw->primitive];
155
156 key->hint_gs_always = 0; /* debug code? */
157
158 key->need_gs_prog = (key->hint_gs_always ||
159 brw->primitive == GL_QUADS ||
160 brw->primitive == GL_QUAD_STRIP ||
161 brw->primitive == GL_LINE_LOOP);
162 }
163
164 /* Calculate interpolants for triangle and line rasterization.
165 */
166 static void prepare_gs_prog(struct brw_context *brw)
167 {
168 struct brw_gs_prog_key key;
169 /* Populate the key:
170 */
171 populate_key(brw, &key);
172
173 if (brw->gs.prog_active != key.need_gs_prog) {
174 brw->state.dirty.cache |= CACHE_NEW_GS_PROG;
175 brw->gs.prog_active = key.need_gs_prog;
176 }
177
178 if (brw->gs.prog_active) {
179 brw->sws->bo_unreference(brw->gs.prog_bo);
180 brw->gs.prog_bo = brw_search_cache(&brw->cache, BRW_GS_PROG,
181 &key, sizeof(key),
182 NULL, 0,
183 &brw->gs.prog_data);
184 if (brw->gs.prog_bo == NULL)
185 compile_gs_prog( brw, &key );
186 }
187 }
188
189
190 const struct brw_tracked_state brw_gs_prog = {
191 .dirty = {
192 .mesa = 0,
193 .brw = BRW_NEW_PRIMITIVE,
194 .cache = CACHE_NEW_VS_PROG
195 },
196 .prepare = prepare_gs_prog
197 };