program: remove unused function _mesa_find_line_column
[mesa.git] / src / mesa / program / program.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007 Brian Paul 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 "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file program.c
27 * Vertex and fragment program support functions.
28 * \author Brian Paul
29 */
30
31
32 /**
33 * \mainpage Mesa vertex and fragment program module
34 *
35 * This module or directory contains most of the code for vertex and
36 * fragment programs and shaders, including state management, parsers,
37 * and (some) software routines for executing programs
38 */
39
40 #ifndef PROGRAM_H
41 #define PROGRAM_H
42
43 #include "main/compiler.h"
44 #include "main/mtypes.h"
45
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 extern struct gl_program _mesa_DummyProgram;
52
53
54 extern void
55 _mesa_init_program(struct gl_context *ctx);
56
57 extern void
58 _mesa_free_program_data(struct gl_context *ctx);
59
60 extern void
61 _mesa_update_default_objects_program(struct gl_context *ctx);
62
63 extern void
64 _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string);
65
66 extern struct gl_program *
67 _mesa_init_vertex_program(struct gl_context *ctx,
68 struct gl_vertex_program *prog,
69 GLenum target, GLuint id);
70
71 extern struct gl_program *
72 _mesa_init_fragment_program(struct gl_context *ctx,
73 struct gl_fragment_program *prog,
74 GLenum target, GLuint id);
75
76 extern struct gl_program *
77 _mesa_init_tess_ctrl_program(struct gl_context *ctx,
78 struct gl_tess_ctrl_program *prog,
79 GLenum target, GLuint id);
80
81 extern struct gl_program *
82 _mesa_init_tess_eval_program(struct gl_context *ctx,
83 struct gl_tess_eval_program *prog,
84 GLenum target, GLuint id);
85
86 extern struct gl_program *
87 _mesa_init_geometry_program(struct gl_context *ctx,
88 struct gl_geometry_program *prog,
89 GLenum target, GLuint id);
90
91 extern struct gl_program *
92 _mesa_init_compute_program(struct gl_context *ctx,
93 struct gl_compute_program *prog,
94 GLenum target, GLuint id);
95
96 extern struct gl_program *
97 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
98
99 extern void
100 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
101
102 extern struct gl_program *
103 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
104
105 extern void
106 _mesa_reference_program_(struct gl_context *ctx,
107 struct gl_program **ptr,
108 struct gl_program *prog);
109
110 static inline void
111 _mesa_reference_program(struct gl_context *ctx,
112 struct gl_program **ptr,
113 struct gl_program *prog)
114 {
115 if (*ptr != prog)
116 _mesa_reference_program_(ctx, ptr, prog);
117 }
118
119 static inline void
120 _mesa_reference_vertprog(struct gl_context *ctx,
121 struct gl_vertex_program **ptr,
122 struct gl_vertex_program *prog)
123 {
124 _mesa_reference_program(ctx, (struct gl_program **) ptr,
125 (struct gl_program *) prog);
126 }
127
128 static inline void
129 _mesa_reference_fragprog(struct gl_context *ctx,
130 struct gl_fragment_program **ptr,
131 struct gl_fragment_program *prog)
132 {
133 _mesa_reference_program(ctx, (struct gl_program **) ptr,
134 (struct gl_program *) prog);
135 }
136
137 static inline void
138 _mesa_reference_geomprog(struct gl_context *ctx,
139 struct gl_geometry_program **ptr,
140 struct gl_geometry_program *prog)
141 {
142 _mesa_reference_program(ctx, (struct gl_program **) ptr,
143 (struct gl_program *) prog);
144 }
145
146 static inline void
147 _mesa_reference_compprog(struct gl_context *ctx,
148 struct gl_compute_program **ptr,
149 struct gl_compute_program *prog)
150 {
151 _mesa_reference_program(ctx, (struct gl_program **) ptr,
152 (struct gl_program *) prog);
153 }
154
155
156 static inline void
157 _mesa_reference_tesscprog(struct gl_context *ctx,
158 struct gl_tess_ctrl_program **ptr,
159 struct gl_tess_ctrl_program *prog)
160 {
161 _mesa_reference_program(ctx, (struct gl_program **) ptr,
162 (struct gl_program *) prog);
163 }
164
165 static inline void
166 _mesa_reference_tesseprog(struct gl_context *ctx,
167 struct gl_tess_eval_program **ptr,
168 struct gl_tess_eval_program *prog)
169 {
170 _mesa_reference_program(ctx, (struct gl_program **) ptr,
171 (struct gl_program *) prog);
172 }
173
174 extern struct gl_program *
175 _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog);
176
177 static inline struct gl_vertex_program *
178 _mesa_clone_vertex_program(struct gl_context *ctx,
179 const struct gl_vertex_program *prog)
180 {
181 return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base);
182 }
183
184 static inline struct gl_tess_ctrl_program *
185 _mesa_clone_tess_ctrl_program(struct gl_context *ctx,
186 const struct gl_tess_ctrl_program *prog)
187 {
188 return (struct gl_tess_ctrl_program *) _mesa_clone_program(ctx, &prog->Base);
189 }
190
191 static inline struct gl_tess_eval_program *
192 _mesa_clone_tess_eval_program(struct gl_context *ctx,
193 const struct gl_tess_eval_program *prog)
194 {
195 return (struct gl_tess_eval_program *) _mesa_clone_program(ctx, &prog->Base);
196 }
197
198 static inline struct gl_geometry_program *
199 _mesa_clone_geometry_program(struct gl_context *ctx,
200 const struct gl_geometry_program *prog)
201 {
202 return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base);
203 }
204
205 static inline struct gl_fragment_program *
206 _mesa_clone_fragment_program(struct gl_context *ctx,
207 const struct gl_fragment_program *prog)
208 {
209 return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base);
210 }
211
212
213 extern GLboolean
214 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
215
216 extern GLboolean
217 _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count);
218
219 extern struct gl_program *
220 _mesa_combine_programs(struct gl_context *ctx,
221 const struct gl_program *progA,
222 const struct gl_program *progB);
223
224 extern void
225 _mesa_find_used_registers(const struct gl_program *prog,
226 gl_register_file file,
227 GLboolean used[], GLuint usedSize);
228
229 extern GLint
230 _mesa_find_free_register(const GLboolean used[],
231 GLuint maxRegs, GLuint firstReg);
232
233
234 extern GLboolean
235 _mesa_valid_register_index(const struct gl_context *ctx,
236 gl_shader_stage shaderType,
237 gl_register_file file, GLint index);
238
239 extern void
240 _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog);
241
242 extern GLint
243 _mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
244 const struct gl_fragment_program *prog,
245 bool ignore_sample_qualifier);
246
247 static inline GLuint
248 _mesa_program_enum_to_shader_stage(GLenum v)
249 {
250 switch (v) {
251 case GL_VERTEX_PROGRAM_ARB:
252 return MESA_SHADER_VERTEX;
253 case GL_FRAGMENT_PROGRAM_ARB:
254 return MESA_SHADER_FRAGMENT;
255 case GL_GEOMETRY_PROGRAM_NV:
256 return MESA_SHADER_GEOMETRY;
257 case GL_TESS_CONTROL_PROGRAM_NV:
258 return MESA_SHADER_TESS_CTRL;
259 case GL_TESS_EVALUATION_PROGRAM_NV:
260 return MESA_SHADER_TESS_EVAL;
261 case GL_COMPUTE_PROGRAM_NV:
262 return MESA_SHADER_COMPUTE;
263 default:
264 assert(0);
265 return ~0;
266 }
267 }
268
269
270 static inline GLenum
271 _mesa_shader_stage_to_program(unsigned stage)
272 {
273 switch (stage) {
274 case MESA_SHADER_VERTEX:
275 return GL_VERTEX_PROGRAM_ARB;
276 case MESA_SHADER_FRAGMENT:
277 return GL_FRAGMENT_PROGRAM_ARB;
278 case MESA_SHADER_GEOMETRY:
279 return GL_GEOMETRY_PROGRAM_NV;
280 case MESA_SHADER_TESS_CTRL:
281 return GL_TESS_CONTROL_PROGRAM_NV;
282 case MESA_SHADER_TESS_EVAL:
283 return GL_TESS_EVALUATION_PROGRAM_NV;
284 case MESA_SHADER_COMPUTE:
285 return GL_COMPUTE_PROGRAM_NV;
286 }
287
288 assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
289 return GL_VERTEX_PROGRAM_ARB;
290 }
291
292
293 /* Cast wrappers from gl_program to derived program types.
294 * (e.g. gl_vertex_program)
295 */
296
297 static inline struct gl_fragment_program *
298 gl_fragment_program(struct gl_program *prog)
299 {
300 return (struct gl_fragment_program *) prog;
301 }
302
303 static inline const struct gl_fragment_program *
304 gl_fragment_program_const(const struct gl_program *prog)
305 {
306 return (const struct gl_fragment_program *) prog;
307 }
308
309
310 static inline struct gl_vertex_program *
311 gl_vertex_program(struct gl_program *prog)
312 {
313 return (struct gl_vertex_program *) prog;
314 }
315
316 static inline const struct gl_vertex_program *
317 gl_vertex_program_const(const struct gl_program *prog)
318 {
319 return (const struct gl_vertex_program *) prog;
320 }
321
322
323 static inline struct gl_geometry_program *
324 gl_geometry_program(struct gl_program *prog)
325 {
326 return (struct gl_geometry_program *) prog;
327 }
328
329 static inline const struct gl_geometry_program *
330 gl_geometry_program_const(const struct gl_program *prog)
331 {
332 return (const struct gl_geometry_program *) prog;
333 }
334
335
336 static inline struct gl_compute_program *
337 gl_compute_program(struct gl_program *prog)
338 {
339 return (struct gl_compute_program *) prog;
340 }
341
342 static inline const struct gl_compute_program *
343 gl_compute_program_const(const struct gl_program *prog)
344 {
345 return (const struct gl_compute_program *) prog;
346 }
347
348 static inline struct gl_tess_ctrl_program *
349 gl_tess_ctrl_program(struct gl_program *prog)
350 {
351 return (struct gl_tess_ctrl_program *) prog;
352 }
353
354 static inline const struct gl_tess_ctrl_program *
355 gl_tess_ctrl_program_const(const struct gl_program *prog)
356 {
357 return (const struct gl_tess_ctrl_program *) prog;
358 }
359
360
361 static inline struct gl_tess_eval_program *
362 gl_tess_eval_program(struct gl_program *prog)
363 {
364 return (struct gl_tess_eval_program *) prog;
365 }
366
367 static inline const struct gl_tess_eval_program *
368 gl_tess_eval_program_const(const struct gl_program *prog)
369 {
370 return (const struct gl_tess_eval_program *) prog;
371 }
372
373
374 #ifdef __cplusplus
375 } /* extern "C" */
376 #endif
377
378 #endif /* PROGRAM_H */