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 */
83 struct gl_program_parameter_list
*parameters
;
86 /** For glDrawPixels variants */
87 unsigned drawpix_sampler
;
88 unsigned pixelmap_sampler
;
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 pipe_shader_state tgsi
;
102 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
104 struct st_fp_variant
*variants
;
109 /** Vertex program variant key */
110 struct st_vp_variant_key
112 struct st_context
*st
; /**< variants are per-context */
113 boolean passthrough_edgeflags
;
115 /** for ARB_color_buffer_float */
121 * This represents a vertex program, especially translated to match
122 * the inputs of a particular fragment shader.
126 /* Parameters which generated this translated version of a vertex
129 struct st_vp_variant_key key
;
132 * TGSI tokens (to later generate a 'draw' module shader for
133 * selection/feedback/rasterpos)
135 struct pipe_shader_state tgsi
;
137 /** Driver's compiled shader */
140 /** For using our private draw module (glRasterPos) */
141 struct draw_vertex_shader
*draw_shader
;
143 /** Next in linked list */
144 struct st_vp_variant
*next
;
146 /** similar to that in st_vertex_program, but with edgeflags info too */
152 * Derived from Mesa gl_fragment_program:
154 struct st_vertex_program
156 struct gl_vertex_program Base
; /**< The Mesa vertex program */
157 struct pipe_shader_state tgsi
;
158 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
160 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
161 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
162 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
165 /** Maps VARYING_SLOT_x to slot */
166 GLuint result_to_output
[VARYING_SLOT_MAX
];
168 /** List of translated variants of this vertex program.
170 struct st_vp_variant
*variants
;
175 /** Geometry program variant key */
176 struct st_gp_variant_key
178 struct st_context
*st
; /**< variants are per-context */
179 /* no other fields yet */
184 * Geometry program variant.
188 /* Parameters which generated this variant. */
189 struct st_gp_variant_key key
;
193 struct st_gp_variant
*next
;
198 * Derived from Mesa gl_geometry_program:
200 struct st_geometry_program
202 struct gl_geometry_program Base
; /**< The Mesa geometry program */
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 glsl_to_tgsi_visitor
* glsl_to_tgsi
;
240 struct st_tcp_variant
*variants
;
245 /** Tessellation evaluation program variant key */
246 struct st_tep_variant_key
248 struct st_context
*st
; /**< variants are per-context */
249 /* no other fields yet */
254 * Tessellation evaluation program variant.
256 struct st_tep_variant
258 /* Parameters which generated this variant. */
259 struct st_tep_variant_key key
;
263 struct st_tep_variant
*next
;
268 * Derived from Mesa gl_tess_eval_program:
270 struct st_tesseval_program
272 struct gl_tess_eval_program Base
; /**< The Mesa tess eval program */
273 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
275 struct st_tep_variant
*variants
;
280 static inline struct st_fragment_program
*
281 st_fragment_program( struct gl_fragment_program
*fp
)
283 return (struct st_fragment_program
*)fp
;
287 static inline struct st_vertex_program
*
288 st_vertex_program( struct gl_vertex_program
*vp
)
290 return (struct st_vertex_program
*)vp
;
293 static inline struct st_geometry_program
*
294 st_geometry_program( struct gl_geometry_program
*gp
)
296 return (struct st_geometry_program
*)gp
;
299 static inline struct st_tessctrl_program
*
300 st_tessctrl_program( struct gl_tess_ctrl_program
*tcp
)
302 return (struct st_tessctrl_program
*)tcp
;
305 static inline struct st_tesseval_program
*
306 st_tesseval_program( struct gl_tess_eval_program
*tep
)
308 return (struct st_tesseval_program
*)tep
;
312 st_reference_vertprog(struct st_context
*st
,
313 struct st_vertex_program
**ptr
,
314 struct st_vertex_program
*prog
)
316 _mesa_reference_program(st
->ctx
,
317 (struct gl_program
**) ptr
,
318 (struct gl_program
*) prog
);
322 st_reference_geomprog(struct st_context
*st
,
323 struct st_geometry_program
**ptr
,
324 struct st_geometry_program
*prog
)
326 _mesa_reference_program(st
->ctx
,
327 (struct gl_program
**) ptr
,
328 (struct gl_program
*) prog
);
332 st_reference_fragprog(struct st_context
*st
,
333 struct st_fragment_program
**ptr
,
334 struct st_fragment_program
*prog
)
336 _mesa_reference_program(st
->ctx
,
337 (struct gl_program
**) ptr
,
338 (struct gl_program
*) prog
);
342 st_reference_tesscprog(struct st_context
*st
,
343 struct st_tessctrl_program
**ptr
,
344 struct st_tessctrl_program
*prog
)
346 _mesa_reference_program(st
->ctx
,
347 (struct gl_program
**) ptr
,
348 (struct gl_program
*) prog
);
352 st_reference_tesseprog(struct st_context
*st
,
353 struct st_tesseval_program
**ptr
,
354 struct st_tesseval_program
*prog
)
356 _mesa_reference_program(st
->ctx
,
357 (struct gl_program
**) ptr
,
358 (struct gl_program
*) prog
);
362 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
364 static inline unsigned
365 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
367 if (attr
>= VARYING_SLOT_VAR0
) {
368 if (st
->needs_texcoord_semantic
)
369 return attr
- VARYING_SLOT_VAR0
;
371 return 9 + (attr
- VARYING_SLOT_VAR0
);
373 if (attr
== VARYING_SLOT_PNTC
) {
374 assert(!st
->needs_texcoord_semantic
);
377 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
378 assert(!st
->needs_texcoord_semantic
);
379 return attr
- VARYING_SLOT_TEX0
;
387 extern struct st_vp_variant
*
388 st_get_vp_variant(struct st_context
*st
,
389 struct st_vertex_program
*stvp
,
390 const struct st_vp_variant_key
*key
);
393 extern struct st_fp_variant
*
394 st_get_fp_variant(struct st_context
*st
,
395 struct st_fragment_program
*stfp
,
396 const struct st_fp_variant_key
*key
);
399 extern struct st_gp_variant
*
400 st_get_gp_variant(struct st_context
*st
,
401 struct st_geometry_program
*stgp
,
402 const struct st_gp_variant_key
*key
);
404 extern struct st_tcp_variant
*
405 st_get_tcp_variant(struct st_context
*st
,
406 struct st_tessctrl_program
*stgp
,
407 const struct st_tcp_variant_key
*key
);
409 extern struct st_tep_variant
*
410 st_get_tep_variant(struct st_context
*st
,
411 struct st_tesseval_program
*stgp
,
412 const struct st_tep_variant_key
*key
);
415 st_release_vp_variants( struct st_context
*st
,
416 struct st_vertex_program
*stvp
);
419 st_release_fp_variants( struct st_context
*st
,
420 struct st_fragment_program
*stfp
);
423 st_release_gp_variants(struct st_context
*st
,
424 struct st_geometry_program
*stgp
);
427 st_release_tcp_variants(struct st_context
*st
,
428 struct st_tessctrl_program
*stgp
);
431 st_release_tep_variants(struct st_context
*st
,
432 struct st_tesseval_program
*stgp
);
435 st_destroy_program_variants(struct st_context
*st
);
438 st_translate_vertex_program(struct st_context
*st
,
439 struct st_vertex_program
*stvp
);
442 st_translate_fragment_program(struct st_context
*st
,
443 struct st_fragment_program
*stfp
);
446 st_print_current_vertex_program(void);
449 st_precompile_shader_variant(struct st_context
*st
,
450 struct gl_program
*prog
);