i965/mesa/st: eliminate gl_compute_program
[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_gl_program(struct gl_program *prog, GLenum target, GLuint id);
68
69 extern struct gl_program *
70 _mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id);
71
72 extern void
73 _mesa_delete_program(struct gl_context *ctx, struct gl_program *prog);
74
75 extern struct gl_program *
76 _mesa_lookup_program(struct gl_context *ctx, GLuint id);
77
78 extern void
79 _mesa_reference_program_(struct gl_context *ctx,
80 struct gl_program **ptr,
81 struct gl_program *prog);
82
83 static inline void
84 _mesa_reference_program(struct gl_context *ctx,
85 struct gl_program **ptr,
86 struct gl_program *prog)
87 {
88 if (*ptr != prog)
89 _mesa_reference_program_(ctx, ptr, prog);
90 }
91
92 static inline void
93 _mesa_reference_fragprog(struct gl_context *ctx,
94 struct gl_fragment_program **ptr,
95 struct gl_fragment_program *prog)
96 {
97 _mesa_reference_program(ctx, (struct gl_program **) ptr,
98 (struct gl_program *) prog);
99 }
100
101 extern GLboolean
102 _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
103
104 extern GLboolean
105 _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count);
106
107 extern void
108 _mesa_find_used_registers(const struct gl_program *prog,
109 gl_register_file file,
110 GLboolean used[], GLuint usedSize);
111
112 extern GLint
113 _mesa_find_free_register(const GLboolean used[],
114 GLuint maxRegs, GLuint firstReg);
115
116 extern GLint
117 _mesa_get_min_invocations_per_fragment(struct gl_context *ctx,
118 const struct gl_fragment_program *prog,
119 bool ignore_sample_qualifier);
120
121 static inline GLuint
122 _mesa_program_enum_to_shader_stage(GLenum v)
123 {
124 switch (v) {
125 case GL_VERTEX_PROGRAM_ARB:
126 return MESA_SHADER_VERTEX;
127 case GL_FRAGMENT_PROGRAM_ARB:
128 return MESA_SHADER_FRAGMENT;
129 case GL_FRAGMENT_SHADER_ATI:
130 return MESA_SHADER_FRAGMENT;
131 case GL_GEOMETRY_PROGRAM_NV:
132 return MESA_SHADER_GEOMETRY;
133 case GL_TESS_CONTROL_PROGRAM_NV:
134 return MESA_SHADER_TESS_CTRL;
135 case GL_TESS_EVALUATION_PROGRAM_NV:
136 return MESA_SHADER_TESS_EVAL;
137 case GL_COMPUTE_PROGRAM_NV:
138 return MESA_SHADER_COMPUTE;
139 default:
140 assert(0);
141 return ~0;
142 }
143 }
144
145
146 static inline GLenum
147 _mesa_shader_stage_to_program(unsigned stage)
148 {
149 switch (stage) {
150 case MESA_SHADER_VERTEX:
151 return GL_VERTEX_PROGRAM_ARB;
152 case MESA_SHADER_FRAGMENT:
153 return GL_FRAGMENT_PROGRAM_ARB;
154 case MESA_SHADER_GEOMETRY:
155 return GL_GEOMETRY_PROGRAM_NV;
156 case MESA_SHADER_TESS_CTRL:
157 return GL_TESS_CONTROL_PROGRAM_NV;
158 case MESA_SHADER_TESS_EVAL:
159 return GL_TESS_EVALUATION_PROGRAM_NV;
160 case MESA_SHADER_COMPUTE:
161 return GL_COMPUTE_PROGRAM_NV;
162 }
163
164 assert(!"Unexpected shader stage in _mesa_shader_stage_to_program");
165 return GL_VERTEX_PROGRAM_ARB;
166 }
167
168
169 static inline struct gl_fragment_program *
170 gl_fragment_program(struct gl_program *prog)
171 {
172 return (struct gl_fragment_program *) prog;
173 }
174
175 static inline const struct gl_fragment_program *
176 gl_fragment_program_const(const struct gl_program *prog)
177 {
178 return (const struct gl_fragment_program *) prog;
179 }
180
181 #ifdef __cplusplus
182 } /* extern "C" */
183 #endif
184
185 #endif /* PROGRAM_H */