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 _mesa_glsl_parse_state
{
46 _mesa_glsl_parse_state(struct gl_context
*ctx
, GLenum target
,
49 /* Callers of this ralloc-based new need not call delete. It's
50 * easier to just ralloc_free 'ctx' (or any of its ancestors). */
51 static void* operator new(size_t size
, void *ctx
)
53 void *mem
= rzalloc_size(ctx
, size
);
59 /* If the user *does* call delete, that's OK, we will just
60 * ralloc_free in that case. */
61 static void operator delete(void *mem
)
67 exec_list translation_unit
;
68 glsl_symbol_table
*symbols
;
71 unsigned language_version
;
72 const char *version_string
;
73 enum _mesa_glsl_parser_targets target
;
76 * Printable list of GLSL versions supported by the current context
79 * This string should probably be generated per-context instead of per
80 * invokation of the compiler. This should be changed when the method of
81 * tracking supported GLSL versions changes.
83 const char *supported_version_string
;
86 * Implementation defined limits that affect built-in variables, etc.
88 * \sa struct gl_constants (in mtypes.h)
93 unsigned MaxClipPlanes
;
94 unsigned MaxTextureUnits
;
95 unsigned MaxTextureCoords
;
96 unsigned MaxVertexAttribs
;
97 unsigned MaxVertexUniformComponents
;
98 unsigned MaxVaryingFloats
;
99 unsigned MaxVertexTextureImageUnits
;
100 unsigned MaxCombinedTextureImageUnits
;
101 unsigned MaxTextureImageUnits
;
102 unsigned MaxFragmentUniformComponents
;
104 /* ARB_draw_buffers */
105 unsigned MaxDrawBuffers
;
108 * Set of GLSL versions supported by the current context
110 * Knowing that version X is supported doesn't mean that versions before
111 * X are also supported. Version 1.00 is only supported in an ES2
112 * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL
113 * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
117 unsigned GLSL_100ES
:1;
125 * During AST to IR conversion, pointer to current IR function
127 * Will be \c NULL whenever the AST to IR conversion is not inside a
128 * function definition.
130 class ir_function_signature
*current_function
;
133 * During AST to IR conversion, pointer to the toplevel IR
134 * instruction list being generated.
136 exec_list
*toplevel_ir
;
138 /** Have we found a return statement in this function? */
141 /** Was there an error during compilation? */
145 * Are all shader inputs / outputs invariant?
147 * This is set when the 'STDGL invariant(all)' pragma is used.
151 /** Loop or switch statement containing the current instructions. */
152 class ast_iteration_statement
*loop_nesting_ast
;
153 class ast_switch_statement
*switch_nesting_ast
;
154 bool is_switch_innermost
; // if switch stmt is closest to break, ...
156 /** Temporary variables needed for switch statement. */
157 ir_variable
*test_var
;
158 ir_variable
*is_fallthru_var
;
159 ir_variable
*is_break_var
;
161 /** List of structures defined in user code. */
162 const glsl_type
**user_structures
;
163 unsigned num_user_structures
;
168 * \name Enable bits for GLSL extensions
171 bool ARB_draw_buffers_enable
;
172 bool ARB_draw_buffers_warn
;
173 bool ARB_draw_instanced_enable
;
174 bool ARB_draw_instanced_warn
;
175 bool ARB_explicit_attrib_location_enable
;
176 bool ARB_explicit_attrib_location_warn
;
177 bool ARB_fragment_coord_conventions_enable
;
178 bool ARB_fragment_coord_conventions_warn
;
179 bool ARB_texture_rectangle_enable
;
180 bool ARB_texture_rectangle_warn
;
181 bool EXT_texture_array_enable
;
182 bool EXT_texture_array_warn
;
183 bool ARB_shader_texture_lod_enable
;
184 bool ARB_shader_texture_lod_warn
;
185 bool ARB_shader_stencil_export_enable
;
186 bool ARB_shader_stencil_export_warn
;
187 bool AMD_conservative_depth_enable
;
188 bool AMD_conservative_depth_warn
;
189 bool ARB_conservative_depth_enable
;
190 bool ARB_conservative_depth_warn
;
191 bool AMD_shader_stencil_export_enable
;
192 bool AMD_shader_stencil_export_warn
;
193 bool OES_texture_3D_enable
;
194 bool OES_texture_3D_warn
;
195 bool OES_EGL_image_external_enable
;
196 bool OES_EGL_image_external_warn
;
199 /** Extensions supported by the OpenGL implementation. */
200 const struct gl_extensions
*extensions
;
202 /** Shaders containing built-in functions that are used for linking. */
203 struct gl_shader
*builtins_to_link
[16];
204 unsigned num_builtins_to_link
;
207 typedef struct YYLTYPE
{
214 # define YYLTYPE_IS_DECLARED 1
215 # define YYLTYPE_IS_TRIVIAL 1
217 # define YYLLOC_DEFAULT(Current, Rhs, N) \
221 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
222 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
223 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
224 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
228 (Current).first_line = (Current).last_line = \
229 YYRHSLOC(Rhs, 0).last_line; \
230 (Current).first_column = (Current).last_column = \
231 YYRHSLOC(Rhs, 0).last_column; \
233 (Current).source = 0; \
236 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
237 const char *fmt
, ...);
240 * Emit a warning to the shader log
242 * \sa _mesa_glsl_error
244 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
245 _mesa_glsl_parse_state
*state
,
246 const char *fmt
, ...);
248 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
251 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
254 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
257 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
260 * Process elements of the #extension directive
263 * If \c name and \c behavior are valid, \c true is returned. Otherwise
264 * \c false is returned.
266 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
267 const char *behavior
,
268 YYLTYPE
*behavior_locp
,
269 _mesa_glsl_parse_state
*state
);
272 * Get the textual name of the specified shader target
275 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
278 #endif /* __cplusplus */
282 * These definitions apply to C and C++
288 extern int preprocess(void *ctx
, const char **shader
, char **info_log
,
289 const struct gl_extensions
*extensions
, int api
);
291 extern void _mesa_destroy_shader_compiler(void);
292 extern void _mesa_destroy_shader_compiler_caches(void);
299 #endif /* GLSL_PARSER_EXTRAS_H */