Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian | b7978af | 2007-01-09 19:17:17 -0700 | [diff] [blame] | 3 | * Version: 6.5.3 |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 4 | * |
Brian | b7978af | 2007-01-09 19:17:17 -0700 | [diff] [blame] | 5 | * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #define DEBUG_PARSING 0 |
| 26 | |
| 27 | /** |
| 28 | * \file arbprogparse.c |
| 29 | * ARB_*_program parser core |
| 30 | * \author Karl Rasche |
| 31 | */ |
| 32 | |
Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 33 | #include "main/glheader.h" |
| 34 | #include "main/imports.h" |
| 35 | #include "shader/grammar/grammar_mesa.h" |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 36 | #include "arbprogparse.h" |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 37 | #include "program.h" |
Brian | c0551f0 | 2006-12-14 15:02:37 -0700 | [diff] [blame] | 38 | #include "prog_parameter.h" |
| 39 | #include "prog_statevars.h" |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 40 | #include "context.h" |
Brian Paul | 6211a14 | 2006-08-24 23:37:13 +0000 | [diff] [blame] | 41 | #include "macros.h" |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 42 | #include "mtypes.h" |
Brian | c0551f0 | 2006-12-14 15:02:37 -0700 | [diff] [blame] | 43 | #include "prog_instruction.h" |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 44 | |
| 45 | |
Brian Paul | 6211a14 | 2006-08-24 23:37:13 +0000 | [diff] [blame] | 46 | /* For ARB programs, use the NV instruction limits */ |
| 47 | #define MAX_INSTRUCTIONS MAX2(MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS, \ |
| 48 | MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS) |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | /** |
| 52 | * This is basically a union of the vertex_program and fragment_program |
| 53 | * structs that we can use to parse the program into |
| 54 | * |
| 55 | * XXX we can probably get rid of this entirely someday. |
| 56 | */ |
| 57 | struct arb_program |
| 58 | { |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 59 | struct gl_program Base; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 60 | |
| 61 | GLuint Position; /* Just used for error reporting while parsing */ |
| 62 | GLuint MajorVersion; |
| 63 | GLuint MinorVersion; |
| 64 | |
| 65 | /* ARB_vertex_progmra options */ |
| 66 | GLboolean HintPositionInvariant; |
| 67 | |
| 68 | /* ARB_fragment_progmra options */ |
| 69 | GLenum PrecisionOption; /* GL_DONT_CARE, GL_NICEST or GL_FASTEST */ |
| 70 | GLenum FogOption; /* GL_NONE, GL_LINEAR, GL_EXP or GL_EXP2 */ |
| 71 | |
| 72 | /* ARB_fragment_program specifics */ |
| 73 | GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 74 | GLbitfield ShadowSamplers; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 75 | GLuint NumAluInstructions; |
| 76 | GLuint NumTexInstructions; |
| 77 | GLuint NumTexIndirections; |
| 78 | |
| 79 | GLboolean UsesKill; |
| 80 | }; |
| 81 | |
Ian Romanick | 9bdfee3 | 2005-07-18 12:31:24 +0000 | [diff] [blame] | 82 | |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 83 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 84 | /* TODO: |
| 85 | * Fragment Program Stuff: |
| 86 | * ----------------------------------------------------- |
| 87 | * |
| 88 | * - things from Michal's email |
| 89 | * + overflow on atoi |
| 90 | * + not-overflowing floats (don't use parse_integer..) |
| 91 | * + can remove range checking in arbparse.c |
| 92 | * |
| 93 | * - check all limits of number of various variables |
| 94 | * + parameters |
| 95 | * |
| 96 | * - test! test! test! |
| 97 | * |
| 98 | * Vertex Program Stuff: |
| 99 | * ----------------------------------------------------- |
| 100 | * - Optimize param array usage and count limits correctly, see spec, |
| 101 | * section 2.14.3.7 |
| 102 | * + Record if an array is reference absolutly or relatively (or both) |
| 103 | * + For absolute arrays, store a bitmap of accesses |
| 104 | * + For single parameters, store an access flag |
| 105 | * + After parsing, make a parameter cleanup and merging pass, where |
| 106 | * relative arrays are layed out first, followed by abs arrays, and |
| 107 | * finally single state. |
| 108 | * + Remap offsets for param src and dst registers |
| 109 | * + Now we can properly count parameter usage |
| 110 | * |
| 111 | * - Multiple state binding errors in param arrays (see spec, just before |
| 112 | * section 2.14.3.3) |
| 113 | * - grep for XXX |
| 114 | * |
| 115 | * Mesa Stuff |
| 116 | * ----------------------------------------------------- |
| 117 | * - User clipping planes vs. PositionInvariant |
| 118 | * - Is it sufficient to just multiply by the mvp to transform in the |
| 119 | * PositionInvariant case? Or do we need something more involved? |
| 120 | * |
| 121 | * - vp_src swizzle is GLubyte, fp_src swizzle is GLuint |
| 122 | * - fetch state listed in program_parameters list |
| 123 | * + WTF should this go??? |
| 124 | * + currently in nvvertexec.c and s_nvfragprog.c |
| 125 | * |
| 126 | * - allow for multiple address registers (and fetch address regs properly) |
| 127 | * |
| 128 | * Cosmetic Stuff |
| 129 | * ----------------------------------------------------- |
| 130 | * - remove any leftover unused grammer.c stuff (dict_ ?) |
| 131 | * - fix grammer.c error handling so its not static |
| 132 | * - #ifdef around stuff pertaining to extentions |
| 133 | * |
| 134 | * Outstanding Questions: |
| 135 | * ----------------------------------------------------- |
| 136 | * - ARB_matrix_palette / ARB_vertex_blend -- not supported |
| 137 | * what gets hacked off because of this: |
| 138 | * + VERTEX_ATTRIB_MATRIXINDEX |
| 139 | * + VERTEX_ATTRIB_WEIGHT |
| 140 | * + MATRIX_MODELVIEW |
| 141 | * + MATRIX_PALETTE |
| 142 | * |
| 143 | * - When can we fetch env/local params from their own register files, and |
| 144 | * when to we have to fetch them into the main state register file? |
| 145 | * (think arrays) |
| 146 | * |
| 147 | * Grammar Changes: |
| 148 | * ----------------------------------------------------- |
| 149 | */ |
| 150 | |
| 151 | /* Changes since moving the file to shader directory |
| 152 | |
| 153 | 2004-III-4 ------------------------------------------------------------ |
| 154 | - added #include "grammar_mesa.h" |
| 155 | - removed grammar specific code part (it resides now in grammar.c) |
| 156 | - added GL_ARB_fragment_program_shadow tokens |
| 157 | - modified #include "arbparse_syn.h" |
| 158 | - major changes inside _mesa_parse_arb_program() |
| 159 | - check the program string for '\0' characters |
| 160 | - copy the program string to a one-byte-longer location to have |
| 161 | it null-terminated |
| 162 | - position invariance test (not writing to result.position) moved |
| 163 | to syntax part |
| 164 | */ |
| 165 | |
| 166 | typedef GLubyte *production; |
| 167 | |
Brian Paul | 11a54c3 | 2006-11-15 19:54:25 +0000 | [diff] [blame] | 168 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 169 | /** |
| 170 | * This is the text describing the rules to parse the grammar |
| 171 | */ |
Brian Paul | 11a54c3 | 2006-11-15 19:54:25 +0000 | [diff] [blame] | 172 | LONGSTRING static char arb_grammar_text[] = |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 173 | #include "arbprogram_syn.h" |
| 174 | ; |
| 175 | |
| 176 | /** |
| 177 | * These should match up with the values defined in arbprogram.syn |
| 178 | */ |
| 179 | |
| 180 | /* |
| 181 | Changes: |
| 182 | - changed and merged V_* and F_* opcode values to OP_*. |
| 183 | - added GL_ARB_fragment_program_shadow specific tokens (michal) |
| 184 | */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 185 | #define REVISION 0x0a |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 186 | |
| 187 | /* program type */ |
| 188 | #define FRAGMENT_PROGRAM 0x01 |
| 189 | #define VERTEX_PROGRAM 0x02 |
| 190 | |
| 191 | /* program section */ |
| 192 | #define OPTION 0x01 |
| 193 | #define INSTRUCTION 0x02 |
| 194 | #define DECLARATION 0x03 |
| 195 | #define END 0x04 |
| 196 | |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 197 | /* GL_ARB_fragment_program option */ |
| 198 | #define ARB_PRECISION_HINT_FASTEST 0x00 |
| 199 | #define ARB_PRECISION_HINT_NICEST 0x01 |
| 200 | #define ARB_FOG_EXP 0x02 |
| 201 | #define ARB_FOG_EXP2 0x03 |
| 202 | #define ARB_FOG_LINEAR 0x04 |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 203 | |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 204 | /* GL_ARB_vertex_program option */ |
| 205 | #define ARB_POSITION_INVARIANT 0x05 |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 206 | |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 207 | /* GL_ARB_fragment_program_shadow option */ |
| 208 | #define ARB_FRAGMENT_PROGRAM_SHADOW 0x06 |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 209 | |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 210 | /* GL_ARB_draw_buffers option */ |
| 211 | #define ARB_DRAW_BUFFERS 0x07 |
Michal Krol | ad22ce8 | 2004-10-11 08:13:25 +0000 | [diff] [blame] | 212 | |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 213 | /* GL_MESA_texture_array option */ |
| 214 | #define MESA_TEXTURE_ARRAY 0x08 |
| 215 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 216 | /* GL_ARB_fragment_program instruction class */ |
| 217 | #define OP_ALU_INST 0x00 |
| 218 | #define OP_TEX_INST 0x01 |
| 219 | |
| 220 | /* GL_ARB_vertex_program instruction class */ |
| 221 | /* OP_ALU_INST */ |
| 222 | |
| 223 | /* GL_ARB_fragment_program instruction type */ |
| 224 | #define OP_ALU_VECTOR 0x00 |
| 225 | #define OP_ALU_SCALAR 0x01 |
| 226 | #define OP_ALU_BINSC 0x02 |
| 227 | #define OP_ALU_BIN 0x03 |
| 228 | #define OP_ALU_TRI 0x04 |
| 229 | #define OP_ALU_SWZ 0x05 |
| 230 | #define OP_TEX_SAMPLE 0x06 |
| 231 | #define OP_TEX_KIL 0x07 |
| 232 | |
| 233 | /* GL_ARB_vertex_program instruction type */ |
| 234 | #define OP_ALU_ARL 0x08 |
| 235 | /* OP_ALU_VECTOR */ |
| 236 | /* OP_ALU_SCALAR */ |
| 237 | /* OP_ALU_BINSC */ |
| 238 | /* OP_ALU_BIN */ |
| 239 | /* OP_ALU_TRI */ |
| 240 | /* OP_ALU_SWZ */ |
| 241 | |
| 242 | /* GL_ARB_fragment_program instruction code */ |
| 243 | #define OP_ABS 0x00 |
| 244 | #define OP_ABS_SAT 0x1B |
| 245 | #define OP_FLR 0x09 |
| 246 | #define OP_FLR_SAT 0x26 |
| 247 | #define OP_FRC 0x0A |
| 248 | #define OP_FRC_SAT 0x27 |
| 249 | #define OP_LIT 0x0C |
| 250 | #define OP_LIT_SAT 0x2A |
| 251 | #define OP_MOV 0x11 |
| 252 | #define OP_MOV_SAT 0x30 |
| 253 | #define OP_COS 0x1F |
| 254 | #define OP_COS_SAT 0x20 |
| 255 | #define OP_EX2 0x07 |
| 256 | #define OP_EX2_SAT 0x25 |
| 257 | #define OP_LG2 0x0B |
| 258 | #define OP_LG2_SAT 0x29 |
| 259 | #define OP_RCP 0x14 |
| 260 | #define OP_RCP_SAT 0x33 |
| 261 | #define OP_RSQ 0x15 |
| 262 | #define OP_RSQ_SAT 0x34 |
| 263 | #define OP_SIN 0x38 |
| 264 | #define OP_SIN_SAT 0x39 |
| 265 | #define OP_SCS 0x35 |
| 266 | #define OP_SCS_SAT 0x36 |
| 267 | #define OP_POW 0x13 |
| 268 | #define OP_POW_SAT 0x32 |
| 269 | #define OP_ADD 0x01 |
| 270 | #define OP_ADD_SAT 0x1C |
| 271 | #define OP_DP3 0x03 |
| 272 | #define OP_DP3_SAT 0x21 |
| 273 | #define OP_DP4 0x04 |
| 274 | #define OP_DP4_SAT 0x22 |
| 275 | #define OP_DPH 0x05 |
| 276 | #define OP_DPH_SAT 0x23 |
| 277 | #define OP_DST 0x06 |
| 278 | #define OP_DST_SAT 0x24 |
| 279 | #define OP_MAX 0x0F |
| 280 | #define OP_MAX_SAT 0x2E |
| 281 | #define OP_MIN 0x10 |
| 282 | #define OP_MIN_SAT 0x2F |
| 283 | #define OP_MUL 0x12 |
| 284 | #define OP_MUL_SAT 0x31 |
| 285 | #define OP_SGE 0x16 |
| 286 | #define OP_SGE_SAT 0x37 |
| 287 | #define OP_SLT 0x17 |
| 288 | #define OP_SLT_SAT 0x3A |
| 289 | #define OP_SUB 0x18 |
| 290 | #define OP_SUB_SAT 0x3B |
| 291 | #define OP_XPD 0x1A |
| 292 | #define OP_XPD_SAT 0x43 |
| 293 | #define OP_CMP 0x1D |
| 294 | #define OP_CMP_SAT 0x1E |
| 295 | #define OP_LRP 0x2B |
| 296 | #define OP_LRP_SAT 0x2C |
| 297 | #define OP_MAD 0x0E |
| 298 | #define OP_MAD_SAT 0x2D |
| 299 | #define OP_SWZ 0x19 |
| 300 | #define OP_SWZ_SAT 0x3C |
| 301 | #define OP_TEX 0x3D |
| 302 | #define OP_TEX_SAT 0x3E |
| 303 | #define OP_TXB 0x3F |
| 304 | #define OP_TXB_SAT 0x40 |
| 305 | #define OP_TXP 0x41 |
| 306 | #define OP_TXP_SAT 0x42 |
| 307 | #define OP_KIL 0x28 |
| 308 | |
| 309 | /* GL_ARB_vertex_program instruction code */ |
| 310 | #define OP_ARL 0x02 |
| 311 | /* OP_ABS */ |
| 312 | /* OP_FLR */ |
| 313 | /* OP_FRC */ |
| 314 | /* OP_LIT */ |
| 315 | /* OP_MOV */ |
| 316 | /* OP_EX2 */ |
| 317 | #define OP_EXP 0x08 |
| 318 | /* OP_LG2 */ |
| 319 | #define OP_LOG 0x0D |
| 320 | /* OP_RCP */ |
| 321 | /* OP_RSQ */ |
| 322 | /* OP_POW */ |
| 323 | /* OP_ADD */ |
| 324 | /* OP_DP3 */ |
| 325 | /* OP_DP4 */ |
| 326 | /* OP_DPH */ |
| 327 | /* OP_DST */ |
| 328 | /* OP_MAX */ |
| 329 | /* OP_MIN */ |
| 330 | /* OP_MUL */ |
| 331 | /* OP_SGE */ |
| 332 | /* OP_SLT */ |
| 333 | /* OP_SUB */ |
| 334 | /* OP_XPD */ |
| 335 | /* OP_MAD */ |
| 336 | /* OP_SWZ */ |
| 337 | |
| 338 | /* fragment attribute binding */ |
| 339 | #define FRAGMENT_ATTRIB_COLOR 0x01 |
| 340 | #define FRAGMENT_ATTRIB_TEXCOORD 0x02 |
| 341 | #define FRAGMENT_ATTRIB_FOGCOORD 0x03 |
| 342 | #define FRAGMENT_ATTRIB_POSITION 0x04 |
| 343 | |
| 344 | /* vertex attribute binding */ |
| 345 | #define VERTEX_ATTRIB_POSITION 0x01 |
| 346 | #define VERTEX_ATTRIB_WEIGHT 0x02 |
| 347 | #define VERTEX_ATTRIB_NORMAL 0x03 |
| 348 | #define VERTEX_ATTRIB_COLOR 0x04 |
| 349 | #define VERTEX_ATTRIB_FOGCOORD 0x05 |
| 350 | #define VERTEX_ATTRIB_TEXCOORD 0x06 |
| 351 | #define VERTEX_ATTRIB_MATRIXINDEX 0x07 |
| 352 | #define VERTEX_ATTRIB_GENERIC 0x08 |
| 353 | |
| 354 | /* fragment result binding */ |
| 355 | #define FRAGMENT_RESULT_COLOR 0x01 |
| 356 | #define FRAGMENT_RESULT_DEPTH 0x02 |
| 357 | |
| 358 | /* vertex result binding */ |
| 359 | #define VERTEX_RESULT_POSITION 0x01 |
| 360 | #define VERTEX_RESULT_COLOR 0x02 |
| 361 | #define VERTEX_RESULT_FOGCOORD 0x03 |
| 362 | #define VERTEX_RESULT_POINTSIZE 0x04 |
| 363 | #define VERTEX_RESULT_TEXCOORD 0x05 |
| 364 | |
| 365 | /* texture target */ |
| 366 | #define TEXTARGET_1D 0x01 |
| 367 | #define TEXTARGET_2D 0x02 |
| 368 | #define TEXTARGET_3D 0x03 |
| 369 | #define TEXTARGET_RECT 0x04 |
| 370 | #define TEXTARGET_CUBE 0x05 |
| 371 | /* GL_ARB_fragment_program_shadow */ |
| 372 | #define TEXTARGET_SHADOW1D 0x06 |
| 373 | #define TEXTARGET_SHADOW2D 0x07 |
| 374 | #define TEXTARGET_SHADOWRECT 0x08 |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 375 | /* GL_MESA_texture_array */ |
| 376 | #define TEXTARGET_1D_ARRAY 0x09 |
| 377 | #define TEXTARGET_2D_ARRAY 0x0a |
Ian Romanick | 69358e7 | 2007-06-05 09:24:27 -0700 | [diff] [blame] | 378 | #define TEXTARGET_SHADOW1D_ARRAY 0x0b |
| 379 | #define TEXTARGET_SHADOW2D_ARRAY 0x0c |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 380 | |
| 381 | /* face type */ |
| 382 | #define FACE_FRONT 0x00 |
| 383 | #define FACE_BACK 0x01 |
| 384 | |
| 385 | /* color type */ |
| 386 | #define COLOR_PRIMARY 0x00 |
| 387 | #define COLOR_SECONDARY 0x01 |
| 388 | |
| 389 | /* component */ |
| 390 | #define COMPONENT_X 0x00 |
| 391 | #define COMPONENT_Y 0x01 |
| 392 | #define COMPONENT_Z 0x02 |
| 393 | #define COMPONENT_W 0x03 |
| 394 | #define COMPONENT_0 0x04 |
| 395 | #define COMPONENT_1 0x05 |
| 396 | |
| 397 | /* array index type */ |
| 398 | #define ARRAY_INDEX_ABSOLUTE 0x00 |
| 399 | #define ARRAY_INDEX_RELATIVE 0x01 |
| 400 | |
| 401 | /* matrix name */ |
| 402 | #define MATRIX_MODELVIEW 0x01 |
| 403 | #define MATRIX_PROJECTION 0x02 |
| 404 | #define MATRIX_MVP 0x03 |
| 405 | #define MATRIX_TEXTURE 0x04 |
| 406 | #define MATRIX_PALETTE 0x05 |
| 407 | #define MATRIX_PROGRAM 0x06 |
| 408 | |
| 409 | /* matrix modifier */ |
| 410 | #define MATRIX_MODIFIER_IDENTITY 0x00 |
| 411 | #define MATRIX_MODIFIER_INVERSE 0x01 |
| 412 | #define MATRIX_MODIFIER_TRANSPOSE 0x02 |
| 413 | #define MATRIX_MODIFIER_INVTRANS 0x03 |
| 414 | |
| 415 | /* constant type */ |
| 416 | #define CONSTANT_SCALAR 0x01 |
| 417 | #define CONSTANT_VECTOR 0x02 |
| 418 | |
| 419 | /* program param type */ |
| 420 | #define PROGRAM_PARAM_ENV 0x01 |
| 421 | #define PROGRAM_PARAM_LOCAL 0x02 |
| 422 | |
| 423 | /* register type */ |
| 424 | #define REGISTER_ATTRIB 0x01 |
| 425 | #define REGISTER_PARAM 0x02 |
| 426 | #define REGISTER_RESULT 0x03 |
| 427 | #define REGISTER_ESTABLISHED_NAME 0x04 |
| 428 | |
| 429 | /* param binding */ |
| 430 | #define PARAM_NULL 0x00 |
| 431 | #define PARAM_ARRAY_ELEMENT 0x01 |
| 432 | #define PARAM_STATE_ELEMENT 0x02 |
| 433 | #define PARAM_PROGRAM_ELEMENT 0x03 |
| 434 | #define PARAM_PROGRAM_ELEMENTS 0x04 |
| 435 | #define PARAM_CONSTANT 0x05 |
| 436 | |
| 437 | /* param state property */ |
| 438 | #define STATE_MATERIAL_PARSER 0x01 |
| 439 | #define STATE_LIGHT_PARSER 0x02 |
| 440 | #define STATE_LIGHT_MODEL 0x03 |
| 441 | #define STATE_LIGHT_PROD 0x04 |
| 442 | #define STATE_FOG 0x05 |
| 443 | #define STATE_MATRIX_ROWS 0x06 |
| 444 | /* GL_ARB_fragment_program */ |
| 445 | #define STATE_TEX_ENV 0x07 |
| 446 | #define STATE_DEPTH 0x08 |
| 447 | /* GL_ARB_vertex_program */ |
| 448 | #define STATE_TEX_GEN 0x09 |
| 449 | #define STATE_CLIP_PLANE 0x0A |
| 450 | #define STATE_POINT 0x0B |
| 451 | |
| 452 | /* state material property */ |
| 453 | #define MATERIAL_AMBIENT 0x01 |
| 454 | #define MATERIAL_DIFFUSE 0x02 |
| 455 | #define MATERIAL_SPECULAR 0x03 |
| 456 | #define MATERIAL_EMISSION 0x04 |
| 457 | #define MATERIAL_SHININESS 0x05 |
| 458 | |
| 459 | /* state light property */ |
| 460 | #define LIGHT_AMBIENT 0x01 |
| 461 | #define LIGHT_DIFFUSE 0x02 |
| 462 | #define LIGHT_SPECULAR 0x03 |
| 463 | #define LIGHT_POSITION 0x04 |
| 464 | #define LIGHT_ATTENUATION 0x05 |
| 465 | #define LIGHT_HALF 0x06 |
| 466 | #define LIGHT_SPOT_DIRECTION 0x07 |
| 467 | |
| 468 | /* state light model property */ |
| 469 | #define LIGHT_MODEL_AMBIENT 0x01 |
| 470 | #define LIGHT_MODEL_SCENECOLOR 0x02 |
| 471 | |
| 472 | /* state light product property */ |
| 473 | #define LIGHT_PROD_AMBIENT 0x01 |
| 474 | #define LIGHT_PROD_DIFFUSE 0x02 |
| 475 | #define LIGHT_PROD_SPECULAR 0x03 |
| 476 | |
| 477 | /* state texture environment property */ |
| 478 | #define TEX_ENV_COLOR 0x01 |
| 479 | |
| 480 | /* state texture generation coord property */ |
| 481 | #define TEX_GEN_EYE 0x01 |
| 482 | #define TEX_GEN_OBJECT 0x02 |
| 483 | |
| 484 | /* state fog property */ |
| 485 | #define FOG_COLOR 0x01 |
| 486 | #define FOG_PARAMS 0x02 |
| 487 | |
| 488 | /* state depth property */ |
| 489 | #define DEPTH_RANGE 0x01 |
| 490 | |
| 491 | /* state point parameters property */ |
| 492 | #define POINT_SIZE 0x01 |
| 493 | #define POINT_ATTENUATION 0x02 |
| 494 | |
| 495 | /* declaration */ |
| 496 | #define ATTRIB 0x01 |
| 497 | #define PARAM 0x02 |
| 498 | #define TEMP 0x03 |
| 499 | #define OUTPUT 0x04 |
| 500 | #define ALIAS 0x05 |
| 501 | /* GL_ARB_vertex_program */ |
| 502 | #define ADDRESS 0x06 |
| 503 | |
| 504 | /*----------------------------------------------------------------------- |
| 505 | * From here on down is the semantic checking portion |
| 506 | * |
| 507 | */ |
| 508 | |
| 509 | /** |
| 510 | * Variable Table Handling functions |
| 511 | */ |
| 512 | typedef enum |
| 513 | { |
| 514 | vt_none, |
| 515 | vt_address, |
| 516 | vt_attrib, |
| 517 | vt_param, |
| 518 | vt_temp, |
| 519 | vt_output, |
| 520 | vt_alias |
| 521 | } var_type; |
| 522 | |
| 523 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 524 | /** |
| 525 | * Setting an explicit field for each of the binding properties is a bit |
| 526 | * wasteful of space, but it should be much more clear when reading later on.. |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 527 | */ |
| 528 | struct var_cache |
| 529 | { |
Brian Paul | 6a769d9 | 2006-04-28 15:42:15 +0000 | [diff] [blame] | 530 | const GLubyte *name; /* don't free() - no need */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 531 | var_type type; |
| 532 | GLuint address_binding; /* The index of the address register we should |
| 533 | * be using */ |
| 534 | GLuint attrib_binding; /* For type vt_attrib, see nvfragprog.h for values */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 535 | GLuint attrib_is_generic; /* If the attrib was specified through a generic |
| 536 | * vertex attrib */ |
| 537 | GLuint temp_binding; /* The index of the temp register we are to use */ |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 538 | GLuint output_binding; /* Output/result register number */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 539 | struct var_cache *alias_binding; /* For type vt_alias, points to the var_cache entry |
| 540 | * that this is aliased to */ |
| 541 | GLuint param_binding_type; /* {PROGRAM_STATE_VAR, PROGRAM_LOCAL_PARAM, |
| 542 | * PROGRAM_ENV_PARAM} */ |
| 543 | GLuint param_binding_begin; /* This is the offset into the program_parameter_list where |
| 544 | * the tokens representing our bound state (or constants) |
| 545 | * start */ |
| 546 | GLuint param_binding_length; /* This is how many entries in the the program_parameter_list |
| 547 | * we take up with our state tokens or constants. Note that |
| 548 | * this is _not_ the same as the number of param registers |
| 549 | * we eventually use */ |
| 550 | struct var_cache *next; |
| 551 | }; |
| 552 | |
| 553 | static GLvoid |
| 554 | var_cache_create (struct var_cache **va) |
| 555 | { |
| 556 | *va = (struct var_cache *) _mesa_malloc (sizeof (struct var_cache)); |
| 557 | if (*va) { |
| 558 | (**va).name = NULL; |
| 559 | (**va).type = vt_none; |
| 560 | (**va).attrib_binding = ~0; |
| 561 | (**va).attrib_is_generic = 0; |
| 562 | (**va).temp_binding = ~0; |
| 563 | (**va).output_binding = ~0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 564 | (**va).param_binding_type = ~0; |
| 565 | (**va).param_binding_begin = ~0; |
| 566 | (**va).param_binding_length = ~0; |
| 567 | (**va).alias_binding = NULL; |
| 568 | (**va).next = NULL; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static GLvoid |
| 573 | var_cache_destroy (struct var_cache **va) |
| 574 | { |
| 575 | if (*va) { |
| 576 | var_cache_destroy (&(**va).next); |
| 577 | _mesa_free (*va); |
| 578 | *va = NULL; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | static GLvoid |
| 583 | var_cache_append (struct var_cache **va, struct var_cache *nv) |
| 584 | { |
| 585 | if (*va) |
| 586 | var_cache_append (&(**va).next, nv); |
| 587 | else |
| 588 | *va = nv; |
| 589 | } |
| 590 | |
| 591 | static struct var_cache * |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 592 | var_cache_find (struct var_cache *va, const GLubyte * name) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 593 | { |
Brian Paul | 0a360cf | 2005-01-17 01:21:03 +0000 | [diff] [blame] | 594 | /*struct var_cache *first = va;*/ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 595 | |
| 596 | while (va) { |
Brian Paul | aa20695 | 2005-09-16 18:14:24 +0000 | [diff] [blame] | 597 | if (!_mesa_strcmp ( (const char*) name, (const char*) va->name)) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 598 | if (va->type == vt_alias) |
Michal Krol | 4334391 | 2005-01-11 15:47:16 +0000 | [diff] [blame] | 599 | return va->alias_binding; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 600 | return va; |
| 601 | } |
| 602 | |
| 603 | va = va->next; |
| 604 | } |
| 605 | |
| 606 | return NULL; |
| 607 | } |
| 608 | |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 609 | |
| 610 | |
| 611 | /** |
| 612 | * Called when an error is detected while parsing/compiling a program. |
| 613 | * Sets the ctx->Program.ErrorString field to descript and records a |
| 614 | * GL_INVALID_OPERATION error. |
| 615 | * \param position position of error in program string |
| 616 | * \param descrip verbose error description |
| 617 | */ |
| 618 | static void |
| 619 | program_error(GLcontext *ctx, GLint position, const char *descrip) |
| 620 | { |
| 621 | if (descrip) { |
| 622 | const char *prefix = "glProgramString(", *suffix = ")"; |
| 623 | char *str = (char *) _mesa_malloc(_mesa_strlen(descrip) + |
| 624 | _mesa_strlen(prefix) + |
| 625 | _mesa_strlen(suffix) + 1); |
| 626 | if (str) { |
| 627 | _mesa_sprintf(str, "%s%s%s", prefix, descrip, suffix); |
| 628 | _mesa_error(ctx, GL_INVALID_OPERATION, str); |
| 629 | _mesa_free(str); |
| 630 | } |
| 631 | } |
| 632 | _mesa_set_program_error(ctx, position, descrip); |
| 633 | } |
| 634 | |
| 635 | |
| 636 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 637 | /** |
| 638 | * constructs an integer from 4 GLubytes in LE format |
| 639 | */ |
| 640 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 641 | parse_position (const GLubyte ** inst) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 642 | { |
| 643 | GLuint value; |
| 644 | |
| 645 | value = (GLuint) (*(*inst)++); |
| 646 | value += (GLuint) (*(*inst)++) * 0x100; |
| 647 | value += (GLuint) (*(*inst)++) * 0x10000; |
| 648 | value += (GLuint) (*(*inst)++) * 0x1000000; |
| 649 | |
| 650 | return value; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * This will, given a string, lookup the string as a variable name in the |
| 655 | * var cache. If the name is found, the var cache node corresponding to the |
| 656 | * var name is returned. If it is not found, a new entry is allocated |
| 657 | * |
| 658 | * \param I Points into the binary array where the string identifier begins |
| 659 | * \param found 1 if the string was found in the var_cache, 0 if it was allocated |
| 660 | * \return The location on the var_cache corresponding the the string starting at I |
| 661 | */ |
| 662 | static struct var_cache * |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 663 | parse_string (const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 664 | struct arb_program *Program, GLuint * found) |
| 665 | { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 666 | const GLubyte *i = *inst; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 667 | struct var_cache *va = NULL; |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 668 | (void) Program; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 669 | |
| 670 | *inst += _mesa_strlen ((char *) i) + 1; |
| 671 | |
| 672 | va = var_cache_find (*vc_head, i); |
| 673 | |
| 674 | if (va) { |
| 675 | *found = 1; |
| 676 | return va; |
| 677 | } |
| 678 | |
| 679 | *found = 0; |
| 680 | var_cache_create (&va); |
Brian Paul | 6a769d9 | 2006-04-28 15:42:15 +0000 | [diff] [blame] | 681 | va->name = (const GLubyte *) i; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 682 | |
| 683 | var_cache_append (vc_head, va); |
| 684 | |
| 685 | return va; |
| 686 | } |
| 687 | |
| 688 | static char * |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 689 | parse_string_without_adding (const GLubyte ** inst, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 690 | { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 691 | const GLubyte *i = *inst; |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 692 | (void) Program; |
| 693 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 694 | *inst += _mesa_strlen ((char *) i) + 1; |
| 695 | |
| 696 | return (char *) i; |
| 697 | } |
| 698 | |
| 699 | /** |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 700 | * \return -1 if we parse '-', return 1 otherwise |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 701 | */ |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 702 | static GLint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 703 | parse_sign (const GLubyte ** inst) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 704 | { |
| 705 | /*return *(*inst)++ != '+'; */ |
| 706 | |
| 707 | if (**inst == '-') { |
| 708 | (*inst)++; |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 709 | return -1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 710 | } |
| 711 | else if (**inst == '+') { |
| 712 | (*inst)++; |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 713 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 716 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * parses and returns signed integer |
| 721 | */ |
| 722 | static GLint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 723 | parse_integer (const GLubyte ** inst, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 724 | { |
| 725 | GLint sign; |
| 726 | GLint value; |
| 727 | |
| 728 | /* check if *inst points to '+' or '-' |
| 729 | * if yes, grab the sign and increment *inst |
| 730 | */ |
| 731 | sign = parse_sign (inst); |
| 732 | |
| 733 | /* now check if *inst points to 0 |
| 734 | * if yes, increment the *inst and return the default value |
| 735 | */ |
| 736 | if (**inst == 0) { |
| 737 | (*inst)++; |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | /* parse the integer as you normally would do it */ |
| 742 | value = _mesa_atoi (parse_string_without_adding (inst, Program)); |
| 743 | |
| 744 | /* now, after terminating 0 there is a position |
| 745 | * to parse it - parse_position() |
| 746 | */ |
| 747 | Program->Position = parse_position (inst); |
| 748 | |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 749 | return value * sign; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /** |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 753 | Accumulate this string of digits, and return them as |
| 754 | a large integer represented in floating point (for range). |
| 755 | If scale is not NULL, also accumulates a power-of-ten |
| 756 | integer scale factor that represents the number of digits |
| 757 | in the string. |
| 758 | */ |
| 759 | static GLdouble |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 760 | parse_float_string(const GLubyte ** inst, struct arb_program *Program, GLdouble *scale) |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 761 | { |
| 762 | GLdouble value = 0.0; |
| 763 | GLdouble oscale = 1.0; |
| 764 | |
| 765 | if (**inst == 0) { /* this string of digits is empty-- do nothing */ |
| 766 | (*inst)++; |
| 767 | } |
| 768 | else { /* nonempty string-- parse out the digits */ |
Michal Krol | 98e3502 | 2005-04-14 10:19:19 +0000 | [diff] [blame] | 769 | while (**inst >= '0' && **inst <= '9') { |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 770 | GLubyte digit = *((*inst)++); |
| 771 | value = value * 10.0 + (GLint) (digit - '0'); |
| 772 | oscale *= 10.0; |
| 773 | } |
| 774 | assert(**inst == 0); /* integer string should end with 0 */ |
| 775 | (*inst)++; /* skip over terminating 0 */ |
| 776 | Program->Position = parse_position(inst); /* skip position (from integer) */ |
| 777 | } |
| 778 | if (scale) |
| 779 | *scale = oscale; |
| 780 | return value; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | Parse an unsigned floating-point number from this stream of tokenized |
| 785 | characters. Example floating-point formats supported: |
| 786 | 12.34 |
| 787 | 12 |
| 788 | 0.34 |
| 789 | .34 |
| 790 | 12.34e-4 |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 791 | */ |
| 792 | static GLfloat |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 793 | parse_float (const GLubyte ** inst, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 794 | { |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 795 | GLint exponent; |
| 796 | GLdouble whole, fraction, fracScale = 1.0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 797 | |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 798 | whole = parse_float_string(inst, Program, 0); |
| 799 | fraction = parse_float_string(inst, Program, &fracScale); |
| 800 | |
| 801 | /* Parse signed exponent */ |
| 802 | exponent = parse_integer(inst, Program); /* This is the exponent */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 803 | |
Brian Paul | 1ff8f50 | 2005-02-16 15:08:29 +0000 | [diff] [blame] | 804 | /* Assemble parts of floating-point number: */ |
| 805 | return (GLfloat) ((whole + fraction / fracScale) * |
| 806 | _mesa_pow(10.0, (GLfloat) exponent)); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | |
| 810 | /** |
| 811 | */ |
| 812 | static GLfloat |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 813 | parse_signed_float (const GLubyte ** inst, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 814 | { |
Brian Paul | 0590895 | 2004-06-08 15:20:23 +0000 | [diff] [blame] | 815 | GLint sign = parse_sign (inst); |
| 816 | GLfloat value = parse_float (inst, Program); |
| 817 | return value * sign; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * This picks out a constant value from the parsed array. The constant vector is r |
| 822 | * returned in the *values array, which should be of length 4. |
| 823 | * |
| 824 | * \param values - The 4 component vector with the constant value in it |
| 825 | */ |
| 826 | static GLvoid |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 827 | parse_constant (const GLubyte ** inst, GLfloat *values, struct arb_program *Program, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 828 | GLboolean use) |
| 829 | { |
| 830 | GLuint components, i; |
| 831 | |
| 832 | |
| 833 | switch (*(*inst)++) { |
| 834 | case CONSTANT_SCALAR: |
| 835 | if (use == GL_TRUE) { |
| 836 | values[0] = |
| 837 | values[1] = |
| 838 | values[2] = values[3] = parse_float (inst, Program); |
| 839 | } |
| 840 | else { |
| 841 | values[0] = |
| 842 | values[1] = |
| 843 | values[2] = values[3] = parse_signed_float (inst, Program); |
| 844 | } |
| 845 | |
| 846 | break; |
| 847 | case CONSTANT_VECTOR: |
| 848 | values[0] = values[1] = values[2] = 0; |
| 849 | values[3] = 1; |
| 850 | components = *(*inst)++; |
| 851 | for (i = 0; i < components; i++) { |
| 852 | values[i] = parse_signed_float (inst, Program); |
| 853 | } |
| 854 | break; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * \param offset The offset from the address register that we should |
| 860 | * address |
| 861 | * |
| 862 | * \return 0 on sucess, 1 on error |
| 863 | */ |
| 864 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 865 | parse_relative_offset(GLcontext *ctx, const GLubyte **inst, |
| 866 | struct arb_program *Program, GLint *offset) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 867 | { |
Brian Paul | 6a769d9 | 2006-04-28 15:42:15 +0000 | [diff] [blame] | 868 | (void) ctx; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 869 | *offset = parse_integer(inst, Program); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * \param color 0 if color type is primary, 1 if color type is secondary |
| 875 | * \return 0 on sucess, 1 on error |
| 876 | */ |
| 877 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 878 | parse_color_type (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 879 | GLint * color) |
| 880 | { |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 881 | (void) ctx; (void) Program; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 882 | *color = *(*inst)++ != COLOR_PRIMARY; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Get an integer corresponding to a generic vertex attribute. |
| 888 | * |
| 889 | * \return 0 on sucess, 1 on error |
| 890 | */ |
| 891 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 892 | parse_generic_attrib_num(GLcontext *ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 893 | struct arb_program *Program, GLuint *attrib) |
| 894 | { |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 895 | GLint i = parse_integer(inst, Program); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 896 | |
Michal Krol | bb38cad | 2006-04-11 11:41:11 +0000 | [diff] [blame] | 897 | if ((i < 0) || (i >= MAX_VERTEX_PROGRAM_ATTRIBS)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 898 | { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 899 | program_error(ctx, Program->Position, |
| 900 | "Invalid generic vertex attribute index"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 901 | return 1; |
| 902 | } |
| 903 | |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 904 | *attrib = (GLuint) i; |
| 905 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | |
| 910 | /** |
Brian Paul | be76b7f | 2004-10-04 14:40:05 +0000 | [diff] [blame] | 911 | * \param color The index of the color buffer to write into |
| 912 | * \return 0 on sucess, 1 on error |
| 913 | */ |
| 914 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 915 | parse_output_color_num (GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | be76b7f | 2004-10-04 14:40:05 +0000 | [diff] [blame] | 916 | struct arb_program *Program, GLuint * color) |
| 917 | { |
| 918 | GLint i = parse_integer (inst, Program); |
| 919 | |
| 920 | if ((i < 0) || (i >= (int)ctx->Const.MaxDrawBuffers)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 921 | program_error(ctx, Program->Position, "Invalid draw buffer index"); |
Brian Paul | be76b7f | 2004-10-04 14:40:05 +0000 | [diff] [blame] | 922 | return 1; |
| 923 | } |
| 924 | |
| 925 | *color = (GLuint) i; |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | /** |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 931 | * \param coord The texture unit index |
| 932 | * \return 0 on sucess, 1 on error |
| 933 | */ |
| 934 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 935 | parse_texcoord_num (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 936 | struct arb_program *Program, GLuint * coord) |
| 937 | { |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 938 | GLint i = parse_integer (inst, Program); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 939 | |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 940 | if ((i < 0) || (i >= (int)ctx->Const.MaxTextureUnits)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 941 | program_error(ctx, Program->Position, "Invalid texture unit index"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 942 | return 1; |
| 943 | } |
| 944 | |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 945 | *coord = (GLuint) i; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * \param coord The weight index |
| 951 | * \return 0 on sucess, 1 on error |
| 952 | */ |
| 953 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 954 | parse_weight_num (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 955 | GLint * coord) |
| 956 | { |
| 957 | *coord = parse_integer (inst, Program); |
| 958 | |
| 959 | if ((*coord < 0) || (*coord >= 1)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 960 | program_error(ctx, Program->Position, "Invalid weight index"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 961 | return 1; |
| 962 | } |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * \param coord The clip plane index |
| 969 | * \return 0 on sucess, 1 on error |
| 970 | */ |
| 971 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 972 | parse_clipplane_num (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 973 | struct arb_program *Program, GLint * coord) |
| 974 | { |
| 975 | *coord = parse_integer (inst, Program); |
| 976 | |
| 977 | if ((*coord < 0) || (*coord >= (GLint) ctx->Const.MaxClipPlanes)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 978 | program_error(ctx, Program->Position, "Invalid clip plane index"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 979 | return 1; |
| 980 | } |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | |
| 986 | /** |
| 987 | * \return 0 on front face, 1 on back face |
| 988 | */ |
| 989 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 990 | parse_face_type (const GLubyte ** inst) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 991 | { |
| 992 | switch (*(*inst)++) { |
| 993 | case FACE_FRONT: |
| 994 | return 0; |
| 995 | |
| 996 | case FACE_BACK: |
| 997 | return 1; |
| 998 | } |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | /** |
| 1004 | * Given a matrix and a modifier token on the binary array, return tokens |
| 1005 | * that _mesa_fetch_state() [program.c] can understand. |
| 1006 | * |
| 1007 | * \param matrix - the matrix we are talking about |
| 1008 | * \param matrix_idx - the index of the matrix we have (for texture & program matricies) |
| 1009 | * \param matrix_modifier - the matrix modifier (trans, inv, etc) |
| 1010 | * \return 0 on sucess, 1 on failure |
| 1011 | */ |
| 1012 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1013 | parse_matrix (GLcontext * ctx, const GLubyte ** inst, struct arb_program *Program, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1014 | GLint * matrix, GLint * matrix_idx, GLint * matrix_modifier) |
| 1015 | { |
| 1016 | GLubyte mat = *(*inst)++; |
| 1017 | |
| 1018 | *matrix_idx = 0; |
| 1019 | |
| 1020 | switch (mat) { |
| 1021 | case MATRIX_MODELVIEW: |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1022 | *matrix = STATE_MODELVIEW_MATRIX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1023 | *matrix_idx = parse_integer (inst, Program); |
| 1024 | if (*matrix_idx > 0) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1025 | program_error(ctx, Program->Position, |
| 1026 | "ARB_vertex_blend not supported"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1027 | return 1; |
| 1028 | } |
| 1029 | break; |
| 1030 | |
| 1031 | case MATRIX_PROJECTION: |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1032 | *matrix = STATE_PROJECTION_MATRIX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1033 | break; |
| 1034 | |
| 1035 | case MATRIX_MVP: |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1036 | *matrix = STATE_MVP_MATRIX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1037 | break; |
| 1038 | |
| 1039 | case MATRIX_TEXTURE: |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1040 | *matrix = STATE_TEXTURE_MATRIX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1041 | *matrix_idx = parse_integer (inst, Program); |
| 1042 | if (*matrix_idx >= (GLint) ctx->Const.MaxTextureUnits) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1043 | program_error(ctx, Program->Position, "Invalid Texture Unit"); |
| 1044 | /* bad *matrix_id */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1045 | return 1; |
| 1046 | } |
| 1047 | break; |
| 1048 | |
| 1049 | /* This is not currently supported (ARB_matrix_palette) */ |
| 1050 | case MATRIX_PALETTE: |
| 1051 | *matrix_idx = parse_integer (inst, Program); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1052 | program_error(ctx, Program->Position, |
| 1053 | "ARB_matrix_palette not supported"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1054 | return 1; |
| 1055 | break; |
| 1056 | |
| 1057 | case MATRIX_PROGRAM: |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1058 | *matrix = STATE_PROGRAM_MATRIX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1059 | *matrix_idx = parse_integer (inst, Program); |
| 1060 | if (*matrix_idx >= (GLint) ctx->Const.MaxProgramMatrices) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1061 | program_error(ctx, Program->Position, "Invalid Program Matrix"); |
| 1062 | /* bad *matrix_idx */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1063 | return 1; |
| 1064 | } |
| 1065 | break; |
| 1066 | } |
| 1067 | |
| 1068 | switch (*(*inst)++) { |
| 1069 | case MATRIX_MODIFIER_IDENTITY: |
| 1070 | *matrix_modifier = 0; |
| 1071 | break; |
| 1072 | case MATRIX_MODIFIER_INVERSE: |
| 1073 | *matrix_modifier = STATE_MATRIX_INVERSE; |
| 1074 | break; |
| 1075 | case MATRIX_MODIFIER_TRANSPOSE: |
| 1076 | *matrix_modifier = STATE_MATRIX_TRANSPOSE; |
| 1077 | break; |
| 1078 | case MATRIX_MODIFIER_INVTRANS: |
| 1079 | *matrix_modifier = STATE_MATRIX_INVTRANS; |
| 1080 | break; |
| 1081 | } |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | /** |
| 1088 | * This parses a state string (rather, the binary version of it) into |
| 1089 | * a 6-token sequence as described in _mesa_fetch_state() [program.c] |
| 1090 | * |
| 1091 | * \param inst - the start in the binary arry to start working from |
| 1092 | * \param state_tokens - the storage for the 6-token state description |
| 1093 | * \return - 0 on sucess, 1 on error |
| 1094 | */ |
| 1095 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1096 | parse_state_single_item (GLcontext * ctx, const GLubyte ** inst, |
Brian | aa9d22a | 2007-02-23 11:21:03 -0700 | [diff] [blame] | 1097 | struct arb_program *Program, |
| 1098 | gl_state_index state_tokens[STATE_LENGTH]) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1099 | { |
| 1100 | switch (*(*inst)++) { |
| 1101 | case STATE_MATERIAL_PARSER: |
| 1102 | state_tokens[0] = STATE_MATERIAL; |
| 1103 | state_tokens[1] = parse_face_type (inst); |
| 1104 | switch (*(*inst)++) { |
| 1105 | case MATERIAL_AMBIENT: |
| 1106 | state_tokens[2] = STATE_AMBIENT; |
| 1107 | break; |
| 1108 | case MATERIAL_DIFFUSE: |
| 1109 | state_tokens[2] = STATE_DIFFUSE; |
| 1110 | break; |
| 1111 | case MATERIAL_SPECULAR: |
| 1112 | state_tokens[2] = STATE_SPECULAR; |
| 1113 | break; |
| 1114 | case MATERIAL_EMISSION: |
| 1115 | state_tokens[2] = STATE_EMISSION; |
| 1116 | break; |
| 1117 | case MATERIAL_SHININESS: |
| 1118 | state_tokens[2] = STATE_SHININESS; |
| 1119 | break; |
| 1120 | } |
| 1121 | break; |
| 1122 | |
| 1123 | case STATE_LIGHT_PARSER: |
| 1124 | state_tokens[0] = STATE_LIGHT; |
| 1125 | state_tokens[1] = parse_integer (inst, Program); |
| 1126 | |
| 1127 | /* Check the value of state_tokens[1] against the # of lights */ |
| 1128 | if (state_tokens[1] >= (GLint) ctx->Const.MaxLights) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1129 | program_error(ctx, Program->Position, "Invalid Light Number"); |
| 1130 | /* bad state_tokens[1] */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1131 | return 1; |
| 1132 | } |
| 1133 | |
| 1134 | switch (*(*inst)++) { |
| 1135 | case LIGHT_AMBIENT: |
| 1136 | state_tokens[2] = STATE_AMBIENT; |
| 1137 | break; |
| 1138 | case LIGHT_DIFFUSE: |
| 1139 | state_tokens[2] = STATE_DIFFUSE; |
| 1140 | break; |
| 1141 | case LIGHT_SPECULAR: |
| 1142 | state_tokens[2] = STATE_SPECULAR; |
| 1143 | break; |
| 1144 | case LIGHT_POSITION: |
| 1145 | state_tokens[2] = STATE_POSITION; |
| 1146 | break; |
| 1147 | case LIGHT_ATTENUATION: |
| 1148 | state_tokens[2] = STATE_ATTENUATION; |
| 1149 | break; |
| 1150 | case LIGHT_HALF: |
Brian | f958aab | 2007-02-21 15:23:11 -0700 | [diff] [blame] | 1151 | state_tokens[2] = STATE_HALF_VECTOR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1152 | break; |
| 1153 | case LIGHT_SPOT_DIRECTION: |
| 1154 | state_tokens[2] = STATE_SPOT_DIRECTION; |
| 1155 | break; |
| 1156 | } |
| 1157 | break; |
| 1158 | |
| 1159 | case STATE_LIGHT_MODEL: |
| 1160 | switch (*(*inst)++) { |
| 1161 | case LIGHT_MODEL_AMBIENT: |
| 1162 | state_tokens[0] = STATE_LIGHTMODEL_AMBIENT; |
| 1163 | break; |
| 1164 | case LIGHT_MODEL_SCENECOLOR: |
| 1165 | state_tokens[0] = STATE_LIGHTMODEL_SCENECOLOR; |
| 1166 | state_tokens[1] = parse_face_type (inst); |
| 1167 | break; |
| 1168 | } |
| 1169 | break; |
| 1170 | |
| 1171 | case STATE_LIGHT_PROD: |
| 1172 | state_tokens[0] = STATE_LIGHTPROD; |
| 1173 | state_tokens[1] = parse_integer (inst, Program); |
| 1174 | |
| 1175 | /* Check the value of state_tokens[1] against the # of lights */ |
| 1176 | if (state_tokens[1] >= (GLint) ctx->Const.MaxLights) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1177 | program_error(ctx, Program->Position, "Invalid Light Number"); |
| 1178 | /* bad state_tokens[1] */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1179 | return 1; |
| 1180 | } |
| 1181 | |
| 1182 | state_tokens[2] = parse_face_type (inst); |
| 1183 | switch (*(*inst)++) { |
| 1184 | case LIGHT_PROD_AMBIENT: |
| 1185 | state_tokens[3] = STATE_AMBIENT; |
| 1186 | break; |
| 1187 | case LIGHT_PROD_DIFFUSE: |
| 1188 | state_tokens[3] = STATE_DIFFUSE; |
| 1189 | break; |
| 1190 | case LIGHT_PROD_SPECULAR: |
| 1191 | state_tokens[3] = STATE_SPECULAR; |
| 1192 | break; |
| 1193 | } |
| 1194 | break; |
| 1195 | |
| 1196 | |
| 1197 | case STATE_FOG: |
| 1198 | switch (*(*inst)++) { |
| 1199 | case FOG_COLOR: |
Brian | f1390a3 | 2007-02-23 17:11:01 -0700 | [diff] [blame] | 1200 | state_tokens[0] = STATE_FOG_COLOR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1201 | break; |
| 1202 | case FOG_PARAMS: |
Brian | f1390a3 | 2007-02-23 17:11:01 -0700 | [diff] [blame] | 1203 | state_tokens[0] = STATE_FOG_PARAMS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1204 | break; |
| 1205 | } |
| 1206 | break; |
| 1207 | |
| 1208 | case STATE_TEX_ENV: |
| 1209 | state_tokens[1] = parse_integer (inst, Program); |
| 1210 | switch (*(*inst)++) { |
| 1211 | case TEX_ENV_COLOR: |
| 1212 | state_tokens[0] = STATE_TEXENV_COLOR; |
| 1213 | break; |
| 1214 | } |
| 1215 | break; |
| 1216 | |
| 1217 | case STATE_TEX_GEN: |
| 1218 | { |
| 1219 | GLuint type, coord; |
| 1220 | |
| 1221 | state_tokens[0] = STATE_TEXGEN; |
| 1222 | /*state_tokens[1] = parse_integer (inst, Program);*/ /* Texture Unit */ |
| 1223 | |
| 1224 | if (parse_texcoord_num (ctx, inst, Program, &coord)) |
| 1225 | return 1; |
| 1226 | state_tokens[1] = coord; |
| 1227 | |
| 1228 | /* EYE or OBJECT */ |
| 1229 | type = *(*inst++); |
| 1230 | |
| 1231 | /* 0 - s, 1 - t, 2 - r, 3 - q */ |
| 1232 | coord = *(*inst++); |
| 1233 | |
| 1234 | if (type == TEX_GEN_EYE) { |
| 1235 | switch (coord) { |
| 1236 | case COMPONENT_X: |
| 1237 | state_tokens[2] = STATE_TEXGEN_EYE_S; |
| 1238 | break; |
| 1239 | case COMPONENT_Y: |
| 1240 | state_tokens[2] = STATE_TEXGEN_EYE_T; |
| 1241 | break; |
| 1242 | case COMPONENT_Z: |
| 1243 | state_tokens[2] = STATE_TEXGEN_EYE_R; |
| 1244 | break; |
| 1245 | case COMPONENT_W: |
| 1246 | state_tokens[2] = STATE_TEXGEN_EYE_Q; |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | else { |
| 1251 | switch (coord) { |
| 1252 | case COMPONENT_X: |
| 1253 | state_tokens[2] = STATE_TEXGEN_OBJECT_S; |
| 1254 | break; |
| 1255 | case COMPONENT_Y: |
| 1256 | state_tokens[2] = STATE_TEXGEN_OBJECT_T; |
| 1257 | break; |
| 1258 | case COMPONENT_Z: |
| 1259 | state_tokens[2] = STATE_TEXGEN_OBJECT_R; |
| 1260 | break; |
| 1261 | case COMPONENT_W: |
| 1262 | state_tokens[2] = STATE_TEXGEN_OBJECT_Q; |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | break; |
| 1268 | |
| 1269 | case STATE_DEPTH: |
| 1270 | switch (*(*inst)++) { |
| 1271 | case DEPTH_RANGE: |
| 1272 | state_tokens[0] = STATE_DEPTH_RANGE; |
| 1273 | break; |
| 1274 | } |
| 1275 | break; |
| 1276 | |
| 1277 | case STATE_CLIP_PLANE: |
| 1278 | state_tokens[0] = STATE_CLIPPLANE; |
| 1279 | state_tokens[1] = parse_integer (inst, Program); |
Brian | aa9d22a | 2007-02-23 11:21:03 -0700 | [diff] [blame] | 1280 | if (parse_clipplane_num (ctx, inst, Program, |
| 1281 | (GLint *) &state_tokens[1])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1282 | return 1; |
| 1283 | break; |
| 1284 | |
| 1285 | case STATE_POINT: |
| 1286 | switch (*(*inst++)) { |
| 1287 | case POINT_SIZE: |
Brian | 776bc9c | 2007-02-22 09:29:46 -0700 | [diff] [blame] | 1288 | state_tokens[0] = STATE_POINT_SIZE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | |
| 1291 | case POINT_ATTENUATION: |
Brian | 776bc9c | 2007-02-22 09:29:46 -0700 | [diff] [blame] | 1292 | state_tokens[0] = STATE_POINT_ATTENUATION; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1293 | break; |
| 1294 | } |
| 1295 | break; |
| 1296 | |
| 1297 | /* XXX: I think this is the correct format for a matrix row */ |
| 1298 | case STATE_MATRIX_ROWS: |
Brian | aa9d22a | 2007-02-23 11:21:03 -0700 | [diff] [blame] | 1299 | if (parse_matrix(ctx, inst, Program, |
| 1300 | (GLint *) &state_tokens[0], |
| 1301 | (GLint *) &state_tokens[1], |
| 1302 | (GLint *) &state_tokens[4])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1303 | return 1; |
| 1304 | |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1305 | state_tokens[2] = parse_integer (inst, Program); /* The first row to grab */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1306 | |
| 1307 | if ((**inst) != 0) { /* Either the last row, 0 */ |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1308 | state_tokens[3] = parse_integer (inst, Program); |
| 1309 | if (state_tokens[3] < state_tokens[2]) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1310 | program_error(ctx, Program->Position, |
| 1311 | "Second matrix index less than the first"); |
| 1312 | /* state_tokens[4] vs. state_tokens[3] */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1313 | return 1; |
| 1314 | } |
| 1315 | } |
| 1316 | else { |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1317 | state_tokens[3] = state_tokens[2]; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1318 | (*inst)++; |
| 1319 | } |
| 1320 | break; |
| 1321 | } |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * This parses a state string (rather, the binary version of it) into |
| 1328 | * a 6-token similar for the state fetching code in program.c |
| 1329 | * |
| 1330 | * One might ask, why fetch these parameters into just like you fetch |
| 1331 | * state when they are already stored in other places? |
| 1332 | * |
| 1333 | * Because of array offsets -> We can stick env/local parameters in the |
| 1334 | * middle of a parameter array and then index someplace into the array |
| 1335 | * when we execute. |
| 1336 | * |
| 1337 | * One optimization might be to only do this for the cases where the |
| 1338 | * env/local parameters end up inside of an array, and leave the |
| 1339 | * single parameters (or arrays of pure env/local pareameters) in their |
| 1340 | * respective register files. |
| 1341 | * |
| 1342 | * For ENV parameters, the format is: |
| 1343 | * state_tokens[0] = STATE_FRAGMENT_PROGRAM / STATE_VERTEX_PROGRAM |
| 1344 | * state_tokens[1] = STATE_ENV |
| 1345 | * state_tokens[2] = the parameter index |
| 1346 | * |
| 1347 | * for LOCAL parameters, the format is: |
| 1348 | * state_tokens[0] = STATE_FRAGMENT_PROGRAM / STATE_VERTEX_PROGRAM |
| 1349 | * state_tokens[1] = STATE_LOCAL |
| 1350 | * state_tokens[2] = the parameter index |
| 1351 | * |
| 1352 | * \param inst - the start in the binary arry to start working from |
| 1353 | * \param state_tokens - the storage for the 6-token state description |
| 1354 | * \return - 0 on sucess, 1 on failure |
| 1355 | */ |
| 1356 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1357 | parse_program_single_item (GLcontext * ctx, const GLubyte ** inst, |
Brian | aa9d22a | 2007-02-23 11:21:03 -0700 | [diff] [blame] | 1358 | struct arb_program *Program, |
| 1359 | gl_state_index state_tokens[STATE_LENGTH]) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1360 | { |
| 1361 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) |
| 1362 | state_tokens[0] = STATE_FRAGMENT_PROGRAM; |
| 1363 | else |
| 1364 | state_tokens[0] = STATE_VERTEX_PROGRAM; |
| 1365 | |
| 1366 | |
| 1367 | switch (*(*inst)++) { |
| 1368 | case PROGRAM_PARAM_ENV: |
| 1369 | state_tokens[1] = STATE_ENV; |
| 1370 | state_tokens[2] = parse_integer (inst, Program); |
| 1371 | |
| 1372 | /* Check state_tokens[2] against the number of ENV parameters available */ |
| 1373 | if (((Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) && |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1374 | (state_tokens[2] >= (GLint) ctx->Const.FragmentProgram.MaxEnvParams)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1375 | || |
| 1376 | ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) && |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1377 | (state_tokens[2] >= (GLint) ctx->Const.VertexProgram.MaxEnvParams))) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1378 | program_error(ctx, Program->Position, |
| 1379 | "Invalid Program Env Parameter"); |
| 1380 | /* bad state_tokens[2] */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1381 | return 1; |
| 1382 | } |
| 1383 | |
| 1384 | break; |
| 1385 | |
| 1386 | case PROGRAM_PARAM_LOCAL: |
| 1387 | state_tokens[1] = STATE_LOCAL; |
| 1388 | state_tokens[2] = parse_integer (inst, Program); |
| 1389 | |
| 1390 | /* Check state_tokens[2] against the number of LOCAL parameters available */ |
| 1391 | if (((Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) && |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1392 | (state_tokens[2] >= (GLint) ctx->Const.FragmentProgram.MaxLocalParams)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1393 | || |
| 1394 | ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) && |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1395 | (state_tokens[2] >= (GLint) ctx->Const.VertexProgram.MaxLocalParams))) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1396 | program_error(ctx, Program->Position, |
| 1397 | "Invalid Program Local Parameter"); |
| 1398 | /* bad state_tokens[2] */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1399 | return 1; |
| 1400 | } |
| 1401 | break; |
| 1402 | } |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * For ARB_vertex_program, programs are not allowed to use both an explicit |
| 1409 | * vertex attribute and a generic vertex attribute corresponding to the same |
| 1410 | * state. See section 2.14.3.1 of the GL_ARB_vertex_program spec. |
| 1411 | * |
| 1412 | * This will walk our var_cache and make sure that nobody does anything fishy. |
| 1413 | * |
| 1414 | * \return 0 on sucess, 1 on error |
| 1415 | */ |
| 1416 | static GLuint |
| 1417 | generic_attrib_check(struct var_cache *vc_head) |
| 1418 | { |
| 1419 | int a; |
| 1420 | struct var_cache *curr; |
| 1421 | GLboolean explicitAttrib[MAX_VERTEX_PROGRAM_ATTRIBS], |
| 1422 | genericAttrib[MAX_VERTEX_PROGRAM_ATTRIBS]; |
| 1423 | |
| 1424 | for (a=0; a<MAX_VERTEX_PROGRAM_ATTRIBS; a++) { |
| 1425 | explicitAttrib[a] = GL_FALSE; |
| 1426 | genericAttrib[a] = GL_FALSE; |
| 1427 | } |
| 1428 | |
| 1429 | curr = vc_head; |
| 1430 | while (curr) { |
| 1431 | if (curr->type == vt_attrib) { |
| 1432 | if (curr->attrib_is_generic) |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1433 | genericAttrib[ curr->attrib_binding ] = GL_TRUE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1434 | else |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1435 | explicitAttrib[ curr->attrib_binding ] = GL_TRUE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | curr = curr->next; |
| 1439 | } |
| 1440 | |
| 1441 | for (a=0; a<MAX_VERTEX_PROGRAM_ATTRIBS; a++) { |
| 1442 | if ((explicitAttrib[a]) && (genericAttrib[a])) |
| 1443 | return 1; |
| 1444 | } |
| 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | /** |
| 1450 | * This will handle the binding side of an ATTRIB var declaration |
| 1451 | * |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1452 | * \param inputReg returns the input register index, one of the |
| 1453 | * VERT_ATTRIB_* or FRAG_ATTRIB_* values. |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1454 | * \return returns 0 on success, 1 on error |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1455 | */ |
| 1456 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1457 | parse_attrib_binding(GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1458 | struct arb_program *Program, |
| 1459 | GLuint *inputReg, GLuint *is_generic) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1460 | { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1461 | GLint err = 0; |
| 1462 | |
| 1463 | *is_generic = 0; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1464 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1465 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
| 1466 | switch (*(*inst)++) { |
| 1467 | case FRAGMENT_ATTRIB_COLOR: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1468 | { |
| 1469 | GLint coord; |
| 1470 | err = parse_color_type (ctx, inst, Program, &coord); |
| 1471 | *inputReg = FRAG_ATTRIB_COL0 + coord; |
| 1472 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1473 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1474 | case FRAGMENT_ATTRIB_TEXCOORD: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1475 | { |
Brian | 8fa6f73 | 2007-02-01 09:24:41 -0700 | [diff] [blame] | 1476 | GLuint texcoord = 0; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1477 | err = parse_texcoord_num (ctx, inst, Program, &texcoord); |
| 1478 | *inputReg = FRAG_ATTRIB_TEX0 + texcoord; |
| 1479 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1480 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1481 | case FRAGMENT_ATTRIB_FOGCOORD: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1482 | *inputReg = FRAG_ATTRIB_FOGC; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1483 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1484 | case FRAGMENT_ATTRIB_POSITION: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1485 | *inputReg = FRAG_ATTRIB_WPOS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1486 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1487 | default: |
| 1488 | err = 1; |
| 1489 | break; |
| 1490 | } |
| 1491 | } |
| 1492 | else { |
| 1493 | switch (*(*inst)++) { |
| 1494 | case VERTEX_ATTRIB_POSITION: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1495 | *inputReg = VERT_ATTRIB_POS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | |
| 1498 | case VERTEX_ATTRIB_WEIGHT: |
| 1499 | { |
| 1500 | GLint weight; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1501 | err = parse_weight_num (ctx, inst, Program, &weight); |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1502 | *inputReg = VERT_ATTRIB_WEIGHT; |
Brian Paul | 3a55750 | 2006-09-05 23:15:29 +0000 | [diff] [blame] | 1503 | #if 1 |
| 1504 | /* hack for Warcraft (see bug 8060) */ |
| 1505 | _mesa_warning(ctx, "Application error: vertex program uses 'vertex.weight' but GL_ARB_vertex_blend not supported."); |
Brian Paul | d9aebd8 | 2006-09-06 05:03:47 +0000 | [diff] [blame] | 1506 | break; |
Brian Paul | 3a55750 | 2006-09-05 23:15:29 +0000 | [diff] [blame] | 1507 | #else |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1508 | program_error(ctx, Program->Position, |
| 1509 | "ARB_vertex_blend not supported"); |
Brian Paul | d9aebd8 | 2006-09-06 05:03:47 +0000 | [diff] [blame] | 1510 | return 1; |
Brian Paul | 3a55750 | 2006-09-05 23:15:29 +0000 | [diff] [blame] | 1511 | #endif |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1512 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1513 | |
| 1514 | case VERTEX_ATTRIB_NORMAL: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1515 | *inputReg = VERT_ATTRIB_NORMAL; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1516 | break; |
| 1517 | |
| 1518 | case VERTEX_ATTRIB_COLOR: |
| 1519 | { |
| 1520 | GLint color; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1521 | err = parse_color_type (ctx, inst, Program, &color); |
| 1522 | if (color) { |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1523 | *inputReg = VERT_ATTRIB_COLOR1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1524 | } |
| 1525 | else { |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1526 | *inputReg = VERT_ATTRIB_COLOR0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | break; |
| 1530 | |
| 1531 | case VERTEX_ATTRIB_FOGCOORD: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1532 | *inputReg = VERT_ATTRIB_FOG; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | |
| 1535 | case VERTEX_ATTRIB_TEXCOORD: |
| 1536 | { |
Brian | 8fa6f73 | 2007-02-01 09:24:41 -0700 | [diff] [blame] | 1537 | GLuint unit = 0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1538 | err = parse_texcoord_num (ctx, inst, Program, &unit); |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1539 | *inputReg = VERT_ATTRIB_TEX0 + unit; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1540 | } |
| 1541 | break; |
| 1542 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1543 | case VERTEX_ATTRIB_MATRIXINDEX: |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1544 | /* Not supported at this time */ |
| 1545 | { |
| 1546 | const char *msg = "ARB_palette_matrix not supported"; |
| 1547 | parse_integer (inst, Program); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1548 | program_error(ctx, Program->Position, msg); |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 1549 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1550 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1551 | |
| 1552 | case VERTEX_ATTRIB_GENERIC: |
| 1553 | { |
| 1554 | GLuint attrib; |
Tilman Sauerbeck | 6c33475 | 2006-06-28 16:26:20 +0000 | [diff] [blame] | 1555 | err = parse_generic_attrib_num(ctx, inst, Program, &attrib); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1556 | if (!err) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1557 | *is_generic = 1; |
Brian Paul | 095c669 | 2006-04-25 00:21:32 +0000 | [diff] [blame] | 1558 | /* Add VERT_ATTRIB_GENERIC0 here because ARB_vertex_program's |
| 1559 | * attributes do not alias the conventional vertex |
| 1560 | * attributes. |
| 1561 | */ |
| 1562 | if (attrib > 0) |
| 1563 | *inputReg = attrib + VERT_ATTRIB_GENERIC0; |
Brian Paul | 919f6a0 | 2006-05-29 14:37:56 +0000 | [diff] [blame] | 1564 | else |
| 1565 | *inputReg = 0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | break; |
| 1569 | |
| 1570 | default: |
| 1571 | err = 1; |
| 1572 | break; |
| 1573 | } |
| 1574 | } |
| 1575 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1576 | if (err) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1577 | program_error(ctx, Program->Position, "Bad attribute binding"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1578 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1579 | |
| 1580 | return err; |
| 1581 | } |
| 1582 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1583 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1584 | /** |
| 1585 | * This translates between a binary token for an output variable type |
| 1586 | * and the mesa token for the same thing. |
| 1587 | * |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1588 | * \param inst The parsed tokens |
| 1589 | * \param outputReg Returned index/number of the output register, |
Brian Paul | 90ebb58 | 2005-11-02 18:06:12 +0000 | [diff] [blame] | 1590 | * one of the VERT_RESULT_* or FRAG_RESULT_* values. |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1591 | */ |
| 1592 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1593 | parse_result_binding(GLcontext *ctx, const GLubyte **inst, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1594 | GLuint *outputReg, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1595 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1596 | const GLubyte token = *(*inst)++; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1597 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1598 | switch (token) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1599 | case FRAGMENT_RESULT_COLOR: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1600 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1601 | GLuint out_color; |
| 1602 | |
Brian Paul | be76b7f | 2004-10-04 14:40:05 +0000 | [diff] [blame] | 1603 | /* This gets result of the color buffer we're supposed to |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1604 | * draw into. This pertains to GL_ARB_draw_buffers. |
Brian Paul | be76b7f | 2004-10-04 14:40:05 +0000 | [diff] [blame] | 1605 | */ |
| 1606 | parse_output_color_num(ctx, inst, Program, &out_color); |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1607 | ASSERT(out_color < MAX_DRAW_BUFFERS); |
Brian Paul | 90ebb58 | 2005-11-02 18:06:12 +0000 | [diff] [blame] | 1608 | *outputReg = FRAG_RESULT_COLR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1609 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1610 | else { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1611 | /* for vtx programs, this is VERTEX_RESULT_POSITION */ |
| 1612 | *outputReg = VERT_RESULT_HPOS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1613 | } |
| 1614 | break; |
| 1615 | |
| 1616 | case FRAGMENT_RESULT_DEPTH: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1617 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1618 | /* for frag programs, this is FRAGMENT_RESULT_DEPTH */ |
Brian Paul | 90ebb58 | 2005-11-02 18:06:12 +0000 | [diff] [blame] | 1619 | *outputReg = FRAG_RESULT_DEPR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1620 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1621 | else { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1622 | /* for vtx programs, this is VERTEX_RESULT_COLOR */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1623 | GLint color_type; |
| 1624 | GLuint face_type = parse_face_type(inst); |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1625 | GLint err = parse_color_type(ctx, inst, Program, &color_type); |
| 1626 | if (err) |
| 1627 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1628 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1629 | if (face_type) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1630 | /* back face */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1631 | if (color_type) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1632 | *outputReg = VERT_RESULT_BFC1; /* secondary color */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1633 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1634 | else { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1635 | *outputReg = VERT_RESULT_BFC0; /* primary color */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1636 | } |
| 1637 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1638 | else { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1639 | /* front face */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1640 | if (color_type) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1641 | *outputReg = VERT_RESULT_COL1; /* secondary color */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1642 | } |
| 1643 | /* primary color */ |
| 1644 | else { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1645 | *outputReg = VERT_RESULT_COL0; /* primary color */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | break; |
| 1650 | |
| 1651 | case VERTEX_RESULT_FOGCOORD: |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1652 | *outputReg = VERT_RESULT_FOGC; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1653 | break; |
| 1654 | |
| 1655 | case VERTEX_RESULT_POINTSIZE: |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1656 | *outputReg = VERT_RESULT_PSIZ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1657 | break; |
| 1658 | |
| 1659 | case VERTEX_RESULT_TEXCOORD: |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1660 | { |
| 1661 | GLuint unit; |
| 1662 | if (parse_texcoord_num (ctx, inst, Program, &unit)) |
| 1663 | return 1; |
| 1664 | *outputReg = VERT_RESULT_TEX0 + unit; |
| 1665 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1666 | break; |
| 1667 | } |
| 1668 | |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1669 | Program->Base.OutputsWritten |= (1 << *outputReg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1674 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1675 | /** |
| 1676 | * This handles the declaration of ATTRIB variables |
| 1677 | * |
| 1678 | * XXX: Still needs |
| 1679 | * parse_vert_attrib_binding(), or something like that |
| 1680 | * |
| 1681 | * \return 0 on sucess, 1 on error |
| 1682 | */ |
| 1683 | static GLint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1684 | parse_attrib (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1685 | struct arb_program *Program) |
| 1686 | { |
| 1687 | GLuint found; |
| 1688 | char *error_msg; |
| 1689 | struct var_cache *attrib_var; |
| 1690 | |
| 1691 | attrib_var = parse_string (inst, vc_head, Program, &found); |
| 1692 | Program->Position = parse_position (inst); |
| 1693 | if (found) { |
| 1694 | error_msg = (char *) |
| 1695 | _mesa_malloc (_mesa_strlen ((char *) attrib_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 1696 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1697 | attrib_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1698 | program_error(ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1699 | _mesa_free (error_msg); |
| 1700 | return 1; |
| 1701 | } |
| 1702 | |
| 1703 | attrib_var->type = vt_attrib; |
| 1704 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1705 | if (parse_attrib_binding(ctx, inst, Program, &attrib_var->attrib_binding, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1706 | &attrib_var->attrib_is_generic)) |
| 1707 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1708 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1709 | if (generic_attrib_check(*vc_head)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1710 | program_error(ctx, Program->Position, |
| 1711 | "Cannot use both a generic vertex attribute " |
| 1712 | "and a specific attribute of the same type"); |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1713 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | Program->Base.NumAttributes++; |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * \param use -- TRUE if we're called when declaring implicit parameters, |
| 1722 | * FALSE if we're declaraing variables. This has to do with |
| 1723 | * if we get a signed or unsigned float for scalar constants |
| 1724 | */ |
| 1725 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1726 | parse_param_elements (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1727 | struct var_cache *param_var, |
| 1728 | struct arb_program *Program, GLboolean use) |
| 1729 | { |
| 1730 | GLint idx; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1731 | GLuint err = 0; |
Brian | aa9d22a | 2007-02-23 11:21:03 -0700 | [diff] [blame] | 1732 | gl_state_index state_tokens[STATE_LENGTH]; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1733 | GLfloat const_values[4]; |
| 1734 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1735 | switch (*(*inst)++) { |
| 1736 | case PARAM_STATE_ELEMENT: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1737 | if (parse_state_single_item (ctx, inst, Program, state_tokens)) |
| 1738 | return 1; |
| 1739 | |
| 1740 | /* If we adding STATE_MATRIX that has multiple rows, we need to |
| 1741 | * unroll it and call _mesa_add_state_reference() for each row |
| 1742 | */ |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1743 | if ((state_tokens[0] == STATE_MODELVIEW_MATRIX || |
| 1744 | state_tokens[0] == STATE_PROJECTION_MATRIX || |
| 1745 | state_tokens[0] == STATE_MVP_MATRIX || |
| 1746 | state_tokens[0] == STATE_TEXTURE_MATRIX || |
| 1747 | state_tokens[0] == STATE_PROGRAM_MATRIX) |
| 1748 | && (state_tokens[2] != state_tokens[3])) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1749 | GLint row; |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1750 | const GLint first_row = state_tokens[2]; |
| 1751 | const GLint last_row = state_tokens[3]; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1752 | |
| 1753 | for (row = first_row; row <= last_row; row++) { |
Brian | 6531952 | 2007-02-21 11:08:21 -0700 | [diff] [blame] | 1754 | state_tokens[2] = state_tokens[3] = row; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1755 | |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1756 | idx = _mesa_add_state_reference(Program->Base.Parameters, |
| 1757 | state_tokens); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1758 | if (param_var->param_binding_begin == ~0U) |
| 1759 | param_var->param_binding_begin = idx; |
| 1760 | param_var->param_binding_length++; |
| 1761 | Program->Base.NumParameters++; |
| 1762 | } |
| 1763 | } |
| 1764 | else { |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1765 | idx = _mesa_add_state_reference(Program->Base.Parameters, |
| 1766 | state_tokens); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1767 | if (param_var->param_binding_begin == ~0U) |
| 1768 | param_var->param_binding_begin = idx; |
| 1769 | param_var->param_binding_length++; |
| 1770 | Program->Base.NumParameters++; |
| 1771 | } |
| 1772 | break; |
| 1773 | |
| 1774 | case PARAM_PROGRAM_ELEMENT: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1775 | if (parse_program_single_item (ctx, inst, Program, state_tokens)) |
| 1776 | return 1; |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1777 | idx = _mesa_add_state_reference (Program->Base.Parameters, state_tokens); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1778 | if (param_var->param_binding_begin == ~0U) |
| 1779 | param_var->param_binding_begin = idx; |
| 1780 | param_var->param_binding_length++; |
| 1781 | Program->Base.NumParameters++; |
| 1782 | |
| 1783 | /* Check if there is more: 0 -> we're done, else its an integer */ |
| 1784 | if (**inst) { |
| 1785 | GLuint out_of_range, new_idx; |
| 1786 | GLuint start_idx = state_tokens[2] + 1; |
| 1787 | GLuint end_idx = parse_integer (inst, Program); |
| 1788 | |
| 1789 | out_of_range = 0; |
| 1790 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
| 1791 | if (((state_tokens[1] == STATE_ENV) |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1792 | && (end_idx >= ctx->Const.FragmentProgram.MaxEnvParams)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1793 | || ((state_tokens[1] == STATE_LOCAL) |
| 1794 | && (end_idx >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1795 | ctx->Const.FragmentProgram.MaxLocalParams))) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1796 | out_of_range = 1; |
| 1797 | } |
| 1798 | else { |
| 1799 | if (((state_tokens[1] == STATE_ENV) |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1800 | && (end_idx >= ctx->Const.VertexProgram.MaxEnvParams)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1801 | || ((state_tokens[1] == STATE_LOCAL) |
| 1802 | && (end_idx >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1803 | ctx->Const.VertexProgram.MaxLocalParams))) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1804 | out_of_range = 1; |
| 1805 | } |
| 1806 | if (out_of_range) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1807 | program_error(ctx, Program->Position, |
| 1808 | "Invalid Program Parameter"); /*end_idx*/ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1809 | return 1; |
| 1810 | } |
| 1811 | |
| 1812 | for (new_idx = start_idx; new_idx <= end_idx; new_idx++) { |
| 1813 | state_tokens[2] = new_idx; |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1814 | idx = _mesa_add_state_reference(Program->Base.Parameters, |
| 1815 | state_tokens); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1816 | param_var->param_binding_length++; |
| 1817 | Program->Base.NumParameters++; |
| 1818 | } |
| 1819 | } |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1820 | else { |
| 1821 | (*inst)++; |
| 1822 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1823 | break; |
| 1824 | |
| 1825 | case PARAM_CONSTANT: |
Brian | 7cbfe8c | 2008-01-18 12:45:55 -0700 | [diff] [blame] | 1826 | /* parsing something like {1.0, 2.0, 3.0, 4.0} */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1827 | parse_constant (inst, const_values, Program, use); |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 1828 | idx = _mesa_add_named_constant(Program->Base.Parameters, |
| 1829 | (char *) param_var->name, |
Brian Paul | 0c6723a | 2006-11-15 23:38:02 +0000 | [diff] [blame] | 1830 | const_values, 4); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1831 | if (param_var->param_binding_begin == ~0U) |
| 1832 | param_var->param_binding_begin = idx; |
Brian | 7cbfe8c | 2008-01-18 12:45:55 -0700 | [diff] [blame] | 1833 | param_var->param_binding_type = PROGRAM_CONSTANT; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1834 | param_var->param_binding_length++; |
| 1835 | Program->Base.NumParameters++; |
| 1836 | break; |
| 1837 | |
| 1838 | default: |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1839 | program_error(ctx, Program->Position, |
| 1840 | "Unexpected token (in parse_param_elements())"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1841 | return 1; |
| 1842 | } |
| 1843 | |
| 1844 | /* Make sure we haven't blown past our parameter limits */ |
| 1845 | if (((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) && |
| 1846 | (Program->Base.NumParameters >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1847 | ctx->Const.VertexProgram.MaxLocalParams)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1848 | || ((Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) |
| 1849 | && (Program->Base.NumParameters >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1850 | ctx->Const.FragmentProgram.MaxLocalParams))) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1851 | program_error(ctx, Program->Position, "Too many parameter variables"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1852 | return 1; |
| 1853 | } |
| 1854 | |
| 1855 | return err; |
| 1856 | } |
| 1857 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1858 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1859 | /** |
| 1860 | * This picks out PARAM program parameter bindings. |
| 1861 | * |
| 1862 | * XXX: This needs to be stressed & tested |
| 1863 | * |
| 1864 | * \return 0 on sucess, 1 on error |
| 1865 | */ |
| 1866 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1867 | parse_param (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1868 | struct arb_program *Program) |
| 1869 | { |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 1870 | GLuint found, err; |
| 1871 | GLint specified_length; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1872 | struct var_cache *param_var; |
| 1873 | |
| 1874 | err = 0; |
| 1875 | param_var = parse_string (inst, vc_head, Program, &found); |
| 1876 | Program->Position = parse_position (inst); |
| 1877 | |
| 1878 | if (found) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1879 | char *error_msg = (char *) |
| 1880 | _mesa_malloc (_mesa_strlen ((char *) param_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 1881 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1882 | param_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1883 | program_error (ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1884 | _mesa_free (error_msg); |
| 1885 | return 1; |
| 1886 | } |
| 1887 | |
| 1888 | specified_length = parse_integer (inst, Program); |
| 1889 | |
| 1890 | if (specified_length < 0) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1891 | program_error(ctx, Program->Position, "Negative parameter array length"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1892 | return 1; |
| 1893 | } |
| 1894 | |
| 1895 | param_var->type = vt_param; |
| 1896 | param_var->param_binding_length = 0; |
| 1897 | |
| 1898 | /* Right now, everything is shoved into the main state register file. |
| 1899 | * |
| 1900 | * In the future, it would be nice to leave things ENV/LOCAL params |
| 1901 | * in their respective register files, if possible |
| 1902 | */ |
| 1903 | param_var->param_binding_type = PROGRAM_STATE_VAR; |
| 1904 | |
| 1905 | /* Remember to: |
| 1906 | * * - add each guy to the parameter list |
| 1907 | * * - increment the param_var->param_binding_len |
| 1908 | * * - store the param_var->param_binding_begin for the first one |
| 1909 | * * - compare the actual len to the specified len at the end |
| 1910 | */ |
| 1911 | while (**inst != PARAM_NULL) { |
| 1912 | if (parse_param_elements (ctx, inst, param_var, Program, GL_FALSE)) |
| 1913 | return 1; |
| 1914 | } |
| 1915 | |
| 1916 | /* Test array length here! */ |
| 1917 | if (specified_length) { |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 1918 | if (specified_length != (int)param_var->param_binding_length) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1919 | program_error(ctx, Program->Position, |
| 1920 | "Declared parameter array length does not match parameter list"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | (*inst)++; |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | /** |
| 1930 | * |
| 1931 | */ |
| 1932 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1933 | parse_param_use (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1934 | struct arb_program *Program, struct var_cache **new_var) |
| 1935 | { |
| 1936 | struct var_cache *param_var; |
| 1937 | |
| 1938 | /* First, insert a dummy entry into the var_cache */ |
| 1939 | var_cache_create (¶m_var); |
Brian Paul | 6a769d9 | 2006-04-28 15:42:15 +0000 | [diff] [blame] | 1940 | param_var->name = (const GLubyte *) " "; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1941 | param_var->type = vt_param; |
| 1942 | |
| 1943 | param_var->param_binding_length = 0; |
| 1944 | /* Don't fill in binding_begin; We use the default value of -1 |
| 1945 | * to tell if its already initialized, elsewhere. |
| 1946 | * |
| 1947 | * param_var->param_binding_begin = 0; |
| 1948 | */ |
| 1949 | param_var->param_binding_type = PROGRAM_STATE_VAR; |
| 1950 | |
| 1951 | var_cache_append (vc_head, param_var); |
| 1952 | |
| 1953 | /* Then fill it with juicy parameter goodness */ |
| 1954 | if (parse_param_elements (ctx, inst, param_var, Program, GL_TRUE)) |
| 1955 | return 1; |
| 1956 | |
| 1957 | *new_var = param_var; |
| 1958 | |
| 1959 | return 0; |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | /** |
| 1964 | * This handles the declaration of TEMP variables |
| 1965 | * |
| 1966 | * \return 0 on sucess, 1 on error |
| 1967 | */ |
| 1968 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1969 | parse_temp (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1970 | struct arb_program *Program) |
| 1971 | { |
| 1972 | GLuint found; |
| 1973 | struct var_cache *temp_var; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1974 | |
| 1975 | while (**inst != 0) { |
| 1976 | temp_var = parse_string (inst, vc_head, Program, &found); |
| 1977 | Program->Position = parse_position (inst); |
| 1978 | if (found) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 1979 | char *error_msg = (char *) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1980 | _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 1981 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1982 | temp_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1983 | program_error(ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1984 | _mesa_free (error_msg); |
| 1985 | return 1; |
| 1986 | } |
| 1987 | |
| 1988 | temp_var->type = vt_temp; |
| 1989 | |
| 1990 | if (((Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) && |
| 1991 | (Program->Base.NumTemporaries >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1992 | ctx->Const.FragmentProgram.MaxTemps)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1993 | || ((Program->Base.Target == GL_VERTEX_PROGRAM_ARB) |
| 1994 | && (Program->Base.NumTemporaries >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 1995 | ctx->Const.VertexProgram.MaxTemps))) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 1996 | program_error(ctx, Program->Position, |
| 1997 | "Too many TEMP variables declared"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 1998 | return 1; |
| 1999 | } |
| 2000 | |
| 2001 | temp_var->temp_binding = Program->Base.NumTemporaries; |
| 2002 | Program->Base.NumTemporaries++; |
| 2003 | } |
| 2004 | (*inst)++; |
| 2005 | |
| 2006 | return 0; |
| 2007 | } |
| 2008 | |
| 2009 | /** |
| 2010 | * This handles variables of the OUTPUT variety |
| 2011 | * |
| 2012 | * \return 0 on sucess, 1 on error |
| 2013 | */ |
| 2014 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2015 | parse_output (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2016 | struct arb_program *Program) |
| 2017 | { |
| 2018 | GLuint found; |
| 2019 | struct var_cache *output_var; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2020 | GLuint err; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2021 | |
| 2022 | output_var = parse_string (inst, vc_head, Program, &found); |
| 2023 | Program->Position = parse_position (inst); |
| 2024 | if (found) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2025 | char *error_msg = (char *) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2026 | _mesa_malloc (_mesa_strlen ((char *) output_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 2027 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2028 | output_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2029 | program_error (ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2030 | _mesa_free (error_msg); |
| 2031 | return 1; |
| 2032 | } |
| 2033 | |
| 2034 | output_var->type = vt_output; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2035 | |
| 2036 | err = parse_result_binding(ctx, inst, &output_var->output_binding, Program); |
| 2037 | return err; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /** |
| 2041 | * This handles variables of the ALIAS kind |
| 2042 | * |
| 2043 | * \return 0 on sucess, 1 on error |
| 2044 | */ |
| 2045 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2046 | parse_alias (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2047 | struct arb_program *Program) |
| 2048 | { |
| 2049 | GLuint found; |
| 2050 | struct var_cache *temp_var; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2051 | |
| 2052 | temp_var = parse_string (inst, vc_head, Program, &found); |
| 2053 | Program->Position = parse_position (inst); |
| 2054 | |
| 2055 | if (found) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2056 | char *error_msg = (char *) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2057 | _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 2058 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2059 | temp_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2060 | program_error(ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2061 | _mesa_free (error_msg); |
| 2062 | return 1; |
| 2063 | } |
| 2064 | |
| 2065 | temp_var->type = vt_alias; |
| 2066 | temp_var->alias_binding = parse_string (inst, vc_head, Program, &found); |
| 2067 | Program->Position = parse_position (inst); |
| 2068 | |
| 2069 | if (!found) |
| 2070 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2071 | char *error_msg = (char *) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2072 | _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); |
| 2073 | _mesa_sprintf (error_msg, "Alias value %s is not defined", |
| 2074 | temp_var->alias_binding->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2075 | program_error (ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2076 | _mesa_free (error_msg); |
| 2077 | return 1; |
| 2078 | } |
| 2079 | |
| 2080 | return 0; |
| 2081 | } |
| 2082 | |
| 2083 | /** |
| 2084 | * This handles variables of the ADDRESS kind |
| 2085 | * |
| 2086 | * \return 0 on sucess, 1 on error |
| 2087 | */ |
| 2088 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2089 | parse_address (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2090 | struct arb_program *Program) |
| 2091 | { |
| 2092 | GLuint found; |
| 2093 | struct var_cache *temp_var; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2094 | |
| 2095 | while (**inst != 0) { |
| 2096 | temp_var = parse_string (inst, vc_head, Program, &found); |
| 2097 | Program->Position = parse_position (inst); |
| 2098 | if (found) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2099 | char *error_msg = (char *) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2100 | _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); |
Brian | 06b019d | 2008-01-18 12:47:20 -0700 | [diff] [blame] | 2101 | _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2102 | temp_var->name); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2103 | program_error (ctx, Program->Position, error_msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2104 | _mesa_free (error_msg); |
| 2105 | return 1; |
| 2106 | } |
| 2107 | |
| 2108 | temp_var->type = vt_address; |
| 2109 | |
| 2110 | if (Program->Base.NumAddressRegs >= |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 2111 | ctx->Const.VertexProgram.MaxAddressRegs) { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2112 | const char *msg = "Too many ADDRESS variables declared"; |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2113 | program_error(ctx, Program->Position, msg); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2114 | return 1; |
| 2115 | } |
| 2116 | |
| 2117 | temp_var->address_binding = Program->Base.NumAddressRegs; |
| 2118 | Program->Base.NumAddressRegs++; |
| 2119 | } |
| 2120 | (*inst)++; |
| 2121 | |
| 2122 | return 0; |
| 2123 | } |
| 2124 | |
| 2125 | /** |
| 2126 | * Parse a program declaration |
| 2127 | * |
| 2128 | * \return 0 on sucess, 1 on error |
| 2129 | */ |
| 2130 | static GLint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2131 | parse_declaration (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2132 | struct arb_program *Program) |
| 2133 | { |
| 2134 | GLint err = 0; |
| 2135 | |
| 2136 | switch (*(*inst)++) { |
| 2137 | case ADDRESS: |
| 2138 | err = parse_address (ctx, inst, vc_head, Program); |
| 2139 | break; |
| 2140 | |
| 2141 | case ALIAS: |
| 2142 | err = parse_alias (ctx, inst, vc_head, Program); |
| 2143 | break; |
| 2144 | |
| 2145 | case ATTRIB: |
| 2146 | err = parse_attrib (ctx, inst, vc_head, Program); |
| 2147 | break; |
| 2148 | |
| 2149 | case OUTPUT: |
| 2150 | err = parse_output (ctx, inst, vc_head, Program); |
| 2151 | break; |
| 2152 | |
| 2153 | case PARAM: |
| 2154 | err = parse_param (ctx, inst, vc_head, Program); |
| 2155 | break; |
| 2156 | |
| 2157 | case TEMP: |
| 2158 | err = parse_temp (ctx, inst, vc_head, Program); |
| 2159 | break; |
| 2160 | } |
| 2161 | |
| 2162 | return err; |
| 2163 | } |
| 2164 | |
| 2165 | /** |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2166 | * Handle the parsing out of a masked destination register, either for a |
| 2167 | * vertex or fragment program. |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2168 | * |
| 2169 | * If we are a vertex program, make sure we don't write to |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2170 | * result.position if we have specified that the program is |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2171 | * position invariant |
| 2172 | * |
| 2173 | * \param File - The register file we write to |
| 2174 | * \param Index - The register index we write to |
| 2175 | * \param WriteMask - The mask controlling which components we write (1->write) |
| 2176 | * |
| 2177 | * \return 0 on sucess, 1 on error |
| 2178 | */ |
| 2179 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2180 | parse_masked_dst_reg (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2181 | struct var_cache **vc_head, struct arb_program *Program, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2182 | enum register_file *File, GLuint *Index, GLint *WriteMask) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2183 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2184 | GLuint tmp, result; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2185 | struct var_cache *dst; |
| 2186 | |
| 2187 | /* We either have a result register specified, or a |
| 2188 | * variable that may or may not be writable |
| 2189 | */ |
| 2190 | switch (*(*inst)++) { |
| 2191 | case REGISTER_RESULT: |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2192 | if (parse_result_binding(ctx, inst, Index, Program)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2193 | return 1; |
| 2194 | *File = PROGRAM_OUTPUT; |
| 2195 | break; |
| 2196 | |
| 2197 | case REGISTER_ESTABLISHED_NAME: |
| 2198 | dst = parse_string (inst, vc_head, Program, &result); |
| 2199 | Program->Position = parse_position (inst); |
| 2200 | |
| 2201 | /* If the name has never been added to our symbol table, we're hosed */ |
| 2202 | if (!result) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2203 | program_error(ctx, Program->Position, "0: Undefined variable"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2204 | return 1; |
| 2205 | } |
| 2206 | |
| 2207 | switch (dst->type) { |
| 2208 | case vt_output: |
| 2209 | *File = PROGRAM_OUTPUT; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2210 | *Index = dst->output_binding; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2211 | break; |
| 2212 | |
| 2213 | case vt_temp: |
| 2214 | *File = PROGRAM_TEMPORARY; |
| 2215 | *Index = dst->temp_binding; |
| 2216 | break; |
| 2217 | |
| 2218 | /* If the var type is not vt_output or vt_temp, no go */ |
| 2219 | default: |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2220 | program_error(ctx, Program->Position, |
| 2221 | "Destination register is read only"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2222 | return 1; |
| 2223 | } |
| 2224 | break; |
| 2225 | |
| 2226 | default: |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2227 | program_error(ctx, Program->Position, |
| 2228 | "Unexpected opcode in parse_masked_dst_reg()"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2229 | return 1; |
| 2230 | } |
| 2231 | |
| 2232 | |
| 2233 | /* Position invariance test */ |
| 2234 | /* This test is done now in syntax portion - when position invariance OPTION |
| 2235 | is specified, "result.position" rule is disabled so there is no way |
| 2236 | to write the position |
| 2237 | */ |
| 2238 | /*if ((Program->HintPositionInvariant) && (*File == PROGRAM_OUTPUT) && |
| 2239 | (*Index == 0)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2240 | program_error(ctx, Program->Position, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2241 | "Vertex program specified position invariance and wrote vertex position"); |
| 2242 | }*/ |
| 2243 | |
| 2244 | /* And then the mask. |
| 2245 | * w,a -> bit 0 |
| 2246 | * z,b -> bit 1 |
| 2247 | * y,g -> bit 2 |
| 2248 | * x,r -> bit 3 |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2249 | * |
| 2250 | * ==> Need to reverse the order of bits for this! |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2251 | */ |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2252 | tmp = (GLint) *(*inst)++; |
| 2253 | *WriteMask = (((tmp>>3) & 0x1) | |
| 2254 | ((tmp>>1) & 0x2) | |
| 2255 | ((tmp<<1) & 0x4) | |
| 2256 | ((tmp<<3) & 0x8)); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2257 | |
| 2258 | return 0; |
| 2259 | } |
| 2260 | |
| 2261 | |
| 2262 | /** |
| 2263 | * Handle the parsing of a address register |
| 2264 | * |
| 2265 | * \param Index - The register index we write to |
| 2266 | * |
| 2267 | * \return 0 on sucess, 1 on error |
| 2268 | */ |
| 2269 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2270 | parse_address_reg (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2271 | struct var_cache **vc_head, |
| 2272 | struct arb_program *Program, GLint * Index) |
| 2273 | { |
| 2274 | struct var_cache *dst; |
| 2275 | GLuint result; |
Aapo Tahkola | 6fc864b | 2006-03-22 21:29:15 +0000 | [diff] [blame] | 2276 | |
| 2277 | *Index = 0; /* XXX */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2278 | |
| 2279 | dst = parse_string (inst, vc_head, Program, &result); |
| 2280 | Program->Position = parse_position (inst); |
| 2281 | |
| 2282 | /* If the name has never been added to our symbol table, we're hosed */ |
| 2283 | if (!result) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2284 | program_error(ctx, Program->Position, "Undefined variable"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2285 | return 1; |
| 2286 | } |
| 2287 | |
| 2288 | if (dst->type != vt_address) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2289 | program_error(ctx, Program->Position, "Variable is not of type ADDRESS"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2290 | return 1; |
| 2291 | } |
| 2292 | |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
Brian Paul | 8e8fa63 | 2005-07-01 02:03:33 +0000 | [diff] [blame] | 2296 | #if 0 /* unused */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2297 | /** |
| 2298 | * Handle the parsing out of a masked address register |
| 2299 | * |
| 2300 | * \param Index - The register index we write to |
| 2301 | * \param WriteMask - The mask controlling which components we write (1->write) |
| 2302 | * |
| 2303 | * \return 0 on sucess, 1 on error |
| 2304 | */ |
| 2305 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2306 | parse_masked_address_reg (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2307 | struct var_cache **vc_head, |
| 2308 | struct arb_program *Program, GLint * Index, |
| 2309 | GLboolean * WriteMask) |
| 2310 | { |
| 2311 | if (parse_address_reg (ctx, inst, vc_head, Program, Index)) |
| 2312 | return 1; |
| 2313 | |
| 2314 | /* This should be 0x8 */ |
| 2315 | (*inst)++; |
| 2316 | |
| 2317 | /* Writemask of .x is implied */ |
| 2318 | WriteMask[0] = 1; |
| 2319 | WriteMask[1] = WriteMask[2] = WriteMask[3] = 0; |
| 2320 | |
| 2321 | return 0; |
| 2322 | } |
Brian Paul | 8e8fa63 | 2005-07-01 02:03:33 +0000 | [diff] [blame] | 2323 | #endif |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2324 | |
| 2325 | /** |
| 2326 | * Parse out a swizzle mask. |
| 2327 | * |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2328 | * Basically convert COMPONENT_X/Y/Z/W to SWIZZLE_X/Y/Z/W |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2329 | * |
| 2330 | * The len parameter allows us to grab 4 components for a vector |
| 2331 | * swizzle, or just 1 component for a scalar src register selection |
| 2332 | */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2333 | static void |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2334 | parse_swizzle_mask(const GLubyte ** inst, GLubyte *swizzle, GLint len) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2335 | { |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2336 | GLint i; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2337 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2338 | for (i = 0; i < 4; i++) |
| 2339 | swizzle[i] = i; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2340 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2341 | for (i = 0; i < len; i++) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2342 | switch (*(*inst)++) { |
| 2343 | case COMPONENT_X: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2344 | swizzle[i] = SWIZZLE_X; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2345 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2346 | case COMPONENT_Y: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2347 | swizzle[i] = SWIZZLE_Y; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2348 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2349 | case COMPONENT_Z: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2350 | swizzle[i] = SWIZZLE_Z; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2351 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2352 | case COMPONENT_W: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2353 | swizzle[i] = SWIZZLE_W; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2354 | break; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2355 | default: |
| 2356 | _mesa_problem(NULL, "bad component in parse_swizzle_mask()"); |
| 2357 | return; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2358 | } |
| 2359 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2362 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2363 | /** |
| 2364 | * Parse an extended swizzle mask which is a sequence of |
| 2365 | * four x/y/z/w/0/1 tokens. |
| 2366 | * \return swizzle four swizzle values |
| 2367 | * \return negateMask four element bitfield |
| 2368 | */ |
| 2369 | static void |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2370 | parse_extended_swizzle_mask(const GLubyte **inst, GLubyte swizzle[4], |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2371 | GLubyte *negateMask) |
| 2372 | { |
| 2373 | GLint i; |
| 2374 | |
| 2375 | *negateMask = 0x0; |
| 2376 | for (i = 0; i < 4; i++) { |
| 2377 | GLubyte swz; |
| 2378 | if (parse_sign(inst) == -1) |
| 2379 | *negateMask |= (1 << i); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2380 | |
| 2381 | swz = *(*inst)++; |
| 2382 | |
| 2383 | switch (swz) { |
| 2384 | case COMPONENT_0: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2385 | swizzle[i] = SWIZZLE_ZERO; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | case COMPONENT_1: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2388 | swizzle[i] = SWIZZLE_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | case COMPONENT_X: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2391 | swizzle[i] = SWIZZLE_X; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2392 | break; |
| 2393 | case COMPONENT_Y: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2394 | swizzle[i] = SWIZZLE_Y; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2395 | break; |
| 2396 | case COMPONENT_Z: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2397 | swizzle[i] = SWIZZLE_Z; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | case COMPONENT_W: |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2400 | swizzle[i] = SWIZZLE_W; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2401 | break; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2402 | default: |
| 2403 | _mesa_problem(NULL, "bad case in parse_extended_swizzle_mask()"); |
| 2404 | return; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2405 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2406 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | |
| 2410 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2411 | parse_src_reg (GLcontext * ctx, const GLubyte ** inst, |
| 2412 | struct var_cache **vc_head, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2413 | struct arb_program *Program, |
| 2414 | enum register_file * File, GLint * Index, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2415 | GLboolean *IsRelOffset ) |
| 2416 | { |
| 2417 | struct var_cache *src; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2418 | GLuint binding, is_generic, found; |
Brian Paul | bd997cd | 2004-07-20 21:12:56 +0000 | [diff] [blame] | 2419 | GLint offset; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2420 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2421 | *IsRelOffset = 0; |
| 2422 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2423 | /* And the binding for the src */ |
| 2424 | switch (*(*inst)++) { |
| 2425 | case REGISTER_ATTRIB: |
| 2426 | if (parse_attrib_binding |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2427 | (ctx, inst, Program, &binding, &is_generic)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2428 | return 1; |
| 2429 | *File = PROGRAM_INPUT; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2430 | *Index = binding; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2431 | |
| 2432 | /* We need to insert a dummy variable into the var_cache so we can |
| 2433 | * catch generic vertex attrib aliasing errors |
| 2434 | */ |
| 2435 | var_cache_create(&src); |
| 2436 | src->type = vt_attrib; |
Brian Paul | 6a769d9 | 2006-04-28 15:42:15 +0000 | [diff] [blame] | 2437 | src->name = (const GLubyte *) "Dummy Attrib Variable"; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2438 | src->attrib_binding = binding; |
| 2439 | src->attrib_is_generic = is_generic; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2440 | var_cache_append(vc_head, src); |
| 2441 | if (generic_attrib_check(*vc_head)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2442 | program_error(ctx, Program->Position, |
| 2443 | "Cannot use both a generic vertex attribute " |
| 2444 | "and a specific attribute of the same type"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2445 | return 1; |
| 2446 | } |
| 2447 | break; |
| 2448 | |
| 2449 | case REGISTER_PARAM: |
| 2450 | switch (**inst) { |
| 2451 | case PARAM_ARRAY_ELEMENT: |
| 2452 | (*inst)++; |
| 2453 | src = parse_string (inst, vc_head, Program, &found); |
| 2454 | Program->Position = parse_position (inst); |
| 2455 | |
| 2456 | if (!found) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2457 | program_error(ctx, Program->Position, |
| 2458 | "2: Undefined variable"); /* src->name */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2459 | return 1; |
| 2460 | } |
| 2461 | |
Brian Paul | 9580179 | 2005-12-06 15:41:43 +0000 | [diff] [blame] | 2462 | *File = (enum register_file) src->param_binding_type; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2463 | |
| 2464 | switch (*(*inst)++) { |
| 2465 | case ARRAY_INDEX_ABSOLUTE: |
| 2466 | offset = parse_integer (inst, Program); |
| 2467 | |
| 2468 | if ((offset < 0) |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 2469 | || (offset >= (int)src->param_binding_length)) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2470 | program_error(ctx, Program->Position, |
| 2471 | "Index out of range"); |
| 2472 | /* offset, src->name */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2473 | return 1; |
| 2474 | } |
| 2475 | |
| 2476 | *Index = src->param_binding_begin + offset; |
| 2477 | break; |
| 2478 | |
| 2479 | case ARRAY_INDEX_RELATIVE: |
| 2480 | { |
| 2481 | GLint addr_reg_idx, rel_off; |
| 2482 | |
| 2483 | /* First, grab the address regiseter */ |
| 2484 | if (parse_address_reg (ctx, inst, vc_head, Program, &addr_reg_idx)) |
| 2485 | return 1; |
| 2486 | |
| 2487 | /* And the .x */ |
| 2488 | ((*inst)++); |
| 2489 | ((*inst)++); |
| 2490 | ((*inst)++); |
| 2491 | ((*inst)++); |
| 2492 | |
| 2493 | /* Then the relative offset */ |
| 2494 | if (parse_relative_offset(ctx, inst, Program, &rel_off)) return 1; |
| 2495 | |
| 2496 | /* And store it properly */ |
| 2497 | *Index = src->param_binding_begin + rel_off; |
| 2498 | *IsRelOffset = 1; |
| 2499 | } |
| 2500 | break; |
| 2501 | } |
| 2502 | break; |
| 2503 | |
| 2504 | default: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2505 | if (parse_param_use (ctx, inst, vc_head, Program, &src)) |
| 2506 | return 1; |
| 2507 | |
Brian Paul | 9580179 | 2005-12-06 15:41:43 +0000 | [diff] [blame] | 2508 | *File = (enum register_file) src->param_binding_type; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2509 | *Index = src->param_binding_begin; |
| 2510 | break; |
| 2511 | } |
| 2512 | break; |
| 2513 | |
| 2514 | case REGISTER_ESTABLISHED_NAME: |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2515 | src = parse_string (inst, vc_head, Program, &found); |
| 2516 | Program->Position = parse_position (inst); |
| 2517 | |
| 2518 | /* If the name has never been added to our symbol table, we're hosed */ |
| 2519 | if (!found) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2520 | program_error(ctx, Program->Position, |
| 2521 | "3: Undefined variable"); /* src->name */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2522 | return 1; |
| 2523 | } |
| 2524 | |
| 2525 | switch (src->type) { |
| 2526 | case vt_attrib: |
| 2527 | *File = PROGRAM_INPUT; |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2528 | *Index = src->attrib_binding; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | |
| 2531 | /* XXX: We have to handle offsets someplace in here! -- or are those above? */ |
| 2532 | case vt_param: |
Brian Paul | 9580179 | 2005-12-06 15:41:43 +0000 | [diff] [blame] | 2533 | *File = (enum register_file) src->param_binding_type; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2534 | *Index = src->param_binding_begin; |
| 2535 | break; |
| 2536 | |
| 2537 | case vt_temp: |
| 2538 | *File = PROGRAM_TEMPORARY; |
| 2539 | *Index = src->temp_binding; |
| 2540 | break; |
| 2541 | |
| 2542 | /* If the var type is vt_output no go */ |
| 2543 | default: |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2544 | program_error(ctx, Program->Position, |
| 2545 | "destination register is read only"); |
| 2546 | /* bad src->name */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2547 | return 1; |
| 2548 | } |
| 2549 | break; |
| 2550 | |
| 2551 | default: |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2552 | program_error(ctx, Program->Position, |
| 2553 | "Unknown token in parse_src_reg"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2554 | return 1; |
| 2555 | } |
| 2556 | |
Markus Amsler | f3c4906 | 2008-03-17 08:35:37 -0600 | [diff] [blame^] | 2557 | /* Add attributes to InputsRead only if they are used the program. |
| 2558 | * This avoids the handling of unused ATTRIB declarations in the drivers. */ |
| 2559 | if (*File == PROGRAM_INPUT) |
| 2560 | Program->Base.InputsRead |= (1 << *Index); |
| 2561 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | /** |
Brian Paul | 18e7c5c | 2005-10-30 21:46:00 +0000 | [diff] [blame] | 2566 | * Parse fragment program vector source register. |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2567 | */ |
| 2568 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2569 | parse_fp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2570 | struct var_cache **vc_head, |
| 2571 | struct arb_program *program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2572 | struct prog_src_register *reg) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2573 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2574 | enum register_file file; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2575 | GLint index; |
| 2576 | GLboolean negate; |
| 2577 | GLubyte swizzle[4]; |
| 2578 | GLboolean isRelOffset; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2579 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2580 | /* Grab the sign */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2581 | negate = (parse_sign (inst) == -1) ? 0xf : 0x0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2582 | |
| 2583 | /* And the src reg */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2584 | if (parse_src_reg(ctx, inst, vc_head, program, &file, &index, &isRelOffset)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2585 | return 1; |
| 2586 | |
| 2587 | /* finally, the swizzle */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2588 | parse_swizzle_mask(inst, swizzle, 4); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2589 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2590 | reg->File = file; |
| 2591 | reg->Index = index; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2592 | reg->NegateBase = negate; |
| 2593 | reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2594 | return 0; |
| 2595 | } |
| 2596 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2597 | |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 2598 | /** |
| 2599 | * Parse fragment program destination register. |
| 2600 | * \return 1 if error, 0 if no error. |
| 2601 | */ |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2602 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2603 | parse_fp_dst_reg(GLcontext * ctx, const GLubyte ** inst, |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2604 | struct var_cache **vc_head, struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2605 | struct prog_dst_register *reg ) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2606 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2607 | GLint mask; |
| 2608 | GLuint idx; |
| 2609 | enum register_file file; |
| 2610 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2611 | if (parse_masked_dst_reg (ctx, inst, vc_head, Program, &file, &idx, &mask)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2612 | return 1; |
| 2613 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2614 | reg->File = file; |
| 2615 | reg->Index = idx; |
| 2616 | reg->WriteMask = mask; |
| 2617 | return 0; |
| 2618 | } |
| 2619 | |
| 2620 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2621 | /** |
| 2622 | * Parse fragment program scalar src register. |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 2623 | * \return 1 if error, 0 if no error. |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2624 | */ |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2625 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2626 | parse_fp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2627 | struct var_cache **vc_head, |
| 2628 | struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2629 | struct prog_src_register *reg ) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2630 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2631 | enum register_file File; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2632 | GLint Index; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2633 | GLubyte Negate; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2634 | GLubyte Swizzle[4]; |
| 2635 | GLboolean IsRelOffset; |
| 2636 | |
| 2637 | /* Grab the sign */ |
| 2638 | Negate = (parse_sign (inst) == -1) ? 0x1 : 0x0; |
| 2639 | |
| 2640 | /* And the src reg */ |
| 2641 | if (parse_src_reg (ctx, inst, vc_head, Program, &File, &Index, &IsRelOffset)) |
| 2642 | return 1; |
| 2643 | |
| 2644 | /* finally, the swizzle */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2645 | parse_swizzle_mask(inst, Swizzle, 1); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2646 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2647 | reg->File = File; |
| 2648 | reg->Index = Index; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2649 | reg->NegateBase = Negate; |
| 2650 | reg->Swizzle = (Swizzle[0] << 0); |
| 2651 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2652 | return 0; |
| 2653 | } |
| 2654 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2655 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2656 | /** |
| 2657 | * This is a big mother that handles getting opcodes into the instruction |
| 2658 | * and handling the src & dst registers for fragment program instructions |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 2659 | * \return 1 if error, 0 if no error |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2660 | */ |
| 2661 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 2662 | parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2663 | struct var_cache **vc_head, struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2664 | struct prog_instruction *fp) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2665 | { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2666 | GLint a; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2667 | GLuint texcoord; |
| 2668 | GLubyte instClass, type, code; |
| 2669 | GLboolean rel; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 2670 | GLuint shadow_tex = 0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2671 | |
Brian Paul | d6272e0 | 2006-10-29 18:03:16 +0000 | [diff] [blame] | 2672 | _mesa_init_instructions(fp, 1); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2673 | |
| 2674 | /* Record the position in the program string for debugging */ |
| 2675 | fp->StringPos = Program->Position; |
| 2676 | |
| 2677 | /* OP_ALU_INST or OP_TEX_INST */ |
| 2678 | instClass = *(*inst)++; |
| 2679 | |
| 2680 | /* OP_ALU_{VECTOR, SCALAR, BINSC, BIN, TRI, SWZ}, |
| 2681 | * OP_TEX_{SAMPLE, KIL} |
| 2682 | */ |
| 2683 | type = *(*inst)++; |
| 2684 | |
| 2685 | /* The actual opcode name */ |
| 2686 | code = *(*inst)++; |
| 2687 | |
| 2688 | /* Increment the correct count */ |
| 2689 | switch (instClass) { |
| 2690 | case OP_ALU_INST: |
| 2691 | Program->NumAluInstructions++; |
| 2692 | break; |
| 2693 | case OP_TEX_INST: |
| 2694 | Program->NumTexInstructions++; |
| 2695 | break; |
| 2696 | } |
| 2697 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2698 | switch (type) { |
| 2699 | case OP_ALU_VECTOR: |
| 2700 | switch (code) { |
| 2701 | case OP_ABS_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2702 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2703 | case OP_ABS: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2704 | fp->Opcode = OPCODE_ABS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | |
| 2707 | case OP_FLR_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2708 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2709 | case OP_FLR: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2710 | fp->Opcode = OPCODE_FLR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2711 | break; |
| 2712 | |
| 2713 | case OP_FRC_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2714 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2715 | case OP_FRC: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2716 | fp->Opcode = OPCODE_FRC; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2717 | break; |
| 2718 | |
| 2719 | case OP_LIT_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2720 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2721 | case OP_LIT: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2722 | fp->Opcode = OPCODE_LIT; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2723 | break; |
| 2724 | |
| 2725 | case OP_MOV_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2726 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2727 | case OP_MOV: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2728 | fp->Opcode = OPCODE_MOV; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2729 | break; |
| 2730 | } |
| 2731 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2732 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2733 | return 1; |
| 2734 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2735 | if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2736 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2737 | break; |
| 2738 | |
| 2739 | case OP_ALU_SCALAR: |
| 2740 | switch (code) { |
| 2741 | case OP_COS_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2742 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2743 | case OP_COS: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2744 | fp->Opcode = OPCODE_COS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2745 | break; |
| 2746 | |
| 2747 | case OP_EX2_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2748 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2749 | case OP_EX2: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2750 | fp->Opcode = OPCODE_EX2; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2751 | break; |
| 2752 | |
| 2753 | case OP_LG2_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2754 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2755 | case OP_LG2: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2756 | fp->Opcode = OPCODE_LG2; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2757 | break; |
| 2758 | |
| 2759 | case OP_RCP_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2760 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2761 | case OP_RCP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2762 | fp->Opcode = OPCODE_RCP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2763 | break; |
| 2764 | |
| 2765 | case OP_RSQ_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2766 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2767 | case OP_RSQ: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2768 | fp->Opcode = OPCODE_RSQ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2769 | break; |
| 2770 | |
| 2771 | case OP_SIN_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2772 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2773 | case OP_SIN: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2774 | fp->Opcode = OPCODE_SIN; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2775 | break; |
| 2776 | |
| 2777 | case OP_SCS_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2778 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2779 | case OP_SCS: |
| 2780 | |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2781 | fp->Opcode = OPCODE_SCS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2782 | break; |
| 2783 | } |
| 2784 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2785 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2786 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2787 | |
| 2788 | if (parse_fp_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2789 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2790 | break; |
| 2791 | |
| 2792 | case OP_ALU_BINSC: |
| 2793 | switch (code) { |
| 2794 | case OP_POW_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2795 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2796 | case OP_POW: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2797 | fp->Opcode = OPCODE_POW; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2798 | break; |
| 2799 | } |
| 2800 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2801 | if (parse_fp_dst_reg(ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2802 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2803 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2804 | for (a = 0; a < 2; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2805 | if (parse_fp_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2806 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2807 | } |
| 2808 | break; |
| 2809 | |
| 2810 | |
| 2811 | case OP_ALU_BIN: |
| 2812 | switch (code) { |
| 2813 | case OP_ADD_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2814 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2815 | case OP_ADD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2816 | fp->Opcode = OPCODE_ADD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2817 | break; |
| 2818 | |
| 2819 | case OP_DP3_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2820 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2821 | case OP_DP3: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2822 | fp->Opcode = OPCODE_DP3; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2823 | break; |
| 2824 | |
| 2825 | case OP_DP4_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2826 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2827 | case OP_DP4: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2828 | fp->Opcode = OPCODE_DP4; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2829 | break; |
| 2830 | |
| 2831 | case OP_DPH_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2832 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2833 | case OP_DPH: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2834 | fp->Opcode = OPCODE_DPH; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2835 | break; |
| 2836 | |
| 2837 | case OP_DST_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2838 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2839 | case OP_DST: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2840 | fp->Opcode = OPCODE_DST; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2841 | break; |
| 2842 | |
| 2843 | case OP_MAX_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2844 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2845 | case OP_MAX: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2846 | fp->Opcode = OPCODE_MAX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2847 | break; |
| 2848 | |
| 2849 | case OP_MIN_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2850 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2851 | case OP_MIN: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2852 | fp->Opcode = OPCODE_MIN; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2853 | break; |
| 2854 | |
| 2855 | case OP_MUL_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2856 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2857 | case OP_MUL: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2858 | fp->Opcode = OPCODE_MUL; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | |
| 2861 | case OP_SGE_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2862 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2863 | case OP_SGE: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2864 | fp->Opcode = OPCODE_SGE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2865 | break; |
| 2866 | |
| 2867 | case OP_SLT_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2868 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2869 | case OP_SLT: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2870 | fp->Opcode = OPCODE_SLT; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | |
| 2873 | case OP_SUB_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2874 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2875 | case OP_SUB: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2876 | fp->Opcode = OPCODE_SUB; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2877 | break; |
| 2878 | |
| 2879 | case OP_XPD_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2880 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2881 | case OP_XPD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2882 | fp->Opcode = OPCODE_XPD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2883 | break; |
| 2884 | } |
| 2885 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2886 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2887 | return 1; |
| 2888 | for (a = 0; a < 2; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2889 | if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) |
| 2890 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2891 | } |
| 2892 | break; |
| 2893 | |
| 2894 | case OP_ALU_TRI: |
| 2895 | switch (code) { |
| 2896 | case OP_CMP_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2897 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2898 | case OP_CMP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2899 | fp->Opcode = OPCODE_CMP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2900 | break; |
| 2901 | |
| 2902 | case OP_LRP_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2903 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2904 | case OP_LRP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2905 | fp->Opcode = OPCODE_LRP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2906 | break; |
| 2907 | |
| 2908 | case OP_MAD_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2909 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2910 | case OP_MAD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2911 | fp->Opcode = OPCODE_MAD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2912 | break; |
| 2913 | } |
| 2914 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2915 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2916 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2917 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2918 | for (a = 0; a < 3; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2919 | if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) |
| 2920 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2921 | } |
| 2922 | break; |
| 2923 | |
| 2924 | case OP_ALU_SWZ: |
| 2925 | switch (code) { |
| 2926 | case OP_SWZ_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2927 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2928 | case OP_SWZ: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2929 | fp->Opcode = OPCODE_SWZ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2930 | break; |
| 2931 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2932 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2933 | return 1; |
| 2934 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2935 | { |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2936 | GLubyte swizzle[4]; |
Brian Paul | 54cfe69 | 2005-10-21 15:22:36 +0000 | [diff] [blame] | 2937 | GLubyte negateMask; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 2938 | enum register_file file; |
| 2939 | GLint index; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2940 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2941 | if (parse_src_reg(ctx, inst, vc_head, Program, &file, &index, &rel)) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2942 | return 1; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2943 | parse_extended_swizzle_mask(inst, swizzle, &negateMask); |
| 2944 | fp->SrcReg[0].File = file; |
| 2945 | fp->SrcReg[0].Index = index; |
Brian Paul | 54cfe69 | 2005-10-21 15:22:36 +0000 | [diff] [blame] | 2946 | fp->SrcReg[0].NegateBase = negateMask; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 2947 | fp->SrcReg[0].Swizzle = MAKE_SWIZZLE4(swizzle[0], |
| 2948 | swizzle[1], |
| 2949 | swizzle[2], |
| 2950 | swizzle[3]); |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2951 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2952 | break; |
| 2953 | |
| 2954 | case OP_TEX_SAMPLE: |
| 2955 | switch (code) { |
| 2956 | case OP_TEX_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2957 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2958 | case OP_TEX: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2959 | fp->Opcode = OPCODE_TEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2960 | break; |
| 2961 | |
| 2962 | case OP_TXP_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2963 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2964 | case OP_TXP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2965 | fp->Opcode = OPCODE_TXP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2966 | break; |
| 2967 | |
| 2968 | case OP_TXB_SAT: |
Brian Paul | e31ac05 | 2005-11-20 17:52:40 +0000 | [diff] [blame] | 2969 | fp->SaturateMode = SATURATE_ZERO_ONE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2970 | case OP_TXB: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2971 | fp->Opcode = OPCODE_TXB; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2972 | break; |
| 2973 | } |
| 2974 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2975 | if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2976 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 2977 | |
| 2978 | if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2979 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2980 | |
| 2981 | /* texImageUnit */ |
| 2982 | if (parse_texcoord_num (ctx, inst, Program, &texcoord)) |
| 2983 | return 1; |
| 2984 | fp->TexSrcUnit = texcoord; |
| 2985 | |
| 2986 | /* texTarget */ |
| 2987 | switch (*(*inst)++) { |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 2988 | case TEXTARGET_SHADOW1D: |
| 2989 | shadow_tex = 1 << texcoord; |
| 2990 | /* FALLTHROUGH */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2991 | case TEXTARGET_1D: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2992 | fp->TexSrcTarget = TEXTURE_1D_INDEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2993 | break; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 2994 | case TEXTARGET_SHADOW2D: |
| 2995 | shadow_tex = 1 << texcoord; |
| 2996 | /* FALLTHROUGH */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2997 | case TEXTARGET_2D: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 2998 | fp->TexSrcTarget = TEXTURE_2D_INDEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 2999 | break; |
| 3000 | case TEXTARGET_3D: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3001 | fp->TexSrcTarget = TEXTURE_3D_INDEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3002 | break; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3003 | case TEXTARGET_SHADOWRECT: |
| 3004 | shadow_tex = 1 << texcoord; |
| 3005 | /* FALLTHROUGH */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3006 | case TEXTARGET_RECT: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3007 | fp->TexSrcTarget = TEXTURE_RECT_INDEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | case TEXTARGET_CUBE: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3010 | fp->TexSrcTarget = TEXTURE_CUBE_INDEX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3011 | break; |
Ian Romanick | 69358e7 | 2007-06-05 09:24:27 -0700 | [diff] [blame] | 3012 | case TEXTARGET_SHADOW1D_ARRAY: |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3013 | shadow_tex = 1 << texcoord; |
| 3014 | /* FALLTHROUGH */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3015 | case TEXTARGET_1D_ARRAY: |
| 3016 | fp->TexSrcTarget = TEXTURE_1D_ARRAY_INDEX; |
| 3017 | break; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3018 | case TEXTARGET_SHADOW2D_ARRAY: |
| 3019 | shadow_tex = 1 << texcoord; |
| 3020 | /* FALLTHROUGH */ |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3021 | case TEXTARGET_2D_ARRAY: |
| 3022 | fp->TexSrcTarget = TEXTURE_2D_ARRAY_INDEX; |
| 3023 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3024 | } |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3025 | |
| 3026 | /* Don't test the first time a particular sampler is seen. Each time |
| 3027 | * after that, make sure the shadow state is the same. |
| 3028 | */ |
| 3029 | if ((_mesa_bitcount(Program->TexturesUsed[texcoord]) > 0) |
| 3030 | && ((Program->ShadowSamplers & (1 << texcoord)) != shadow_tex)) { |
| 3031 | program_error(ctx, Program->Position, |
| 3032 | "texture image unit used for shadow sampling and non-shadow sampling"); |
| 3033 | return 1; |
| 3034 | } |
| 3035 | |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 3036 | Program->TexturesUsed[texcoord] |= (1 << fp->TexSrcTarget); |
| 3037 | /* Check that both "2D" and "CUBE" (for example) aren't both used */ |
| 3038 | if (_mesa_bitcount(Program->TexturesUsed[texcoord]) > 1) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3039 | program_error(ctx, Program->Position, |
| 3040 | "multiple targets used on one texture image unit"); |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 3041 | return 1; |
| 3042 | } |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3043 | |
| 3044 | |
| 3045 | Program->ShadowSamplers |= shadow_tex; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3046 | break; |
| 3047 | |
| 3048 | case OP_TEX_KIL: |
Keith Whitwell | c3626a9 | 2005-11-01 17:25:49 +0000 | [diff] [blame] | 3049 | Program->UsesKill = 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3050 | if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3051 | return 1; |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3052 | fp->Opcode = OPCODE_KIL; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3053 | break; |
Brian Paul | b7fc1c3 | 2006-08-30 23:38:03 +0000 | [diff] [blame] | 3054 | default: |
| 3055 | _mesa_problem(ctx, "bad type 0x%x in parse_fp_instruction()", type); |
| 3056 | return 1; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | return 0; |
| 3060 | } |
| 3061 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3062 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3063 | parse_vp_dst_reg(GLcontext * ctx, const GLubyte ** inst, |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3064 | struct var_cache **vc_head, struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3065 | struct prog_dst_register *reg ) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3066 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3067 | GLint mask; |
| 3068 | GLuint idx; |
| 3069 | enum register_file file; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3070 | |
| 3071 | if (parse_masked_dst_reg(ctx, inst, vc_head, Program, &file, &idx, &mask)) |
| 3072 | return 1; |
| 3073 | |
| 3074 | reg->File = file; |
| 3075 | reg->Index = idx; |
| 3076 | reg->WriteMask = mask; |
| 3077 | return 0; |
| 3078 | } |
| 3079 | |
| 3080 | /** |
| 3081 | * Handle the parsing out of a masked address register |
| 3082 | * |
| 3083 | * \param Index - The register index we write to |
| 3084 | * \param WriteMask - The mask controlling which components we write (1->write) |
| 3085 | * |
| 3086 | * \return 0 on sucess, 1 on error |
| 3087 | */ |
| 3088 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3089 | parse_vp_address_reg (GLcontext * ctx, const GLubyte ** inst, |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3090 | struct var_cache **vc_head, |
| 3091 | struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3092 | struct prog_dst_register *reg) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3093 | { |
| 3094 | GLint idx; |
| 3095 | |
| 3096 | if (parse_address_reg (ctx, inst, vc_head, Program, &idx)) |
| 3097 | return 1; |
| 3098 | |
| 3099 | /* This should be 0x8 */ |
| 3100 | (*inst)++; |
| 3101 | |
| 3102 | reg->File = PROGRAM_ADDRESS; |
| 3103 | reg->Index = idx; |
| 3104 | |
| 3105 | /* Writemask of .x is implied */ |
| 3106 | reg->WriteMask = 0x1; |
| 3107 | return 0; |
| 3108 | } |
| 3109 | |
| 3110 | /** |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3111 | * Parse vertex program vector source register. |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3112 | */ |
| 3113 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3114 | parse_vp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3115 | struct var_cache **vc_head, |
| 3116 | struct arb_program *program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3117 | struct prog_src_register *reg ) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3118 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3119 | enum register_file file; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3120 | GLint index; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3121 | GLubyte negateMask; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3122 | GLubyte swizzle[4]; |
| 3123 | GLboolean isRelOffset; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3124 | |
| 3125 | /* Grab the sign */ |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3126 | negateMask = (parse_sign (inst) == -1) ? 0xf : 0x0; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3127 | |
| 3128 | /* And the src reg */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3129 | if (parse_src_reg (ctx, inst, vc_head, program, &file, &index, &isRelOffset)) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3130 | return 1; |
| 3131 | |
| 3132 | /* finally, the swizzle */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3133 | parse_swizzle_mask(inst, swizzle, 4); |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3134 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3135 | reg->File = file; |
| 3136 | reg->Index = index; |
| 3137 | reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], |
| 3138 | swizzle[2], swizzle[3]); |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3139 | reg->NegateBase = negateMask; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3140 | reg->RelAddr = isRelOffset; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3141 | return 0; |
| 3142 | } |
| 3143 | |
| 3144 | |
| 3145 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3146 | parse_vp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst, |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3147 | struct var_cache **vc_head, |
| 3148 | struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3149 | struct prog_src_register *reg ) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3150 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3151 | enum register_file File; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3152 | GLint Index; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3153 | GLubyte Negate; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3154 | GLubyte Swizzle[4]; |
| 3155 | GLboolean IsRelOffset; |
| 3156 | |
| 3157 | /* Grab the sign */ |
| 3158 | Negate = (parse_sign (inst) == -1) ? 0x1 : 0x0; |
| 3159 | |
| 3160 | /* And the src reg */ |
| 3161 | if (parse_src_reg (ctx, inst, vc_head, Program, &File, &Index, &IsRelOffset)) |
| 3162 | return 1; |
| 3163 | |
| 3164 | /* finally, the swizzle */ |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3165 | parse_swizzle_mask(inst, Swizzle, 1); |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3166 | |
| 3167 | reg->File = File; |
| 3168 | reg->Index = Index; |
| 3169 | reg->Swizzle = (Swizzle[0] << 0); |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3170 | reg->NegateBase = Negate; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3171 | reg->RelAddr = IsRelOffset; |
| 3172 | return 0; |
| 3173 | } |
| 3174 | |
| 3175 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3176 | /** |
| 3177 | * This is a big mother that handles getting opcodes into the instruction |
| 3178 | * and handling the src & dst registers for vertex program instructions |
| 3179 | */ |
| 3180 | static GLuint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3181 | parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3182 | struct var_cache **vc_head, struct arb_program *Program, |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3183 | struct prog_instruction *vp) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3184 | { |
| 3185 | GLint a; |
| 3186 | GLubyte type, code; |
| 3187 | |
| 3188 | /* OP_ALU_{ARL, VECTOR, SCALAR, BINSC, BIN, TRI, SWZ} */ |
| 3189 | type = *(*inst)++; |
| 3190 | |
| 3191 | /* The actual opcode name */ |
| 3192 | code = *(*inst)++; |
| 3193 | |
Brian Paul | d6272e0 | 2006-10-29 18:03:16 +0000 | [diff] [blame] | 3194 | _mesa_init_instructions(vp, 1); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3195 | /* Record the position in the program string for debugging */ |
| 3196 | vp->StringPos = Program->Position; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3197 | |
| 3198 | switch (type) { |
| 3199 | /* XXX: */ |
| 3200 | case OP_ALU_ARL: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3201 | vp->Opcode = OPCODE_ARL; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3202 | |
| 3203 | /* Remember to set SrcReg.RelAddr; */ |
| 3204 | |
| 3205 | /* Get the masked address register [dst] */ |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3206 | if (parse_vp_address_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3207 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3208 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3209 | vp->DstReg.File = PROGRAM_ADDRESS; |
| 3210 | |
| 3211 | /* Get a scalar src register */ |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3212 | if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3213 | return 1; |
| 3214 | |
| 3215 | break; |
| 3216 | |
| 3217 | case OP_ALU_VECTOR: |
| 3218 | switch (code) { |
| 3219 | case OP_ABS: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3220 | vp->Opcode = OPCODE_ABS; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3221 | break; |
| 3222 | case OP_FLR: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3223 | vp->Opcode = OPCODE_FLR; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3224 | break; |
| 3225 | case OP_FRC: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3226 | vp->Opcode = OPCODE_FRC; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3227 | break; |
| 3228 | case OP_LIT: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3229 | vp->Opcode = OPCODE_LIT; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3230 | break; |
| 3231 | case OP_MOV: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3232 | vp->Opcode = OPCODE_MOV; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3235 | |
| 3236 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3237 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3238 | |
| 3239 | if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3240 | return 1; |
| 3241 | break; |
| 3242 | |
| 3243 | case OP_ALU_SCALAR: |
| 3244 | switch (code) { |
| 3245 | case OP_EX2: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3246 | vp->Opcode = OPCODE_EX2; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3247 | break; |
| 3248 | case OP_EXP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3249 | vp->Opcode = OPCODE_EXP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3250 | break; |
| 3251 | case OP_LG2: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3252 | vp->Opcode = OPCODE_LG2; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3253 | break; |
| 3254 | case OP_LOG: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3255 | vp->Opcode = OPCODE_LOG; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3256 | break; |
| 3257 | case OP_RCP: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3258 | vp->Opcode = OPCODE_RCP; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | case OP_RSQ: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3261 | vp->Opcode = OPCODE_RSQ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3262 | break; |
| 3263 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3264 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3265 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3266 | |
| 3267 | if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3268 | return 1; |
| 3269 | break; |
| 3270 | |
| 3271 | case OP_ALU_BINSC: |
| 3272 | switch (code) { |
| 3273 | case OP_POW: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3274 | vp->Opcode = OPCODE_POW; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3275 | break; |
| 3276 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3277 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3278 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3279 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3280 | for (a = 0; a < 2; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3281 | if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3282 | return 1; |
| 3283 | } |
| 3284 | break; |
| 3285 | |
| 3286 | case OP_ALU_BIN: |
| 3287 | switch (code) { |
| 3288 | case OP_ADD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3289 | vp->Opcode = OPCODE_ADD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3290 | break; |
| 3291 | case OP_DP3: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3292 | vp->Opcode = OPCODE_DP3; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3293 | break; |
| 3294 | case OP_DP4: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3295 | vp->Opcode = OPCODE_DP4; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3296 | break; |
| 3297 | case OP_DPH: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3298 | vp->Opcode = OPCODE_DPH; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3299 | break; |
| 3300 | case OP_DST: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3301 | vp->Opcode = OPCODE_DST; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | case OP_MAX: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3304 | vp->Opcode = OPCODE_MAX; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3305 | break; |
| 3306 | case OP_MIN: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3307 | vp->Opcode = OPCODE_MIN; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3308 | break; |
| 3309 | case OP_MUL: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3310 | vp->Opcode = OPCODE_MUL; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3311 | break; |
| 3312 | case OP_SGE: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3313 | vp->Opcode = OPCODE_SGE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | case OP_SLT: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3316 | vp->Opcode = OPCODE_SLT; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | case OP_SUB: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3319 | vp->Opcode = OPCODE_SUB; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | case OP_XPD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3322 | vp->Opcode = OPCODE_XPD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3323 | break; |
| 3324 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3325 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3326 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3327 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3328 | for (a = 0; a < 2; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3329 | if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3330 | return 1; |
| 3331 | } |
| 3332 | break; |
| 3333 | |
| 3334 | case OP_ALU_TRI: |
| 3335 | switch (code) { |
| 3336 | case OP_MAD: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3337 | vp->Opcode = OPCODE_MAD; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| 3340 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3341 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3342 | return 1; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3343 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3344 | for (a = 0; a < 3; a++) { |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3345 | if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3346 | return 1; |
| 3347 | } |
| 3348 | break; |
| 3349 | |
| 3350 | case OP_ALU_SWZ: |
| 3351 | switch (code) { |
| 3352 | case OP_SWZ: |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3353 | vp->Opcode = OPCODE_SWZ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3354 | break; |
| 3355 | } |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3356 | { |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3357 | GLubyte swizzle[4]; |
| 3358 | GLubyte negateMask; |
| 3359 | GLboolean relAddr; |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3360 | enum register_file file; |
| 3361 | GLint index; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3362 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3363 | if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) |
| 3364 | return 1; |
| 3365 | |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3366 | if (parse_src_reg(ctx, inst, vc_head, Program, &file, &index, &relAddr)) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3367 | return 1; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3368 | parse_extended_swizzle_mask (inst, swizzle, &negateMask); |
| 3369 | vp->SrcReg[0].File = file; |
| 3370 | vp->SrcReg[0].Index = index; |
Brian Paul | 7e80751 | 2005-11-05 17:10:45 +0000 | [diff] [blame] | 3371 | vp->SrcReg[0].NegateBase = negateMask; |
Brian Paul | 32df89e | 2005-10-29 18:26:43 +0000 | [diff] [blame] | 3372 | vp->SrcReg[0].Swizzle = MAKE_SWIZZLE4(swizzle[0], |
| 3373 | swizzle[1], |
| 3374 | swizzle[2], |
| 3375 | swizzle[3]); |
| 3376 | vp->SrcReg[0].RelAddr = relAddr; |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 3377 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3378 | break; |
| 3379 | } |
| 3380 | return 0; |
| 3381 | } |
| 3382 | |
| 3383 | #if DEBUG_PARSING |
| 3384 | |
| 3385 | static GLvoid |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3386 | debug_variables (GLcontext * ctx, struct var_cache *vc_head, |
| 3387 | struct arb_program *Program) |
| 3388 | { |
| 3389 | struct var_cache *vc; |
| 3390 | GLint a, b; |
| 3391 | |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3392 | fprintf (stderr, "debug_variables, vc_head: %p\n", (void*) vc_head); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3393 | |
| 3394 | /* First of all, print out the contents of the var_cache */ |
| 3395 | vc = vc_head; |
| 3396 | while (vc) { |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3397 | fprintf (stderr, "[%p]\n", (void*) vc); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3398 | switch (vc->type) { |
| 3399 | case vt_none: |
| 3400 | fprintf (stderr, "UNDEFINED %s\n", vc->name); |
| 3401 | break; |
| 3402 | case vt_attrib: |
| 3403 | fprintf (stderr, "ATTRIB %s\n", vc->name); |
| 3404 | fprintf (stderr, " binding: 0x%x\n", vc->attrib_binding); |
| 3405 | break; |
| 3406 | case vt_param: |
| 3407 | fprintf (stderr, "PARAM %s begin: %d len: %d\n", vc->name, |
| 3408 | vc->param_binding_begin, vc->param_binding_length); |
| 3409 | b = vc->param_binding_begin; |
| 3410 | for (a = 0; a < vc->param_binding_length; a++) { |
| 3411 | fprintf (stderr, "%s\n", |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3412 | Program->Base.Parameters->Parameters[a + b].Name); |
| 3413 | if (Program->Base.Parameters->Parameters[a + b].Type == PROGRAM_STATE_VAR) { |
| 3414 | const char *s; |
| 3415 | s = _mesa_program_state_string(Program->Base.Parameters->Parameters |
| 3416 | [a + b].StateIndexes); |
| 3417 | fprintf(stderr, "%s\n", s); |
| 3418 | _mesa_free((char *) s); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3419 | } |
| 3420 | else |
| 3421 | fprintf (stderr, "%f %f %f %f\n", |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3422 | Program->Base.Parameters->ParameterValues[a + b][0], |
| 3423 | Program->Base.Parameters->ParameterValues[a + b][1], |
| 3424 | Program->Base.Parameters->ParameterValues[a + b][2], |
| 3425 | Program->Base.Parameters->ParameterValues[a + b][3]); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3426 | } |
| 3427 | break; |
| 3428 | case vt_temp: |
| 3429 | fprintf (stderr, "TEMP %s\n", vc->name); |
| 3430 | fprintf (stderr, " binding: 0x%x\n", vc->temp_binding); |
| 3431 | break; |
| 3432 | case vt_output: |
| 3433 | fprintf (stderr, "OUTPUT %s\n", vc->name); |
| 3434 | fprintf (stderr, " binding: 0x%x\n", vc->output_binding); |
| 3435 | break; |
| 3436 | case vt_alias: |
| 3437 | fprintf (stderr, "ALIAS %s\n", vc->name); |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3438 | fprintf (stderr, " binding: 0x%p (%s)\n", |
| 3439 | (void*) vc->alias_binding, vc->alias_binding->name); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3440 | break; |
Brian | b618ac8 | 2007-02-22 09:39:25 -0700 | [diff] [blame] | 3441 | default: |
| 3442 | /* nothing */ |
| 3443 | ; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3444 | } |
| 3445 | vc = vc->next; |
| 3446 | } |
| 3447 | } |
| 3448 | |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3449 | #endif /* DEBUG_PARSING */ |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3450 | |
| 3451 | |
| 3452 | /** |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3453 | * The main loop for parsing a fragment or vertex program |
| 3454 | * |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3455 | * \return 1 on error, 0 on success |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3456 | */ |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3457 | static GLint |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3458 | parse_instructions(GLcontext * ctx, const GLubyte * inst, |
| 3459 | struct var_cache **vc_head, struct arb_program *Program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3460 | { |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3461 | const GLuint maxInst = (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) |
| 3462 | ? ctx->Const.FragmentProgram.MaxInstructions |
| 3463 | : ctx->Const.VertexProgram.MaxInstructions; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3464 | GLint err = 0; |
| 3465 | |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3466 | ASSERT(MAX_INSTRUCTIONS >= maxInst); |
| 3467 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3468 | Program->MajorVersion = (GLuint) * inst++; |
| 3469 | Program->MinorVersion = (GLuint) * inst++; |
| 3470 | |
| 3471 | while (*inst != END) { |
| 3472 | switch (*inst++) { |
| 3473 | |
| 3474 | case OPTION: |
| 3475 | switch (*inst++) { |
| 3476 | case ARB_PRECISION_HINT_FASTEST: |
| 3477 | Program->PrecisionOption = GL_FASTEST; |
| 3478 | break; |
| 3479 | |
| 3480 | case ARB_PRECISION_HINT_NICEST: |
| 3481 | Program->PrecisionOption = GL_NICEST; |
| 3482 | break; |
| 3483 | |
| 3484 | case ARB_FOG_EXP: |
| 3485 | Program->FogOption = GL_EXP; |
| 3486 | break; |
| 3487 | |
| 3488 | case ARB_FOG_EXP2: |
| 3489 | Program->FogOption = GL_EXP2; |
| 3490 | break; |
| 3491 | |
| 3492 | case ARB_FOG_LINEAR: |
| 3493 | Program->FogOption = GL_LINEAR; |
| 3494 | break; |
| 3495 | |
| 3496 | case ARB_POSITION_INVARIANT: |
| 3497 | if (Program->Base.Target == GL_VERTEX_PROGRAM_ARB) |
Brian Paul | 45cd2f9 | 2005-11-03 02:25:10 +0000 | [diff] [blame] | 3498 | Program->HintPositionInvariant = GL_TRUE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3499 | break; |
| 3500 | |
| 3501 | case ARB_FRAGMENT_PROGRAM_SHADOW: |
| 3502 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
| 3503 | /* TODO ARB_fragment_program_shadow code */ |
| 3504 | } |
| 3505 | break; |
Michal Krol | ad22ce8 | 2004-10-11 08:13:25 +0000 | [diff] [blame] | 3506 | |
| 3507 | case ARB_DRAW_BUFFERS: |
| 3508 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
| 3509 | /* do nothing for now */ |
| 3510 | } |
| 3511 | break; |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3512 | |
| 3513 | case MESA_TEXTURE_ARRAY: |
| 3514 | /* do nothing for now */ |
| 3515 | break; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3516 | } |
| 3517 | break; |
| 3518 | |
| 3519 | case INSTRUCTION: |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3520 | /* check length */ |
| 3521 | if (Program->Base.NumInstructions + 1 >= maxInst) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3522 | program_error(ctx, Program->Position, |
| 3523 | "Max instruction count exceeded"); |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3524 | return 1; |
| 3525 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3526 | Program->Position = parse_position (&inst); |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3527 | /* parse the current instruction */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3528 | if (Program->Base.Target == GL_FRAGMENT_PROGRAM_ARB) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3529 | err = parse_fp_instruction (ctx, &inst, vc_head, Program, |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3530 | &Program->Base.Instructions[Program->Base.NumInstructions]); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3531 | } |
| 3532 | else { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3533 | err = parse_vp_instruction (ctx, &inst, vc_head, Program, |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3534 | &Program->Base.Instructions[Program->Base.NumInstructions]); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
Brian Paul | 72030e0 | 2005-11-03 03:30:34 +0000 | [diff] [blame] | 3537 | /* increment instuction count */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3538 | Program->Base.NumInstructions++; |
| 3539 | break; |
| 3540 | |
| 3541 | case DECLARATION: |
| 3542 | err = parse_declaration (ctx, &inst, vc_head, Program); |
| 3543 | break; |
| 3544 | |
| 3545 | default: |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | if (err) |
| 3550 | break; |
| 3551 | } |
| 3552 | |
| 3553 | /* Finally, tag on an OPCODE_END instruction */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3554 | { |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3555 | const GLuint numInst = Program->Base.NumInstructions; |
Brian Paul | d6272e0 | 2006-10-29 18:03:16 +0000 | [diff] [blame] | 3556 | _mesa_init_instructions(Program->Base.Instructions + numInst, 1); |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3557 | Program->Base.Instructions[numInst].Opcode = OPCODE_END; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3558 | /* YYY Wrong Position in program, whatever, at least not random -> crash |
| 3559 | Program->Position = parse_position (&inst); |
| 3560 | */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3561 | Program->Base.Instructions[numInst].StringPos = Program->Position; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3562 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3563 | Program->Base.NumInstructions++; |
| 3564 | |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 3565 | /* |
| 3566 | * Initialize native counts to logical counts. The device driver may |
| 3567 | * change them if program is translated into a hardware program. |
| 3568 | */ |
| 3569 | Program->Base.NumNativeInstructions = Program->Base.NumInstructions; |
| 3570 | Program->Base.NumNativeTemporaries = Program->Base.NumTemporaries; |
| 3571 | Program->Base.NumNativeParameters = Program->Base.NumParameters; |
| 3572 | Program->Base.NumNativeAttributes = Program->Base.NumAttributes; |
| 3573 | Program->Base.NumNativeAddressRegs = Program->Base.NumAddressRegs; |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 3574 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3575 | return err; |
| 3576 | } |
| 3577 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3578 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3579 | /* XXX temporary */ |
Brian | 5cc1292 | 2006-12-14 14:27:05 -0700 | [diff] [blame] | 3580 | LONGSTRING static char core_grammar_text[] = |
Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 3581 | #include "shader/grammar/grammar_syn.h" |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3582 | ; |
| 3583 | |
Brian Paul | 7aebaf3 | 2005-10-30 21:23:23 +0000 | [diff] [blame] | 3584 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3585 | /** |
| 3586 | * Set a grammar parameter. |
| 3587 | * \param name the grammar parameter |
| 3588 | * \param value the new parameter value |
| 3589 | * \return 0 if OK, 1 if error |
| 3590 | */ |
| 3591 | static int |
| 3592 | set_reg8 (GLcontext *ctx, grammar id, const char *name, GLubyte value) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3593 | { |
| 3594 | char error_msg[300]; |
| 3595 | GLint error_pos; |
| 3596 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3597 | if (grammar_set_reg8 (id, (const byte *) name, value)) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3598 | return 0; |
| 3599 | |
| 3600 | grammar_get_last_error ((byte *) error_msg, 300, &error_pos); |
| 3601 | _mesa_set_program_error (ctx, error_pos, error_msg); |
| 3602 | _mesa_error (ctx, GL_INVALID_OPERATION, "Grammar Register Error"); |
| 3603 | return 1; |
| 3604 | } |
| 3605 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3606 | |
| 3607 | /** |
| 3608 | * Enable support for the given language option in the parser. |
| 3609 | * \return 1 if OK, 0 if error |
| 3610 | */ |
| 3611 | static int |
| 3612 | enable_ext(GLcontext *ctx, grammar id, const char *name) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3613 | { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3614 | return !set_reg8(ctx, id, name, 1); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3617 | |
| 3618 | /** |
| 3619 | * Enable parser extensions based on which OpenGL extensions are supported |
| 3620 | * by this rendering context. |
| 3621 | * |
| 3622 | * \return GL_TRUE if OK, GL_FALSE if error. |
| 3623 | */ |
| 3624 | static GLboolean |
| 3625 | enable_parser_extensions(GLcontext *ctx, grammar id) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3626 | { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3627 | #if 0 |
| 3628 | /* These are not supported at this time */ |
| 3629 | if ((ctx->Extensions.ARB_vertex_blend || |
| 3630 | ctx->Extensions.EXT_vertex_weighting) |
Brian Paul | 43cc1dc | 2006-09-05 23:11:09 +0000 | [diff] [blame] | 3631 | && !enable_ext(ctx, id, "vertex_blend")) |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3632 | return GL_FALSE; |
| 3633 | if (ctx->Extensions.ARB_matrix_palette |
| 3634 | && !enable_ext(ctx, id, "matrix_palette")) |
| 3635 | return GL_FALSE; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3636 | #endif |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3637 | if (ctx->Extensions.ARB_fragment_program_shadow |
| 3638 | && !enable_ext(ctx, id, "fragment_program_shadow")) |
| 3639 | return GL_FALSE; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3640 | if (ctx->Extensions.EXT_point_parameters |
| 3641 | && !enable_ext(ctx, id, "point_parameters")) |
| 3642 | return GL_FALSE; |
| 3643 | if (ctx->Extensions.EXT_secondary_color |
| 3644 | && !enable_ext(ctx, id, "secondary_color")) |
| 3645 | return GL_FALSE; |
| 3646 | if (ctx->Extensions.EXT_fog_coord |
| 3647 | && !enable_ext(ctx, id, "fog_coord")) |
| 3648 | return GL_FALSE; |
| 3649 | if (ctx->Extensions.NV_texture_rectangle |
| 3650 | && !enable_ext(ctx, id, "texture_rectangle")) |
| 3651 | return GL_FALSE; |
| 3652 | if (ctx->Extensions.ARB_draw_buffers |
| 3653 | && !enable_ext(ctx, id, "draw_buffers")) |
| 3654 | return GL_FALSE; |
Ian Romanick | bb372f1 | 2007-05-16 15:34:22 -0700 | [diff] [blame] | 3655 | if (ctx->Extensions.MESA_texture_array |
| 3656 | && !enable_ext(ctx, id, "texture_array")) |
| 3657 | return GL_FALSE; |
Brian Paul | 3a55750 | 2006-09-05 23:15:29 +0000 | [diff] [blame] | 3658 | #if 1 |
| 3659 | /* hack for Warcraft (see bug 8060) */ |
| 3660 | enable_ext(ctx, id, "vertex_blend"); |
| 3661 | #endif |
| 3662 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3663 | return GL_TRUE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3666 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3667 | /** |
| 3668 | * This kicks everything off. |
| 3669 | * |
| 3670 | * \param ctx - The GL Context |
| 3671 | * \param str - The program string |
| 3672 | * \param len - The program string length |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3673 | * \param program - The arb_program struct to return all the parsed info in |
| 3674 | * \return GL_TRUE on sucess, GL_FALSE on error |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3675 | */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3676 | static GLboolean |
| 3677 | _mesa_parse_arb_program(GLcontext *ctx, GLenum target, |
| 3678 | const GLubyte *str, GLsizei len, |
| 3679 | struct arb_program *program) |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3680 | { |
| 3681 | GLint a, err, error_pos; |
| 3682 | char error_msg[300]; |
| 3683 | GLuint parsed_len; |
| 3684 | struct var_cache *vc_head; |
| 3685 | grammar arbprogram_syn_id; |
| 3686 | GLubyte *parsed, *inst; |
| 3687 | GLubyte *strz = NULL; |
| 3688 | static int arbprogram_syn_is_ok = 0; /* XXX temporary */ |
| 3689 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3690 | /* set the program target before parsing */ |
| 3691 | program->Base.Target = target; |
| 3692 | |
Brian Paul | 7f76b8f | 2004-09-10 01:05:39 +0000 | [diff] [blame] | 3693 | /* Reset error state */ |
| 3694 | _mesa_set_program_error(ctx, -1, NULL); |
| 3695 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3696 | /* check if arb_grammar_text (arbprogram.syn) is syntactically correct */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3697 | if (!arbprogram_syn_is_ok) { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3698 | /* One-time initialization of parsing system */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3699 | grammar grammar_syn_id; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3700 | GLuint parsed_len; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3701 | |
| 3702 | grammar_syn_id = grammar_load_from_text ((byte *) core_grammar_text); |
| 3703 | if (grammar_syn_id == 0) { |
| 3704 | grammar_get_last_error ((byte *) error_msg, 300, &error_pos); |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3705 | /* XXX this is not a GL error - it's an implementation bug! - FIX */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3706 | _mesa_set_program_error (ctx, error_pos, error_msg); |
| 3707 | _mesa_error (ctx, GL_INVALID_OPERATION, |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3708 | "glProgramStringARB(Error loading grammar rule set)"); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3709 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3712 | err = !grammar_check(grammar_syn_id, (byte *) arb_grammar_text, |
| 3713 | &parsed, &parsed_len); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3714 | |
Brian Paul | 49a80ca | 2006-04-28 15:40:11 +0000 | [diff] [blame] | 3715 | /* 'parsed' is unused here */ |
| 3716 | _mesa_free (parsed); |
| 3717 | parsed = NULL; |
| 3718 | |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3719 | /* NOTE: we can't destroy grammar_syn_id right here because |
| 3720 | * grammar_destroy() can reset the last error |
| 3721 | */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3722 | if (err) { |
| 3723 | /* XXX this is not a GL error - it's an implementation bug! - FIX */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3724 | grammar_get_last_error ((byte *) error_msg, 300, &error_pos); |
| 3725 | _mesa_set_program_error (ctx, error_pos, error_msg); |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3726 | _mesa_error (ctx, GL_INVALID_OPERATION, |
| 3727 | "glProgramString(Error loading grammar rule set"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3728 | grammar_destroy (grammar_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3729 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | grammar_destroy (grammar_syn_id); |
| 3733 | |
| 3734 | arbprogram_syn_is_ok = 1; |
| 3735 | } |
| 3736 | |
| 3737 | /* create the grammar object */ |
| 3738 | arbprogram_syn_id = grammar_load_from_text ((byte *) arb_grammar_text); |
| 3739 | if (arbprogram_syn_id == 0) { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3740 | /* XXX this is not a GL error - it's an implementation bug! - FIX */ |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3741 | grammar_get_last_error ((GLubyte *) error_msg, 300, &error_pos); |
| 3742 | _mesa_set_program_error (ctx, error_pos, error_msg); |
| 3743 | _mesa_error (ctx, GL_INVALID_OPERATION, |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3744 | "glProgramString(Error loading grammer rule set)"); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3745 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | /* Set program_target register value */ |
Brian Paul | 55194df | 2005-11-19 23:29:18 +0000 | [diff] [blame] | 3749 | if (set_reg8 (ctx, arbprogram_syn_id, "program_target", |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3750 | program->Base.Target == GL_FRAGMENT_PROGRAM_ARB ? 0x10 : 0x20)) { |
| 3751 | grammar_destroy (arbprogram_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3752 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3753 | } |
| 3754 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3755 | if (!enable_parser_extensions(ctx, arbprogram_syn_id)) { |
| 3756 | grammar_destroy(arbprogram_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3757 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | /* check for NULL character occurences */ |
| 3761 | { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3762 | GLint i; |
| 3763 | for (i = 0; i < len; i++) { |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3764 | if (str[i] == '\0') { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3765 | program_error(ctx, i, "illegal character"); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3766 | grammar_destroy (arbprogram_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3767 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3768 | } |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3769 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /* copy the program string to a null-terminated string */ |
Brian Paul | bdd15b5 | 2004-05-04 15:11:06 +0000 | [diff] [blame] | 3773 | strz = (GLubyte *) _mesa_malloc (len + 1); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3774 | if (!strz) { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3775 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB"); |
| 3776 | grammar_destroy (arbprogram_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3777 | return GL_FALSE; |
| 3778 | } |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3779 | _mesa_memcpy (strz, str, len); |
| 3780 | strz[len] = '\0'; |
| 3781 | |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 3782 | /* do a fast check on program string - initial production buffer is 4K */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3783 | err = !grammar_fast_check(arbprogram_syn_id, strz, |
| 3784 | &parsed, &parsed_len, 0x1000); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3785 | |
| 3786 | /* Syntax parse error */ |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3787 | if (err) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3788 | grammar_get_last_error((GLubyte *) error_msg, 300, &error_pos); |
| 3789 | program_error(ctx, error_pos, error_msg); |
Brian Paul | 5fe9029 | 2004-07-20 21:15:13 +0000 | [diff] [blame] | 3790 | |
Brian Paul | b3aefd1 | 2005-09-19 20:12:32 +0000 | [diff] [blame] | 3791 | #if DEBUG_PARSING |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3792 | /* useful for debugging */ |
Brian Paul | b3aefd1 | 2005-09-19 20:12:32 +0000 | [diff] [blame] | 3793 | do { |
Brian Paul | 5fe9029 | 2004-07-20 21:15:13 +0000 | [diff] [blame] | 3794 | int line, col; |
| 3795 | char *s; |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3796 | fprintf(stderr, "program: %s\n", (char *) strz); |
| 3797 | fprintf(stderr, "Error Pos: %d\n", ctx->program.ErrorPos); |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3798 | s = (char *) _mesa_find_line_column(strz, strz+ctx->program.ErrorPos, |
| 3799 | &line, &col); |
Brian Paul | b3aefd1 | 2005-09-19 20:12:32 +0000 | [diff] [blame] | 3800 | fprintf(stderr, "line %d col %d: %s\n", line, col, s); |
| 3801 | } while (0) |
| 3802 | #endif |
Brian Paul | 5fe9029 | 2004-07-20 21:15:13 +0000 | [diff] [blame] | 3803 | |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3804 | _mesa_free(strz); |
| 3805 | _mesa_free(parsed); |
| 3806 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3807 | grammar_destroy (arbprogram_syn_id); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3808 | return GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3811 | grammar_destroy (arbprogram_syn_id); |
| 3812 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3813 | /* |
| 3814 | * Program string is syntactically correct at this point |
| 3815 | * Parse the tokenized version of the program now, generating |
| 3816 | * vertex/fragment program instructions. |
| 3817 | */ |
| 3818 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3819 | /* Initialize the arb_program struct */ |
| 3820 | program->Base.String = strz; |
Brian Paul | 383c39e | 2006-08-25 15:14:25 +0000 | [diff] [blame] | 3821 | program->Base.Instructions = _mesa_alloc_instructions(MAX_INSTRUCTIONS); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3822 | program->Base.NumInstructions = |
| 3823 | program->Base.NumTemporaries = |
| 3824 | program->Base.NumParameters = |
| 3825 | program->Base.NumAttributes = program->Base.NumAddressRegs = 0; |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 3826 | program->Base.Parameters = _mesa_new_parameter_list (); |
| 3827 | program->Base.InputsRead = 0x0; |
| 3828 | program->Base.OutputsWritten = 0x0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3829 | program->Position = 0; |
| 3830 | program->MajorVersion = program->MinorVersion = 0; |
| 3831 | program->PrecisionOption = GL_DONT_CARE; |
| 3832 | program->FogOption = GL_NONE; |
| 3833 | program->HintPositionInvariant = GL_FALSE; |
| 3834 | for (a = 0; a < MAX_TEXTURE_IMAGE_UNITS; a++) |
Brian Paul | 45cd2f9 | 2005-11-03 02:25:10 +0000 | [diff] [blame] | 3835 | program->TexturesUsed[a] = 0x0; |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3836 | program->ShadowSamplers = 0x0; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3837 | program->NumAluInstructions = |
| 3838 | program->NumTexInstructions = |
| 3839 | program->NumTexIndirections = 0; |
Keith Whitwell | c3626a9 | 2005-11-01 17:25:49 +0000 | [diff] [blame] | 3840 | program->UsesKill = 0; |
| 3841 | |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3842 | vc_head = NULL; |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3843 | err = GL_FALSE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3844 | |
| 3845 | /* Start examining the tokens in the array */ |
| 3846 | inst = parsed; |
| 3847 | |
| 3848 | /* Check the grammer rev */ |
| 3849 | if (*inst++ != REVISION) { |
Brian Paul | a088f16 | 2006-09-05 23:08:51 +0000 | [diff] [blame] | 3850 | program_error (ctx, 0, "Grammar version mismatch"); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3851 | err = GL_TRUE; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3852 | } |
| 3853 | else { |
Michal Krol | b80bc05 | 2004-10-21 14:09:54 +0000 | [diff] [blame] | 3854 | /* ignore program target */ |
| 3855 | inst++; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3856 | err = parse_instructions(ctx, inst, &vc_head, program); |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | /*debug_variables(ctx, vc_head, program); */ |
| 3860 | |
| 3861 | /* We're done with the parsed binary array */ |
| 3862 | var_cache_destroy (&vc_head); |
| 3863 | |
| 3864 | _mesa_free (parsed); |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3865 | |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3866 | /* Reallocate the instruction array from size [MAX_INSTRUCTIONS] |
| 3867 | * to size [ap.Base.NumInstructions]. |
| 3868 | */ |
Brian Paul | a754390 | 2006-08-24 21:58:32 +0000 | [diff] [blame] | 3869 | program->Base.Instructions |
| 3870 | = _mesa_realloc_instructions(program->Base.Instructions, |
| 3871 | MAX_INSTRUCTIONS, |
| 3872 | program->Base.NumInstructions); |
| 3873 | |
Brian Paul | 4570364 | 2005-10-29 15:52:31 +0000 | [diff] [blame] | 3874 | return !err; |
Jouk Jansen | 40322e1 | 2004-04-05 08:50:36 +0000 | [diff] [blame] | 3875 | } |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3876 | |
| 3877 | |
| 3878 | |
| 3879 | void |
| 3880 | _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, |
| 3881 | const GLvoid *str, GLsizei len, |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 3882 | struct gl_fragment_program *program) |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3883 | { |
| 3884 | struct arb_program ap; |
| 3885 | GLuint i; |
| 3886 | |
| 3887 | ASSERT(target == GL_FRAGMENT_PROGRAM_ARB); |
Brian Paul | 9580179 | 2005-12-06 15:41:43 +0000 | [diff] [blame] | 3888 | if (!_mesa_parse_arb_program(ctx, target, (const GLubyte*) str, len, &ap)) { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3889 | /* Error in the program. Just return. */ |
| 3890 | return; |
| 3891 | } |
| 3892 | |
| 3893 | /* Copy the relevant contents of the arb_program struct into the |
| 3894 | * fragment_program struct. |
| 3895 | */ |
| 3896 | program->Base.String = ap.Base.String; |
| 3897 | program->Base.NumInstructions = ap.Base.NumInstructions; |
| 3898 | program->Base.NumTemporaries = ap.Base.NumTemporaries; |
| 3899 | program->Base.NumParameters = ap.Base.NumParameters; |
| 3900 | program->Base.NumAttributes = ap.Base.NumAttributes; |
| 3901 | program->Base.NumAddressRegs = ap.Base.NumAddressRegs; |
Roland Scheidegger | e6de1ed | 2006-08-30 11:55:18 +0000 | [diff] [blame] | 3902 | program->Base.NumNativeInstructions = ap.Base.NumNativeInstructions; |
| 3903 | program->Base.NumNativeTemporaries = ap.Base.NumNativeTemporaries; |
| 3904 | program->Base.NumNativeParameters = ap.Base.NumNativeParameters; |
| 3905 | program->Base.NumNativeAttributes = ap.Base.NumNativeAttributes; |
| 3906 | program->Base.NumNativeAddressRegs = ap.Base.NumNativeAddressRegs; |
Brian | 21f9979 | 2007-01-09 11:00:21 -0700 | [diff] [blame] | 3907 | program->Base.NumAluInstructions = ap.Base.NumAluInstructions; |
| 3908 | program->Base.NumTexInstructions = ap.Base.NumTexInstructions; |
| 3909 | program->Base.NumTexIndirections = ap.Base.NumTexIndirections; |
| 3910 | program->Base.NumNativeAluInstructions = ap.Base.NumAluInstructions; |
| 3911 | program->Base.NumNativeTexInstructions = ap.Base.NumTexInstructions; |
| 3912 | program->Base.NumNativeTexIndirections = ap.Base.NumTexIndirections; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3913 | program->Base.InputsRead = ap.Base.InputsRead; |
| 3914 | program->Base.OutputsWritten = ap.Base.OutputsWritten; |
Brian | d1284d3 | 2008-03-12 15:33:41 -0600 | [diff] [blame] | 3915 | for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) { |
Brian | c9db223 | 2007-01-04 17:22:19 -0700 | [diff] [blame] | 3916 | program->Base.TexturesUsed[i] = ap.TexturesUsed[i]; |
Brian | d1284d3 | 2008-03-12 15:33:41 -0600 | [diff] [blame] | 3917 | if (ap.TexturesUsed[i]) |
| 3918 | program->Base.SamplersUsed |= (1 << i); |
| 3919 | } |
Ian Romanick | 7b559a9 | 2007-06-07 13:58:50 -0700 | [diff] [blame] | 3920 | program->Base.ShadowSamplers = ap.ShadowSamplers; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3921 | program->FogOption = ap.FogOption; |
Keith Whitwell | 7ecdfb2 | 2007-03-04 21:47:05 +0000 | [diff] [blame] | 3922 | program->UsesKill = ap.UsesKill; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3923 | |
| 3924 | if (program->Base.Instructions) |
| 3925 | _mesa_free(program->Base.Instructions); |
| 3926 | program->Base.Instructions = ap.Base.Instructions; |
| 3927 | |
| 3928 | if (program->Base.Parameters) |
| 3929 | _mesa_free_parameter_list(program->Base.Parameters); |
| 3930 | program->Base.Parameters = ap.Base.Parameters; |
| 3931 | |
| 3932 | #if DEBUG_FP |
Brian Paul | 11a54c3 | 2006-11-15 19:54:25 +0000 | [diff] [blame] | 3933 | _mesa_printf("____________Fragment program %u ________\n", program->Base.ID); |
| 3934 | _mesa_print_program(&program->Base); |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3935 | #endif |
| 3936 | } |
| 3937 | |
| 3938 | |
| 3939 | |
| 3940 | /** |
| 3941 | * Parse the vertex program string. If success, update the given |
| 3942 | * vertex_program object with the new program. Else, leave the vertex_program |
| 3943 | * object unchanged. |
| 3944 | */ |
| 3945 | void |
| 3946 | _mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target, |
| 3947 | const GLvoid *str, GLsizei len, |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 3948 | struct gl_vertex_program *program) |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3949 | { |
| 3950 | struct arb_program ap; |
| 3951 | |
| 3952 | ASSERT(target == GL_VERTEX_PROGRAM_ARB); |
| 3953 | |
Brian Paul | 9580179 | 2005-12-06 15:41:43 +0000 | [diff] [blame] | 3954 | if (!_mesa_parse_arb_program(ctx, target, (const GLubyte*) str, len, &ap)) { |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3955 | /* Error in the program. Just return. */ |
| 3956 | return; |
| 3957 | } |
| 3958 | |
| 3959 | /* Copy the relevant contents of the arb_program struct into the |
| 3960 | * vertex_program struct. |
| 3961 | */ |
| 3962 | program->Base.String = ap.Base.String; |
| 3963 | program->Base.NumInstructions = ap.Base.NumInstructions; |
| 3964 | program->Base.NumTemporaries = ap.Base.NumTemporaries; |
| 3965 | program->Base.NumParameters = ap.Base.NumParameters; |
| 3966 | program->Base.NumAttributes = ap.Base.NumAttributes; |
| 3967 | program->Base.NumAddressRegs = ap.Base.NumAddressRegs; |
Roland Scheidegger | e6de1ed | 2006-08-30 11:55:18 +0000 | [diff] [blame] | 3968 | program->Base.NumNativeInstructions = ap.Base.NumNativeInstructions; |
| 3969 | program->Base.NumNativeTemporaries = ap.Base.NumNativeTemporaries; |
| 3970 | program->Base.NumNativeParameters = ap.Base.NumNativeParameters; |
| 3971 | program->Base.NumNativeAttributes = ap.Base.NumNativeAttributes; |
| 3972 | program->Base.NumNativeAddressRegs = ap.Base.NumNativeAddressRegs; |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3973 | program->Base.InputsRead = ap.Base.InputsRead; |
| 3974 | program->Base.OutputsWritten = ap.Base.OutputsWritten; |
| 3975 | program->IsPositionInvariant = ap.HintPositionInvariant; |
| 3976 | |
| 3977 | if (program->Base.Instructions) |
| 3978 | _mesa_free(program->Base.Instructions); |
| 3979 | program->Base.Instructions = ap.Base.Instructions; |
| 3980 | |
| 3981 | if (program->Base.Parameters) |
| 3982 | _mesa_free_parameter_list(program->Base.Parameters); |
| 3983 | program->Base.Parameters = ap.Base.Parameters; |
| 3984 | |
| 3985 | #if DEBUG_VP |
Roland Scheidegger | 54dac2c | 2007-02-09 00:36:40 +0100 | [diff] [blame] | 3986 | _mesa_printf("____________Vertex program %u __________\n", program->Base.Id); |
Brian Paul | 8c41a14 | 2005-11-19 15:36:28 +0000 | [diff] [blame] | 3987 | _mesa_print_program(&program->Base); |
| 3988 | #endif |
| 3989 | } |