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, ...
59 struct _mesa_glsl_parse_state
{
60 _mesa_glsl_parse_state(struct gl_context
*_ctx
, GLenum target
,
63 /* Callers of this ralloc-based new need not call delete. It's
64 * easier to just ralloc_free 'ctx' (or any of its ancestors). */
65 static void* operator new(size_t size
, void *ctx
)
67 void *mem
= rzalloc_size(ctx
, size
);
73 /* If the user *does* call delete, that's OK, we will just
74 * ralloc_free in that case. */
75 static void operator delete(void *mem
)
80 struct gl_context
*const ctx
;
82 exec_list translation_unit
;
83 glsl_symbol_table
*symbols
;
86 unsigned language_version
;
87 const char *version_string
;
88 enum _mesa_glsl_parser_targets target
;
91 * Printable list of GLSL versions supported by the current context
94 * This string should probably be generated per-context instead of per
95 * invokation of the compiler. This should be changed when the method of
96 * tracking supported GLSL versions changes.
98 const char *supported_version_string
;
101 * Implementation defined limits that affect built-in variables, etc.
103 * \sa struct gl_constants (in mtypes.h)
108 unsigned MaxClipPlanes
;
109 unsigned MaxTextureUnits
;
110 unsigned MaxTextureCoords
;
111 unsigned MaxVertexAttribs
;
112 unsigned MaxVertexUniformComponents
;
113 unsigned MaxVaryingFloats
;
114 unsigned MaxVertexTextureImageUnits
;
115 unsigned MaxCombinedTextureImageUnits
;
116 unsigned MaxTextureImageUnits
;
117 unsigned MaxFragmentUniformComponents
;
119 /* ARB_draw_buffers */
120 unsigned MaxDrawBuffers
;
123 * Set of GLSL versions supported by the current context
125 * Knowing that version X is supported doesn't mean that versions before
126 * X are also supported. Version 1.00 is only supported in an ES2
127 * context or when GL_ARB_ES2_compatibility is supported. In an OpenGL
128 * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
132 unsigned GLSL_100ES
:1;
141 * During AST to IR conversion, pointer to current IR function
143 * Will be \c NULL whenever the AST to IR conversion is not inside a
144 * function definition.
146 class ir_function_signature
*current_function
;
149 * During AST to IR conversion, pointer to the toplevel IR
150 * instruction list being generated.
152 exec_list
*toplevel_ir
;
154 /** Have we found a return statement in this function? */
157 /** Was there an error during compilation? */
161 * Are all shader inputs / outputs invariant?
163 * This is set when the 'STDGL invariant(all)' pragma is used.
167 /** Loop or switch statement containing the current instructions. */
168 class ast_iteration_statement
*loop_nesting_ast
;
170 struct glsl_switch_state switch_state
;
172 /** List of structures defined in user code. */
173 const glsl_type
**user_structures
;
174 unsigned num_user_structures
;
179 * \name Enable bits for GLSL extensions
182 bool ARB_draw_buffers_enable
;
183 bool ARB_draw_buffers_warn
;
184 bool ARB_draw_instanced_enable
;
185 bool ARB_draw_instanced_warn
;
186 bool ARB_explicit_attrib_location_enable
;
187 bool ARB_explicit_attrib_location_warn
;
188 bool ARB_fragment_coord_conventions_enable
;
189 bool ARB_fragment_coord_conventions_warn
;
190 bool ARB_texture_rectangle_enable
;
191 bool ARB_texture_rectangle_warn
;
192 bool EXT_texture_array_enable
;
193 bool EXT_texture_array_warn
;
194 bool ARB_shader_texture_lod_enable
;
195 bool ARB_shader_texture_lod_warn
;
196 bool ARB_shader_stencil_export_enable
;
197 bool ARB_shader_stencil_export_warn
;
198 bool AMD_conservative_depth_enable
;
199 bool AMD_conservative_depth_warn
;
200 bool ARB_conservative_depth_enable
;
201 bool ARB_conservative_depth_warn
;
202 bool AMD_shader_stencil_export_enable
;
203 bool AMD_shader_stencil_export_warn
;
204 bool OES_texture_3D_enable
;
205 bool OES_texture_3D_warn
;
206 bool OES_EGL_image_external_enable
;
207 bool OES_EGL_image_external_warn
;
208 bool ARB_shader_bit_encoding_enable
;
209 bool ARB_shader_bit_encoding_warn
;
212 /** Extensions supported by the OpenGL implementation. */
213 const struct gl_extensions
*extensions
;
215 /** Shaders containing built-in functions that are used for linking. */
216 struct gl_shader
*builtins_to_link
[16];
217 unsigned num_builtins_to_link
;
220 typedef struct YYLTYPE
{
227 # define YYLTYPE_IS_DECLARED 1
228 # define YYLTYPE_IS_TRIVIAL 1
230 # define YYLLOC_DEFAULT(Current, Rhs, N) \
234 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
235 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
236 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
237 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
241 (Current).first_line = (Current).last_line = \
242 YYRHSLOC(Rhs, 0).last_line; \
243 (Current).first_column = (Current).last_column = \
244 YYRHSLOC(Rhs, 0).last_column; \
246 (Current).source = 0; \
249 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
250 const char *fmt
, ...);
253 * Emit a warning to the shader log
255 * \sa _mesa_glsl_error
257 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
258 _mesa_glsl_parse_state
*state
,
259 const char *fmt
, ...);
261 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
264 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
267 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
270 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
273 * Process elements of the #extension directive
276 * If \c name and \c behavior are valid, \c true is returned. Otherwise
277 * \c false is returned.
279 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
280 const char *behavior
,
281 YYLTYPE
*behavior_locp
,
282 _mesa_glsl_parse_state
*state
);
285 * Get the textual name of the specified shader target
288 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
291 #endif /* __cplusplus */
295 * These definitions apply to C and C++
301 extern int preprocess(void *ctx
, const char **shader
, char **info_log
,
302 const struct gl_extensions
*extensions
, int api
);
304 extern void _mesa_destroy_shader_compiler(void);
305 extern void _mesa_destroy_shader_compiler_caches(void);
312 #endif /* GLSL_PARSER_EXTRAS_H */