mesa: add misc tessellation shader support
[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 const GLubyte *
67 _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
68 GLint *line, GLint *col);
69
70
71 extern struct gl_program *
72 _mesa_init_vertex_program(struct gl_context *ctx,
73 struct gl_vertex_program *prog,
74 GLenum target, GLuint id);
75
76 extern struct gl_program *
77 _mesa_init_fragment_program(struct gl_context *ctx,
78 struct gl_fragment_program *prog,
79 GLenum target, GLuint id);
80
81 extern struct gl_program *
82 _mesa_init_tess_ctrl_program(struct gl_context *ctx,
83 struct gl_tess_ctrl_program *prog,
84 GLenum target, GLuint id);
85
86 extern struct gl_program *
87 _mesa_init_tess_eval_program(struct gl_context *ctx,
88 struct gl_tess_eval_program *prog,
89 GLenum target, GLuint id);
90
91 extern struct gl_program *
92 _mesa_init_geometry_program(struct gl_context *ctx,
93 struct gl_geometry_program *prog,
94 GLenum target, GLuint id);
95
96 extern struct gl_program *
97 _mesa_init_compute_program(struct gl_context *ctx,
98 struct gl_compute_program *prog,
99 GLenum target, GLuint id);
100
101 extern struct gl_program *
102 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
103
104 extern void
105 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
106
107 extern struct gl_program *
108 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
109
110 extern void
111 _mesa_reference_program_(struct gl_context *ctx,
112 struct gl_program **ptr,
113 struct gl_program *prog);
114
115 static inline void
116 _mesa_reference_program(struct gl_context *ctx,
117 struct gl_program **ptr,
118 struct gl_program *prog)
119 {
120 if (*ptr != prog)
121 _mesa_reference_program_(ctx, ptr, prog);
122 }
123
124 static inline void
125 _mesa_reference_vertprog(struct gl_context *ctx,
126 struct gl_vertex_program **ptr,
127 struct gl_vertex_program *prog)
128 {
129 _mesa_reference_program(ctx, (struct gl_program **) ptr,
130 (struct gl_program *) prog);
131 }
132
133 static inline void
134 _mesa_reference_fragprog(struct gl_context *ctx,
135 struct gl_fragment_program **ptr,
136 struct gl_fragment_program *prog)
137 {
138 _mesa_reference_program(ctx, (struct gl_program **) ptr,
139 (struct gl_program *) prog);
140 }
141
142 static inline void
143 _mesa_reference_geomprog(struct gl_context *ctx,
144 struct gl_geometry_program **ptr,
145 struct gl_geometry_program *prog)
146 {
147 _mesa_reference_program(ctx, (struct gl_program **) ptr,
148 (struct gl_program *) prog);
149 }
150
151 static inline void
152 _mesa_reference_compprog(struct gl_context *ctx,
153 struct gl_compute_program **ptr,
154 struct gl_compute_program *prog)
155 {
156 _mesa_reference_program(ctx, (struct gl_program **) ptr,
157 (struct gl_program *) prog);
158 }
159
160
161 static inline void
162 _mesa_reference_tesscprog(struct gl_context *ctx,
163 struct gl_tess_ctrl_program **ptr,
164 struct gl_tess_ctrl_program *prog)
165 {
166 _mesa_reference_program(ctx, (struct gl_program **) ptr,
167 (struct gl_program *) prog);
168 }
169
170 static inline void
171 _mesa_reference_tesseprog(struct gl_context *ctx,
172 struct gl_tess_eval_program **ptr,
173 struct gl_tess_eval_program *prog)
174 {
175 _mesa_reference_program(ctx, (struct gl_program **) ptr,
176 (struct gl_program *) prog);
177 }
178
179 extern struct gl_program *
180 _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog);
181
182 static inline struct gl_vertex_program *
183 _mesa_clone_vertex_program(struct gl_context *ctx,
184 const struct gl_vertex_program *prog)
185 {
186 return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base);
187 }
188
189 static inline struct gl_tess_ctrl_program *
190 _mesa_clone_tess_ctrl_program(struct gl_context *ctx,
191 const struct gl_tess_ctrl_program *prog)
192 {
193 return (struct gl_tess_ctrl_program *) _mesa_clone_program(ctx, &prog->Base);
194 }
195
196 static inline struct gl_tess_eval_program *
197 _mesa_clone_tess_eval_program(struct gl_context *ctx,
198 const struct gl_tess_eval_program *prog)
199 {
200 return (struct gl_tess_eval_program *) _mesa_clone_program(ctx, &prog->Base);
201 }
202
203 static inline struct gl_geometry_program *
204 _mesa_clone_geometry_program(struct gl_context *ctx,
205 const struct gl_geometry_program *prog)
206 {
207 return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base);
208 }
209
210 static inline struct gl_fragment_program *
211 _mesa_clone_fragment_program(struct gl_context *ctx,
212 const struct gl_fragment_program *prog)
213 {
214 return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base);
215 }
216
217
218 extern GLboolean
219 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
220
221 extern GLboolean
222 _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count);
223
224 extern struct gl_program *
225 _mesa_combine_programs(struct gl_context *ctx,
226 const struct gl_program *progA,
227 const struct gl_program *progB);
228
229 extern void
230 _mesa_find_used_registers(const struct gl_program *prog,
231 gl_register_file file,
232 GLboolean used[], GLuint usedSize);
233
234 extern GLint
235 _mesa_find_free_register(const GLboolean used[],
236 GLuint maxRegs, GLuint firstReg);
237
238
239 extern GLboolean
240 _mesa_valid_register_index(const struct gl_context *ctx,
241 gl_shader_stage shaderType,
242 gl_register_file file, GLint index);
243
244 extern void
245 _mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog);
246
247 extern GLint
248 _mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
249 const struct gl_fragment_program *prog,
250 bool ignore_sample_qualifier);
251
252 static inline GLuint
253 _mesa_program_enum_to_shader_stage(GLenum v)
254 {
255 switch (v) {
256 case GL_VERTEX_PROGRAM_ARB:
257 return MESA_SHADER_VERTEX;
258 case GL_FRAGMENT_PROGRAM_ARB:
259 return MESA_SHADER_FRAGMENT;
260 case GL_GEOMETRY_PROGRAM_NV:
261 return MESA_SHADER_GEOMETRY;
262 case GL_TESS_CONTROL_PROGRAM_NV:
263 return MESA_SHADER_TESS_CTRL;
264 case GL_TESS_EVALUATION_PROGRAM_NV:
265 return MESA_SHADER_TESS_EVAL;
266 case GL_COMPUTE_PROGRAM_NV:
267 return MESA_SHADER_COMPUTE;
268 default:
269 assert(0);
270 return ~0;
271 }
272 }
273
274
275 static inline GLenum
276 _mesa_shader_stage_to_program(unsigned stage)
277 {
278 switch (stage) {
279 case MESA_SHADER_VERTEX:
280 return GL_VERTEX_PROGRAM_ARB;
281 case MESA_SHADER_FRAGMENT:
282 return GL_FRAGMENT_PROGRAM_ARB;
283 case MESA_SHADER_GEOMETRY:
284 return GL_GEOMETRY_PROGRAM_NV;
285 case MESA_SHADER_TESS_CTRL:
286 return GL_TESS_CONTROL_PROGRAM_NV;
287 case MESA_SHADER_TESS_EVAL:
288 return GL_TESS_EVALUATION_PROGRAM_NV;
289 case MESA_SHADER_COMPUTE:
290 return GL_COMPUTE_PROGRAM_NV;
291 }
292
293 assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
294 return GL_VERTEX_PROGRAM_ARB;
295 }
296
297
298 /* Cast wrappers from gl_program to derived program types.
299 * (e.g. gl_vertex_program)
300 */
301
302 static inline struct gl_fragment_program *
303 gl_fragment_program(struct gl_program *prog)
304 {
305 return (struct gl_fragment_program *) prog;
306 }
307
308 static inline const struct gl_fragment_program *
309 gl_fragment_program_const(const struct gl_program *prog)
310 {
311 return (const struct gl_fragment_program *) prog;
312 }
313
314
315 static inline struct gl_vertex_program *
316 gl_vertex_program(struct gl_program *prog)
317 {
318 return (struct gl_vertex_program *) prog;
319 }
320
321 static inline const struct gl_vertex_program *
322 gl_vertex_program_const(const struct gl_program *prog)
323 {
324 return (const struct gl_vertex_program *) prog;
325 }
326
327
328 static inline struct gl_geometry_program *
329 gl_geometry_program(struct gl_program *prog)
330 {
331 return (struct gl_geometry_program *) prog;
332 }
333
334 static inline const struct gl_geometry_program *
335 gl_geometry_program_const(const struct gl_program *prog)
336 {
337 return (const struct gl_geometry_program *) prog;
338 }
339
340
341 static inline struct gl_compute_program *
342 gl_compute_program(struct gl_program *prog)
343 {
344 return (struct gl_compute_program *) prog;
345 }
346
347 static inline const struct gl_compute_program *
348 gl_compute_program_const(const struct gl_program *prog)
349 {
350 return (const struct gl_compute_program *) prog;
351 }
352
353 static inline struct gl_tess_ctrl_program *
354 gl_tess_ctrl_program(struct gl_program *prog)
355 {
356 return (struct gl_tess_ctrl_program *) prog;
357 }
358
359 static inline const struct gl_tess_ctrl_program *
360 gl_tess_ctrl_program_const(const struct gl_program *prog)
361 {
362 return (const struct gl_tess_ctrl_program *) prog;
363 }
364
365
366 static inline struct gl_tess_eval_program *
367 gl_tess_eval_program(struct gl_program *prog)
368 {
369 return (struct gl_tess_eval_program *) prog;
370 }
371
372 static inline const struct gl_tess_eval_program *
373 gl_tess_eval_program_const(const struct gl_program *prog)
374 {
375 return (const struct gl_tess_eval_program *) prog;
376 }
377
378
379 #ifdef __cplusplus
380 } /* extern "C" */
381 #endif
382
383 #endif /* PROGRAM_H */