2 * Copyright © 2010 Intel Corporation
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:
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
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.
25 #ifndef GLSL_PARSER_EXTRAS_H
26 #define GLSL_PARSER_EXTRAS_H
29 * Most of the definitions here only apply to C++
35 #include "glsl_symbol_table.h"
37 enum _mesa_glsl_parser_targets
{
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
;
52 /** Table of constant values already used in case labels */
53 struct hash_table
*labels_ht
;
54 class ast_case_label
*previous_default
;
56 bool is_switch_innermost
; // if switch stmt is closest to break, ...
60 glsl_compute_version_string(void *mem_ctx
, bool is_es
, unsigned version
);
62 typedef struct YYLTYPE
{
69 # define YYLTYPE_IS_DECLARED 1
70 # define YYLTYPE_IS_TRIVIAL 1
72 struct _mesa_glsl_parse_state
{
73 _mesa_glsl_parse_state(struct gl_context
*_ctx
, GLenum target
,
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
)
80 void *mem
= rzalloc_size(ctx
, size
);
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
)
94 * Generate a string representing the GLSL version currently being compiled
95 * (useful for error messages).
97 const char *get_version_string()
99 return glsl_compute_version_string(this, this->es_shader
,
100 this->language_version
);
104 * Determine whether the current GLSL version is sufficiently high to
105 * support a certain feature.
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.
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
115 bool is_version(unsigned required_glsl_version
,
116 unsigned required_glsl_es_version
)
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
;
124 bool check_version(unsigned required_glsl_version
,
125 unsigned required_glsl_es_version
,
126 YYLTYPE
*locp
, const char *fmt
, ...) PRINTFLIKE(5, 6);
128 bool check_precision_qualifiers_allowed(YYLTYPE
*locp
)
130 return check_version(130, 100, locp
,
131 "precision qualifiers are forbidden");
134 bool check_bitwise_operations_allowed(YYLTYPE
*locp
)
136 return check_version(130, 300, locp
, "bit-wise operations are forbidden");
139 void process_version_directive(YYLTYPE
*locp
, int version
,
142 struct gl_context
*const ctx
;
144 exec_list translation_unit
;
145 glsl_symbol_table
*symbols
;
147 unsigned num_uniform_blocks
;
148 unsigned uniform_block_array_size
;
149 struct gl_uniform_block
*uniform_blocks
;
152 unsigned language_version
;
153 enum _mesa_glsl_parser_targets target
;
156 * Default uniform layout qualifiers tracked during parsing.
157 * Currently affects uniform blocks and uniform buffer variables in
160 struct ast_type_qualifier
*default_uniform_qualifier
;
163 * Printable list of GLSL versions supported by the current context
166 * This string should probably be generated per-context instead of per
167 * invokation of the compiler. This should be changed when the method of
168 * tracking supported GLSL versions changes.
170 const char *supported_version_string
;
173 * Implementation defined limits that affect built-in variables, etc.
175 * \sa struct gl_constants (in mtypes.h)
180 unsigned MaxClipPlanes
;
181 unsigned MaxTextureUnits
;
182 unsigned MaxTextureCoords
;
183 unsigned MaxVertexAttribs
;
184 unsigned MaxVertexUniformComponents
;
185 unsigned MaxVaryingFloats
;
186 unsigned MaxVertexTextureImageUnits
;
187 unsigned MaxCombinedTextureImageUnits
;
188 unsigned MaxTextureImageUnits
;
189 unsigned MaxFragmentUniformComponents
;
191 /* ARB_draw_buffers */
192 unsigned MaxDrawBuffers
;
196 * During AST to IR conversion, pointer to current IR function
198 * Will be \c NULL whenever the AST to IR conversion is not inside a
199 * function definition.
201 class ir_function_signature
*current_function
;
204 * During AST to IR conversion, pointer to the toplevel IR
205 * instruction list being generated.
207 exec_list
*toplevel_ir
;
209 /** Have we found a return statement in this function? */
212 /** Was there an error during compilation? */
216 * Are all shader inputs / outputs invariant?
218 * This is set when the 'STDGL invariant(all)' pragma is used.
222 /** Loop or switch statement containing the current instructions. */
223 class ast_iteration_statement
*loop_nesting_ast
;
225 struct glsl_switch_state switch_state
;
227 /** List of structures defined in user code. */
228 const glsl_type
**user_structures
;
229 unsigned num_user_structures
;
234 * \name Enable bits for GLSL extensions
237 bool ARB_draw_buffers_enable
;
238 bool ARB_draw_buffers_warn
;
239 bool ARB_draw_instanced_enable
;
240 bool ARB_draw_instanced_warn
;
241 bool ARB_explicit_attrib_location_enable
;
242 bool ARB_explicit_attrib_location_warn
;
243 bool ARB_fragment_coord_conventions_enable
;
244 bool ARB_fragment_coord_conventions_warn
;
245 bool ARB_texture_rectangle_enable
;
246 bool ARB_texture_rectangle_warn
;
247 bool EXT_texture_array_enable
;
248 bool EXT_texture_array_warn
;
249 bool ARB_shader_texture_lod_enable
;
250 bool ARB_shader_texture_lod_warn
;
251 bool ARB_shader_stencil_export_enable
;
252 bool ARB_shader_stencil_export_warn
;
253 bool AMD_conservative_depth_enable
;
254 bool AMD_conservative_depth_warn
;
255 bool ARB_conservative_depth_enable
;
256 bool ARB_conservative_depth_warn
;
257 bool AMD_shader_stencil_export_enable
;
258 bool AMD_shader_stencil_export_warn
;
259 bool OES_texture_3D_enable
;
260 bool OES_texture_3D_warn
;
261 bool OES_EGL_image_external_enable
;
262 bool OES_EGL_image_external_warn
;
263 bool ARB_shader_bit_encoding_enable
;
264 bool ARB_shader_bit_encoding_warn
;
265 bool ARB_uniform_buffer_object_enable
;
266 bool ARB_uniform_buffer_object_warn
;
267 bool OES_standard_derivatives_enable
;
268 bool OES_standard_derivatives_warn
;
269 bool ARB_texture_cube_map_array_enable
;
270 bool ARB_texture_cube_map_array_warn
;
273 /** Extensions supported by the OpenGL implementation. */
274 const struct gl_extensions
*extensions
;
276 /** Shaders containing built-in functions that are used for linking. */
277 struct gl_shader
*builtins_to_link
[16];
278 unsigned num_builtins_to_link
;
281 # define YYLLOC_DEFAULT(Current, Rhs, N) \
285 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
286 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
287 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
288 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
292 (Current).first_line = (Current).last_line = \
293 YYRHSLOC(Rhs, 0).last_line; \
294 (Current).first_column = (Current).last_column = \
295 YYRHSLOC(Rhs, 0).last_column; \
297 (Current).source = 0; \
300 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
301 const char *fmt
, ...);
304 * Emit a warning to the shader log
306 * \sa _mesa_glsl_error
308 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
309 _mesa_glsl_parse_state
*state
,
310 const char *fmt
, ...);
312 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
315 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
318 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
321 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
324 * Process elements of the #extension directive
327 * If \c name and \c behavior are valid, \c true is returned. Otherwise
328 * \c false is returned.
330 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
331 const char *behavior
,
332 YYLTYPE
*behavior_locp
,
333 _mesa_glsl_parse_state
*state
);
336 * Get the textual name of the specified shader target
339 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
342 #endif /* __cplusplus */
346 * These definitions apply to C and C++
352 extern int glcpp_preprocess(void *ctx
, const char **shader
, char **info_log
,
353 const struct gl_extensions
*extensions
, int api
);
355 extern void _mesa_destroy_shader_compiler(void);
356 extern void _mesa_destroy_shader_compiler_caches(void);
363 #endif /* GLSL_PARSER_EXTRAS_H */