st/mesa: add missing ETC2 entries to format_map
[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 uint bitmap_sampler;
84
85 /** For glDrawPixels variants */
86 unsigned drawpix_sampler;
87 unsigned pixelmap_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 pipe_shader_state tgsi;
101 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
102
103 struct st_fp_variant *variants;
104 };
105
106
107
108 /** Vertex program variant key */
109 struct st_vp_variant_key
110 {
111 struct st_context *st; /**< variants are per-context */
112 boolean passthrough_edgeflags;
113
114 /** for ARB_color_buffer_float */
115 boolean clamp_color;
116 };
117
118
119 /**
120 * This represents a vertex program, especially translated to match
121 * the inputs of a particular fragment shader.
122 */
123 struct st_vp_variant
124 {
125 /* Parameters which generated this translated version of a vertex
126 * shader:
127 */
128 struct st_vp_variant_key key;
129
130 /**
131 * TGSI tokens (to later generate a 'draw' module shader for
132 * selection/feedback/rasterpos)
133 */
134 struct pipe_shader_state tgsi;
135
136 /** Driver's compiled shader */
137 void *driver_shader;
138
139 /** For using our private draw module (glRasterPos) */
140 struct draw_vertex_shader *draw_shader;
141
142 /** Next in linked list */
143 struct st_vp_variant *next;
144
145 /** similar to that in st_vertex_program, but with edgeflags info too */
146 GLuint num_inputs;
147 };
148
149
150 /**
151 * Derived from Mesa gl_fragment_program:
152 */
153 struct st_vertex_program
154 {
155 struct gl_vertex_program Base; /**< The Mesa vertex program */
156 struct pipe_shader_state tgsi;
157 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
158
159 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
160 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
161 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
162 GLuint num_inputs;
163
164 /** Maps VARYING_SLOT_x to slot */
165 GLuint result_to_output[VARYING_SLOT_MAX];
166
167 /** List of translated variants of this vertex program.
168 */
169 struct st_vp_variant *variants;
170 };
171
172
173
174 /** Key shared by all shaders except VP, FP */
175 struct st_basic_variant_key
176 {
177 struct st_context *st; /**< variants are per-context */
178 };
179
180
181 /**
182 * Geometry program variant.
183 */
184 struct st_basic_variant
185 {
186 /* Parameters which generated this variant. */
187 struct st_basic_variant_key key;
188
189 void *driver_shader;
190
191 struct st_basic_variant *next;
192 };
193
194
195 /**
196 * Derived from Mesa gl_geometry_program:
197 */
198 struct st_geometry_program
199 {
200 struct gl_geometry_program Base; /**< The Mesa geometry program */
201 struct pipe_shader_state tgsi;
202 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
203
204 struct st_basic_variant *variants;
205 };
206
207
208 /**
209 * Derived from Mesa gl_tess_ctrl_program:
210 */
211 struct st_tessctrl_program
212 {
213 struct gl_tess_ctrl_program Base; /**< The Mesa tess ctrl program */
214 struct pipe_shader_state tgsi;
215 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
216
217 struct st_basic_variant *variants;
218 };
219
220
221 /**
222 * Derived from Mesa gl_tess_eval_program:
223 */
224 struct st_tesseval_program
225 {
226 struct gl_tess_eval_program Base; /**< The Mesa tess eval program */
227 struct pipe_shader_state tgsi;
228 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
229
230 struct st_basic_variant *variants;
231 };
232
233
234 /**
235 * Derived from Mesa gl_compute_program:
236 */
237 struct st_compute_program
238 {
239 struct gl_compute_program Base; /**< The Mesa compute program */
240 struct pipe_compute_state tgsi;
241 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
242
243 struct st_basic_variant *variants;
244 };
245
246
247 static inline struct st_fragment_program *
248 st_fragment_program( struct gl_fragment_program *fp )
249 {
250 return (struct st_fragment_program *)fp;
251 }
252
253
254 static inline struct st_vertex_program *
255 st_vertex_program( struct gl_vertex_program *vp )
256 {
257 return (struct st_vertex_program *)vp;
258 }
259
260 static inline struct st_geometry_program *
261 st_geometry_program( struct gl_geometry_program *gp )
262 {
263 return (struct st_geometry_program *)gp;
264 }
265
266 static inline struct st_tessctrl_program *
267 st_tessctrl_program( struct gl_tess_ctrl_program *tcp )
268 {
269 return (struct st_tessctrl_program *)tcp;
270 }
271
272 static inline struct st_tesseval_program *
273 st_tesseval_program( struct gl_tess_eval_program *tep )
274 {
275 return (struct st_tesseval_program *)tep;
276 }
277
278 static inline struct st_compute_program *
279 st_compute_program( struct gl_compute_program *cp )
280 {
281 return (struct st_compute_program *)cp;
282 }
283
284 static inline void
285 st_reference_vertprog(struct st_context *st,
286 struct st_vertex_program **ptr,
287 struct st_vertex_program *prog)
288 {
289 _mesa_reference_program(st->ctx,
290 (struct gl_program **) ptr,
291 (struct gl_program *) prog);
292 }
293
294 static inline void
295 st_reference_geomprog(struct st_context *st,
296 struct st_geometry_program **ptr,
297 struct st_geometry_program *prog)
298 {
299 _mesa_reference_program(st->ctx,
300 (struct gl_program **) ptr,
301 (struct gl_program *) prog);
302 }
303
304 static inline void
305 st_reference_fragprog(struct st_context *st,
306 struct st_fragment_program **ptr,
307 struct st_fragment_program *prog)
308 {
309 _mesa_reference_program(st->ctx,
310 (struct gl_program **) ptr,
311 (struct gl_program *) prog);
312 }
313
314 static inline void
315 st_reference_tesscprog(struct st_context *st,
316 struct st_tessctrl_program **ptr,
317 struct st_tessctrl_program *prog)
318 {
319 _mesa_reference_program(st->ctx,
320 (struct gl_program **) ptr,
321 (struct gl_program *) prog);
322 }
323
324 static inline void
325 st_reference_tesseprog(struct st_context *st,
326 struct st_tesseval_program **ptr,
327 struct st_tesseval_program *prog)
328 {
329 _mesa_reference_program(st->ctx,
330 (struct gl_program **) ptr,
331 (struct gl_program *) prog);
332 }
333
334 static inline void
335 st_reference_compprog(struct st_context *st,
336 struct st_compute_program **ptr,
337 struct st_compute_program *prog)
338 {
339 _mesa_reference_program(st->ctx,
340 (struct gl_program **) ptr,
341 (struct gl_program *) prog);
342 }
343
344 /**
345 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
346 */
347 static inline unsigned
348 st_get_generic_varying_index(struct st_context *st, GLuint attr)
349 {
350 if (attr >= VARYING_SLOT_VAR0) {
351 if (st->needs_texcoord_semantic)
352 return attr - VARYING_SLOT_VAR0;
353 else
354 return 9 + (attr - VARYING_SLOT_VAR0);
355 }
356 if (attr == VARYING_SLOT_PNTC) {
357 assert(!st->needs_texcoord_semantic);
358 return 8;
359 }
360 if (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7) {
361 assert(!st->needs_texcoord_semantic);
362 return attr - VARYING_SLOT_TEX0;
363 }
364
365 assert(0);
366 return 0;
367 }
368
369
370 extern struct st_vp_variant *
371 st_get_vp_variant(struct st_context *st,
372 struct st_vertex_program *stvp,
373 const struct st_vp_variant_key *key);
374
375
376 extern struct st_fp_variant *
377 st_get_fp_variant(struct st_context *st,
378 struct st_fragment_program *stfp,
379 const struct st_fp_variant_key *key);
380
381 extern struct st_basic_variant *
382 st_get_cp_variant(struct st_context *st,
383 struct pipe_compute_state *tgsi,
384 struct st_basic_variant **variants);
385
386 extern struct st_basic_variant *
387 st_get_basic_variant(struct st_context *st,
388 unsigned pipe_shader,
389 struct pipe_shader_state *tgsi,
390 struct st_basic_variant **variants);
391
392 extern void
393 st_release_vp_variants( struct st_context *st,
394 struct st_vertex_program *stvp );
395
396 extern void
397 st_release_fp_variants( struct st_context *st,
398 struct st_fragment_program *stfp );
399
400 extern void
401 st_release_cp_variants(struct st_context *st,
402 struct st_compute_program *stcp);
403
404 extern void
405 st_release_basic_variants(struct st_context *st, GLenum target,
406 struct st_basic_variant **variants,
407 struct pipe_shader_state *tgsi);
408
409 extern void
410 st_destroy_program_variants(struct st_context *st);
411
412 extern bool
413 st_translate_vertex_program(struct st_context *st,
414 struct st_vertex_program *stvp);
415
416 extern bool
417 st_translate_fragment_program(struct st_context *st,
418 struct st_fragment_program *stfp);
419
420 extern bool
421 st_translate_geometry_program(struct st_context *st,
422 struct st_geometry_program *stgp);
423
424 extern bool
425 st_translate_tessctrl_program(struct st_context *st,
426 struct st_tessctrl_program *sttcp);
427
428 extern bool
429 st_translate_tesseval_program(struct st_context *st,
430 struct st_tesseval_program *sttep);
431
432 extern bool
433 st_translate_compute_program(struct st_context *st,
434 struct st_compute_program *stcp);
435
436 extern void
437 st_print_current_vertex_program(void);
438
439 extern void
440 st_precompile_shader_variant(struct st_context *st,
441 struct gl_program *prog);
442
443 #ifdef __cplusplus
444 }
445 #endif
446
447 #endif