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
;
55 bool is_switch_innermost
; // if switch stmt is closest to break, ...
58 struct _mesa_glsl_parse_state
{
59 _mesa_glsl_parse_state(struct gl_context
*ctx
, GLenum target
,
62 /* Callers of this ralloc-based new need not call delete. It's
63 * easier to just ralloc_free 'ctx' (or any of its ancestors). */
64 static void* operator new(size_t size
, void *ctx
)
66 void *mem
= rzalloc_size(ctx
, size
);
72 /* If the user *does* call delete, that's OK, we will just
73 * ralloc_free in that case. */
74 static void operator delete(void *mem
)
80 exec_list translation_unit
;
81 glsl_symbol_table
*symbols
;
84 unsigned language_version
;
85 const char *version_string
;
86 enum _mesa_glsl_parser_targets target
;
89 * Printable list of GLSL versions supported by the current context
92 * This string should probably be generated per-context instead of per
93 * invokation of the compiler. This should be changed when the method of
94 * tracking supported GLSL versions changes.
96 const char *supported_version_string
;
99 * Implementation defined limits that affect built-in variables, etc.
101 * \sa struct gl_constants (in mtypes.h)
106 unsigned MaxClipPlanes
;
107 unsigned MaxTextureUnits
;
108 unsigned MaxTextureCoords
;
109 unsigned MaxVertexAttribs
;
110 unsigned MaxVertexUniformComponents
;
111 unsigned MaxVaryingFloats
;
112 unsigned MaxVertexTextureImageUnits
;
113 unsigned MaxCombinedTextureImageUnits
;
114 unsigned MaxTextureImageUnits
;
115 unsigned MaxFragmentUniformComponents
;
117 /* ARB_draw_buffers */
118 unsigned MaxDrawBuffers
;
121 * Set of GLSL versions supported by the current context
123 * Knowing that version X is supported doesn't mean that versions before
124 * X are also supported. Version 1.00 is only supported in an ES2
125 * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL
126 * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
130 unsigned GLSL_100ES
:1;
138 * During AST to IR conversion, pointer to current IR function
140 * Will be \c NULL whenever the AST to IR conversion is not inside a
141 * function definition.
143 class ir_function_signature
*current_function
;
146 * During AST to IR conversion, pointer to the toplevel IR
147 * instruction list being generated.
149 exec_list
*toplevel_ir
;
151 /** Have we found a return statement in this function? */
154 /** Was there an error during compilation? */
158 * Are all shader inputs / outputs invariant?
160 * This is set when the 'STDGL invariant(all)' pragma is used.
164 /** Loop or switch statement containing the current instructions. */
165 class ast_iteration_statement
*loop_nesting_ast
;
167 struct glsl_switch_state switch_state
;
169 /** List of structures defined in user code. */
170 const glsl_type
**user_structures
;
171 unsigned num_user_structures
;
176 * \name Enable bits for GLSL extensions
179 bool ARB_draw_buffers_enable
;
180 bool ARB_draw_buffers_warn
;
181 bool ARB_draw_instanced_enable
;
182 bool ARB_draw_instanced_warn
;
183 bool ARB_explicit_attrib_location_enable
;
184 bool ARB_explicit_attrib_location_warn
;
185 bool ARB_fragment_coord_conventions_enable
;
186 bool ARB_fragment_coord_conventions_warn
;
187 bool ARB_texture_rectangle_enable
;
188 bool ARB_texture_rectangle_warn
;
189 bool EXT_texture_array_enable
;
190 bool EXT_texture_array_warn
;
191 bool ARB_shader_texture_lod_enable
;
192 bool ARB_shader_texture_lod_warn
;
193 bool ARB_shader_stencil_export_enable
;
194 bool ARB_shader_stencil_export_warn
;
195 bool AMD_conservative_depth_enable
;
196 bool AMD_conservative_depth_warn
;
197 bool ARB_conservative_depth_enable
;
198 bool ARB_conservative_depth_warn
;
199 bool AMD_shader_stencil_export_enable
;
200 bool AMD_shader_stencil_export_warn
;
201 bool OES_texture_3D_enable
;
202 bool OES_texture_3D_warn
;
203 bool OES_EGL_image_external_enable
;
204 bool OES_EGL_image_external_warn
;
207 /** Extensions supported by the OpenGL implementation. */
208 const struct gl_extensions
*extensions
;
210 /** Shaders containing built-in functions that are used for linking. */
211 struct gl_shader
*builtins_to_link
[16];
212 unsigned num_builtins_to_link
;
215 typedef struct YYLTYPE
{
222 # define YYLTYPE_IS_DECLARED 1
223 # define YYLTYPE_IS_TRIVIAL 1
225 # define YYLLOC_DEFAULT(Current, Rhs, N) \
229 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
230 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
231 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
232 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
236 (Current).first_line = (Current).last_line = \
237 YYRHSLOC(Rhs, 0).last_line; \
238 (Current).first_column = (Current).last_column = \
239 YYRHSLOC(Rhs, 0).last_column; \
241 (Current).source = 0; \
244 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
245 const char *fmt
, ...);
248 * Emit a warning to the shader log
250 * \sa _mesa_glsl_error
252 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
253 _mesa_glsl_parse_state
*state
,
254 const char *fmt
, ...);
256 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
259 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
262 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
265 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
268 * Process elements of the #extension directive
271 * If \c name and \c behavior are valid, \c true is returned. Otherwise
272 * \c false is returned.
274 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
275 const char *behavior
,
276 YYLTYPE
*behavior_locp
,
277 _mesa_glsl_parse_state
*state
);
280 * Get the textual name of the specified shader target
283 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
286 #endif /* __cplusplus */
290 * These definitions apply to C and C++
296 extern int preprocess(void *ctx
, const char **shader
, char **info_log
,
297 const struct gl_extensions
*extensions
, int api
);
299 extern void _mesa_destroy_shader_compiler(void);
300 extern void _mesa_destroy_shader_compiler_caches(void);
307 #endif /* GLSL_PARSER_EXTRAS_H */