Merge remote-tracking branch 'origin/master' into vulkan
[mesa.git] / src / mesa / program / program_parse_extra.c
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 #include <string.h>
25 #include "main/mtypes.h"
26 #include "prog_instruction.h"
27 #include "program_parser.h"
28
29
30 /**
31 * Extra assembly-level parser routines
32 *
33 * \author Ian Romanick <ian.d.romanick@intel.com>
34 */
35
36 int
37 _mesa_parse_instruction_suffix(const struct asm_parser_state *state,
38 const char *suffix,
39 struct prog_instruction *inst)
40 {
41 inst->Saturate = GL_FALSE;
42
43
44 /* The only possible suffix element is the saturation selector from
45 * ARB_fragment_program.
46 */
47 if (state->mode == ARB_fragment) {
48 if (strcmp(suffix, "_SAT") == 0) {
49 inst->Saturate = GL_TRUE;
50 suffix += 4;
51 }
52 }
53
54
55 /* It is an error for all of the suffix string not to be consumed.
56 */
57 return suffix[0] == '\0';
58 }
59
60
61 int
62 _mesa_ARBvp_parse_option(struct asm_parser_state *state, const char *option)
63 {
64 if (strcmp(option, "ARB_position_invariant") == 0) {
65 state->option.PositionInvariant = 1;
66 return 1;
67 }
68
69 return 0;
70 }
71
72
73 int
74 _mesa_ARBfp_parse_option(struct asm_parser_state *state, const char *option)
75 {
76 unsigned fog_option;
77
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.
82 */
83 if (strncmp(option, "ARB_", 4) == 0) {
84 /* Advance the pointer past the "ARB_" prefix.
85 */
86 option += 4;
87
88
89 if (strncmp(option, "fog_", 4) == 0) {
90 option += 4;
91
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;
98 } else {
99 /* invalid option */
100 return 0;
101 }
102
103 if (state->option.Fog == OPTION_NONE) {
104 state->option.Fog = fog_option;
105 return 1;
106 }
107
108 /* The ARB_fragment_program specification instructs us to handle
109 * redundant options in two seemingly contradictory ways:
110 *
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."
116 *
117 * Issue 27 says:
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."
123 *
124 * We choose to allow programs to specify the same OPTION redundantly,
125 * but fail to load programs that specify contradictory options.
126 */
127 return state->option.Fog == fog_option ? 1 : 0;
128 } else if (strncmp(option, "precision_hint_", 15) == 0) {
129 option += 15;
130
131 /* The ARB_fragment_program spec, 3.11.4.5.2 says:
132 *
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.
137 */
138
139 if (strcmp(option, "nicest") == 0 && state->option.PrecisionHint != OPTION_FASTEST) {
140 state->option.PrecisionHint = OPTION_NICEST;
141 return 1;
142 } else if (strcmp(option, "fastest") == 0 && state->option.PrecisionHint != OPTION_NICEST) {
143 state->option.PrecisionHint = OPTION_FASTEST;
144 return 1;
145 }
146
147 return 0;
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.
151 */
152 state->option.DrawBuffers = 1;
153 return 1;
154 } else if (strcmp(option, "fragment_program_shadow") == 0) {
155 if (state->ctx->Extensions.ARB_fragment_program_shadow) {
156 state->option.Shadow = 1;
157 return 1;
158 }
159 } else if (strncmp(option, "fragment_coord_", 15) == 0) {
160 option += 15;
161 if (state->ctx->Extensions.ARB_fragment_coord_conventions) {
162 if (strcmp(option, "origin_upper_left") == 0) {
163 state->option.OriginUpperLeft = 1;
164 return 1;
165 }
166 else if (strcmp(option, "pixel_center_integer") == 0) {
167 state->option.PixelCenterInteger = 1;
168 return 1;
169 }
170 }
171 }
172 } else if (strncmp(option, "ATI_", 4) == 0) {
173 option += 4;
174
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.
178 */
179 state->option.DrawBuffers = 1;
180 return 1;
181 }
182 }
183
184 return 0;
185 }