Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 193d211 | 2004-02-12 21:57:29 +0000 | [diff] [blame] | 3 | * Version: 6.1 |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 193d211 | 2004-02-12 21:57:29 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +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 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 25 | #define DEBUG_VP 0 |
| 26 | |
Brian Paul | 2c50b92 | 2003-08-06 19:23:20 +0000 | [diff] [blame] | 27 | /** |
| 28 | * \file arbvertparse.c |
| 29 | * ARB_vertex_program parser. |
| 30 | * \author Karl Rasche |
| 31 | */ |
| 32 | |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 33 | #include "glheader.h" |
| 34 | #include "context.h" |
Brian Paul | ba254c0 | 2003-11-21 16:38:56 +0000 | [diff] [blame] | 35 | #include "arbvertparse.h" |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 36 | #include "hash.h" |
| 37 | #include "imports.h" |
| 38 | #include "macros.h" |
| 39 | #include "mtypes.h" |
| 40 | #include "nvprogram.h" |
| 41 | #include "nvvertparse.h" |
| 42 | #include "nvvertprog.h" |
| 43 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 44 | #include "arbparse.h" |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 45 | |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 46 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 47 | static GLvoid |
| 48 | debug_vp_inst(GLint num, struct vp_instruction *vp) |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 49 | { |
| 50 | GLint a; |
| 51 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 52 | for (a=0; a<num; a++) { |
| 53 | switch (vp[a].Opcode) { |
| 54 | case VP_OPCODE_MOV: |
| 55 | fprintf(stderr, "VP_OPCODE_MOV"); break; |
| 56 | |
| 57 | case VP_OPCODE_LIT: |
| 58 | fprintf(stderr, "VP_OPCODE_LIT"); break; |
| 59 | |
| 60 | case VP_OPCODE_RCP: |
| 61 | fprintf(stderr, "VP_OPCODE_RCP"); break; |
| 62 | |
| 63 | case VP_OPCODE_RSQ: |
| 64 | fprintf(stderr, "VP_OPCODE_RSQ"); break; |
| 65 | |
| 66 | case VP_OPCODE_EXP: |
| 67 | fprintf(stderr, "VP_OPCODE_EXP"); break; |
| 68 | |
| 69 | case VP_OPCODE_LOG: |
| 70 | fprintf(stderr, "VP_OPCODE_LOG"); break; |
| 71 | |
| 72 | case VP_OPCODE_MUL: |
| 73 | fprintf(stderr, "VP_OPCODE_MUL"); break; |
| 74 | |
| 75 | case VP_OPCODE_ADD: |
| 76 | fprintf(stderr, "VP_OPCODE_ADD"); break; |
| 77 | |
| 78 | case VP_OPCODE_DP3: |
| 79 | fprintf(stderr, "VP_OPCODE_DP3"); break; |
| 80 | |
| 81 | case VP_OPCODE_DP4: |
| 82 | fprintf(stderr, "VP_OPCODE_DP4"); break; |
| 83 | |
| 84 | case VP_OPCODE_DST: |
| 85 | fprintf(stderr, "VP_OPCODE_DST"); break; |
| 86 | |
| 87 | case VP_OPCODE_MIN: |
| 88 | fprintf(stderr, "VP_OPCODE_MIN"); break; |
| 89 | |
| 90 | case VP_OPCODE_MAX: |
| 91 | fprintf(stderr, "VP_OPCODE_MAX"); break; |
| 92 | |
| 93 | case VP_OPCODE_SLT: |
| 94 | fprintf(stderr, "VP_OPCODE_SLT"); break; |
| 95 | |
| 96 | case VP_OPCODE_SGE: |
| 97 | fprintf(stderr, "VP_OPCODE_SGE"); break; |
| 98 | |
| 99 | case VP_OPCODE_MAD: |
| 100 | fprintf(stderr, "VP_OPCODE_MAD"); break; |
| 101 | |
| 102 | case VP_OPCODE_ARL: |
| 103 | fprintf(stderr, "VP_OPCODE_ARL"); break; |
| 104 | |
| 105 | case VP_OPCODE_DPH: |
| 106 | fprintf(stderr, "VP_OPCODE_DPH"); break; |
| 107 | |
| 108 | case VP_OPCODE_RCC: |
| 109 | fprintf(stderr, "VP_OPCODE_RCC"); break; |
| 110 | |
| 111 | case VP_OPCODE_SUB: |
| 112 | fprintf(stderr, "VP_OPCODE_SUB"); break; |
| 113 | |
| 114 | case VP_OPCODE_ABS: |
| 115 | fprintf(stderr, "VP_OPCODE_ABS"); break; |
| 116 | |
| 117 | case VP_OPCODE_FLR: |
| 118 | fprintf(stderr, "VP_OPCODE_FLR"); break; |
| 119 | |
| 120 | case VP_OPCODE_FRC: |
| 121 | fprintf(stderr, "VP_OPCODE_FRC"); break; |
| 122 | |
| 123 | case VP_OPCODE_EX2: |
| 124 | fprintf(stderr, "VP_OPCODE_EX2"); break; |
| 125 | |
| 126 | case VP_OPCODE_LG2: |
| 127 | fprintf(stderr, "VP_OPCODE_LG2"); break; |
| 128 | |
| 129 | case VP_OPCODE_POW: |
| 130 | fprintf(stderr, "VP_OPCODE_POW"); break; |
| 131 | |
| 132 | case VP_OPCODE_XPD: |
| 133 | fprintf(stderr, "VP_OPCODE_XPD"); break; |
| 134 | |
| 135 | case VP_OPCODE_SWZ: |
| 136 | fprintf(stderr, "VP_OPCODE_SWZ"); break; |
| 137 | |
| 138 | case VP_OPCODE_END: |
| 139 | fprintf(stderr, "VP_OPCODE_END"); break; |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 142 | fprintf(stderr, " D(0x%x:%d:%d%d%d%d) ", vp[a].DstReg.File, vp[a].DstReg.Index, |
| 143 | vp[a].DstReg.WriteMask[0], |
| 144 | vp[a].DstReg.WriteMask[1], |
| 145 | vp[a].DstReg.WriteMask[2], |
| 146 | vp[a].DstReg.WriteMask[3]); |
| 147 | |
| 148 | fprintf(stderr, "S1(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[0].File, vp[a].SrcReg[0].Index, |
| 149 | vp[a].SrcReg[0].Swizzle[0], |
| 150 | vp[a].SrcReg[0].Swizzle[1], |
| 151 | vp[a].SrcReg[0].Swizzle[2], |
| 152 | vp[a].SrcReg[0].Swizzle[3]); |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 153 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 154 | fprintf(stderr, "S2(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[1].File, vp[a].SrcReg[1].Index, |
| 155 | vp[a].SrcReg[1].Swizzle[0], |
| 156 | vp[a].SrcReg[1].Swizzle[1], |
| 157 | vp[a].SrcReg[1].Swizzle[2], |
| 158 | vp[a].SrcReg[1].Swizzle[3]); |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 159 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 160 | fprintf(stderr, "S3(0x%x:%d:%d%d%d%d)", vp[a].SrcReg[2].File, vp[a].SrcReg[2].Index, |
| 161 | vp[a].SrcReg[2].Swizzle[0], |
| 162 | vp[a].SrcReg[2].Swizzle[1], |
| 163 | vp[a].SrcReg[2].Swizzle[2], |
| 164 | vp[a].SrcReg[2].Swizzle[3]); |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 165 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 166 | fprintf(stderr, "\n"); |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 171 | void |
| 172 | _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 173 | const GLubyte * str, GLsizei len, |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 174 | struct vertex_program *program) |
| 175 | { |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 176 | GLuint retval; |
| 177 | struct arb_program ap; |
| 178 | |
Brian Paul | ba254c0 | 2003-11-21 16:38:56 +0000 | [diff] [blame] | 179 | retval = _mesa_parse_arb_program(ctx, str, len, &ap); |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 180 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 181 | /* copy the relvant contents of the arb_program struct into the |
| 182 | * fragment_program struct |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 183 | */ |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 184 | program->Base.NumInstructions = ap.Base.NumInstructions; |
| 185 | program->Base.NumTemporaries = ap.Base.NumTemporaries; |
| 186 | program->Base.NumParameters = ap.Base.NumParameters; |
| 187 | program->Base.NumAttributes = ap.Base.NumAttributes; |
| 188 | program->Base.NumAddressRegs = ap.Base.NumAddressRegs; |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 189 | |
Karl Rasche | 1c27a1e | 2003-11-19 13:15:13 +0000 | [diff] [blame] | 190 | program->IsPositionInvariant = ap.HintPositionInvariant; |
| 191 | program->InputsRead = ap.InputsRead; |
| 192 | program->OutputsWritten = ap.OutputsWritten; |
| 193 | program->Parameters = ap.Parameters; |
Karl Rasche | 4eebfa1 | 2003-11-23 17:54:39 +0000 | [diff] [blame] | 194 | |
| 195 | /* Parse error. Allocate a dummy program and return */ |
| 196 | if (retval) |
| 197 | { |
| 198 | program->Instructions = (struct vp_instruction *) _mesa_malloc ( |
| 199 | sizeof(struct vp_instruction) ); |
| 200 | program->Instructions[0].Opcode = VP_OPCODE_END; |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | /* Eh.. we parsed something that wasn't a vertex program. doh! */ |
Brian Paul | 193d211 | 2004-02-12 21:57:29 +0000 | [diff] [blame] | 205 | if (ap.Base.Target != GL_VERTEX_PROGRAM_ARB) |
Karl Rasche | 4eebfa1 | 2003-11-23 17:54:39 +0000 | [diff] [blame] | 206 | { |
| 207 | program->Instructions = (struct vp_instruction *) _mesa_malloc ( |
| 208 | sizeof(struct vp_instruction) ); |
| 209 | program->Instructions[0].Opcode = VP_OPCODE_END; |
| 210 | |
| 211 | _mesa_error (ctx, GL_INVALID_OPERATION, "Parsed a non-vertex program as a vertex program"); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | program->Instructions = ap.VPInstructions; |
| 216 | |
| 217 | #if DEBUG_VP |
| 218 | debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions); |
| 219 | #else |
| 220 | (void) debug_vp_inst; |
| 221 | #endif |
| 222 | |
Brian Paul | 9a0d97a | 2003-07-18 16:43:45 +0000 | [diff] [blame] | 223 | } |