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? */
62 GLuint drawpixels_z
:1; /**< glDrawPixels(GL_DEPTH) */
63 GLuint drawpixels_stencil
:1; /**< glDrawPixels(GL_STENCIL) */
65 /** for ARB_color_buffer_float */
68 /** for ARB_sample_shading */
69 GLuint persample_shading
:1;
74 * Variant of a fragment program.
78 /** Parameters which generated this version of fragment program */
79 struct st_fp_variant_key key
;
81 struct pipe_shader_state tgsi
;
83 /** Driver's compiled shader */
86 /** For glBitmap variants */
87 struct gl_program_parameter_list
*parameters
;
90 /** next in linked list */
91 struct st_fp_variant
*next
;
96 * Derived from Mesa gl_fragment_program:
98 struct st_fragment_program
100 struct gl_fragment_program Base
;
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 glsl_to_tgsi_visitor
* glsl_to_tgsi
;
158 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
159 GLuint input_to_index
[VERT_ATTRIB_MAX
];
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
];
166 GLuint output_slot_to_attr
[VARYING_SLOT_MAX
];
167 ubyte output_semantic_name
[VARYING_SLOT_MAX
];
168 ubyte output_semantic_index
[VARYING_SLOT_MAX
];
171 /** List of translated variants of this vertex program.
173 struct st_vp_variant
*variants
;
178 /** Geometry program variant key */
179 struct st_gp_variant_key
181 struct st_context
*st
; /**< variants are per-context */
182 /* no other fields yet */
187 * Geometry program variant.
191 /* Parameters which generated this variant. */
192 struct st_gp_variant_key key
;
196 struct st_gp_variant
*next
;
201 * Derived from Mesa gl_geometry_program:
203 struct st_geometry_program
205 struct gl_geometry_program Base
; /**< The Mesa geometry program */
206 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
208 struct st_gp_variant
*variants
;
213 /** Tessellation control program variant key */
214 struct st_tcp_variant_key
216 struct st_context
*st
; /**< variants are per-context */
217 /* no other fields yet */
222 * Tessellation control program variant.
224 struct st_tcp_variant
226 /* Parameters which generated this variant. */
227 struct st_tcp_variant_key key
;
231 struct st_tcp_variant
*next
;
236 * Derived from Mesa gl_tess_ctrl_program:
238 struct st_tessctrl_program
240 struct gl_tess_ctrl_program Base
; /**< The Mesa tess ctrl program */
241 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
243 struct st_tcp_variant
*variants
;
248 /** Tessellation evaluation program variant key */
249 struct st_tep_variant_key
251 struct st_context
*st
; /**< variants are per-context */
252 /* no other fields yet */
257 * Tessellation evaluation program variant.
259 struct st_tep_variant
261 /* Parameters which generated this variant. */
262 struct st_tep_variant_key key
;
266 struct st_tep_variant
*next
;
271 * Derived from Mesa gl_tess_eval_program:
273 struct st_tesseval_program
275 struct gl_tess_eval_program Base
; /**< The Mesa tess eval program */
276 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
278 struct st_tep_variant
*variants
;
283 static inline struct st_fragment_program
*
284 st_fragment_program( struct gl_fragment_program
*fp
)
286 return (struct st_fragment_program
*)fp
;
290 static inline struct st_vertex_program
*
291 st_vertex_program( struct gl_vertex_program
*vp
)
293 return (struct st_vertex_program
*)vp
;
296 static inline struct st_geometry_program
*
297 st_geometry_program( struct gl_geometry_program
*gp
)
299 return (struct st_geometry_program
*)gp
;
302 static inline struct st_tessctrl_program
*
303 st_tessctrl_program( struct gl_tess_ctrl_program
*tcp
)
305 return (struct st_tessctrl_program
*)tcp
;
308 static inline struct st_tesseval_program
*
309 st_tesseval_program( struct gl_tess_eval_program
*tep
)
311 return (struct st_tesseval_program
*)tep
;
315 st_reference_vertprog(struct st_context
*st
,
316 struct st_vertex_program
**ptr
,
317 struct st_vertex_program
*prog
)
319 _mesa_reference_program(st
->ctx
,
320 (struct gl_program
**) ptr
,
321 (struct gl_program
*) prog
);
325 st_reference_geomprog(struct st_context
*st
,
326 struct st_geometry_program
**ptr
,
327 struct st_geometry_program
*prog
)
329 _mesa_reference_program(st
->ctx
,
330 (struct gl_program
**) ptr
,
331 (struct gl_program
*) prog
);
335 st_reference_fragprog(struct st_context
*st
,
336 struct st_fragment_program
**ptr
,
337 struct st_fragment_program
*prog
)
339 _mesa_reference_program(st
->ctx
,
340 (struct gl_program
**) ptr
,
341 (struct gl_program
*) prog
);
345 st_reference_tesscprog(struct st_context
*st
,
346 struct st_tessctrl_program
**ptr
,
347 struct st_tessctrl_program
*prog
)
349 _mesa_reference_program(st
->ctx
,
350 (struct gl_program
**) ptr
,
351 (struct gl_program
*) prog
);
355 st_reference_tesseprog(struct st_context
*st
,
356 struct st_tesseval_program
**ptr
,
357 struct st_tesseval_program
*prog
)
359 _mesa_reference_program(st
->ctx
,
360 (struct gl_program
**) ptr
,
361 (struct gl_program
*) prog
);
365 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
367 static inline unsigned
368 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
370 if (attr
>= VARYING_SLOT_VAR0
) {
371 if (st
->needs_texcoord_semantic
)
372 return attr
- VARYING_SLOT_VAR0
;
374 return 9 + (attr
- VARYING_SLOT_VAR0
);
376 if (attr
== VARYING_SLOT_PNTC
) {
377 assert(!st
->needs_texcoord_semantic
);
380 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
381 assert(!st
->needs_texcoord_semantic
);
382 return attr
- VARYING_SLOT_TEX0
;
390 extern struct st_vp_variant
*
391 st_get_vp_variant(struct st_context
*st
,
392 struct st_vertex_program
*stvp
,
393 const struct st_vp_variant_key
*key
);
396 extern struct st_fp_variant
*
397 st_get_fp_variant(struct st_context
*st
,
398 struct st_fragment_program
*stfp
,
399 const struct st_fp_variant_key
*key
);
402 extern struct st_gp_variant
*
403 st_get_gp_variant(struct st_context
*st
,
404 struct st_geometry_program
*stgp
,
405 const struct st_gp_variant_key
*key
);
407 extern struct st_tcp_variant
*
408 st_get_tcp_variant(struct st_context
*st
,
409 struct st_tessctrl_program
*stgp
,
410 const struct st_tcp_variant_key
*key
);
412 extern struct st_tep_variant
*
413 st_get_tep_variant(struct st_context
*st
,
414 struct st_tesseval_program
*stgp
,
415 const struct st_tep_variant_key
*key
);
418 st_release_vp_variants( struct st_context
*st
,
419 struct st_vertex_program
*stvp
);
422 st_release_fp_variants( struct st_context
*st
,
423 struct st_fragment_program
*stfp
);
426 st_release_gp_variants(struct st_context
*st
,
427 struct st_geometry_program
*stgp
);
430 st_release_tcp_variants(struct st_context
*st
,
431 struct st_tessctrl_program
*stgp
);
434 st_release_tep_variants(struct st_context
*st
,
435 struct st_tesseval_program
*stgp
);
438 st_destroy_program_variants(struct st_context
*st
);
442 st_print_current_vertex_program(void);
445 st_precompile_shader_variant(struct st_context
*st
,
446 struct gl_program
*prog
);