Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * Copyright © 2010 Intel Corporation |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
8 | * and/or sell copies of the Software, and to permit persons to whom the |
||
9 | * Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
11 | * The above copyright notice and this permission notice (including the next |
||
12 | * paragraph) shall be included in all copies or substantial portions of the |
||
13 | * Software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
21 | * DEALINGS IN THE SOFTWARE. |
||
22 | */ |
||
23 | |||
24 | #pragma once |
||
25 | #ifndef GLSL_PARSER_EXTRAS_H |
||
26 | #define GLSL_PARSER_EXTRAS_H |
||
27 | |||
28 | /* |
||
29 | * Most of the definitions here only apply to C++ |
||
30 | */ |
||
31 | #ifdef __cplusplus |
||
32 | |||
33 | |||
34 | #include |
||
35 | #include "glsl_symbol_table.h" |
||
36 | |||
37 | enum _mesa_glsl_parser_targets { |
||
38 | vertex_shader, |
||
39 | geometry_shader, |
||
40 | fragment_shader |
||
41 | }; |
||
42 | |||
43 | struct gl_context; |
||
44 | |||
45 | struct glsl_switch_state { |
||
46 | /** Temporary variables needed for switch statement. */ |
||
47 | ir_variable *test_var; |
||
48 | ir_variable *is_fallthru_var; |
||
49 | ir_variable *is_break_var; |
||
50 | class ast_switch_statement *switch_nesting_ast; |
||
51 | |||
52 | /** Table of constant values already used in case labels */ |
||
53 | struct hash_table *labels_ht; |
||
54 | class ast_case_label *previous_default; |
||
55 | |||
56 | bool is_switch_innermost; // if switch stmt is closest to break, ... |
||
57 | }; |
||
58 | |||
59 | const char * |
||
60 | glsl_compute_version_string(void *mem_ctx, bool is_es, unsigned version); |
||
61 | |||
62 | typedef struct YYLTYPE { |
||
63 | int first_line; |
||
64 | int first_column; |
||
65 | int last_line; |
||
66 | int last_column; |
||
67 | unsigned source; |
||
68 | } YYLTYPE; |
||
69 | # define YYLTYPE_IS_DECLARED 1 |
||
70 | # define YYLTYPE_IS_TRIVIAL 1 |
||
71 | |||
72 | struct _mesa_glsl_parse_state { |
||
73 | _mesa_glsl_parse_state(struct gl_context *_ctx, GLenum target, |
||
74 | void *mem_ctx); |
||
75 | |||
76 | /* Callers of this ralloc-based new need not call delete. It's |
||
77 | * easier to just ralloc_free 'ctx' (or any of its ancestors). */ |
||
78 | static void* operator new(size_t size, void *ctx) |
||
79 | { |
||
80 | void *mem = rzalloc_size(ctx, size); |
||
81 | assert(mem != NULL); |
||
82 | |||
83 | return mem; |
||
84 | } |
||
85 | |||
86 | /* If the user *does* call delete, that's OK, we will just |
||
87 | * ralloc_free in that case. */ |
||
88 | static void operator delete(void *mem) |
||
89 | { |
||
90 | ralloc_free(mem); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Generate a string representing the GLSL version currently being compiled |
||
95 | * (useful for error messages). |
||
96 | */ |
||
97 | const char *get_version_string() |
||
98 | { |
||
99 | return glsl_compute_version_string(this, this->es_shader, |
||
100 | this->language_version); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Determine whether the current GLSL version is sufficiently high to |
||
105 | * support a certain feature. |
||
106 | * |
||
107 | * \param required_glsl_version is the desktop GLSL version that is |
||
108 | * required to support the feature, or 0 if no version of desktop GLSL |
||
109 | * supports the feature. |
||
110 | * |
||
111 | * \param required_glsl_es_version is the GLSL ES version that is required |
||
112 | * to support the feature, or 0 if no version of GLSL ES suports the |
||
113 | * feature. |
||
114 | */ |
||
115 | bool is_version(unsigned required_glsl_version, |
||
116 | unsigned required_glsl_es_version) |
||
117 | { |
||
118 | unsigned required_version = this->es_shader ? |
||
119 | required_glsl_es_version : required_glsl_version; |
||
120 | return required_version != 0 |
||
121 | && this->language_version >= required_version; |
||
122 | } |
||
123 | |||
124 | bool check_version(unsigned required_glsl_version, |
||
125 | unsigned required_glsl_es_version, |
||
126 | YYLTYPE *locp, const char *fmt, ...) PRINTFLIKE(5, 6); |
||
127 | |||
128 | bool check_precision_qualifiers_allowed(YYLTYPE *locp) |
||
129 | { |
||
130 | return check_version(130, 100, locp, |
||
131 | "precision qualifiers are forbidden"); |
||
132 | } |
||
133 | |||
134 | bool check_bitwise_operations_allowed(YYLTYPE *locp) |
||
135 | { |
||
136 | return check_version(130, 300, locp, "bit-wise operations are forbidden"); |
||
137 | } |
||
138 | |||
139 | void process_version_directive(YYLTYPE *locp, int version, |
||
140 | const char *ident); |
||
141 | |||
142 | struct gl_context *const ctx; |
||
143 | void *scanner; |
||
144 | exec_list translation_unit; |
||
145 | glsl_symbol_table *symbols; |
||
146 | |||
147 | unsigned num_uniform_blocks; |
||
148 | unsigned uniform_block_array_size; |
||
149 | struct gl_uniform_block *uniform_blocks; |
||
150 | |||
151 | unsigned num_supported_versions; |
||
152 | struct { |
||
153 | unsigned ver; |
||
154 | bool es; |
||
155 | } supported_versions[12]; |
||
156 | |||
157 | bool es_shader; |
||
158 | unsigned language_version; |
||
159 | enum _mesa_glsl_parser_targets target; |
||
160 | |||
161 | /** |
||
162 | * Number of nested struct_specifier levels |
||
163 | * |
||
164 | * Outside a struct_specifer, this is zero. |
||
165 | */ |
||
166 | unsigned struct_specifier_depth; |
||
167 | |||
168 | /** |
||
169 | * Default uniform layout qualifiers tracked during parsing. |
||
170 | * Currently affects uniform blocks and uniform buffer variables in |
||
171 | * those blocks. |
||
172 | */ |
||
173 | struct ast_type_qualifier *default_uniform_qualifier; |
||
174 | |||
175 | /** |
||
176 | * Printable list of GLSL versions supported by the current context |
||
177 | * |
||
178 | * \note |
||
179 | * This string should probably be generated per-context instead of per |
||
180 | * invokation of the compiler. This should be changed when the method of |
||
181 | * tracking supported GLSL versions changes. |
||
182 | */ |
||
183 | const char *supported_version_string; |
||
184 | |||
185 | /** |
||
186 | * Implementation defined limits that affect built-in variables, etc. |
||
187 | * |
||
188 | * \sa struct gl_constants (in mtypes.h) |
||
189 | */ |
||
190 | struct { |
||
191 | /* 1.10 */ |
||
192 | unsigned MaxLights; |
||
193 | unsigned MaxClipPlanes; |
||
194 | unsigned MaxTextureUnits; |
||
195 | unsigned MaxTextureCoords; |
||
196 | unsigned MaxVertexAttribs; |
||
197 | unsigned MaxVertexUniformComponents; |
||
198 | unsigned MaxVaryingFloats; |
||
199 | unsigned MaxVertexTextureImageUnits; |
||
200 | unsigned MaxCombinedTextureImageUnits; |
||
201 | unsigned MaxTextureImageUnits; |
||
202 | unsigned MaxFragmentUniformComponents; |
||
203 | |||
204 | /* ARB_draw_buffers */ |
||
205 | unsigned MaxDrawBuffers; |
||
206 | |||
207 | /* 3.00 ES */ |
||
208 | int MinProgramTexelOffset; |
||
209 | int MaxProgramTexelOffset; |
||
210 | } Const; |
||
211 | |||
212 | /** |
||
213 | * During AST to IR conversion, pointer to current IR function |
||
214 | * |
||
215 | * Will be \c NULL whenever the AST to IR conversion is not inside a |
||
216 | * function definition. |
||
217 | */ |
||
218 | class ir_function_signature *current_function; |
||
219 | |||
220 | /** |
||
221 | * During AST to IR conversion, pointer to the toplevel IR |
||
222 | * instruction list being generated. |
||
223 | */ |
||
224 | exec_list *toplevel_ir; |
||
225 | |||
226 | /** Have we found a return statement in this function? */ |
||
227 | bool found_return; |
||
228 | |||
229 | /** Was there an error during compilation? */ |
||
230 | bool error; |
||
231 | |||
232 | /** |
||
233 | * Are all shader inputs / outputs invariant? |
||
234 | * |
||
235 | * This is set when the 'STDGL invariant(all)' pragma is used. |
||
236 | */ |
||
237 | bool all_invariant; |
||
238 | |||
239 | /** Loop or switch statement containing the current instructions. */ |
||
240 | class ast_iteration_statement *loop_nesting_ast; |
||
241 | |||
242 | struct glsl_switch_state switch_state; |
||
243 | |||
244 | /** List of structures defined in user code. */ |
||
245 | const glsl_type **user_structures; |
||
246 | unsigned num_user_structures; |
||
247 | |||
248 | char *info_log; |
||
249 | |||
250 | /** |
||
251 | * \name Enable bits for GLSL extensions |
||
252 | */ |
||
253 | /*@{*/ |
||
254 | bool ARB_draw_buffers_enable; |
||
255 | bool ARB_draw_buffers_warn; |
||
256 | bool ARB_draw_instanced_enable; |
||
257 | bool ARB_draw_instanced_warn; |
||
258 | bool ARB_explicit_attrib_location_enable; |
||
259 | bool ARB_explicit_attrib_location_warn; |
||
260 | bool ARB_fragment_coord_conventions_enable; |
||
261 | bool ARB_fragment_coord_conventions_warn; |
||
262 | bool ARB_texture_rectangle_enable; |
||
263 | bool ARB_texture_rectangle_warn; |
||
264 | bool EXT_texture_array_enable; |
||
265 | bool EXT_texture_array_warn; |
||
266 | bool ARB_shader_texture_lod_enable; |
||
267 | bool ARB_shader_texture_lod_warn; |
||
268 | bool ARB_shader_stencil_export_enable; |
||
269 | bool ARB_shader_stencil_export_warn; |
||
270 | bool AMD_conservative_depth_enable; |
||
271 | bool AMD_conservative_depth_warn; |
||
272 | bool ARB_conservative_depth_enable; |
||
273 | bool ARB_conservative_depth_warn; |
||
274 | bool AMD_shader_stencil_export_enable; |
||
275 | bool AMD_shader_stencil_export_warn; |
||
276 | bool OES_texture_3D_enable; |
||
277 | bool OES_texture_3D_warn; |
||
278 | bool OES_EGL_image_external_enable; |
||
279 | bool OES_EGL_image_external_warn; |
||
280 | bool ARB_shader_bit_encoding_enable; |
||
281 | bool ARB_shader_bit_encoding_warn; |
||
282 | bool ARB_uniform_buffer_object_enable; |
||
283 | bool ARB_uniform_buffer_object_warn; |
||
284 | bool OES_standard_derivatives_enable; |
||
285 | bool OES_standard_derivatives_warn; |
||
286 | bool ARB_texture_cube_map_array_enable; |
||
287 | bool ARB_texture_cube_map_array_warn; |
||
288 | bool ARB_shading_language_packing_enable; |
||
289 | bool ARB_shading_language_packing_warn; |
||
290 | bool ARB_texture_multisample_enable; |
||
291 | bool ARB_texture_multisample_warn; |
||
292 | bool ARB_texture_query_lod_enable; |
||
293 | bool ARB_texture_query_lod_warn; |
||
294 | bool ARB_gpu_shader5_enable; |
||
295 | bool ARB_gpu_shader5_warn; |
||
296 | bool AMD_vertex_shader_layer_enable; |
||
297 | bool AMD_vertex_shader_layer_warn; |
||
298 | bool ARB_shading_language_420pack_enable; |
||
299 | bool ARB_shading_language_420pack_warn; |
||
300 | /*@}*/ |
||
301 | |||
302 | /** Extensions supported by the OpenGL implementation. */ |
||
303 | const struct gl_extensions *extensions; |
||
304 | |||
305 | /** Shaders containing built-in functions that are used for linking. */ |
||
306 | struct gl_shader *builtins_to_link[16]; |
||
307 | unsigned num_builtins_to_link; |
||
308 | }; |
||
309 | |||
310 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ |
||
311 | do { \ |
||
312 | if (N) \ |
||
313 | { \ |
||
314 | (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ |
||
315 | (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ |
||
316 | (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ |
||
317 | (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ |
||
318 | } \ |
||
319 | else \ |
||
320 | { \ |
||
321 | (Current).first_line = (Current).last_line = \ |
||
322 | YYRHSLOC(Rhs, 0).last_line; \ |
||
323 | (Current).first_column = (Current).last_column = \ |
||
324 | YYRHSLOC(Rhs, 0).last_column; \ |
||
325 | } \ |
||
326 | (Current).source = 0; \ |
||
327 | } while (0) |
||
328 | |||
329 | extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, |
||
330 | const char *fmt, ...); |
||
331 | |||
332 | /** |
||
333 | * Emit a warning to the shader log |
||
334 | * |
||
335 | * \sa _mesa_glsl_error |
||
336 | */ |
||
337 | extern void _mesa_glsl_warning(const YYLTYPE *locp, |
||
338 | _mesa_glsl_parse_state *state, |
||
339 | const char *fmt, ...); |
||
340 | |||
341 | extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, |
||
342 | const char *string); |
||
343 | |||
344 | extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state); |
||
345 | |||
346 | union YYSTYPE; |
||
347 | extern int _mesa_glsl_lexer_lex(union YYSTYPE *yylval, YYLTYPE *yylloc, |
||
348 | void *scanner); |
||
349 | |||
350 | extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *); |
||
351 | |||
352 | /** |
||
353 | * Process elements of the #extension directive |
||
354 | * |
||
355 | * \return |
||
356 | * If \c name and \c behavior are valid, \c true is returned. Otherwise |
||
357 | * \c false is returned. |
||
358 | */ |
||
359 | extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, |
||
360 | const char *behavior, |
||
361 | YYLTYPE *behavior_locp, |
||
362 | _mesa_glsl_parse_state *state); |
||
363 | |||
364 | /** |
||
365 | * Get the textual name of the specified shader target |
||
366 | */ |
||
367 | extern const char * |
||
368 | _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target); |
||
369 | |||
370 | |||
371 | #endif /* __cplusplus */ |
||
372 | |||
373 | |||
374 | /* |
||
375 | * These definitions apply to C and C++ |
||
376 | */ |
||
377 | #ifdef __cplusplus |
||
378 | extern "C" { |
||
379 | #endif |
||
380 | |||
381 | extern const char * |
||
382 | _mesa_glsl_shader_target_name(GLenum type); |
||
383 | |||
384 | extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log, |
||
385 | const struct gl_extensions *extensions, struct gl_context *gl_ctx); |
||
386 | |||
387 | extern void _mesa_destroy_shader_compiler(void); |
||
388 | extern void _mesa_destroy_shader_compiler_caches(void); |
||
389 | |||
390 | #ifdef __cplusplus |
||
391 | } |
||
392 | #endif |
||
393 | |||
394 | |||
395 | #endif /* GLSL_PARSER_EXTRAS_H */ |