1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <keith@tungstengraphics.com>
37 #include "main/mtypes.h"
38 #include "program/program.h"
39 #include "pipe/p_state.h"
40 #include "st_context.h"
43 /** Fragment program variant key */
44 struct st_fp_varient_key
46 struct st_context
*st
; /**< variants are per-context */
49 GLuint bitmap
:1; /**< glBitmap varient? */
51 /** for glDrawPixels */
52 GLuint drawpixels
:1; /**< glDrawPixels varient */
53 GLuint scaleAndBias
:1; /**< glDrawPixels w/ scale and/or bias? */
54 GLuint pixelMaps
:1; /**< glDrawPixels w/ pixel lookup map? */
55 GLuint drawpixels_z
:1; /**< glDrawPixels(GL_DEPTH) */
56 GLuint drawpixels_stencil
:1; /**< glDrawPixels(GL_STENCIL) */
61 * Variant of a fragment program.
65 /** Parameters which generated this version of fragment program */
66 struct st_fp_varient_key key
;
68 /** Driver's compiled shader */
71 /** For glBitmap variants */
72 struct gl_program_parameter_list
*parameters
;
75 /** next in linked list */
76 struct st_fp_varient
*next
;
81 * Derived from Mesa gl_fragment_program:
83 struct st_fragment_program
85 struct gl_fragment_program Base
;
87 struct pipe_shader_state tgsi
;
89 struct st_fp_varient
*varients
;
94 struct st_vp_varient_key
96 struct st_context
*st
; /**< variants are per-context */
97 boolean passthrough_edgeflags
;
102 * This represents a vertex program, especially translated to match
103 * the inputs of a particular fragment shader.
107 /* Parameters which generated this translated version of a vertex
110 struct st_vp_varient_key key
;
113 * TGSI tokens (to later generate a 'draw' module shader for
114 * selection/feedback/rasterpos)
116 struct pipe_shader_state tgsi
;
118 /** Driver's compiled shader */
121 /** For using our private draw module (glRasterPos) */
122 struct draw_vertex_shader
*draw_shader
;
124 /** Next in linked list */
125 struct st_vp_varient
*next
;
127 /** similar to that in st_vertex_program, but with information about edgeflags too */
133 * Derived from Mesa gl_fragment_program:
135 struct st_vertex_program
137 struct gl_vertex_program Base
; /**< The Mesa vertex program */
139 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
140 GLuint input_to_index
[VERT_ATTRIB_MAX
];
141 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
142 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
145 /** Maps VERT_RESULT_x to slot */
146 GLuint result_to_output
[VERT_RESULT_MAX
];
147 ubyte output_semantic_name
[VERT_RESULT_MAX
];
148 ubyte output_semantic_index
[VERT_RESULT_MAX
];
151 /** List of translated varients of this vertex program.
153 struct st_vp_varient
*varients
;
158 struct st_gp_varient_key
160 struct st_context
*st
; /**< variants are per-context */
161 /* no other fields yet */
166 * Geometry program variant.
170 /* Parameters which generated this translated version of a vertex */
171 struct st_gp_varient_key key
;
175 struct st_gp_varient
*next
;
180 * Derived from Mesa gl_geometry_program:
182 struct st_geometry_program
184 struct gl_geometry_program Base
; /**< The Mesa geometry program */
186 /** map GP input back to VP output */
187 GLuint input_map
[PIPE_MAX_SHADER_INPUTS
];
189 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
190 GLuint input_to_index
[GEOM_ATTRIB_MAX
];
191 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
192 GLuint index_to_input
[PIPE_MAX_SHADER_INPUTS
];
196 GLuint input_to_slot
[GEOM_ATTRIB_MAX
]; /**< Maps GEOM_ATTRIB_x to slot */
197 GLuint num_input_slots
;
199 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
200 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
202 struct pipe_shader_state tgsi
;
204 struct st_gp_varient
*varients
;
209 static INLINE
struct st_fragment_program
*
210 st_fragment_program( struct gl_fragment_program
*fp
)
212 return (struct st_fragment_program
*)fp
;
216 static INLINE
struct st_vertex_program
*
217 st_vertex_program( struct gl_vertex_program
*vp
)
219 return (struct st_vertex_program
*)vp
;
222 static INLINE
struct st_geometry_program
*
223 st_geometry_program( struct gl_geometry_program
*gp
)
225 return (struct st_geometry_program
*)gp
;
229 st_reference_vertprog(struct st_context
*st
,
230 struct st_vertex_program
**ptr
,
231 struct st_vertex_program
*prog
)
233 _mesa_reference_program(st
->ctx
,
234 (struct gl_program
**) ptr
,
235 (struct gl_program
*) prog
);
239 st_reference_geomprog(struct st_context
*st
,
240 struct st_geometry_program
**ptr
,
241 struct st_geometry_program
*prog
)
243 _mesa_reference_program(st
->ctx
,
244 (struct gl_program
**) ptr
,
245 (struct gl_program
*) prog
);
249 st_reference_fragprog(struct st_context
*st
,
250 struct st_fragment_program
**ptr
,
251 struct st_fragment_program
*prog
)
253 _mesa_reference_program(st
->ctx
,
254 (struct gl_program
**) ptr
,
255 (struct gl_program
*) prog
);
259 extern struct st_vp_varient
*
260 st_get_vp_varient(struct st_context
*st
,
261 struct st_vertex_program
*stvp
,
262 const struct st_vp_varient_key
*key
);
265 extern struct st_fp_varient
*
266 st_get_fp_varient(struct st_context
*st
,
267 struct st_fragment_program
*stfp
,
268 const struct st_fp_varient_key
*key
);
271 extern struct st_gp_varient
*
272 st_get_gp_varient(struct st_context
*st
,
273 struct st_geometry_program
*stgp
,
274 const struct st_gp_varient_key
*key
);
279 st_vp_release_varients( struct st_context
*st
,
280 struct st_vertex_program
*stvp
);
283 st_fp_release_varients( struct st_context
*st
,
284 struct st_fragment_program
*stfp
);
287 st_gp_release_varients(struct st_context
*st
,
288 struct st_geometry_program
*stgp
);
292 st_print_shaders(struct gl_context
*ctx
);
295 st_destroy_program_variants(struct st_context
*st
);