meson: add support for xlib glx
[mesa.git] / src / mesa / main / shaderobj.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2004-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 #ifndef SHADEROBJ_H
27 #define SHADEROBJ_H
28
29
30 #include "main/compiler.h"
31 #include "main/glheader.h"
32 #include "main/mtypes.h"
33 #include "program/ir_to_mesa.h"
34
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 /**
42 * Internal functions
43 */
44
45 extern void
46 _mesa_init_shader_state(struct gl_context * ctx);
47
48 extern void
49 _mesa_free_shader_state(struct gl_context *ctx);
50
51
52 extern void
53 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
54 struct gl_shader *sh);
55
56 extern struct gl_shader *
57 _mesa_lookup_shader(struct gl_context *ctx, GLuint name);
58
59 extern struct gl_shader *
60 _mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller);
61
62
63
64 extern void
65 _mesa_reference_shader_program_(struct gl_context *ctx,
66 struct gl_shader_program **ptr,
67 struct gl_shader_program *shProg);
68
69 void
70 _mesa_reference_shader_program_data(struct gl_context *ctx,
71 struct gl_shader_program_data **ptr,
72 struct gl_shader_program_data *data);
73
74 static inline void
75 _mesa_reference_shader_program(struct gl_context *ctx,
76 struct gl_shader_program **ptr,
77 struct gl_shader_program *shProg)
78 {
79 if (*ptr != shProg)
80 _mesa_reference_shader_program_(ctx, ptr, shProg);
81 }
82
83 extern struct gl_shader *
84 _mesa_new_shader(GLuint name, gl_shader_stage type);
85
86 extern void
87 _mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh);
88
89 extern void
90 _mesa_delete_linked_shader(struct gl_context *ctx,
91 struct gl_linked_shader *sh);
92
93 extern struct gl_shader_program *
94 _mesa_lookup_shader_program(struct gl_context *ctx, GLuint name);
95
96 extern struct gl_shader_program *
97 _mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name,
98 const char *caller);
99
100 extern struct gl_shader_program *
101 _mesa_new_shader_program(GLuint name);
102
103 extern struct gl_shader_program_data *
104 _mesa_create_shader_program_data(void);
105
106 extern void
107 _mesa_clear_shader_program_data(struct gl_context *ctx,
108 struct gl_shader_program *shProg);
109
110 extern void
111 _mesa_free_shader_program_data(struct gl_context *ctx,
112 struct gl_shader_program *shProg);
113
114 extern void
115 _mesa_delete_shader_program(struct gl_context *ctx,
116 struct gl_shader_program *shProg);
117
118
119 extern void
120 _mesa_init_shader_object_functions(struct dd_function_table *driver);
121
122 static inline gl_shader_stage
123 _mesa_shader_enum_to_shader_stage(GLenum v)
124 {
125 switch (v) {
126 case GL_VERTEX_SHADER:
127 return MESA_SHADER_VERTEX;
128 case GL_FRAGMENT_SHADER:
129 return MESA_SHADER_FRAGMENT;
130 case GL_GEOMETRY_SHADER:
131 return MESA_SHADER_GEOMETRY;
132 case GL_TESS_CONTROL_SHADER:
133 return MESA_SHADER_TESS_CTRL;
134 case GL_TESS_EVALUATION_SHADER:
135 return MESA_SHADER_TESS_EVAL;
136 case GL_COMPUTE_SHADER:
137 return MESA_SHADER_COMPUTE;
138 default:
139 unreachable("bad value in _mesa_shader_enum_to_shader_stage()");
140 }
141 }
142
143 /* 8 bytes + another underscore */
144 #define MESA_SUBROUTINE_PREFIX_LEN 9
145 static inline const char *
146 _mesa_shader_stage_to_subroutine_prefix(gl_shader_stage stage)
147 {
148 switch (stage) {
149 case MESA_SHADER_VERTEX:
150 return "__subu_v";
151 case MESA_SHADER_GEOMETRY:
152 return "__subu_g";
153 case MESA_SHADER_FRAGMENT:
154 return "__subu_f";
155 case MESA_SHADER_COMPUTE:
156 return "__subu_c";
157 case MESA_SHADER_TESS_CTRL:
158 return "__subu_t";
159 case MESA_SHADER_TESS_EVAL:
160 return "__subu_e";
161 default:
162 return NULL;
163 }
164 }
165
166 static inline gl_shader_stage
167 _mesa_shader_stage_from_subroutine_uniform(GLenum subuniform)
168 {
169 switch (subuniform) {
170 case GL_VERTEX_SUBROUTINE_UNIFORM:
171 return MESA_SHADER_VERTEX;
172 case GL_GEOMETRY_SUBROUTINE_UNIFORM:
173 return MESA_SHADER_GEOMETRY;
174 case GL_FRAGMENT_SUBROUTINE_UNIFORM:
175 return MESA_SHADER_FRAGMENT;
176 case GL_COMPUTE_SUBROUTINE_UNIFORM:
177 return MESA_SHADER_COMPUTE;
178 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM:
179 return MESA_SHADER_TESS_CTRL;
180 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM:
181 return MESA_SHADER_TESS_EVAL;
182 }
183 unreachable("not reached");
184 }
185
186 static inline gl_shader_stage
187 _mesa_shader_stage_from_subroutine(GLenum subroutine)
188 {
189 switch (subroutine) {
190 case GL_VERTEX_SUBROUTINE:
191 return MESA_SHADER_VERTEX;
192 case GL_GEOMETRY_SUBROUTINE:
193 return MESA_SHADER_GEOMETRY;
194 case GL_FRAGMENT_SUBROUTINE:
195 return MESA_SHADER_FRAGMENT;
196 case GL_COMPUTE_SUBROUTINE:
197 return MESA_SHADER_COMPUTE;
198 case GL_TESS_CONTROL_SUBROUTINE:
199 return MESA_SHADER_TESS_CTRL;
200 case GL_TESS_EVALUATION_SUBROUTINE:
201 return MESA_SHADER_TESS_EVAL;
202 }
203 unreachable("not reached");
204 }
205
206 static inline GLenum
207 _mesa_shader_stage_to_subroutine(gl_shader_stage stage)
208 {
209 switch (stage) {
210 case MESA_SHADER_VERTEX:
211 return GL_VERTEX_SUBROUTINE;
212 case MESA_SHADER_GEOMETRY:
213 return GL_GEOMETRY_SUBROUTINE;
214 case MESA_SHADER_FRAGMENT:
215 return GL_FRAGMENT_SUBROUTINE;
216 case MESA_SHADER_COMPUTE:
217 return GL_COMPUTE_SUBROUTINE;
218 case MESA_SHADER_TESS_CTRL:
219 return GL_TESS_CONTROL_SUBROUTINE;
220 case MESA_SHADER_TESS_EVAL:
221 return GL_TESS_EVALUATION_SUBROUTINE;
222 case MESA_SHADER_NONE:
223 break;
224 }
225 unreachable("not reached");
226 }
227
228 static inline GLenum
229 _mesa_shader_stage_to_subroutine_uniform(gl_shader_stage stage)
230 {
231 switch (stage) {
232 case MESA_SHADER_VERTEX:
233 return GL_VERTEX_SUBROUTINE_UNIFORM;
234 case MESA_SHADER_GEOMETRY:
235 return GL_GEOMETRY_SUBROUTINE_UNIFORM;
236 case MESA_SHADER_FRAGMENT:
237 return GL_FRAGMENT_SUBROUTINE_UNIFORM;
238 case MESA_SHADER_COMPUTE:
239 return GL_COMPUTE_SUBROUTINE_UNIFORM;
240 case MESA_SHADER_TESS_CTRL:
241 return GL_TESS_CONTROL_SUBROUTINE_UNIFORM;
242 case MESA_SHADER_TESS_EVAL:
243 return GL_TESS_EVALUATION_SUBROUTINE_UNIFORM;
244 case MESA_SHADER_NONE:
245 break;
246 }
247 unreachable("not reached");
248 }
249
250 extern bool
251 _mesa_validate_pipeline_io(struct gl_pipeline_object *);
252
253 #ifdef __cplusplus
254 }
255 #endif
256
257 #endif /* SHADEROBJ_H */