glsl_to_tgsi: remove a bad assertion
[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 #include "st_glsl_to_tgsi.h"
42
43
44 /** Fragment program variant key */
45 struct st_fp_variant_key
46 {
47 struct st_context *st; /**< variants are per-context */
48
49 /** for glBitmap */
50 GLuint bitmap:1; /**< glBitmap variant? */
51
52 /** for glDrawPixels */
53 GLuint drawpixels:1; /**< glDrawPixels variant */
54 GLuint scaleAndBias:1; /**< glDrawPixels w/ scale and/or bias? */
55 GLuint pixelMaps:1; /**< glDrawPixels w/ pixel lookup map? */
56 GLuint drawpixels_z:1; /**< glDrawPixels(GL_DEPTH) */
57 GLuint drawpixels_stencil:1; /**< glDrawPixels(GL_STENCIL) */
58 };
59
60
61 /**
62 * Variant of a fragment program.
63 */
64 struct st_fp_variant
65 {
66 /** Parameters which generated this version of fragment program */
67 struct st_fp_variant_key key;
68
69 /** Driver's compiled shader */
70 void *driver_shader;
71
72 /** For glBitmap variants */
73 struct gl_program_parameter_list *parameters;
74 uint bitmap_sampler;
75
76 /** next in linked list */
77 struct st_fp_variant *next;
78 };
79
80
81 /**
82 * Derived from Mesa gl_fragment_program:
83 */
84 struct st_fragment_program
85 {
86 struct gl_fragment_program Base;
87 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
88
89 /** maps a Mesa FRAG_ATTRIB_x to a packed TGSI input index */
90 GLuint input_to_index[FRAG_ATTRIB_MAX];
91 /** maps a TGSI input index back to a Mesa FRAG_ATTRIB_x */
92 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
93 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
94 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
95 GLuint num_inputs;
96 GLuint interp_mode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
97
98 /** Maps FRAG_RESULT_x to slot */
99 GLuint result_to_output[FRAG_RESULT_MAX];
100 ubyte output_semantic_name[FRAG_RESULT_MAX];
101 ubyte output_semantic_index[FRAG_RESULT_MAX];
102 GLuint num_outputs;
103
104 struct pipe_shader_state tgsi;
105
106 struct st_fp_variant *variants;
107 };
108
109
110
111 /** Vertex program variant key */
112 struct st_vp_variant_key
113 {
114 struct st_context *st; /**< variants are per-context */
115 boolean passthrough_edgeflags;
116 };
117
118
119 /**
120 * This represents a vertex program, especially translated to match
121 * the inputs of a particular fragment shader.
122 */
123 struct st_vp_variant
124 {
125 /* Parameters which generated this translated version of a vertex
126 * shader:
127 */
128 struct st_vp_variant_key key;
129
130 /**
131 * TGSI tokens (to later generate a 'draw' module shader for
132 * selection/feedback/rasterpos)
133 */
134 struct pipe_shader_state tgsi;
135
136 /** Driver's compiled shader */
137 void *driver_shader;
138
139 /** For using our private draw module (glRasterPos) */
140 struct draw_vertex_shader *draw_shader;
141
142 /** Next in linked list */
143 struct st_vp_variant *next;
144
145 /** similar to that in st_vertex_program, but with edgeflags info too */
146 GLuint num_inputs;
147 };
148
149
150 /**
151 * Derived from Mesa gl_fragment_program:
152 */
153 struct st_vertex_program
154 {
155 struct gl_vertex_program Base; /**< The Mesa vertex program */
156 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
157
158 /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
159 GLuint input_to_index[VERT_ATTRIB_MAX];
160 /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
161 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
162 GLuint num_inputs;
163
164 /** Maps VERT_RESULT_x to slot */
165 GLuint result_to_output[VERT_RESULT_MAX];
166 ubyte output_semantic_name[VERT_RESULT_MAX];
167 ubyte output_semantic_index[VERT_RESULT_MAX];
168 GLuint num_outputs;
169
170 /** List of translated variants of this vertex program.
171 */
172 struct st_vp_variant *variants;
173 };
174
175
176
177 /** Geometry program variant key */
178 struct st_gp_variant_key
179 {
180 struct st_context *st; /**< variants are per-context */
181 /* no other fields yet */
182 };
183
184
185 /**
186 * Geometry program variant.
187 */
188 struct st_gp_variant
189 {
190 /* Parameters which generated this translated version of a vertex */
191 struct st_gp_variant_key key;
192
193 void *driver_shader;
194
195 struct st_gp_variant *next;
196 };
197
198
199 /**
200 * Derived from Mesa gl_geometry_program:
201 */
202 struct st_geometry_program
203 {
204 struct gl_geometry_program Base; /**< The Mesa geometry program */
205 struct glsl_to_tgsi_visitor* glsl_to_tgsi;
206
207 /** map GP input back to VP output */
208 GLuint input_map[PIPE_MAX_SHADER_INPUTS];
209
210 /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */
211 GLuint input_to_index[GEOM_ATTRIB_MAX];
212 /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */
213 GLuint index_to_input[PIPE_MAX_SHADER_INPUTS];
214
215 GLuint num_inputs;
216
217 GLuint input_to_slot[GEOM_ATTRIB_MAX]; /**< Maps GEOM_ATTRIB_x to slot */
218 GLuint num_input_slots;
219
220 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
221 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
222
223 struct pipe_shader_state tgsi;
224
225 struct st_gp_variant *variants;
226 };
227
228
229
230 static INLINE struct st_fragment_program *
231 st_fragment_program( struct gl_fragment_program *fp )
232 {
233 return (struct st_fragment_program *)fp;
234 }
235
236
237 static INLINE struct st_vertex_program *
238 st_vertex_program( struct gl_vertex_program *vp )
239 {
240 return (struct st_vertex_program *)vp;
241 }
242
243 static INLINE struct st_geometry_program *
244 st_geometry_program( struct gl_geometry_program *gp )
245 {
246 return (struct st_geometry_program *)gp;
247 }
248
249 static INLINE void
250 st_reference_vertprog(struct st_context *st,
251 struct st_vertex_program **ptr,
252 struct st_vertex_program *prog)
253 {
254 _mesa_reference_program(st->ctx,
255 (struct gl_program **) ptr,
256 (struct gl_program *) prog);
257 }
258
259 static INLINE void
260 st_reference_geomprog(struct st_context *st,
261 struct st_geometry_program **ptr,
262 struct st_geometry_program *prog)
263 {
264 _mesa_reference_program(st->ctx,
265 (struct gl_program **) ptr,
266 (struct gl_program *) prog);
267 }
268
269 static INLINE void
270 st_reference_fragprog(struct st_context *st,
271 struct st_fragment_program **ptr,
272 struct st_fragment_program *prog)
273 {
274 _mesa_reference_program(st->ctx,
275 (struct gl_program **) ptr,
276 (struct gl_program *) prog);
277 }
278
279
280 extern struct st_vp_variant *
281 st_get_vp_variant(struct st_context *st,
282 struct st_vertex_program *stvp,
283 const struct st_vp_variant_key *key);
284
285
286 extern struct st_fp_variant *
287 st_get_fp_variant(struct st_context *st,
288 struct st_fragment_program *stfp,
289 const struct st_fp_variant_key *key);
290
291
292 extern struct st_gp_variant *
293 st_get_gp_variant(struct st_context *st,
294 struct st_geometry_program *stgp,
295 const struct st_gp_variant_key *key);
296
297
298 extern void
299 st_prepare_vertex_program(struct gl_context *ctx,
300 struct st_vertex_program *stvp);
301
302 extern GLboolean
303 st_prepare_fragment_program(struct gl_context *ctx,
304 struct st_fragment_program *stfp);
305
306
307 extern void
308 st_release_vp_variants( struct st_context *st,
309 struct st_vertex_program *stvp );
310
311 extern void
312 st_release_fp_variants( struct st_context *st,
313 struct st_fragment_program *stfp );
314
315 extern void
316 st_release_gp_variants(struct st_context *st,
317 struct st_geometry_program *stgp);
318
319
320 extern void
321 st_print_shaders(struct gl_context *ctx);
322
323 extern void
324 st_destroy_program_variants(struct st_context *st);
325
326
327 #endif