st/mesa: cleanup st_geometry_program structure
[mesa.git] / src / mesa / state_tracker / st_program.h
1 /**************************************************************************
2 *
3 * Copyright 2003 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keithw@vmware.com>
31 */
32
33
34 #ifndef ST_PROGRAM_H
35 #define ST_PROGRAM_H
36
37 #include "main/mtypes.h"
38 #include "program/program.h"
39 #include "pipe/p_state.h"
40 #include "st_context.h"
41 #include "st_glsl_to_tgsi.h"
42
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48
49 /** Fragment program variant key */
50 struct st_fp_variant_key
51 {
52 struct st_context *st; /**< variants are per-context */
53
54 /** for glBitmap */
55 GLuint bitmap:1; /**< glBitmap variant? */
56
57 /** for glDrawPixels */
58 GLuint drawpixels:1; /**< glDrawPixels variant */
59 GLuint scaleAndBias:1; /**< glDrawPixels w/ scale and/or bias? */
60 GLuint pixelMaps:1; /**< glDrawPixels w/ pixel lookup map? */
61 GLuint drawpixels_z:1; /**< glDrawPixels(GL_DEPTH) */
62 GLuint drawpixels_stencil:1; /**< glDrawPixels(GL_STENCIL) */
63
64 /** for ARB_color_buffer_float */
65 GLuint clamp_color:1;
66
67 /** for ARB_sample_shading */
68 GLuint persample_shading:1;
69 };
70
71
72 /**
73 * Variant of a fragment program.
74 */
75 struct st_fp_variant
76 {
77 /** Parameters which generated this version of fragment program */
78 struct st_fp_variant_key key;
79
80 struct pipe_shader_state tgsi;
81
82 /** Driver's compiled shader */
83 void *driver_shader;
84
85 /** For glBitmap variants */
86 struct gl_program_parameter_list *parameters;
87 uint bitmap_sampler;
88
89 /** next in linked list */
90 struct st_fp_variant *next;
91 };
92
93
94 /**
95 * Derived from Mesa gl_fragment_program:
96 */
97 struct st_fragment_program
98 {
99 struct gl_fragment_program Base;
100 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
101
102 struct st_fp_variant *variants;
103 };
104
105
106
107 /** Vertex program variant key */
108 struct st_vp_variant_key
109 {
110 struct st_context *st; /**< variants are per-context */
111 boolean passthrough_edgeflags;
112
113 /** for ARB_color_buffer_float */
114 boolean clamp_color;
115 };
116
117
118 /**
119 * This represents a vertex program, especially translated to match
120 * the inputs of a particular fragment shader.
121 */
122 struct st_vp_variant
123 {
124 /* Parameters which generated this translated version of a vertex
125 * shader:
126 */
127 struct st_vp_variant_key key;
128
129 /**
130 * TGSI tokens (to later generate a 'draw' module shader for
131 * selection/feedback/rasterpos)
132 */
133 struct pipe_shader_state tgsi;
134
135 /** Driver's compiled shader */
136 void *driver_shader;
137
138 /** For using our private draw module (glRasterPos) */
139 struct draw_vertex_shader *draw_shader;
140
141 /** Next in linked list */
142 struct st_vp_variant *next;
143
144 /** similar to that in st_vertex_program, but with edgeflags info too */
145 GLuint num_inputs;
146 };
147
148
149 /**
150 * Derived from Mesa gl_fragment_program:
151 */
152 struct st_vertex_program
153 {
154 struct gl_vertex_program Base; /**< The Mesa vertex program */
155 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
156
157 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
158 GLuint input_to_index[VERT_ATTRIB_MAX];
159 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
160 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
161 GLuint num_inputs;
162
163 /** Maps VARYING_SLOT_x to slot */
164 GLuint result_to_output[VARYING_SLOT_MAX];
165 ubyte output_semantic_name[VARYING_SLOT_MAX];
166 ubyte output_semantic_index[VARYING_SLOT_MAX];
167 GLuint num_outputs;
168
169 /** List of translated variants of this vertex program.
170 */
171 struct st_vp_variant *variants;
172 };
173
174
175
176 /** Geometry program variant key */
177 struct st_gp_variant_key
178 {
179 struct st_context *st; /**< variants are per-context */
180 /* no other fields yet */
181 };
182
183
184 /**
185 * Geometry program variant.
186 */
187 struct st_gp_variant
188 {
189 /* Parameters which generated this translated version of a vertex */
190 struct st_gp_variant_key key;
191
192 void *driver_shader;
193
194 struct st_gp_variant *next;
195 };
196
197
198 /**
199 * Derived from Mesa gl_geometry_program:
200 */
201 struct st_geometry_program
202 {
203 struct gl_geometry_program Base; /**< The Mesa geometry program */
204 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
205
206 struct st_gp_variant *variants;
207 };
208
209
210
211 static INLINE struct st_fragment_program *
212 st_fragment_program( struct gl_fragment_program *fp )
213 {
214 return (struct st_fragment_program *)fp;
215 }
216
217
218 static INLINE struct st_vertex_program *
219 st_vertex_program( struct gl_vertex_program *vp )
220 {
221 return (struct st_vertex_program *)vp;
222 }
223
224 static INLINE struct st_geometry_program *
225 st_geometry_program( struct gl_geometry_program *gp )
226 {
227 return (struct st_geometry_program *)gp;
228 }
229
230 static INLINE void
231 st_reference_vertprog(struct st_context *st,
232 struct st_vertex_program **ptr,
233 struct st_vertex_program *prog)
234 {
235 _mesa_reference_program(st->ctx,
236 (struct gl_program **) ptr,
237 (struct gl_program *) prog);
238 }
239
240 static INLINE void
241 st_reference_geomprog(struct st_context *st,
242 struct st_geometry_program **ptr,
243 struct st_geometry_program *prog)
244 {
245 _mesa_reference_program(st->ctx,
246 (struct gl_program **) ptr,
247 (struct gl_program *) prog);
248 }
249
250 static INLINE void
251 st_reference_fragprog(struct st_context *st,
252 struct st_fragment_program **ptr,
253 struct st_fragment_program *prog)
254 {
255 _mesa_reference_program(st->ctx,
256 (struct gl_program **) ptr,
257 (struct gl_program *) prog);
258 }
259
260 /**
261 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
262 */
263 static INLINE unsigned
264 st_get_generic_varying_index(struct st_context *st, GLuint attr)
265 {
266 if (attr >= VARYING_SLOT_VAR0) {
267 if (st->needs_texcoord_semantic)
268 return attr - VARYING_SLOT_VAR0;
269 else
270 return 9 + (attr - VARYING_SLOT_VAR0);
271 }
272 if (attr == VARYING_SLOT_PNTC) {
273 assert(!st->needs_texcoord_semantic);
274 return 8;
275 }
276 if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
277 assert(!st->needs_texcoord_semantic);
278 return attr - VARYING_SLOT_TEX0;
279 }
280
281 assert(0);
282 return 0;
283 }
284
285
286 extern struct st_vp_variant *
287 st_get_vp_variant(struct st_context *st,
288 struct st_vertex_program *stvp,
289 const struct st_vp_variant_key *key);
290
291
292 extern struct st_fp_variant *
293 st_get_fp_variant(struct st_context *st,
294 struct st_fragment_program *stfp,
295 const struct st_fp_variant_key *key);
296
297
298 extern struct st_gp_variant *
299 st_get_gp_variant(struct st_context *st,
300 struct st_geometry_program *stgp,
301 const struct st_gp_variant_key *key);
302
303
304 extern void
305 st_prepare_vertex_program(struct gl_context *ctx,
306 struct st_vertex_program *stvp);
307
308 extern GLboolean
309 st_prepare_fragment_program(struct gl_context *ctx,
310 struct st_fragment_program *stfp);
311
312
313 extern void
314 st_release_vp_variants( struct st_context *st,
315 struct st_vertex_program *stvp );
316
317 extern void
318 st_release_fp_variants( struct st_context *st,
319 struct st_fragment_program *stfp );
320
321 extern void
322 st_release_gp_variants(struct st_context *st,
323 struct st_geometry_program *stgp);
324
325
326 extern void
327 st_print_shaders(struct gl_context *ctx);
328
329 extern void
330 st_destroy_program_variants(struct st_context *st);
331
332
333 extern void
334 st_print_current_vertex_program(void);
335
336
337 #ifdef __cplusplus
338 }
339 #endif
340
341 #endif