i965 gs: Remove unnecessary mapping of key->primitive.
[mesa.git] / src / mesa / drivers / dri / 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 "main/glheader.h"
33 #include "main/macros.h"
34 #include "main/enums.h"
35
36 #include "intel_batchbuffer.h"
37
38 #include "brw_defines.h"
39 #include "brw_context.h"
40 #include "brw_eu.h"
41 #include "brw_util.h"
42 #include "brw_state.h"
43 #include "brw_gs.h"
44
45 #include "glsl/ralloc.h"
46
47 static void compile_gs_prog( struct brw_context *brw,
48 struct brw_gs_prog_key *key )
49 {
50 struct intel_context *intel = &brw->intel;
51 struct brw_gs_compile c;
52 const GLuint *program;
53 void *mem_ctx;
54 GLuint program_size;
55
56 /* Gen6: VF has already converted into polygon, and LINELOOP is
57 * converted to LINESTRIP at the beginning of the 3D pipeline.
58 */
59 if (intel->gen >= 6)
60 return;
61
62 memset(&c, 0, sizeof(c));
63
64 c.key = *key;
65 /* The geometry shader needs to access the entire VUE. */
66 struct brw_vue_map vue_map;
67 brw_compute_vue_map(&vue_map, intel, c.key.userclip_active, c.key.attrs);
68 c.nr_regs = (vue_map.num_slots + 1)/2;
69
70 mem_ctx = NULL;
71
72 /* Begin the compilation:
73 */
74 brw_init_compile(brw, &c.func, mem_ctx);
75
76 c.func.single_program_flow = 1;
77
78 /* For some reason the thread is spawned with only 4 channels
79 * unmasked.
80 */
81 brw_set_mask_control(&c.func, BRW_MASK_DISABLE);
82
83
84 /* Note that primitives which don't require a GS program have
85 * already been weeded out by this stage:
86 */
87
88 switch (key->primitive) {
89 case _3DPRIM_QUADLIST:
90 brw_gs_quads( &c, key );
91 break;
92 case _3DPRIM_QUADSTRIP:
93 brw_gs_quad_strip( &c, key );
94 break;
95 case _3DPRIM_LINELOOP:
96 brw_gs_lines( &c );
97 break;
98 default:
99 ralloc_free(mem_ctx);
100 return;
101 }
102
103 /* get the program
104 */
105 program = brw_get_program(&c.func, &program_size);
106
107 if (unlikely(INTEL_DEBUG & DEBUG_GS)) {
108 int i;
109
110 printf("gs:\n");
111 for (i = 0; i < program_size / sizeof(struct brw_instruction); i++)
112 brw_disasm(stdout, &((struct brw_instruction *)program)[i],
113 intel->gen);
114 printf("\n");
115 }
116
117 brw_upload_cache(&brw->cache, BRW_GS_PROG,
118 &c.key, sizeof(c.key),
119 program, program_size,
120 &c.prog_data, sizeof(c.prog_data),
121 &brw->gs.prog_offset, &brw->gs.prog_data);
122 ralloc_free(mem_ctx);
123 }
124
125 static void populate_key( struct brw_context *brw,
126 struct brw_gs_prog_key *key )
127 {
128 struct gl_context *ctx = &brw->intel.ctx;
129 struct intel_context *intel = &brw->intel;
130
131 memset(key, 0, sizeof(*key));
132
133 /* CACHE_NEW_VS_PROG */
134 key->attrs = brw->vs.prog_data->outputs_written;
135
136 /* BRW_NEW_PRIMITIVE */
137 key->primitive = brw->primitive;
138
139 /* _NEW_LIGHT */
140 key->pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);
141 if (key->primitive == _3DPRIM_QUADLIST && ctx->Light.ShadeModel != GL_FLAT) {
142 /* Provide consistent primitive order with brw_set_prim's
143 * optimization of single quads to trifans.
144 */
145 key->pv_first = true;
146 }
147
148 /* _NEW_TRANSFORM */
149 key->userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
150
151 key->need_gs_prog = (intel->gen >= 6)
152 ? 0
153 : (brw->primitive == _3DPRIM_QUADLIST ||
154 brw->primitive == _3DPRIM_QUADSTRIP ||
155 brw->primitive == _3DPRIM_LINELOOP);
156 }
157
158 /* Calculate interpolants for triangle and line rasterization.
159 */
160 static void
161 brw_upload_gs_prog(struct brw_context *brw)
162 {
163 struct brw_gs_prog_key key;
164 /* Populate the key:
165 */
166 populate_key(brw, &key);
167
168 if (brw->gs.prog_active != key.need_gs_prog) {
169 brw->state.dirty.cache |= CACHE_NEW_GS_PROG;
170 brw->gs.prog_active = key.need_gs_prog;
171 }
172
173 if (brw->gs.prog_active) {
174 if (!brw_search_cache(&brw->cache, BRW_GS_PROG,
175 &key, sizeof(key),
176 &brw->gs.prog_offset, &brw->gs.prog_data)) {
177 compile_gs_prog( brw, &key );
178 }
179 }
180 }
181
182
183 const struct brw_tracked_state brw_gs_prog = {
184 .dirty = {
185 .mesa = (_NEW_LIGHT |
186 _NEW_TRANSFORM),
187 .brw = BRW_NEW_PRIMITIVE,
188 .cache = CACHE_NEW_VS_PROG
189 },
190 .emit = brw_upload_gs_prog
191 };