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"
49 /** Fragment program variant key */
50 struct st_fp_variant_key
52 struct st_context
*st
; /**< variants are per-context */
55 GLuint bitmap
:1; /**< glBitmap variant? */
57 /** for glDrawPixels */
58 GLuint drawpixels
:1; /**< glDrawPixels variant */
59 GLuint scaleAndBias
:1; /**< glDrawPixels w/ scale and/or bias? */
60 GLuint pixelMaps
:1; /**< glDrawPixels w/ pixel lookup map? */
61 GLuint drawpixels_z
:1; /**< glDrawPixels(GL_DEPTH) */
62 GLuint drawpixels_stencil
:1; /**< glDrawPixels(GL_STENCIL) */
64 /** for ARB_color_buffer_float */
67 /** for ARB_sample_shading */
68 GLuint persample_shading
:1;
73 * Variant of a fragment program.
77 /** Parameters which generated this version of fragment program */
78 struct st_fp_variant_key key
;
80 struct pipe_shader_state tgsi
;
82 /** Driver's compiled shader */
85 /** For glBitmap variants */
86 struct gl_program_parameter_list
*parameters
;
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 glsl_to_tgsi_visitor
* glsl_to_tgsi
;
102 struct st_fp_variant
*variants
;
107 /** Vertex program variant key */
108 struct st_vp_variant_key
110 struct st_context
*st
; /**< variants are per-context */
111 boolean passthrough_edgeflags
;
113 /** for ARB_color_buffer_float */
119 * This represents a vertex program, especially translated to match
120 * the inputs of a particular fragment shader.
124 /* Parameters which generated this translated version of a vertex
127 struct st_vp_variant_key key
;
130 * TGSI tokens (to later generate a 'draw' module shader for
131 * selection/feedback/rasterpos)
133 struct pipe_shader_state tgsi
;
135 /** Driver's compiled shader */
138 /** For using our private draw module (glRasterPos) */
139 struct draw_vertex_shader
*draw_shader
;
141 /** Next in linked list */
142 struct st_vp_variant
*next
;
144 /** similar to that in st_vertex_program, but with edgeflags info too */
150 * Derived from Mesa gl_fragment_program:
152 struct st_vertex_program
154 struct gl_vertex_program Base
; /**< The Mesa vertex program */
155 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
157 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
158 GLuint input_to_index
[VERT_ATTRIB_MAX
];
159 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
160 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
163 /** Maps VARYING_SLOT_x to slot */
164 GLuint result_to_output
[VARYING_SLOT_MAX
];
165 ubyte output_semantic_name
[VARYING_SLOT_MAX
];
166 ubyte output_semantic_index
[VARYING_SLOT_MAX
];
169 /** List of translated variants of this vertex program.
171 struct st_vp_variant
*variants
;
176 /** Geometry program variant key */
177 struct st_gp_variant_key
179 struct st_context
*st
; /**< variants are per-context */
180 /* no other fields yet */
185 * Geometry program variant.
189 /* Parameters which generated this translated version of a vertex */
190 struct st_gp_variant_key key
;
194 struct st_gp_variant
*next
;
199 * Derived from Mesa gl_geometry_program:
201 struct st_geometry_program
203 struct gl_geometry_program Base
; /**< The Mesa geometry program */
204 struct glsl_to_tgsi_visitor
* glsl_to_tgsi
;
206 struct st_gp_variant
*variants
;
211 static INLINE
struct st_fragment_program
*
212 st_fragment_program( struct gl_fragment_program
*fp
)
214 return (struct st_fragment_program
*)fp
;
218 static INLINE
struct st_vertex_program
*
219 st_vertex_program( struct gl_vertex_program
*vp
)
221 return (struct st_vertex_program
*)vp
;
224 static INLINE
struct st_geometry_program
*
225 st_geometry_program( struct gl_geometry_program
*gp
)
227 return (struct st_geometry_program
*)gp
;
231 st_reference_vertprog(struct st_context
*st
,
232 struct st_vertex_program
**ptr
,
233 struct st_vertex_program
*prog
)
235 _mesa_reference_program(st
->ctx
,
236 (struct gl_program
**) ptr
,
237 (struct gl_program
*) prog
);
241 st_reference_geomprog(struct st_context
*st
,
242 struct st_geometry_program
**ptr
,
243 struct st_geometry_program
*prog
)
245 _mesa_reference_program(st
->ctx
,
246 (struct gl_program
**) ptr
,
247 (struct gl_program
*) prog
);
251 st_reference_fragprog(struct st_context
*st
,
252 struct st_fragment_program
**ptr
,
253 struct st_fragment_program
*prog
)
255 _mesa_reference_program(st
->ctx
,
256 (struct gl_program
**) ptr
,
257 (struct gl_program
*) prog
);
261 * This defines mapping from Mesa VARYING_SLOTs to TGSI GENERIC slots.
263 static INLINE
unsigned
264 st_get_generic_varying_index(struct st_context
*st
, GLuint attr
)
266 if (attr
>= VARYING_SLOT_VAR0
) {
267 if (st
->needs_texcoord_semantic
)
268 return attr
- VARYING_SLOT_VAR0
;
270 return 9 + (attr
- VARYING_SLOT_VAR0
);
272 if (attr
== VARYING_SLOT_PNTC
) {
273 assert(!st
->needs_texcoord_semantic
);
276 if (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) {
277 assert(!st
->needs_texcoord_semantic
);
278 return attr
- VARYING_SLOT_TEX0
;
286 extern struct st_vp_variant
*
287 st_get_vp_variant(struct st_context
*st
,
288 struct st_vertex_program
*stvp
,
289 const struct st_vp_variant_key
*key
);
292 extern struct st_fp_variant
*
293 st_get_fp_variant(struct st_context
*st
,
294 struct st_fragment_program
*stfp
,
295 const struct st_fp_variant_key
*key
);
298 extern struct st_gp_variant
*
299 st_get_gp_variant(struct st_context
*st
,
300 struct st_geometry_program
*stgp
,
301 const struct st_gp_variant_key
*key
);
305 st_prepare_vertex_program(struct gl_context
*ctx
,
306 struct st_vertex_program
*stvp
);
309 st_prepare_fragment_program(struct gl_context
*ctx
,
310 struct st_fragment_program
*stfp
);
314 st_release_vp_variants( struct st_context
*st
,
315 struct st_vertex_program
*stvp
);
318 st_release_fp_variants( struct st_context
*st
,
319 struct st_fragment_program
*stfp
);
322 st_release_gp_variants(struct st_context
*st
,
323 struct st_geometry_program
*stgp
);
327 st_print_shaders(struct gl_context
*ctx
);
330 st_destroy_program_variants(struct st_context
*st
);
334 st_print_current_vertex_program(void);