mesa/st: Fix vertex buffer leak
[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_variant_key
45 {
46 struct st_context *st; /**< variants are per-context */
47
48 /** for glBitmap */
49 GLuint bitmap:1; /**< glBitmap variant? */
50
51 /** for glDrawPixels */
52 GLuint drawpixels:1; /**< glDrawPixels variant */
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_variant
64 {
65 /** Parameters which generated this version of fragment program */
66 struct st_fp_variant_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_variant *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_variant *variants;
90 };
91
92
93
94 /** Vertex program variant key */
95 struct st_vp_variant_key
96 {
97 struct st_context *st; /**< variants are per-context */
98 boolean passthrough_edgeflags;
99 };
100
101
102 /**
103 * This represents a vertex program, especially translated to match
104 * the inputs of a particular fragment shader.
105 */
106 struct st_vp_variant
107 {
108 /* Parameters which generated this translated version of a vertex
109 * shader:
110 */
111 struct st_vp_variant_key key;
112
113 /**
114 * TGSI tokens (to later generate a 'draw' module shader for
115 * selection/feedback/rasterpos)
116 */
117 struct pipe_shader_state tgsi;
118
119 /** Driver's compiled shader */
120 void *driver_shader;
121
122 /** For using our private draw module (glRasterPos) */
123 struct draw_vertex_shader *draw_shader;
124
125 /** Next in linked list */
126 struct st_vp_variant *next;
127
128 /** similar to that in st_vertex_program, but with edgeflags info too */
129 GLuint num_inputs;
130 };
131
132
133 /**
134 * Derived from Mesa gl_fragment_program:
135 */
136 struct st_vertex_program
137 {
138 struct gl_vertex_program Base; /**< The Mesa vertex program */
139
140 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
141 GLuint input_to_index[VERT_ATTRIB_MAX];
142 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
143 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
144 GLuint num_inputs;
145
146 /** Maps VERT_RESULT_x to slot */
147 GLuint result_to_output[VERT_RESULT_MAX];
148 ubyte output_semantic_name[VERT_RESULT_MAX];
149 ubyte output_semantic_index[VERT_RESULT_MAX];
150 GLuint num_outputs;
151
152 /** List of translated variants of this vertex program.
153 */
154 struct st_vp_variant *variants;
155 };
156
157
158
159 /** Geometry program variant key */
160 struct st_gp_variant_key
161 {
162 struct st_context *st; /**< variants are per-context */
163 /* no other fields yet */
164 };
165
166
167 /**
168 * Geometry program variant.
169 */
170 struct st_gp_variant
171 {
172 /* Parameters which generated this translated version of a vertex */
173 struct st_gp_variant_key key;
174
175 void *driver_shader;
176
177 struct st_gp_variant *next;
178 };
179
180
181 /**
182 * Derived from Mesa gl_geometry_program:
183 */
184 struct st_geometry_program
185 {
186 struct gl_geometry_program Base; /**< The Mesa geometry program */
187
188 /** map GP input back to VP output */
189 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
190
191 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
192 GLuint input_to_index[GEOM_ATTRIB_MAX];
193 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
194 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
195
196 GLuint num_inputs;
197
198 GLuint input_to_slot[GEOM_ATTRIB_MAX]; /**< Maps GEOM_ATTRIB_x to slot */
199 GLuint num_input_slots;
200
201 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
202 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
203
204 struct pipe_shader_state tgsi;
205
206 struct st_gp_variant *variants;
207 };
208
209
210
211 static INLINE struct st_fragment_program *
212 st_fragment_program( struct gl_fragment_program *fp )
213 {
214 return (struct st_fragment_program *)fp;
215 }
216
217
218 static INLINE struct st_vertex_program *
219 st_vertex_program( struct gl_vertex_program *vp )
220 {
221 return (struct st_vertex_program *)vp;
222 }
223
224 static INLINE struct st_geometry_program *
225 st_geometry_program( struct gl_geometry_program *gp )
226 {
227 return (struct st_geometry_program *)gp;
228 }
229
230 static INLINE void
231 st_reference_vertprog(struct st_context *st,
232 struct st_vertex_program **ptr,
233 struct st_vertex_program *prog)
234 {
235 _mesa_reference_program(st->ctx,
236 (struct gl_program **) ptr,
237 (struct gl_program *) prog);
238 }
239
240 static INLINE void
241 st_reference_geomprog(struct st_context *st,
242 struct st_geometry_program **ptr,
243 struct st_geometry_program *prog)
244 {
245 _mesa_reference_program(st->ctx,
246 (struct gl_program **) ptr,
247 (struct gl_program *) prog);
248 }
249
250 static INLINE void
251 st_reference_fragprog(struct st_context *st,
252 struct st_fragment_program **ptr,
253 struct st_fragment_program *prog)
254 {
255 _mesa_reference_program(st->ctx,
256 (struct gl_program **) ptr,
257 (struct gl_program *) prog);
258 }
259
260
261 extern struct st_vp_variant *
262 st_get_vp_variant(struct st_context *st,
263 struct st_vertex_program *stvp,
264 const struct st_vp_variant_key *key);
265
266
267 extern struct st_fp_variant *
268 st_get_fp_variant(struct st_context *st,
269 struct st_fragment_program *stfp,
270 const struct st_fp_variant_key *key);
271
272
273 extern struct st_gp_variant *
274 st_get_gp_variant(struct st_context *st,
275 struct st_geometry_program *stgp,
276 const struct st_gp_variant_key *key);
277
278
279
280 extern void
281 st_release_vp_variants( struct st_context *st,
282 struct st_vertex_program *stvp );
283
284 extern void
285 st_release_fp_variants( struct st_context *st,
286 struct st_fragment_program *stfp );
287
288 extern void
289 st_release_gp_variants(struct st_context *st,
290 struct st_geometry_program *stgp);
291
292
293 extern void
294 st_print_shaders(struct gl_context *ctx);
295
296 extern void
297 st_destroy_program_variants(struct st_context *st);
298
299
300 #endif