10ac1bace5912bf67f1c9f4d17497ea6cf422f73
[mesa.git] / src / mesa / state_tracker / st_program.h
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33
34 #ifndef ST_PROGRAM_H
35 #define ST_PROGRAM_H
36
37 #include "main/mtypes.h"
38 #include "program/program.h"
39 #include "pipe/p_state.h"
40 #include "st_context.h"
41
42
43 /** Fragment program variant key */
44 struct st_fp_varient_key
45 {
46 struct st_context *st; /**< variants are per-context */
47
48 /** for glBitmap */
49 GLuint bitmap:1; /**< glBitmap varient? */
50
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) */
57 };
58
59
60 /**
61 * Variant of a fragment program.
62 */
63 struct st_fp_varient
64 {
65 /** Parameters which generated this version of fragment program */
66 struct st_fp_varient_key key;
67
68 /** Driver's compiled shader */
69 void *driver_shader;
70
71 /** For glBitmap variants */
72 struct gl_program_parameter_list *parameters;
73 uint bitmap_sampler;
74
75 /** next in linked list */
76 struct st_fp_varient *next;
77 };
78
79
80 /**
81 * Derived from Mesa gl_fragment_program:
82 */
83 struct st_fragment_program
84 {
85 struct gl_fragment_program Base;
86
87 struct pipe_shader_state tgsi;
88
89 struct st_fp_varient *varients;
90 };
91
92
93
94 struct st_vp_varient_key
95 {
96 struct st_context *st; /**< variants are per-context */
97 boolean passthrough_edgeflags;
98 };
99
100
101 /**
102 * This represents a vertex program, especially translated to match
103 * the inputs of a particular fragment shader.
104 */
105 struct st_vp_varient
106 {
107 /* Parameters which generated this translated version of a vertex
108 * shader:
109 */
110 struct st_vp_varient_key key;
111
112 /**
113 * TGSI tokens (to later generate a 'draw' module shader for
114 * selection/feedback/rasterpos)
115 */
116 struct pipe_shader_state tgsi;
117
118 /** Driver's compiled shader */
119 void *driver_shader;
120
121 /** For using our private draw module (glRasterPos) */
122 struct draw_vertex_shader *draw_shader;
123
124 /** Next in linked list */
125 struct st_vp_varient *next;
126
127 /** similar to that in st_vertex_program, but with information about edgeflags too */
128 GLuint num_inputs;
129 };
130
131
132 /**
133 * Derived from Mesa gl_fragment_program:
134 */
135 struct st_vertex_program
136 {
137 struct gl_vertex_program Base; /**< The Mesa vertex program */
138
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];
143 GLuint num_inputs;
144
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];
149 GLuint num_outputs;
150
151 /** List of translated varients of this vertex program.
152 */
153 struct st_vp_varient *varients;
154 };
155
156
157
158 struct st_gp_varient_key
159 {
160 struct st_context *st; /**< variants are per-context */
161 /* no other fields yet */
162 };
163
164
165 /**
166 * Geometry program variant.
167 */
168 struct st_gp_varient
169 {
170 /* Parameters which generated this translated version of a vertex */
171 struct st_gp_varient_key key;
172
173 void *driver_shader;
174
175 struct st_gp_varient *next;
176 };
177
178
179 /**
180 * Derived from Mesa gl_geometry_program:
181 */
182 struct st_geometry_program
183 {
184 struct gl_geometry_program Base; /**< The Mesa geometry program */
185
186 /** map GP input back to VP output */
187 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
188
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];
193
194 GLuint num_inputs;
195
196 GLuint input_to_slot[GEOM_ATTRIB_MAX]; /**< Maps GEOM_ATTRIB_x to slot */
197 GLuint num_input_slots;
198
199 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
200 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
201
202 struct pipe_shader_state tgsi;
203
204 struct st_gp_varient *varients;
205 };
206
207
208
209 static INLINE struct st_fragment_program *
210 st_fragment_program( struct gl_fragment_program *fp )
211 {
212 return (struct st_fragment_program *)fp;
213 }
214
215
216 static INLINE struct st_vertex_program *
217 st_vertex_program( struct gl_vertex_program *vp )
218 {
219 return (struct st_vertex_program *)vp;
220 }
221
222 static INLINE struct st_geometry_program *
223 st_geometry_program( struct gl_geometry_program *gp )
224 {
225 return (struct st_geometry_program *)gp;
226 }
227
228 static INLINE void
229 st_reference_vertprog(struct st_context *st,
230 struct st_vertex_program **ptr,
231 struct st_vertex_program *prog)
232 {
233 _mesa_reference_program(st->ctx,
234 (struct gl_program **) ptr,
235 (struct gl_program *) prog);
236 }
237
238 static INLINE void
239 st_reference_geomprog(struct st_context *st,
240 struct st_geometry_program **ptr,
241 struct st_geometry_program *prog)
242 {
243 _mesa_reference_program(st->ctx,
244 (struct gl_program **) ptr,
245 (struct gl_program *) prog);
246 }
247
248 static INLINE void
249 st_reference_fragprog(struct st_context *st,
250 struct st_fragment_program **ptr,
251 struct st_fragment_program *prog)
252 {
253 _mesa_reference_program(st->ctx,
254 (struct gl_program **) ptr,
255 (struct gl_program *) prog);
256 }
257
258
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);
263
264
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);
269
270
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);
275
276
277
278 extern void
279 st_vp_release_varients( struct st_context *st,
280 struct st_vertex_program *stvp );
281
282 extern void
283 st_fp_release_varients( struct st_context *st,
284 struct st_fragment_program *stfp );
285
286 extern void
287 st_gp_release_varients(struct st_context *st,
288 struct st_geometry_program *stgp);
289
290
291 extern void
292 st_print_shaders(struct gl_context *ctx);
293
294 extern void
295 st_destroy_program_variants(struct st_context *st);
296
297
298 #endif