st/mesa: translate geometry shaders into TGSI when we get them
[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 #define ST_DOUBLE_ATTRIB_PLACEHOLDER 0xffffffff
49
50 /** Fragment program variant key */
51 struct st_fp_variant_key
52 {
53 struct st_context *st; /**< variants are per-context */
54
55 /** for glBitmap */
56 GLuint bitmap:1; /**< glBitmap variant? */
57
58 /** for glDrawPixels */
59 GLuint drawpixels:1; /**< glDrawPixels variant */
60 GLuint scaleAndBias:1; /**< glDrawPixels w/ scale and/or bias? */
61 GLuint pixelMaps:1; /**< glDrawPixels w/ pixel lookup map? */
62
63 /** for ARB_color_buffer_float */
64 GLuint clamp_color:1;
65
66 /** for ARB_sample_shading */
67 GLuint persample_shading:1;
68 };
69
70
71 /**
72 * Variant of a fragment program.
73 */
74 struct st_fp_variant
75 {
76 /** Parameters which generated this version of fragment program */
77 struct st_fp_variant_key key;
78
79 /** Driver's compiled shader */
80 void *driver_shader;
81
82 /** For glBitmap variants */
83 struct gl_program_parameter_list *parameters;
84 uint bitmap_sampler;
85
86 /** For glDrawPixels variants */
87 unsigned drawpix_sampler;
88 unsigned pixelmap_sampler;
89
90 /** next in linked list */
91 struct st_fp_variant *next;
92 };
93
94
95 /**
96 * Derived from Mesa gl_fragment_program:
97 */
98 struct st_fragment_program
99 {
100 struct gl_fragment_program Base;
101 struct pipe_shader_state tgsi;
102 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
103
104 struct st_fp_variant *variants;
105 };
106
107
108
109 /** Vertex program variant key */
110 struct st_vp_variant_key
111 {
112 struct st_context *st; /**< variants are per-context */
113 boolean passthrough_edgeflags;
114
115 /** for ARB_color_buffer_float */
116 boolean clamp_color;
117 };
118
119
120 /**
121 * This represents a vertex program, especially translated to match
122 * the inputs of a particular fragment shader.
123 */
124 struct st_vp_variant
125 {
126 /* Parameters which generated this translated version of a vertex
127 * shader:
128 */
129 struct st_vp_variant_key key;
130
131 /**
132 * TGSI tokens (to later generate a 'draw' module shader for
133 * selection/feedback/rasterpos)
134 */
135 struct pipe_shader_state tgsi;
136
137 /** Driver's compiled shader */
138 void *driver_shader;
139
140 /** For using our private draw module (glRasterPos) */
141 struct draw_vertex_shader *draw_shader;
142
143 /** Next in linked list */
144 struct st_vp_variant *next;
145
146 /** similar to that in st_vertex_program, but with edgeflags info too */
147 GLuint num_inputs;
148 };
149
150
151 /**
152 * Derived from Mesa gl_fragment_program:
153 */
154 struct st_vertex_program
155 {
156 struct gl_vertex_program Base; /**< The Mesa vertex program */
157 struct pipe_shader_state tgsi;
158 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
159
160 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
161 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
162 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
163 GLuint num_inputs;
164
165 /** Maps VARYING_SLOT_x to slot */
166 GLuint result_to_output[VARYING_SLOT_MAX];
167
168 /** List of translated variants of this vertex program.
169 */
170 struct st_vp_variant *variants;
171 };
172
173
174
175 /** Geometry program variant key */
176 struct st_gp_variant_key
177 {
178 struct st_context *st; /**< variants are per-context */
179 /* no other fields yet */
180 };
181
182
183 /**
184 * Geometry program variant.
185 */
186 struct st_gp_variant
187 {
188 /* Parameters which generated this variant. */
189 struct st_gp_variant_key key;
190
191 void *driver_shader;
192
193 struct st_gp_variant *next;
194 };
195
196
197 /**
198 * Derived from Mesa gl_geometry_program:
199 */
200 struct st_geometry_program
201 {
202 struct gl_geometry_program Base; /**< The Mesa geometry program */
203 struct pipe_shader_state tgsi;
204 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
205
206 struct st_gp_variant *variants;
207 };
208
209
210
211 /** Tessellation control program variant key */
212 struct st_tcp_variant_key
213 {
214 struct st_context *st; /**< variants are per-context */
215 /* no other fields yet */
216 };
217
218
219 /**
220 * Tessellation control program variant.
221 */
222 struct st_tcp_variant
223 {
224 /* Parameters which generated this variant. */
225 struct st_tcp_variant_key key;
226
227 void *driver_shader;
228
229 struct st_tcp_variant *next;
230 };
231
232
233 /**
234 * Derived from Mesa gl_tess_ctrl_program:
235 */
236 struct st_tessctrl_program
237 {
238 struct gl_tess_ctrl_program Base; /**< The Mesa tess ctrl program */
239 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
240
241 struct st_tcp_variant *variants;
242 };
243
244
245
246 /** Tessellation evaluation program variant key */
247 struct st_tep_variant_key
248 {
249 struct st_context *st; /**< variants are per-context */
250 /* no other fields yet */
251 };
252
253
254 /**
255 * Tessellation evaluation program variant.
256 */
257 struct st_tep_variant
258 {
259 /* Parameters which generated this variant. */
260 struct st_tep_variant_key key;
261
262 void *driver_shader;
263
264 struct st_tep_variant *next;
265 };
266
267
268 /**
269 * Derived from Mesa gl_tess_eval_program:
270 */
271 struct st_tesseval_program
272 {
273 struct gl_tess_eval_program Base; /**< The Mesa tess eval program */
274 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
275
276 struct st_tep_variant *variants;
277 };
278
279
280
281 static inline struct st_fragment_program *
282 st_fragment_program( struct gl_fragment_program *fp )
283 {
284 return (struct st_fragment_program *)fp;
285 }
286
287
288 static inline struct st_vertex_program *
289 st_vertex_program( struct gl_vertex_program *vp )
290 {
291 return (struct st_vertex_program *)vp;
292 }
293
294 static inline struct st_geometry_program *
295 st_geometry_program( struct gl_geometry_program *gp )
296 {
297 return (struct st_geometry_program *)gp;
298 }
299
300 static inline struct st_tessctrl_program *
301 st_tessctrl_program( struct gl_tess_ctrl_program *tcp )
302 {
303 return (struct st_tessctrl_program *)tcp;
304 }
305
306 static inline struct st_tesseval_program *
307 st_tesseval_program( struct gl_tess_eval_program *tep )
308 {
309 return (struct st_tesseval_program *)tep;
310 }
311
312 static inline void
313 st_reference_vertprog(struct st_context *st,
314 struct st_vertex_program **ptr,
315 struct st_vertex_program *prog)
316 {
317 _mesa_reference_program(st->ctx,
318 (struct gl_program **) ptr,
319 (struct gl_program *) prog);
320 }
321
322 static inline void
323 st_reference_geomprog(struct st_context *st,
324 struct st_geometry_program **ptr,
325 struct st_geometry_program *prog)
326 {
327 _mesa_reference_program(st->ctx,
328 (struct gl_program **) ptr,
329 (struct gl_program *) prog);
330 }
331
332 static inline void
333 st_reference_fragprog(struct st_context *st,
334 struct st_fragment_program **ptr,
335 struct st_fragment_program *prog)
336 {
337 _mesa_reference_program(st->ctx,
338 (struct gl_program **) ptr,
339 (struct gl_program *) prog);
340 }
341
342 static inline void
343 st_reference_tesscprog(struct st_context *st,
344 struct st_tessctrl_program **ptr,
345 struct st_tessctrl_program *prog)
346 {
347 _mesa_reference_program(st->ctx,
348 (struct gl_program **) ptr,
349 (struct gl_program *) prog);
350 }
351
352 static inline void
353 st_reference_tesseprog(struct st_context *st,
354 struct st_tesseval_program **ptr,
355 struct st_tesseval_program *prog)
356 {
357 _mesa_reference_program(st->ctx,
358 (struct gl_program **) ptr,
359 (struct gl_program *) prog);
360 }
361
362 /**
363 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
364 */
365 static inline unsigned
366 st_get_generic_varying_index(struct st_context *st, GLuint attr)
367 {
368 if (attr >= VARYING_SLOT_VAR0) {
369 if (st->needs_texcoord_semantic)
370 return attr - VARYING_SLOT_VAR0;
371 else
372 return 9 + (attr - VARYING_SLOT_VAR0);
373 }
374 if (attr == VARYING_SLOT_PNTC) {
375 assert(!st->needs_texcoord_semantic);
376 return 8;
377 }
378 if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
379 assert(!st->needs_texcoord_semantic);
380 return attr - VARYING_SLOT_TEX0;
381 }
382
383 assert(0);
384 return 0;
385 }
386
387
388 extern struct st_vp_variant *
389 st_get_vp_variant(struct st_context *st,
390 struct st_vertex_program *stvp,
391 const struct st_vp_variant_key *key);
392
393
394 extern struct st_fp_variant *
395 st_get_fp_variant(struct st_context *st,
396 struct st_fragment_program *stfp,
397 const struct st_fp_variant_key *key);
398
399
400 extern struct st_gp_variant *
401 st_get_gp_variant(struct st_context *st,
402 struct st_geometry_program *stgp,
403 const struct st_gp_variant_key *key);
404
405 extern struct st_tcp_variant *
406 st_get_tcp_variant(struct st_context *st,
407 struct st_tessctrl_program *stgp,
408 const struct st_tcp_variant_key *key);
409
410 extern struct st_tep_variant *
411 st_get_tep_variant(struct st_context *st,
412 struct st_tesseval_program *stgp,
413 const struct st_tep_variant_key *key);
414
415 extern void
416 st_release_vp_variants( struct st_context *st,
417 struct st_vertex_program *stvp );
418
419 extern void
420 st_release_fp_variants( struct st_context *st,
421 struct st_fragment_program *stfp );
422
423 extern void
424 st_release_gp_variants(struct st_context *st,
425 struct st_geometry_program *stgp);
426
427 extern void
428 st_release_tcp_variants(struct st_context *st,
429 struct st_tessctrl_program *stgp);
430
431 extern void
432 st_release_tep_variants(struct st_context *st,
433 struct st_tesseval_program *stgp);
434
435 extern void
436 st_destroy_program_variants(struct st_context *st);
437
438 extern bool
439 st_translate_vertex_program(struct st_context *st,
440 struct st_vertex_program *stvp);
441
442 extern bool
443 st_translate_fragment_program(struct st_context *st,
444 struct st_fragment_program *stfp);
445
446 extern bool
447 st_translate_geometry_program(struct st_context *st,
448 struct st_geometry_program *stgp);
449
450 extern void
451 st_print_current_vertex_program(void);
452
453 extern void
454 st_precompile_shader_variant(struct st_context *st,
455 struct gl_program *prog);
456
457 #ifdef __cplusplus
458 }
459 #endif
460
461 #endif