| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.2 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 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_VP 0 |
| 26 |
|
| 27 |
/** |
| 28 |
* \file arbvertparse.c |
| 29 |
* ARB_vertex_program parser. |
| 30 |
* \author Karl Rasche |
| 31 |
*/ |
| 32 |
|
| 33 |
#include "glheader.h" |
| 34 |
#include "context.h" |
| 35 |
#include "arbvertparse.h" |
| 36 |
#include "hash.h" |
| 37 |
#include "imports.h" |
| 38 |
#include "macros.h" |
| 39 |
#include "mtypes.h" |
| 40 |
#include "program.h" |
| 41 |
#include "nvprogram.h" |
| 42 |
#include "nvvertparse.h" |
| 43 |
#include "nvvertprog.h" |
| 44 |
|
| 45 |
#include "arbprogparse.h" |
| 46 |
|
| 47 |
|
| 48 |
/** |
| 49 |
* XXX this is probably redundant. We've already got code like this |
| 50 |
* in the nvvertparse.c file. Combine/clean-up someday. |
| 51 |
*/ |
| 52 |
void _mesa_debug_vp_inst(GLint num, struct vp_instruction *vp) |
| 53 |
{ |
| 54 |
GLint a; |
| 55 |
static const char *opcode_string[] = { |
| 56 |
"ABS", |
| 57 |
"ADD", |
| 58 |
"ARL", |
| 59 |
"DP3", |
| 60 |
"DP4", |
| 61 |
"DPH", |
| 62 |
"DST", |
| 63 |
"END", /* Placeholder */ |
| 64 |
"EX2", /* ARB only */ |
| 65 |
"EXP", |
| 66 |
"FLR", /* ARB */ |
| 67 |
"FRC", /* ARB */ |
| 68 |
"LG2", /* ARB only */ |
| 69 |
"LIT", |
| 70 |
"LOG", |
| 71 |
"MAD", |
| 72 |
"MAX", |
| 73 |
"MIN", |
| 74 |
"MOV", |
| 75 |
"MUL", |
| 76 |
"POW", /* ARB only */ |
| 77 |
"PRINT", /* Mesa only */ |
| 78 |
"RCC", |
| 79 |
"RCP", |
| 80 |
"RSQ", |
| 81 |
"SGE", |
| 82 |
"SLT", |
| 83 |
"SUB", |
| 84 |
"SWZ", /* ARB only */ |
| 85 |
"XPD" /* ARB only */ |
| 86 |
}; |
| 87 |
|
| 88 |
static const char *file_string[] = { |
| 89 |
"TEMP", |
| 90 |
"INPUT", |
| 91 |
"OUTPUT", |
| 92 |
"LOCAL", |
| 93 |
"ENV", |
| 94 |
"NAMED", |
| 95 |
"STATE", |
| 96 |
"WRITE_ONLY", |
| 97 |
"ADDR" |
| 98 |
}; |
| 99 |
|
| 100 |
static const char swz[] = "xyzw01??"; |
| 101 |
|
| 102 |
for (a=0; a<num; a++) { |
| 103 |
_mesa_printf("%s", opcode_string[vp[a].Opcode]); |
| 104 |
|
| 105 |
if (vp[a].DstReg.File != 0xf) { |
| 106 |
if (vp[a].DstReg.WriteMask != 0xf) |
| 107 |
_mesa_printf(" %s[%d].%s%s%s%s ", file_string[vp[a].DstReg.File], vp[a].DstReg.Index, |
| 108 |
GET_BIT(vp[a].DstReg.WriteMask, 0) ? "x" : "", |
| 109 |
GET_BIT(vp[a].DstReg.WriteMask, 1) ? "y" : "", |
| 110 |
GET_BIT(vp[a].DstReg.WriteMask, 2) ? "z" : "", |
| 111 |
GET_BIT(vp[a].DstReg.WriteMask, 3) ? "w" : ""); |
| 112 |
else |
| 113 |
_mesa_printf(" %s[%d] ", file_string[vp[a].DstReg.File], vp[a].DstReg.Index); |
| 114 |
} |
| 115 |
|
| 116 |
if (vp[a].SrcReg[0].File != 0xf) { |
| 117 |
if (vp[a].SrcReg[0].Swizzle != SWIZZLE_NOOP || |
| 118 |
vp[a].SrcReg[0].Negate) |
| 119 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[vp[a].SrcReg[0].File], vp[a].SrcReg[0].Index, |
| 120 |
vp[a].SrcReg[0].Negate ? "-" : "", |
| 121 |
swz[GET_SWZ(vp[a].SrcReg[0].Swizzle, 0)], |
| 122 |
swz[GET_SWZ(vp[a].SrcReg[0].Swizzle, 1)], |
| 123 |
swz[GET_SWZ(vp[a].SrcReg[0].Swizzle, 2)], |
| 124 |
swz[GET_SWZ(vp[a].SrcReg[0].Swizzle, 3)]); |
| 125 |
else |
| 126 |
_mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[0].File], vp[a].SrcReg[0].Index); |
| 127 |
} |
| 128 |
|
| 129 |
if (vp[a].SrcReg[1].File != 0xf) { |
| 130 |
if (vp[a].SrcReg[1].Swizzle != SWIZZLE_NOOP || |
| 131 |
vp[a].SrcReg[1].Negate) |
| 132 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[vp[a].SrcReg[1].File], vp[a].SrcReg[1].Index, |
| 133 |
vp[a].SrcReg[1].Negate ? "-" : "", |
| 134 |
swz[GET_SWZ(vp[a].SrcReg[1].Swizzle, 0)], |
| 135 |
swz[GET_SWZ(vp[a].SrcReg[1].Swizzle, 1)], |
| 136 |
swz[GET_SWZ(vp[a].SrcReg[1].Swizzle, 2)], |
| 137 |
swz[GET_SWZ(vp[a].SrcReg[1].Swizzle, 3)]); |
| 138 |
else |
| 139 |
_mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[1].File], vp[a].SrcReg[1].Index); |
| 140 |
} |
| 141 |
|
| 142 |
if (vp[a].SrcReg[2].File != 0xf) { |
| 143 |
if (vp[a].SrcReg[2].Swizzle != SWIZZLE_NOOP || |
| 144 |
vp[a].SrcReg[2].Negate) |
| 145 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[vp[a].SrcReg[2].File], vp[a].SrcReg[2].Index, |
| 146 |
vp[a].SrcReg[2].Negate ? "-" : "", |
| 147 |
swz[GET_SWZ(vp[a].SrcReg[2].Swizzle, 0)], |
| 148 |
swz[GET_SWZ(vp[a].SrcReg[2].Swizzle, 1)], |
| 149 |
swz[GET_SWZ(vp[a].SrcReg[2].Swizzle, 2)], |
| 150 |
swz[GET_SWZ(vp[a].SrcReg[2].Swizzle, 3)]); |
| 151 |
else |
| 152 |
_mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[2].File], vp[a].SrcReg[2].Index); |
| 153 |
} |
| 154 |
|
| 155 |
_mesa_printf("\n"); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
/** |
| 161 |
* Parse the vertex program string. If success, update the given |
| 162 |
* vertex_program object with the new program. Else, leave the vertex_program |
| 163 |
* object unchanged. |
| 164 |
*/ |
| 165 |
void |
| 166 |
_mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, |
| 167 |
const GLubyte * str, GLsizei len, |
| 168 |
struct vertex_program *program) |
| 169 |
{ |
| 170 |
struct arb_program ap; |
| 171 |
(void) target; |
| 172 |
|
| 173 |
/* set the program target before parsing */ |
| 174 |
ap.Base.Target = GL_VERTEX_PROGRAM_ARB; |
| 175 |
|
| 176 |
if (!_mesa_parse_arb_program(ctx, str, len, &ap)) { |
| 177 |
/* Error in the program. Just return. */ |
| 178 |
return; |
| 179 |
} |
| 180 |
|
| 181 |
/* Copy the relevant contents of the arb_program struct into the |
| 182 |
* vertex_program struct. |
| 183 |
*/ |
| 184 |
program->Base.String = ap.Base.String; |
| 185 |
program->Base.NumInstructions = ap.Base.NumInstructions; |
| 186 |
program->Base.NumTemporaries = ap.Base.NumTemporaries; |
| 187 |
program->Base.NumParameters = ap.Base.NumParameters; |
| 188 |
program->Base.NumAttributes = ap.Base.NumAttributes; |
| 189 |
program->Base.NumAddressRegs = ap.Base.NumAddressRegs; |
| 190 |
|
| 191 |
program->IsPositionInvariant = ap.HintPositionInvariant; |
| 192 |
program->InputsRead = ap.InputsRead; |
| 193 |
program->OutputsWritten = ap.OutputsWritten; |
| 194 |
|
| 195 |
if (program->Parameters) { |
| 196 |
/* free previous program's parameters */ |
| 197 |
_mesa_free_parameter_list(program->Parameters); |
| 198 |
} |
| 199 |
program->Parameters = ap.Parameters; |
| 200 |
|
| 201 |
program->Instructions = ap.VPInstructions; |
| 202 |
|
| 203 |
#if DEBUG_VP |
| 204 |
_mesa_debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions); |
| 205 |
#endif |
| 206 |
|
| 207 |
} |