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 "main/atifragshader.h"
39 #include "program/program.h"
40 #include "pipe/p_state.h"
41 #include "st_context.h"
42 #include "st_glsl_to_tgsi.h"
49 #define ST_DOUBLE_ATTRIB_PLACEHOLDER 0xffffffff
51 /** Fragment program variant key */
52 struct st_fp_variant_key
54 struct st_context
*st
; /**< variants are per-context */
57 GLuint bitmap
:1; /**< glBitmap variant? */
59 /** for glDrawPixels */
60 GLuint drawpixels
:1; /**< glDrawPixels variant */
61 GLuint scaleAndBias
:1; /**< glDrawPixels w/ scale and/or bias? */
62 GLuint pixelMaps
:1; /**< glDrawPixels w/ pixel lookup map? */
64 /** for ARB_color_buffer_float */
67 /** for ARB_sample_shading */
68 GLuint persample_shading
:1;
70 /** needed for ATI_fragment_shader */
73 /** needed for ATI_fragment_shader */
74 char texture_targets
[MAX_NUM_FRAGMENT_REGISTERS_ATI
];
79 * Variant of a fragment program.
83 /** Parameters which generated this version of fragment program */
84 struct st_fp_variant_key key
;
86 /** Driver's compiled shader */
89 /** For glBitmap variants */
92 /** For glDrawPixels variants */
93 unsigned drawpix_sampler
;
94 unsigned pixelmap_sampler
;
96 /** next in linked list */
97 struct st_fp_variant
*next
;
102 * Derived from Mesa gl_fragment_program:
104 struct st_fragment_program
106 struct gl_fragment_program Base
;
107 struct pipe_shader_state tgsi
;
108 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
109 struct ati_fragment_shader
*ati_fs
;
111 struct st_fp_variant
*variants
;
116 /** Vertex program variant key */
117 struct st_vp_variant_key
119 struct st_context
*st
; /**< variants are per-context */
120 boolean passthrough_edgeflags
;
122 /** for ARB_color_buffer_float */
128 * This represents a vertex program, especially translated to match
129 * the inputs of a particular fragment shader.
133 /* Parameters which generated this translated version of a vertex
136 struct st_vp_variant_key key
;
139 * TGSI tokens (to later generate a 'draw' module shader for
140 * selection/feedback/rasterpos)
142 struct pipe_shader_state tgsi
;
144 /** Driver's compiled shader */
147 /** For using our private draw module (glRasterPos) */
148 struct draw_vertex_shader
*draw_shader
;
150 /** Next in linked list */
151 struct st_vp_variant
*next
;
153 /** similar to that in st_vertex_program, but with edgeflags info too */
159 * Derived from Mesa gl_fragment_program:
161 struct st_vertex_program
163 struct gl_vertex_program Base
; /**< The Mesa vertex program */
164 struct pipe_shader_state tgsi
;
165 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
167 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
168 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
169 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
172 /** Maps VARYING_SLOT_x to slot */
173 GLuint result_to_output
[VARYING_SLOT_MAX
];
175 /** List of translated variants of this vertex program.
177 struct st_vp_variant
*variants
;
182 /** Key shared by all shaders except VP, FP */
183 struct st_basic_variant_key
185 struct st_context
*st
; /**< variants are per-context */
190 * Geometry program variant.
192 struct st_basic_variant
194 /* Parameters which generated this variant. */
195 struct st_basic_variant_key key
;
199 struct st_basic_variant
*next
;
204 * Derived from Mesa gl_geometry_program:
206 struct st_geometry_program
208 struct gl_geometry_program Base
; /**< The Mesa geometry program */
209 struct pipe_shader_state tgsi
;
210 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
212 struct st_basic_variant
*variants
;
217 * Derived from Mesa gl_tess_ctrl_program:
219 struct st_tessctrl_program
221 struct gl_tess_ctrl_program Base
; /**< The Mesa tess ctrl program */
222 struct pipe_shader_state tgsi
;
223 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
225 struct st_basic_variant
*variants
;
230 * Derived from Mesa gl_tess_eval_program:
232 struct st_tesseval_program
234 struct gl_tess_eval_program Base
; /**< The Mesa tess eval program */
235 struct pipe_shader_state tgsi
;
236 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
238 struct st_basic_variant
*variants
;
243 * Derived from Mesa gl_compute_program:
245 struct st_compute_program
247 struct gl_compute_program Base
; /**< The Mesa compute program */
248 struct pipe_compute_state tgsi
;
249 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
251 struct st_basic_variant
*variants
;
255 static inline struct st_fragment_program
*
256 st_fragment_program( struct gl_fragment_program
*fp
)
258 return (struct st_fragment_program
*)fp
;
262 static inline struct st_vertex_program
*
263 st_vertex_program( struct gl_vertex_program
*vp
)
265 return (struct st_vertex_program
*)vp
;
268 static inline struct st_geometry_program
*
269 st_geometry_program( struct gl_geometry_program
*gp
)
271 return (struct st_geometry_program
*)gp
;
274 static inline struct st_tessctrl_program
*
275 st_tessctrl_program( struct gl_tess_ctrl_program
*tcp
)
277 return (struct st_tessctrl_program
*)tcp
;
280 static inline struct st_tesseval_program
*
281 st_tesseval_program( struct gl_tess_eval_program
*tep
)
283 return (struct st_tesseval_program
*)tep
;
286 static inline struct st_compute_program
*
287 st_compute_program( struct gl_compute_program
*cp
)
289 return (struct st_compute_program
*)cp
;
293 st_reference_vertprog(struct st_context
*st
,
294 struct st_vertex_program
**ptr
,
295 struct st_vertex_program
*prog
)
297 _mesa_reference_program(st
->ctx
,
298 (struct gl_program
**) ptr
,
299 (struct gl_program
*) prog
);
303 st_reference_geomprog(struct st_context
*st
,
304 struct st_geometry_program
**ptr
,
305 struct st_geometry_program
*prog
)
307 _mesa_reference_program(st
->ctx
,
308 (struct gl_program
**) ptr
,
309 (struct gl_program
*) prog
);
313 st_reference_fragprog(struct st_context
*st
,
314 struct st_fragment_program
**ptr
,
315 struct st_fragment_program
*prog
)
317 _mesa_reference_program(st
->ctx
,
318 (struct gl_program
**) ptr
,
319 (struct gl_program
*) prog
);
323 st_reference_tesscprog(struct st_context
*st
,
324 struct st_tessctrl_program
**ptr
,
325 struct st_tessctrl_program
*prog
)
327 _mesa_reference_program(st
->ctx
,
328 (struct gl_program
**) ptr
,
329 (struct gl_program
*) prog
);
333 st_reference_tesseprog(struct st_context
*st
,
334 struct st_tesseval_program
**ptr
,
335 struct st_tesseval_program
*prog
)
337 _mesa_reference_program(st
->ctx
,
338 (struct gl_program
**) ptr
,
339 (struct gl_program
*) prog
);
343 st_reference_compprog(struct st_context
*st
,
344 struct st_compute_program
**ptr
,
345 struct st_compute_program
*prog
)
347 _mesa_reference_program(st
->ctx
,
348 (struct gl_program
**) ptr
,
349 (struct gl_program
*) prog
);
353 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
355 static inline unsigned
356 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
358 if (attr
>= VARYING_SLOT_VAR0
) {
359 if (st
->needs_texcoord_semantic
)
360 return attr
- VARYING_SLOT_VAR0
;
362 return 9 + (attr
- VARYING_SLOT_VAR0
);
364 if (attr
== VARYING_SLOT_PNTC
) {
365 assert(!st
->needs_texcoord_semantic
);
368 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
369 assert(!st
->needs_texcoord_semantic
);
370 return attr
- VARYING_SLOT_TEX0
;
378 extern struct st_vp_variant
*
379 st_get_vp_variant(struct st_context
*st
,
380 struct st_vertex_program
*stvp
,
381 const struct st_vp_variant_key
*key
);
384 extern struct st_fp_variant
*
385 st_get_fp_variant(struct st_context
*st
,
386 struct st_fragment_program
*stfp
,
387 const struct st_fp_variant_key
*key
);
389 extern struct st_basic_variant
*
390 st_get_cp_variant(struct st_context
*st
,
391 struct pipe_compute_state
*tgsi
,
392 struct st_basic_variant
**variants
);
394 extern struct st_basic_variant
*
395 st_get_basic_variant(struct st_context
*st
,
396 unsigned pipe_shader
,
397 struct pipe_shader_state
*tgsi
,
398 struct st_basic_variant
**variants
);
401 st_release_vp_variants( struct st_context
*st
,
402 struct st_vertex_program
*stvp
);
405 st_release_fp_variants( struct st_context
*st
,
406 struct st_fragment_program
*stfp
);
409 st_release_cp_variants(struct st_context
*st
,
410 struct st_compute_program
*stcp
);
413 st_release_basic_variants(struct st_context
*st
, GLenum target
,
414 struct st_basic_variant
**variants
,
415 struct pipe_shader_state
*tgsi
);
418 st_destroy_program_variants(struct st_context
*st
);
421 st_translate_vertex_program(struct st_context
*st
,
422 struct st_vertex_program
*stvp
);
425 st_translate_fragment_program(struct st_context
*st
,
426 struct st_fragment_program
*stfp
);
429 st_translate_geometry_program(struct st_context
*st
,
430 struct st_geometry_program
*stgp
);
433 st_translate_tessctrl_program(struct st_context
*st
,
434 struct st_tessctrl_program
*sttcp
);
437 st_translate_tesseval_program(struct st_context
*st
,
438 struct st_tesseval_program
*sttep
);
441 st_translate_compute_program(struct st_context
*st
,
442 struct st_compute_program
*stcp
);
445 st_print_current_vertex_program(void);
448 st_precompile_shader_variant(struct st_context
*st
,
449 struct gl_program
*prog
);