Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / glsl / glsl_parser_extras.h
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 <stdlib.h>
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 _mesa_glsl_parse_state {
46    _mesa_glsl_parse_state(struct gl_context *ctx, GLenum target,
47                           void *mem_ctx);
48
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)
52    {
53       void *mem = rzalloc_size(ctx, size);
54       assert(mem != NULL);
55
56       return mem;
57    }
58
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)
62    {
63       ralloc_free(mem);
64    }
65
66    void *scanner;
67    exec_list translation_unit;
68    glsl_symbol_table *symbols;
69
70    bool es_shader;
71    unsigned language_version;
72    const char *version_string;
73    enum _mesa_glsl_parser_targets target;
74
75    /**
76     * Printable list of GLSL versions supported by the current context
77     *
78     * \note
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.
82     */
83    const char *supported_version_string;
84
85    /**
86     * Implementation defined limits that affect built-in variables, etc.
87     *
88     * \sa struct gl_constants (in mtypes.h)
89     */
90    struct {
91       /* 1.10 */
92       unsigned MaxLights;
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;
103
104       /* ARB_draw_buffers */
105       unsigned MaxDrawBuffers;
106
107       /**
108        * Set of GLSL versions supported by the current context
109        *
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
114        * supported.
115        */
116       /*@{*/
117       unsigned GLSL_100ES:1;
118       unsigned GLSL_110:1;
119       unsigned GLSL_120:1;
120       unsigned GLSL_130:1;
121       /*@}*/
122    } Const;
123
124    /**
125     * During AST to IR conversion, pointer to current IR function
126     *
127     * Will be \c NULL whenever the AST to IR conversion is not inside a
128     * function definition.
129     */
130    class ir_function_signature *current_function;
131
132    /**
133     * During AST to IR conversion, pointer to the toplevel IR
134     * instruction list being generated.
135     */
136    exec_list *toplevel_ir;
137
138    /** Have we found a return statement in this function? */
139    bool found_return;
140
141    /** Was there an error during compilation? */
142    bool error;
143
144    /**
145     * Are all shader inputs / outputs invariant?
146     *
147     * This is set when the 'STDGL invariant(all)' pragma is used.
148     */
149    bool all_invariant;
150
151    /** Loop or switch statement containing the current instructions. */
152    class ir_instruction *loop_or_switch_nesting;
153    class ast_iteration_statement *loop_or_switch_nesting_ast;
154
155    /** List of structures defined in user code. */
156    const glsl_type **user_structures;
157    unsigned num_user_structures;
158
159    char *info_log;
160
161    /**
162     * \name Enable bits for GLSL extensions
163     */
164    /*@{*/
165    bool ARB_draw_buffers_enable;
166    bool ARB_draw_buffers_warn;
167    bool ARB_draw_instanced_enable;
168    bool ARB_draw_instanced_warn;
169    bool ARB_explicit_attrib_location_enable;
170    bool ARB_explicit_attrib_location_warn;
171    bool ARB_fragment_coord_conventions_enable;
172    bool ARB_fragment_coord_conventions_warn;
173    bool ARB_texture_rectangle_enable;
174    bool ARB_texture_rectangle_warn;
175    bool EXT_texture_array_enable;
176    bool EXT_texture_array_warn;
177    bool ARB_shader_texture_lod_enable;
178    bool ARB_shader_texture_lod_warn;
179    bool ARB_shader_stencil_export_enable;
180    bool ARB_shader_stencil_export_warn;
181    bool AMD_conservative_depth_enable;
182    bool AMD_conservative_depth_warn;
183    bool AMD_shader_stencil_export_enable;
184    bool AMD_shader_stencil_export_warn;
185    bool OES_texture_3D_enable;
186    bool OES_texture_3D_warn;
187    /*@}*/
188
189    /** Extensions supported by the OpenGL implementation. */
190    const struct gl_extensions *extensions;
191
192    /** Shaders containing built-in functions that are used for linking. */
193    struct gl_shader *builtins_to_link[16];
194    unsigned num_builtins_to_link;
195 };
196
197 typedef struct YYLTYPE {
198    int first_line;
199    int first_column;
200    int last_line;
201    int last_column;
202    unsigned source;
203 } YYLTYPE;
204 # define YYLTYPE_IS_DECLARED 1
205 # define YYLTYPE_IS_TRIVIAL 1
206
207 # define YYLLOC_DEFAULT(Current, Rhs, N)                        \
208 do {                                                            \
209    if (N)                                                       \
210    {                                                            \
211       (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;     \
212       (Current).first_column = YYRHSLOC(Rhs, 1).first_column;   \
213       (Current).last_line    = YYRHSLOC(Rhs, N).last_line;      \
214       (Current).last_column  = YYRHSLOC(Rhs, N).last_column;    \
215    }                                                            \
216    else                                                         \
217    {                                                            \
218       (Current).first_line   = (Current).last_line =            \
219          YYRHSLOC(Rhs, 0).last_line;                            \
220       (Current).first_column = (Current).last_column =          \
221          YYRHSLOC(Rhs, 0).last_column;                          \
222    }                                                            \
223    (Current).source = 0;                                        \
224 } while (0)
225
226 extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
227                              const char *fmt, ...);
228
229 /**
230  * Emit a warning to the shader log
231  *
232  * \sa _mesa_glsl_error
233  */
234 extern void _mesa_glsl_warning(const YYLTYPE *locp,
235                                _mesa_glsl_parse_state *state,
236                                const char *fmt, ...);
237
238 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
239                                   const char *string);
240
241 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state);
242
243 union YYSTYPE;
244 extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc, 
245                           void *scanner);
246
247 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *);
248
249 /**
250  * Process elements of the #extension directive
251  *
252  * \return
253  * If \c name and \c behavior are valid, \c true is returned.  Otherwise
254  * \c false is returned.
255  */
256 extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
257                                          const char *behavior,
258                                          YYLTYPE *behavior_locp,
259                                          _mesa_glsl_parse_state *state);
260
261 /**
262  * Get the textual name of the specified shader target
263  */
264 extern const char *
265 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target);
266
267
268 #endif /* __cplusplus */
269
270
271 /*
272  * These definitions apply to C and C++
273  */
274 #ifdef __cplusplus
275 extern "C" {
276 #endif
277
278 extern int preprocess(void *ctx, const char **shader, char **info_log,
279                       const struct gl_extensions *extensions, int api);
280
281 extern void _mesa_destroy_shader_compiler(void);
282 extern void _mesa_destroy_shader_compiler_caches(void);
283
284 #ifdef __cplusplus
285 }
286 #endif
287
288
289 #endif /* GLSL_PARSER_EXTRAS_H */