1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keithw@vmware.com>
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"
48 #define ST_DOUBLE_ATTRIB_PLACEHOLDER 0xffffffff
50 /** Fragment program variant key */
51 struct st_fp_variant_key
53 struct st_context
*st
; /**< variants are per-context */
56 GLuint bitmap
:1; /**< glBitmap variant? */
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? */
63 /** for ARB_color_buffer_float */
66 /** for ARB_sample_shading */
67 GLuint persample_shading
:1;
72 * Variant of a fragment program.
76 /** Parameters which generated this version of fragment program */
77 struct st_fp_variant_key key
;
79 /** Driver's compiled shader */
82 /** For glBitmap variants */
85 /** For glDrawPixels variants */
86 unsigned drawpix_sampler
;
87 unsigned pixelmap_sampler
;
89 /** next in linked list */
90 struct st_fp_variant
*next
;
95 * Derived from Mesa gl_fragment_program:
97 struct st_fragment_program
99 struct gl_fragment_program Base
;
100 struct pipe_shader_state tgsi
;
101 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
103 struct st_fp_variant
*variants
;
108 /** Vertex program variant key */
109 struct st_vp_variant_key
111 struct st_context
*st
; /**< variants are per-context */
112 boolean passthrough_edgeflags
;
114 /** for ARB_color_buffer_float */
120 * This represents a vertex program, especially translated to match
121 * the inputs of a particular fragment shader.
125 /* Parameters which generated this translated version of a vertex
128 struct st_vp_variant_key key
;
131 * TGSI tokens (to later generate a 'draw' module shader for
132 * selection/feedback/rasterpos)
134 struct pipe_shader_state tgsi
;
136 /** Driver's compiled shader */
139 /** For using our private draw module (glRasterPos) */
140 struct draw_vertex_shader
*draw_shader
;
142 /** Next in linked list */
143 struct st_vp_variant
*next
;
145 /** similar to that in st_vertex_program, but with edgeflags info too */
151 * Derived from Mesa gl_fragment_program:
153 struct st_vertex_program
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
;
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
];
164 /** Maps VARYING_SLOT_x to slot */
165 GLuint result_to_output
[VARYING_SLOT_MAX
];
167 /** List of translated variants of this vertex program.
169 struct st_vp_variant
*variants
;
174 /** Geometry program variant key */
175 struct st_gp_variant_key
177 struct st_context
*st
; /**< variants are per-context */
178 /* no other fields yet */
183 * Geometry program variant.
187 /* Parameters which generated this variant. */
188 struct st_gp_variant_key key
;
192 struct st_gp_variant
*next
;
197 * Derived from Mesa gl_geometry_program:
199 struct st_geometry_program
201 struct gl_geometry_program Base
; /**< The Mesa geometry program */
202 struct pipe_shader_state tgsi
;
203 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
205 struct st_gp_variant
*variants
;
210 /** Tessellation control program variant key */
211 struct st_tcp_variant_key
213 struct st_context
*st
; /**< variants are per-context */
214 /* no other fields yet */
219 * Tessellation control program variant.
221 struct st_tcp_variant
223 /* Parameters which generated this variant. */
224 struct st_tcp_variant_key key
;
228 struct st_tcp_variant
*next
;
233 * Derived from Mesa gl_tess_ctrl_program:
235 struct st_tessctrl_program
237 struct gl_tess_ctrl_program Base
; /**< The Mesa tess ctrl program */
238 struct pipe_shader_state tgsi
;
239 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
241 struct st_tcp_variant
*variants
;
246 /** Tessellation evaluation program variant key */
247 struct st_tep_variant_key
249 struct st_context
*st
; /**< variants are per-context */
250 /* no other fields yet */
255 * Tessellation evaluation program variant.
257 struct st_tep_variant
259 /* Parameters which generated this variant. */
260 struct st_tep_variant_key key
;
264 struct st_tep_variant
*next
;
269 * Derived from Mesa gl_tess_eval_program:
271 struct st_tesseval_program
273 struct gl_tess_eval_program Base
; /**< The Mesa tess eval program */
274 struct pipe_shader_state tgsi
;
275 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
277 struct st_tep_variant
*variants
;
282 static inline struct st_fragment_program
*
283 st_fragment_program( struct gl_fragment_program
*fp
)
285 return (struct st_fragment_program
*)fp
;
289 static inline struct st_vertex_program
*
290 st_vertex_program( struct gl_vertex_program
*vp
)
292 return (struct st_vertex_program
*)vp
;
295 static inline struct st_geometry_program
*
296 st_geometry_program( struct gl_geometry_program
*gp
)
298 return (struct st_geometry_program
*)gp
;
301 static inline struct st_tessctrl_program
*
302 st_tessctrl_program( struct gl_tess_ctrl_program
*tcp
)
304 return (struct st_tessctrl_program
*)tcp
;
307 static inline struct st_tesseval_program
*
308 st_tesseval_program( struct gl_tess_eval_program
*tep
)
310 return (struct st_tesseval_program
*)tep
;
314 st_reference_vertprog(struct st_context
*st
,
315 struct st_vertex_program
**ptr
,
316 struct st_vertex_program
*prog
)
318 _mesa_reference_program(st
->ctx
,
319 (struct gl_program
**) ptr
,
320 (struct gl_program
*) prog
);
324 st_reference_geomprog(struct st_context
*st
,
325 struct st_geometry_program
**ptr
,
326 struct st_geometry_program
*prog
)
328 _mesa_reference_program(st
->ctx
,
329 (struct gl_program
**) ptr
,
330 (struct gl_program
*) prog
);
334 st_reference_fragprog(struct st_context
*st
,
335 struct st_fragment_program
**ptr
,
336 struct st_fragment_program
*prog
)
338 _mesa_reference_program(st
->ctx
,
339 (struct gl_program
**) ptr
,
340 (struct gl_program
*) prog
);
344 st_reference_tesscprog(struct st_context
*st
,
345 struct st_tessctrl_program
**ptr
,
346 struct st_tessctrl_program
*prog
)
348 _mesa_reference_program(st
->ctx
,
349 (struct gl_program
**) ptr
,
350 (struct gl_program
*) prog
);
354 st_reference_tesseprog(struct st_context
*st
,
355 struct st_tesseval_program
**ptr
,
356 struct st_tesseval_program
*prog
)
358 _mesa_reference_program(st
->ctx
,
359 (struct gl_program
**) ptr
,
360 (struct gl_program
*) prog
);
364 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
366 static inline unsigned
367 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
369 if (attr
>= VARYING_SLOT_VAR0
) {
370 if (st
->needs_texcoord_semantic
)
371 return attr
- VARYING_SLOT_VAR0
;
373 return 9 + (attr
- VARYING_SLOT_VAR0
);
375 if (attr
== VARYING_SLOT_PNTC
) {
376 assert(!st
->needs_texcoord_semantic
);
379 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
380 assert(!st
->needs_texcoord_semantic
);
381 return attr
- VARYING_SLOT_TEX0
;
389 extern struct st_vp_variant
*
390 st_get_vp_variant(struct st_context
*st
,
391 struct st_vertex_program
*stvp
,
392 const struct st_vp_variant_key
*key
);
395 extern struct st_fp_variant
*
396 st_get_fp_variant(struct st_context
*st
,
397 struct st_fragment_program
*stfp
,
398 const struct st_fp_variant_key
*key
);
401 extern struct st_gp_variant
*
402 st_get_gp_variant(struct st_context
*st
,
403 struct st_geometry_program
*stgp
,
404 const struct st_gp_variant_key
*key
);
406 extern struct st_tcp_variant
*
407 st_get_tcp_variant(struct st_context
*st
,
408 struct st_tessctrl_program
*sttcp
,
409 const struct st_tcp_variant_key
*key
);
411 extern struct st_tep_variant
*
412 st_get_tep_variant(struct st_context
*st
,
413 struct st_tesseval_program
*sttep
,
414 const struct st_tep_variant_key
*key
);
417 st_release_vp_variants( struct st_context
*st
,
418 struct st_vertex_program
*stvp
);
421 st_release_fp_variants( struct st_context
*st
,
422 struct st_fragment_program
*stfp
);
425 st_release_gp_variants(struct st_context
*st
,
426 struct st_geometry_program
*stgp
);
429 st_release_tcp_variants(struct st_context
*st
,
430 struct st_tessctrl_program
*sttcp
);
433 st_release_tep_variants(struct st_context
*st
,
434 struct st_tesseval_program
*sttep
);
437 st_destroy_program_variants(struct st_context
*st
);
440 st_translate_vertex_program(struct st_context
*st
,
441 struct st_vertex_program
*stvp
);
444 st_translate_fragment_program(struct st_context
*st
,
445 struct st_fragment_program
*stfp
);
448 st_translate_geometry_program(struct st_context
*st
,
449 struct st_geometry_program
*stgp
);
452 st_translate_tessctrl_program(struct st_context
*st
,
453 struct st_tessctrl_program
*sttcp
);
456 st_translate_tesseval_program(struct st_context
*st
,
457 struct st_tesseval_program
*sttep
);
460 st_print_current_vertex_program(void);
463 st_precompile_shader_variant(struct st_context
*st
,
464 struct gl_program
*prog
);