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 struct pipe_shader_state tgsi
;
81 /** Driver's compiled shader */
84 /** For glBitmap variants */
85 struct gl_program_parameter_list
*parameters
;
88 /** next in linked list */
89 struct st_fp_variant
*next
;
94 * Derived from Mesa gl_fragment_program:
96 struct st_fragment_program
98 struct gl_fragment_program Base
;
99 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
101 struct st_fp_variant
*variants
;
106 /** Vertex program variant key */
107 struct st_vp_variant_key
109 struct st_context
*st
; /**< variants are per-context */
110 boolean passthrough_edgeflags
;
112 /** for ARB_color_buffer_float */
118 * This represents a vertex program, especially translated to match
119 * the inputs of a particular fragment shader.
123 /* Parameters which generated this translated version of a vertex
126 struct st_vp_variant_key key
;
129 * TGSI tokens (to later generate a 'draw' module shader for
130 * selection/feedback/rasterpos)
132 struct pipe_shader_state tgsi
;
134 /** Driver's compiled shader */
137 /** For using our private draw module (glRasterPos) */
138 struct draw_vertex_shader
*draw_shader
;
140 /** Next in linked list */
141 struct st_vp_variant
*next
;
143 /** similar to that in st_vertex_program, but with edgeflags info too */
149 * Derived from Mesa gl_fragment_program:
151 struct st_vertex_program
153 struct gl_vertex_program Base
; /**< The Mesa vertex program */
154 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
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
];
161 /** Maps VARYING_SLOT_x to slot */
162 GLuint result_to_output
[VARYING_SLOT_MAX
];
164 /** List of translated variants of this vertex program.
166 struct st_vp_variant
*variants
;
171 /** Geometry program variant key */
172 struct st_gp_variant_key
174 struct st_context
*st
; /**< variants are per-context */
175 /* no other fields yet */
180 * Geometry program variant.
184 /* Parameters which generated this variant. */
185 struct st_gp_variant_key key
;
189 struct st_gp_variant
*next
;
194 * Derived from Mesa gl_geometry_program:
196 struct st_geometry_program
198 struct gl_geometry_program Base
; /**< The Mesa geometry program */
199 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
201 struct st_gp_variant
*variants
;
206 /** Tessellation control program variant key */
207 struct st_tcp_variant_key
209 struct st_context
*st
; /**< variants are per-context */
210 /* no other fields yet */
215 * Tessellation control program variant.
217 struct st_tcp_variant
219 /* Parameters which generated this variant. */
220 struct st_tcp_variant_key key
;
224 struct st_tcp_variant
*next
;
229 * Derived from Mesa gl_tess_ctrl_program:
231 struct st_tessctrl_program
233 struct gl_tess_ctrl_program Base
; /**< The Mesa tess ctrl program */
234 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
236 struct st_tcp_variant
*variants
;
241 /** Tessellation evaluation program variant key */
242 struct st_tep_variant_key
244 struct st_context
*st
; /**< variants are per-context */
245 /* no other fields yet */
250 * Tessellation evaluation program variant.
252 struct st_tep_variant
254 /* Parameters which generated this variant. */
255 struct st_tep_variant_key key
;
259 struct st_tep_variant
*next
;
264 * Derived from Mesa gl_tess_eval_program:
266 struct st_tesseval_program
268 struct gl_tess_eval_program Base
; /**< The Mesa tess eval program */
269 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
271 struct st_tep_variant
*variants
;
276 static inline struct st_fragment_program
*
277 st_fragment_program( struct gl_fragment_program
*fp
)
279 return (struct st_fragment_program
*)fp
;
283 static inline struct st_vertex_program
*
284 st_vertex_program( struct gl_vertex_program
*vp
)
286 return (struct st_vertex_program
*)vp
;
289 static inline struct st_geometry_program
*
290 st_geometry_program( struct gl_geometry_program
*gp
)
292 return (struct st_geometry_program
*)gp
;
295 static inline struct st_tessctrl_program
*
296 st_tessctrl_program( struct gl_tess_ctrl_program
*tcp
)
298 return (struct st_tessctrl_program
*)tcp
;
301 static inline struct st_tesseval_program
*
302 st_tesseval_program( struct gl_tess_eval_program
*tep
)
304 return (struct st_tesseval_program
*)tep
;
308 st_reference_vertprog(struct st_context
*st
,
309 struct st_vertex_program
**ptr
,
310 struct st_vertex_program
*prog
)
312 _mesa_reference_program(st
->ctx
,
313 (struct gl_program
**) ptr
,
314 (struct gl_program
*) prog
);
318 st_reference_geomprog(struct st_context
*st
,
319 struct st_geometry_program
**ptr
,
320 struct st_geometry_program
*prog
)
322 _mesa_reference_program(st
->ctx
,
323 (struct gl_program
**) ptr
,
324 (struct gl_program
*) prog
);
328 st_reference_fragprog(struct st_context
*st
,
329 struct st_fragment_program
**ptr
,
330 struct st_fragment_program
*prog
)
332 _mesa_reference_program(st
->ctx
,
333 (struct gl_program
**) ptr
,
334 (struct gl_program
*) prog
);
338 st_reference_tesscprog(struct st_context
*st
,
339 struct st_tessctrl_program
**ptr
,
340 struct st_tessctrl_program
*prog
)
342 _mesa_reference_program(st
->ctx
,
343 (struct gl_program
**) ptr
,
344 (struct gl_program
*) prog
);
348 st_reference_tesseprog(struct st_context
*st
,
349 struct st_tesseval_program
**ptr
,
350 struct st_tesseval_program
*prog
)
352 _mesa_reference_program(st
->ctx
,
353 (struct gl_program
**) ptr
,
354 (struct gl_program
*) prog
);
358 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
360 static inline unsigned
361 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
363 if (attr
>= VARYING_SLOT_VAR0
) {
364 if (st
->needs_texcoord_semantic
)
365 return attr
- VARYING_SLOT_VAR0
;
367 return 9 + (attr
- VARYING_SLOT_VAR0
);
369 if (attr
== VARYING_SLOT_PNTC
) {
370 assert(!st
->needs_texcoord_semantic
);
373 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
374 assert(!st
->needs_texcoord_semantic
);
375 return attr
- VARYING_SLOT_TEX0
;
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
);
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
);
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
);
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
);
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
);
411 st_release_vp_variants( struct st_context
*st
,
412 struct st_vertex_program
*stvp
);
415 st_release_fp_variants( struct st_context
*st
,
416 struct st_fragment_program
*stfp
);
419 st_release_gp_variants(struct st_context
*st
,
420 struct st_geometry_program
*stgp
);
423 st_release_tcp_variants(struct st_context
*st
,
424 struct st_tessctrl_program
*stgp
);
427 st_release_tep_variants(struct st_context
*st
,
428 struct st_tesseval_program
*stgp
);
431 st_destroy_program_variants(struct st_context
*st
);
435 st_print_current_vertex_program(void);
438 st_precompile_shader_variant(struct st_context
*st
,
439 struct gl_program
*prog
);