| 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_FP 0 |
| 26 |
|
| 27 |
/** |
| 28 |
* \file arbfragparse.c |
| 29 |
* ARB_fragment_program parser. |
| 30 |
* \author Karl Rasche |
| 31 |
*/ |
| 32 |
|
| 33 |
#include "glheader.h" |
| 34 |
#include "context.h" |
| 35 |
#include "imports.h" |
| 36 |
#include "macros.h" |
| 37 |
#include "mtypes.h" |
| 38 |
#include "program.h" |
| 39 |
#include "arbprogparse.h" |
| 40 |
#include "arbfragparse.h" |
| 41 |
|
| 42 |
void |
| 43 |
_mesa_debug_fp_inst(GLint num, struct fp_instruction *fp) |
| 44 |
{ |
| 45 |
GLint a; |
| 46 |
|
| 47 |
static const char *opcode_string[] = { |
| 48 |
"ABS", /* ARB_f_p only */ |
| 49 |
"ADD", |
| 50 |
"CMP", /* ARB_f_p only */ |
| 51 |
"COS", |
| 52 |
"DDX", /* NV_f_p only */ |
| 53 |
"DDY", /* NV_f_p only */ |
| 54 |
"DP3", |
| 55 |
"DP4", |
| 56 |
"DPH", /* ARB_f_p only */ |
| 57 |
"DST", |
| 58 |
"END", /* private opcode */ |
| 59 |
"EX2", |
| 60 |
"FLR", |
| 61 |
"FRC", |
| 62 |
"KIL", /* ARB_f_p only */ |
| 63 |
"KIL_NV", /* NV_f_p only */ |
| 64 |
"LG2", |
| 65 |
"LIT", |
| 66 |
"LRP", |
| 67 |
"MAD", |
| 68 |
"MAX", |
| 69 |
"MIN", |
| 70 |
"MOV", |
| 71 |
"MUL", |
| 72 |
"PK2H", /* NV_f_p only */ |
| 73 |
"PK2US", /* NV_f_p only */ |
| 74 |
"PK4B", /* NV_f_p only */ |
| 75 |
"PK4UB", /* NV_f_p only */ |
| 76 |
"POW", |
| 77 |
"PRINT", /* Mesa only */ |
| 78 |
"RCP", |
| 79 |
"RFL", /* NV_f_p only */ |
| 80 |
"RSQ", |
| 81 |
"SCS", /* ARB_f_p only */ |
| 82 |
"SEQ", /* NV_f_p only */ |
| 83 |
"SFL", /* NV_f_p only */ |
| 84 |
"SGE", /* NV_f_p only */ |
| 85 |
"SGT", /* NV_f_p only */ |
| 86 |
"SIN", |
| 87 |
"SLE", /* NV_f_p only */ |
| 88 |
"SLT", |
| 89 |
"SNE", /* NV_f_p only */ |
| 90 |
"STR", /* NV_f_p only */ |
| 91 |
"SUB", |
| 92 |
"SWZ", /* ARB_f_p only */ |
| 93 |
"TEX", |
| 94 |
"TXB", /* ARB_f_p only */ |
| 95 |
"TXD", /* NV_f_p only */ |
| 96 |
"TXP", /* ARB_f_p only */ |
| 97 |
"TXP_NV", /* NV_f_p only */ |
| 98 |
"UP2H", /* NV_f_p only */ |
| 99 |
"UP2US", /* NV_f_p only */ |
| 100 |
"UP4B", /* NV_f_p only */ |
| 101 |
"UP4UB", /* NV_f_p only */ |
| 102 |
"X2D", /* NV_f_p only - 2d mat mul */ |
| 103 |
"XPD", /* ARB_f_p only - cross product */ |
| 104 |
}; |
| 105 |
|
| 106 |
static const char *file_string[] = { |
| 107 |
"TEMP", |
| 108 |
"INPUT", |
| 109 |
"OUTPUT", |
| 110 |
"LOCAL", |
| 111 |
"ENV", |
| 112 |
"NAMED", |
| 113 |
"STATE", |
| 114 |
"WRITE_ONLY", |
| 115 |
"ADDR" |
| 116 |
}; |
| 117 |
|
| 118 |
static const char swz[] = "xyzw01??"; |
| 119 |
|
| 120 |
for (a=0; a<num; a++) { |
| 121 |
_mesa_printf("%s", opcode_string[fp[a].Opcode]); |
| 122 |
|
| 123 |
if (fp[a].Saturate) |
| 124 |
_mesa_printf("_SAT"); |
| 125 |
|
| 126 |
if (fp[a].DstReg.File != 0xf) { |
| 127 |
if (fp[a].DstReg.WriteMask != 0xf || |
| 128 |
fp[a].SrcReg[0].NegateBase) |
| 129 |
_mesa_printf(" %s[%d].%s%s%s%s ", file_string[fp[a].DstReg.File], fp[a].DstReg.Index, |
| 130 |
GET_BIT(fp[a].DstReg.WriteMask, 0) ? "x" : "", |
| 131 |
GET_BIT(fp[a].DstReg.WriteMask, 1) ? "y" : "", |
| 132 |
GET_BIT(fp[a].DstReg.WriteMask, 2) ? "z" : "", |
| 133 |
GET_BIT(fp[a].DstReg.WriteMask, 3) ? "w" : ""); |
| 134 |
else |
| 135 |
_mesa_printf(" %s[%d] ", file_string[fp[a].DstReg.File], fp[a].DstReg.Index); |
| 136 |
} |
| 137 |
|
| 138 |
if (fp[a].SrcReg[0].File != 0xf) { |
| 139 |
if (fp[a].SrcReg[0].Swizzle != SWIZZLE_NOOP || |
| 140 |
fp[a].SrcReg[0].NegateBase) |
| 141 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[0].File], fp[a].SrcReg[0].Index, |
| 142 |
fp[a].SrcReg[0].NegateBase ? "-" : "", |
| 143 |
swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 0)], |
| 144 |
swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 1)], |
| 145 |
swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 2)], |
| 146 |
swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 3)]); |
| 147 |
else |
| 148 |
_mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[0].File], fp[a].SrcReg[0].Index); |
| 149 |
} |
| 150 |
|
| 151 |
if (fp[a].SrcReg[1].File != 0xf) { |
| 152 |
if (fp[a].SrcReg[1].Swizzle != SWIZZLE_NOOP || |
| 153 |
fp[a].SrcReg[1].NegateBase) |
| 154 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[1].File], fp[a].SrcReg[1].Index, |
| 155 |
fp[a].SrcReg[1].NegateBase ? "-" : "", |
| 156 |
swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 0)], |
| 157 |
swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 1)], |
| 158 |
swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 2)], |
| 159 |
swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 3)]); |
| 160 |
else |
| 161 |
_mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[1].File], fp[a].SrcReg[1].Index); |
| 162 |
} |
| 163 |
|
| 164 |
if (fp[a].SrcReg[2].File != 0xf) { |
| 165 |
if (fp[a].SrcReg[2].Swizzle != SWIZZLE_NOOP || |
| 166 |
fp[a].SrcReg[2].NegateBase) |
| 167 |
_mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[2].File], fp[a].SrcReg[2].Index, |
| 168 |
fp[a].SrcReg[1].NegateBase ? "-" : "", |
| 169 |
swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 0)], |
| 170 |
swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 1)], |
| 171 |
swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 2)], |
| 172 |
swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 3)]); |
| 173 |
else |
| 174 |
_mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[2].File], fp[a].SrcReg[2].Index); |
| 175 |
} |
| 176 |
|
| 177 |
_mesa_printf("\n"); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
void |
| 183 |
_mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target, |
| 184 |
const GLubyte * str, GLsizei len, |
| 185 |
struct fragment_program *program) |
| 186 |
{ |
| 187 |
GLuint i; |
| 188 |
struct arb_program ap; |
| 189 |
(void) target; |
| 190 |
|
| 191 |
/* set the program target before parsing */ |
| 192 |
ap.Base.Target = GL_FRAGMENT_PROGRAM_ARB; |
| 193 |
|
| 194 |
if (!_mesa_parse_arb_program(ctx, str, len, &ap)) { |
| 195 |
/* Error in the program. Just return. */ |
| 196 |
return; |
| 197 |
} |
| 198 |
|
| 199 |
/* Copy the relevant contents of the arb_program struct into the |
| 200 |
* fragment_program struct. |
| 201 |
*/ |
| 202 |
program->Base.String = ap.Base.String; |
| 203 |
program->Base.NumInstructions = ap.Base.NumInstructions; |
| 204 |
program->Base.NumTemporaries = ap.Base.NumTemporaries; |
| 205 |
program->Base.NumParameters = ap.Base.NumParameters; |
| 206 |
program->Base.NumAttributes = ap.Base.NumAttributes; |
| 207 |
program->Base.NumAddressRegs = ap.Base.NumAddressRegs; |
| 208 |
program->NumAluInstructions = ap.NumAluInstructions; |
| 209 |
program->NumTexInstructions = ap.NumTexInstructions; |
| 210 |
program->NumTexIndirections = ap.NumTexIndirections; |
| 211 |
|
| 212 |
program->InputsRead = ap.InputsRead; |
| 213 |
program->OutputsWritten = ap.OutputsWritten; |
| 214 |
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) |
| 215 |
program->TexturesUsed[i] = ap.TexturesUsed[i]; |
| 216 |
|
| 217 |
if (program->Parameters) { |
| 218 |
/* free previous program's parameters */ |
| 219 |
_mesa_free_parameter_list(program->Parameters); |
| 220 |
} |
| 221 |
program->Parameters = ap.Parameters; |
| 222 |
program->FogOption = ap.FogOption; |
| 223 |
|
| 224 |
#if DEBUG_FP |
| 225 |
_mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions); |
| 226 |
#endif |
| 227 |
|
| 228 |
program->Instructions = ap.FPInstructions; |
| 229 |
} |