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