• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2009 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 #ifndef PROGRAM_PARSER_H
25 #define PROGRAM_PARSER_H
26 
27 #include "main/config.h"
28 #include "program/prog_parameter.h"
29 
30 struct gl_context;
31 
32 enum asm_type {
33    at_none,
34    at_address,
35    at_attrib,
36    at_param,
37    at_temp,
38    at_output
39 };
40 
41 struct asm_symbol {
42    struct asm_symbol *next;    /**< List linkage for freeing. */
43    const char *name;
44    enum asm_type type;
45    unsigned attrib_binding;
46    unsigned output_binding;   /**< Output / result register number. */
47 
48    /**
49     * One of PROGRAM_STATE_VAR or PROGRAM_CONSTANT.
50     */
51    unsigned param_binding_type;
52 
53    /**
54     * Offset into the program_parameter_list where the tokens representing our
55     * bound state (or constants) start.
56     */
57    unsigned param_binding_begin;
58 
59    /**
60     * Constants put into the parameter list may be swizzled.  This
61     * field contain's the symbol's swizzle. (SWIZZLE_X/Y/Z/W)
62     */
63    unsigned param_binding_swizzle;
64 
65    /* This is how many entries in the program_parameter_list we take up
66     * with our state tokens or constants. Note that this is _not_ the same as
67     * the number of param registers we eventually use.
68     */
69    unsigned param_binding_length;
70 
71    /**
72     * Index of the temp register assigned to this variable.
73     */
74    unsigned temp_binding;
75 
76    /**
77     * Flag whether or not a PARAM is an array
78     */
79    unsigned param_is_array:1;
80 
81 
82    /**
83     * Flag whether or not a PARAM array is accessed indirectly
84     */
85    unsigned param_accessed_indirectly:1;
86 
87 
88    /**
89     * \brief Is first pass of parameter layout done with this variable?
90     *
91     * The parameter layout routine operates in two passes.  This flag tracks
92     * whether or not the first pass has handled this variable.
93     *
94     * \sa _mesa_layout_parameters
95     */
96    unsigned pass1_done:1;
97 };
98 
99 
100 struct asm_vector {
101    unsigned count;
102    gl_constant_value data[4];
103 };
104 
105 
106 struct asm_swizzle_mask {
107    unsigned swizzle:12;
108    unsigned mask:4;
109 };
110 
111 
112 struct asm_src_register {
113    struct prog_src_register Base;
114 
115    /**
116     * Symbol associated with indirect access to parameter arrays.
117     *
118     * If \c Base::RelAddr is 1, this will point to the symbol for the parameter
119     * that is being dereferenced.  Further, \c Base::Index will be the offset
120     * from the address register being used.
121     */
122    struct asm_symbol *Symbol;
123 };
124 
125 
126 struct asm_instruction {
127    struct prog_instruction Base;
128    struct asm_instruction *next;
129    struct asm_src_register SrcReg[3];
130 };
131 
132 
133 struct asm_parser_state {
134    struct gl_context *ctx;
135    struct gl_program *prog;
136 
137    /** Memory context to attach instructions to. */
138    void *mem_ctx;
139 
140    /**
141     * Per-program target limits
142     */
143    struct gl_program_constants *limits;
144 
145    struct _mesa_symbol_table *st;
146 
147    /**
148     * Linked list of symbols
149     *
150     * This list is \b only used when cleaning up compiler state and freeing
151     * memory.
152     */
153    struct asm_symbol *sym;
154 
155    /**
156     * State for the lexer.
157     */
158    void *scanner;
159 
160    /**
161     * Linked list of instructions generated during parsing.
162     */
163    /*@{*/
164    struct asm_instruction *inst_head;
165    struct asm_instruction *inst_tail;
166    /*@}*/
167 
168 
169    /**
170     * Selected limits copied from gl_constants
171     *
172     * These are limits from the GL context, but various bits in the program
173     * must be validated against these values.
174     */
175    /*@{*/
176    unsigned MaxTextureCoordUnits;
177    unsigned MaxTextureImageUnits;
178    unsigned MaxTextureUnits;
179    unsigned MaxClipPlanes;
180    unsigned MaxLights;
181    unsigned MaxProgramMatrices;
182    unsigned MaxDrawBuffers;
183    /*@}*/
184 
185    /**
186     * Value to use in state vector accessors for environment and local
187     * parameters
188     */
189    unsigned state_param_enum_env;
190    unsigned state_param_enum_local;
191 
192 
193    /**
194     * Input attributes bound to specific names
195     *
196     * This is only needed so that errors can be properly produced when
197     * multiple ATTRIB statements bind illegal combinations of vertex
198     * attributes.
199     */
200    GLbitfield64 InputsBound;
201 
202    enum {
203       invalid_mode = 0,
204       ARB_vertex,
205       ARB_fragment
206    } mode;
207 
208    struct {
209       unsigned PositionInvariant:1;
210       unsigned Fog:2;
211       unsigned PrecisionHint:2;
212       unsigned DrawBuffers:1;
213       unsigned Shadow:1;
214       unsigned TexRect:1;
215       unsigned TexArray:1;
216       unsigned OriginUpperLeft:1;
217       unsigned PixelCenterInteger:1;
218    } option;
219 
220    struct {
221       unsigned UsesKill:1;
222    } fragment;
223 };
224 
225 #define OPTION_NONE        0
226 #define OPTION_FOG_EXP     1
227 #define OPTION_FOG_EXP2    2
228 #define OPTION_FOG_LINEAR  3
229 #define OPTION_NICEST      1
230 #define OPTION_FASTEST     2
231 
232 typedef struct YYLTYPE {
233    int first_line;
234    int first_column;
235    int last_line;
236    int last_column;
237    int position;
238 } YYLTYPE;
239 
240 #define YYLTYPE_IS_DECLARED 1
241 #define YYLTYPE_IS_TRIVIAL 1
242 
243 
244 extern GLboolean _mesa_parse_arb_program(struct gl_context *ctx, GLenum target,
245     const GLubyte *str, GLsizei len, struct asm_parser_state *state);
246 
247 
248 
249 /* From program_lexer.l. */
250 extern void _mesa_program_lexer_dtor(void *scanner);
251 
252 extern void _mesa_program_lexer_ctor(void **scanner,
253     struct asm_parser_state *state, const char *string, size_t len);
254 
255 
256 /**
257  *\name From program_parse_extra.c
258  */
259 /*@{*/
260 
261 /**
262  * Parses and processes an option string to an ARB vertex program
263  *
264  * \return
265  * Non-zero on success, zero on failure.
266  */
267 extern int _mesa_ARBvp_parse_option(struct asm_parser_state *state,
268     const char *option);
269 
270 /**
271  * Parses and processes an option string to an ARB fragment program
272  *
273  * \return
274  * Non-zero on success, zero on failure.
275  */
276 extern int _mesa_ARBfp_parse_option(struct asm_parser_state *state,
277     const char *option);
278 
279 /**
280  * Parses and processes instruction suffixes
281  *
282  * Instruction suffixes, such as \c _SAT, are processed.  The relevant bits
283  * are set in \c inst.  If suffixes are encountered that are either not known
284  * or not supported by the modes and options set in \c state, zero will be
285  * returned.
286  *
287  * \return
288  * Non-zero on success, zero on failure.
289  */
290 extern int _mesa_parse_instruction_suffix(const struct asm_parser_state *state,
291     const char *suffix, struct prog_instruction *inst);
292 
293 /*@}*/
294 
295 #endif /* PROGRAM_PARSER_H */
296