2 * Copyright © 2009 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 #include "main/mtypes.h"
26 #include "prog_instruction.h"
27 #include "program_parser.h"
31 * Extra assembly-level parser routines
33 * \author Ian Romanick <ian.d.romanick@intel.com>
37 _mesa_parse_instruction_suffix(const struct asm_parser_state
*state
,
39 struct prog_instruction
*inst
)
43 inst
->Saturate
= GL_FALSE
;
44 inst
->Precision
= FLOAT32
;
47 /* The first possible suffix element is the precision specifier from
48 * NV_fragment_program_option.
50 if (state
->option
.NV_fragment
) {
53 inst
->Precision
= FLOAT16
;
57 inst
->Precision
= FLOAT32
;
61 inst
->Precision
= FIXED12
;
69 /* The next possible suffix element is the condition code modifier selection
70 * from NV_fragment_program_option.
72 if (state
->option
.NV_fragment
) {
73 if (suffix
[0] == 'C') {
80 /* The final possible suffix element is the saturation selector from
81 * ARB_fragment_program.
83 if (state
->mode
== ARB_fragment
) {
84 if (strcmp(suffix
, "_SAT") == 0) {
85 inst
->Saturate
= GL_TRUE
;
91 /* It is an error for all of the suffix string not to be consumed.
93 return suffix
[0] == '\0';
98 _mesa_parse_cc(const char *s
)
118 } else if (s
[1] == 'T') {
126 } else if (s
[1] == 'T') {
147 return ((cond
== 0) || (s
[2] != '\0')) ? 0 : cond
;
152 _mesa_ARBvp_parse_option(struct asm_parser_state
*state
, const char *option
)
154 if (strcmp(option
, "ARB_position_invariant") == 0) {
155 state
->option
.PositionInvariant
= 1;
164 _mesa_ARBfp_parse_option(struct asm_parser_state
*state
, const char *option
)
168 /* All of the options currently supported start with "ARB_". The code is
169 * currently structured with nested if-statements because eventually options
170 * that start with "NV_" will be supported. This structure will result in
171 * less churn when those options are added.
173 if (strncmp(option
, "ARB_", 4) == 0) {
174 /* Advance the pointer past the "ARB_" prefix.
179 if (strncmp(option
, "fog_", 4) == 0) {
182 if (strcmp(option
, "exp") == 0) {
183 fog_option
= OPTION_FOG_EXP
;
184 } else if (strcmp(option
, "exp2") == 0) {
185 fog_option
= OPTION_FOG_EXP2
;
186 } else if (strcmp(option
, "linear") == 0) {
187 fog_option
= OPTION_FOG_LINEAR
;
193 if (state
->option
.Fog
== OPTION_NONE
) {
194 state
->option
.Fog
= fog_option
;
198 /* The ARB_fragment_program specification instructs us to handle
199 * redundant options in two seemingly contradictory ways:
201 * Section 3.11.4.5.1 says:
202 * "Only one fog application option may be specified by any given
203 * fragment program. A fragment program that specifies more than one
204 * of the program options "ARB_fog_exp", "ARB_fog_exp2", and
205 * "ARB_fog_linear", will fail to load."
208 * "The three mandatory options are ARB_fog_exp, ARB_fog_exp2, and
209 * ARB_fog_linear. As these options are mutually exclusive by
210 * nature, specifying more than one is not useful. If more than one
211 * is specified, the last one encountered in the <optionSequence>
212 * will be the one to actually modify the execution environment."
214 * We choose to allow programs to specify the same OPTION redundantly,
215 * but fail to load programs that specify contradictory options.
217 return state
->option
.Fog
== fog_option
? 1 : 0;
218 } else if (strncmp(option
, "precision_hint_", 15) == 0) {
221 /* The ARB_fragment_program spec, 3.11.4.5.2 says:
223 * "Only one precision control option may be specified by any given
224 * fragment program. A fragment program that specifies both the
225 * "ARB_precision_hint_fastest" and "ARB_precision_hint_nicest"
226 * program options will fail to load.
229 if (strcmp(option
, "nicest") == 0 && state
->option
.PrecisionHint
!= OPTION_FASTEST
) {
230 state
->option
.PrecisionHint
= OPTION_NICEST
;
232 } else if (strcmp(option
, "fastest") == 0 && state
->option
.PrecisionHint
!= OPTION_NICEST
) {
233 state
->option
.PrecisionHint
= OPTION_FASTEST
;
238 } else if (strcmp(option
, "draw_buffers") == 0) {
239 /* Don't need to check extension availability because all Mesa-based
240 * drivers support GL_ARB_draw_buffers.
242 state
->option
.DrawBuffers
= 1;
244 } else if (strcmp(option
, "fragment_program_shadow") == 0) {
245 if (state
->ctx
->Extensions
.ARB_fragment_program_shadow
) {
246 state
->option
.Shadow
= 1;
249 } else if (strncmp(option
, "fragment_coord_", 15) == 0) {
251 if (state
->ctx
->Extensions
.ARB_fragment_coord_conventions
) {
252 if (strcmp(option
, "origin_upper_left") == 0) {
253 state
->option
.OriginUpperLeft
= 1;
256 else if (strcmp(option
, "pixel_center_integer") == 0) {
257 state
->option
.PixelCenterInteger
= 1;
262 } else if (strncmp(option
, "ATI_", 4) == 0) {
265 if (strcmp(option
, "draw_buffers") == 0) {
266 /* Don't need to check extension availability because all Mesa-based
267 * drivers support GL_ATI_draw_buffers.
269 state
->option
.DrawBuffers
= 1;
272 } else if (strncmp(option
, "NV_fragment_program", 19) == 0) {
275 /* Other NV_fragment_program strings may be supported later.
277 if (option
[0] == '\0') {
278 if (state
->ctx
->Extensions
.NV_fragment_program_option
) {
279 state
->option
.NV_fragment
= 1;