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