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
)
41 inst
->Saturate
= GL_FALSE
;
44 /* The only possible suffix element is the saturation selector from
45 * ARB_fragment_program.
47 if (state
->mode
== ARB_fragment
) {
48 if (strcmp(suffix
, "_SAT") == 0) {
49 inst
->Saturate
= GL_TRUE
;
55 /* It is an error for all of the suffix string not to be consumed.
57 return suffix
[0] == '\0';
62 _mesa_ARBvp_parse_option(struct asm_parser_state
*state
, const char *option
)
64 if (strcmp(option
, "ARB_position_invariant") == 0) {
65 state
->option
.PositionInvariant
= 1;
74 _mesa_ARBfp_parse_option(struct asm_parser_state
*state
, const char *option
)
78 /* All of the options currently supported start with "ARB_". The code is
79 * currently structured with nested if-statements because eventually options
80 * that start with "NV_" will be supported. This structure will result in
81 * less churn when those options are added.
83 if (strncmp(option
, "ARB_", 4) == 0) {
84 /* Advance the pointer past the "ARB_" prefix.
89 if (strncmp(option
, "fog_", 4) == 0) {
92 if (strcmp(option
, "exp") == 0) {
93 fog_option
= OPTION_FOG_EXP
;
94 } else if (strcmp(option
, "exp2") == 0) {
95 fog_option
= OPTION_FOG_EXP2
;
96 } else if (strcmp(option
, "linear") == 0) {
97 fog_option
= OPTION_FOG_LINEAR
;
103 if (state
->option
.Fog
== OPTION_NONE
) {
104 state
->option
.Fog
= fog_option
;
108 /* The ARB_fragment_program specification instructs us to handle
109 * redundant options in two seemingly contradictory ways:
111 * Section 3.11.4.5.1 says:
112 * "Only one fog application option may be specified by any given
113 * fragment program. A fragment program that specifies more than one
114 * of the program options "ARB_fog_exp", "ARB_fog_exp2", and
115 * "ARB_fog_linear", will fail to load."
118 * "The three mandatory options are ARB_fog_exp, ARB_fog_exp2, and
119 * ARB_fog_linear. As these options are mutually exclusive by
120 * nature, specifying more than one is not useful. If more than one
121 * is specified, the last one encountered in the <optionSequence>
122 * will be the one to actually modify the execution environment."
124 * We choose to allow programs to specify the same OPTION redundantly,
125 * but fail to load programs that specify contradictory options.
127 return state
->option
.Fog
== fog_option
? 1 : 0;
128 } else if (strncmp(option
, "precision_hint_", 15) == 0) {
131 /* The ARB_fragment_program spec, 3.11.4.5.2 says:
133 * "Only one precision control option may be specified by any given
134 * fragment program. A fragment program that specifies both the
135 * "ARB_precision_hint_fastest" and "ARB_precision_hint_nicest"
136 * program options will fail to load.
139 if (strcmp(option
, "nicest") == 0 && state
->option
.PrecisionHint
!= OPTION_FASTEST
) {
140 state
->option
.PrecisionHint
= OPTION_NICEST
;
142 } else if (strcmp(option
, "fastest") == 0 && state
->option
.PrecisionHint
!= OPTION_NICEST
) {
143 state
->option
.PrecisionHint
= OPTION_FASTEST
;
148 } else if (strcmp(option
, "draw_buffers") == 0) {
149 /* Don't need to check extension availability because all Mesa-based
150 * drivers support GL_ARB_draw_buffers.
152 state
->option
.DrawBuffers
= 1;
154 } else if (strcmp(option
, "fragment_program_shadow") == 0) {
155 if (state
->ctx
->Extensions
.ARB_fragment_program_shadow
) {
156 state
->option
.Shadow
= 1;
159 } else if (strncmp(option
, "fragment_coord_", 15) == 0) {
161 if (state
->ctx
->Extensions
.ARB_fragment_coord_conventions
) {
162 if (strcmp(option
, "origin_upper_left") == 0) {
163 state
->option
.OriginUpperLeft
= 1;
166 else if (strcmp(option
, "pixel_center_integer") == 0) {
167 state
->option
.PixelCenterInteger
= 1;
172 } else if (strncmp(option
, "ATI_", 4) == 0) {
175 if (strcmp(option
, "draw_buffers") == 0) {
176 /* Don't need to check extension availability because all Mesa-based
177 * drivers support GL_ATI_draw_buffers.
179 state
->option
.DrawBuffers
= 1;