summaryrefslogtreecommitdiff
path: root/src/mesa/program/program_parser.h
blob: be952d4b9c88b7b3e5973e15ee9b6e25081f3e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * Copyright © 2009 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
#pragma once

#include "main/config.h"

#ifndef MTYPES_H
struct __GLcontextRec;
typedef struct __GLcontextRec GLcontext;
#endif

enum asm_type {
   at_none,
   at_address,
   at_attrib,
   at_param,
   at_temp,
   at_output
};

struct asm_symbol {
   struct asm_symbol *next;    /**< List linkage for freeing. */
   const char *name;
   enum asm_type type;
   unsigned attrib_binding;
   unsigned output_binding;   /**< Output / result register number. */

   /**
    * One of PROGRAM_STATE_VAR, PROGRAM_LOCAL_PARAM, or PROGRAM_ENV_PARAM.
    */
   unsigned param_binding_type;

   /** 
    * Offset into the program_parameter_list where the tokens representing our
    * bound state (or constants) start.
    */
   unsigned param_binding_begin;

   /**
    * Constants put into the parameter list may be swizzled.  This
    * field contain's the symbol's swizzle. (SWIZZLE_X/Y/Z/W)
    */
   unsigned param_binding_swizzle;

   /* This is how many entries in the program_parameter_list we take up
    * with our state tokens or constants. Note that this is _not_ the same as
    * the number of param registers we eventually use.
    */
   unsigned param_binding_length;

   /**
    * Index of the temp register assigned to this variable.
    */
   unsigned temp_binding;

   /**
    * Flag whether or not a PARAM is an array
    */
   unsigned param_is_array:1;


   /**
    * Flag whether or not a PARAM array is accessed indirectly
    */
   unsigned param_accessed_indirectly:1;


   /**
    * \brief Is first pass of parameter layout done with this variable?
    *
    * The parameter layout routine operates in two passes.  This flag tracks
    * whether or not the first pass has handled this variable.
    *
    * \sa _mesa_layout_parameters
    */
   unsigned pass1_done:1;
};


struct asm_vector {
   unsigned count;
   float    data[4];
};


struct asm_swizzle_mask {
   unsigned swizzle:12;
   unsigned mask:4;
};


struct asm_src_register {
   struct prog_src_register Base;

   /**
    * Symbol associated with indirect access to parameter arrays.
    *
    * If \c Base::RelAddr is 1, this will point to the symbol for the parameter
    * that is being dereferenced.  Further, \c Base::Index will be the offset
    * from the address register being used.
    */
   struct asm_symbol *Symbol;
};


struct asm_instruction {
   struct prog_instruction Base;
   struct asm_instruction *next;
   struct asm_src_register SrcReg[3];
};


struct asm_parser_state {
   GLcontext *ctx;
   struct gl_program *prog;

   /**
    * Per-program target limits
    */
   struct gl_program_constants *limits;

   struct _mesa_symbol_table *st;

   /**
    * Linked list of symbols
    *
    * This list is \b only used when cleaning up compiler state and freeing
    * memory.
    */
   struct asm_symbol *sym;

   /**
    * State for the lexer.
    */
   void *scanner;

   /**
    * Linked list of instructions generated during parsing.
    */
   /*@{*/
   struct asm_instruction *inst_head;
   struct asm_instruction *inst_tail;
   /*@}*/


   /**
    * Selected limits copied from gl_constants
    *
    * These are limits from the GL context, but various bits in the program
    * must be validated against these values.
    */
   /*@{*/
   unsigned MaxTextureCoordUnits;
   unsigned MaxTextureImageUnits;
   unsigned MaxTextureUnits;
   unsigned MaxClipPlanes;
   unsigned MaxLights;
   unsigned MaxProgramMatrices;
   /*@}*/

   /**
    * Value to use in state vector accessors for environment and local
    * parameters
    */
   unsigned state_param_enum;


   /**
    * Input attributes bound to specific names
    *
    * This is only needed so that errors can be properly produced when
    * multiple ATTRIB statements bind illegal combinations of vertex
    * attributes.
    */
   unsigned InputsBound;

   enum {
      invalid_mode = 0,
      ARB_vertex,
      ARB_fragment
   } mode;

   struct {
      unsigned PositionInvariant:1;
      unsigned Fog:2;
      unsigned PrecisionHint:2;
      unsigned DrawBuffers:1;
      unsigned Shadow:1;
      unsigned TexRect:1;
      unsigned TexArray:1;
      unsigned NV_fragment:1;
      unsigned OriginUpperLeft:1;
      unsigned PixelCenterInteger:1;
   } option;

   struct {
      unsigned UsesKill:1;
   } fragment;
};

#define OPTION_NONE        0
#define OPTION_FOG_EXP     1
#define OPTION_FOG_EXP2    2
#define OPTION_FOG_LINEAR  3
#define OPTION_NICEST      1
#define OPTION_FASTEST     2

typedef struct YYLTYPE {
   int first_line;
   int first_column;
   int last_line;
   int last_column;
   int position;
} YYLTYPE;

#define YYLTYPE_IS_DECLARED 1
#define YYLTYPE_IS_TRIVIAL 1


extern GLboolean _mesa_parse_arb_program(GLcontext *ctx, GLenum target,
    const GLubyte *str, GLsizei len, struct asm_parser_state *state);



/* From program_lexer.l. */
extern void _mesa_program_lexer_dtor(void *scanner);

extern void _mesa_program_lexer_ctor(void **scanner,
    struct asm_parser_state *state, const char *string, size_t len);


/**
 *\name From program_parse_extra.c
 */
/*@{*/

/**
 * Parses and processes an option string to an ARB vertex program
 *
 * \return
 * Non-zero on success, zero on failure.
 */
extern int _mesa_ARBvp_parse_option(struct asm_parser_state *state,
    const char *option);

/**
 * Parses and processes an option string to an ARB fragment program
 *
 * \return
 * Non-zero on success, zero on failure.
 */
extern int _mesa_ARBfp_parse_option(struct asm_parser_state *state,
    const char *option);

/**
 * Parses and processes instruction suffixes
 *
 * Instruction suffixes, such as \c _SAT, are processed.  The relevant bits
 * are set in \c inst.  If suffixes are encountered that are either not known
 * or not supported by the modes and options set in \c state, zero will be
 * returned.
 *
 * \return
 * Non-zero on success, zero on failure.
 */
extern int _mesa_parse_instruction_suffix(const struct asm_parser_state *state,
    const char *suffix, struct prog_instruction *inst);

/**
 * Parses a condition code name
 *
 * The condition code names (e.g., \c LT, \c GT, \c NE) were added to assembly
 * shaders with the \c GL_NV_fragment_program_option extension.  This function
 * converts a string representation into one of the \c COND_ macros.
 *
 * \return
 * One of the \c COND_ macros defined in prog_instruction.h on success or zero
 * on failure.
 */
extern int _mesa_parse_cc(const char *s);

/*@}*/