static GLboolean Parse_SwizzleSrcReg(struct parse_state *parseState, struct vp_src_register *srcReg) { GLubyte token[100]; srcReg->RelAddr = GL_FALSE; /* check for '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-') { (void) Parse_String(parseState, "-"); srcReg->Negate = GL_TRUE; if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { srcReg->Negate = GL_FALSE; } /* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */ if (token[0] == 'R') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &srcReg->Index)) RETURN_ERROR; } else if (token[0] == 'c') { if (!Parse_ParamReg(parseState, srcReg)) RETURN_ERROR; } else if (token[0] == 'v') { srcReg->File = PROGRAM_INPUT; if (!Parse_AttribReg(parseState, &srcReg->Index)) RETURN_ERROR; } else { RETURN_ERROR2("Bad source register name", token); } /* init swizzle fields */ srcReg->Swizzle[0] = 0; srcReg->Swizzle[1] = 1; srcReg->Swizzle[2] = 2; srcReg->Swizzle[3] = 3; /* Look for optional swizzle suffix */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '.') { (void) Parse_String(parseState, "."); /* consume . */ if (!Parse_Token(parseState, token)) RETURN_ERROR; if (token[1] == 0) { /* single letter swizzle */ if (token[0] == 'x') ASSIGN_4V(srcReg->Swizzle, 0, 0, 0, 0); else if (token[0] == 'y') ASSIGN_4V(srcReg->Swizzle, 1, 1, 1, 1); else if (token[0] == 'z') ASSIGN_4V(srcReg->Swizzle, 2, 2, 2, 2); else if (token[0] == 'w') ASSIGN_4V(srcReg->Swizzle, 3, 3, 3, 3); else RETURN_ERROR1("Expected x, y, z, or w"); } else { /* 2, 3 or 4-component swizzle */ GLint k; for (k = 0; token[k] && k < 5; k++) { if (token[k] == 'x') srcReg->Swizzle[k] = 0; else if (token[k] == 'y') srcReg->Swizzle[k] = 1; else if (token[k] == 'z') srcReg->Swizzle[k] = 2; else if (token[k] == 'w') srcReg->Swizzle[k] = 3; else RETURN_ERROR; } if (k >= 5) RETURN_ERROR; } } return GL_TRUE; }
static GLboolean Parse_ScalarSrcReg(struct parse_state *parseState, struct vp_src_register *srcReg) { GLubyte token[100]; srcReg->RelAddr = GL_FALSE; /* check for '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-') { srcReg->Negate = GL_TRUE; (void) Parse_String(parseState, "-"); /* consume '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { srcReg->Negate = GL_FALSE; } /* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */ if (token[0] == 'R') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &srcReg->Index)) RETURN_ERROR; } else if (token[0] == 'c') { if (!Parse_ParamReg(parseState, srcReg)) RETURN_ERROR; } else if (token[0] == 'v') { srcReg->File = PROGRAM_INPUT; if (!Parse_AttribReg(parseState, &srcReg->Index)) RETURN_ERROR; } else { RETURN_ERROR2("Bad source register name", token); } /* Look for .[xyzw] suffix */ if (!Parse_String(parseState, ".")) RETURN_ERROR; if (!Parse_Token(parseState, token)) RETURN_ERROR; if (token[0] == 'x' && token[1] == 0) { srcReg->Swizzle[0] = 0; } else if (token[0] == 'y' && token[1] == 0) { srcReg->Swizzle[0] = 1; } else if (token[0] == 'z' && token[1] == 0) { srcReg->Swizzle[0] = 2; } else if (token[0] == 'w' && token[1] == 0) { srcReg->Swizzle[0] = 3; } else { RETURN_ERROR1("Bad scalar source suffix"); } srcReg->Swizzle[1] = srcReg->Swizzle[2] = srcReg->Swizzle[3] = 0; return GL_TRUE; }
static GLboolean Parse_ParamReg(struct parse_state *parseState, struct vp_src_register *srcReg) { GLubyte token[100]; if (!Parse_String(parseState, "c")) RETURN_ERROR; if (!Parse_String(parseState, "[")) RETURN_ERROR; if (!Peek_Token(parseState, token)) RETURN_ERROR; if (IsDigit(token[0])) { /* a numbered program parameter register */ GLint reg; (void) Parse_Token(parseState, token); reg = _mesa_atoi((char *) token); if (reg >= MAX_NV_VERTEX_PROGRAM_PARAMS) RETURN_ERROR1("Bad program parameter number"); srcReg->File = PROGRAM_ENV_PARAM; srcReg->Index = reg; } else if (_mesa_strcmp((const char *) token, "A0") == 0) { /* address register "A0.x" */ if (!Parse_AddrReg(parseState)) RETURN_ERROR; srcReg->RelAddr = GL_TRUE; srcReg->File = PROGRAM_ENV_PARAM; /* Look for +/-N offset */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-' || token[0] == '+') { const GLubyte sign = token[0]; (void) Parse_Token(parseState, token); /* consume +/- */ /* an integer should be next */ if (!Parse_Token(parseState, token)) RETURN_ERROR; if (IsDigit(token[0])) { const GLint k = _mesa_atoi((char *) token); if (sign == '-') { if (k > 64) RETURN_ERROR1("Bad address offset"); srcReg->Index = -k; } else { if (k > 63) RETURN_ERROR1("Bad address offset"); srcReg->Index = k; } } else { RETURN_ERROR; } } else { /* probably got a ']', catch it below */ } } else { RETURN_ERROR; } /* Match closing ']' */ if (!Parse_String(parseState, "]")) RETURN_ERROR; return GL_TRUE; }
static GLboolean Parse_MaskedDstReg(struct parse_state *parseState, struct vp_dst_register *dstReg) { GLubyte token[100]; /* Dst reg can be R<n> or o[n] */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == 'R') { /* a temporary register */ dstReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &dstReg->Index)) RETURN_ERROR; } else if (!parseState->isStateProgram && token[0] == 'o') { /* an output register */ dstReg->File = PROGRAM_OUTPUT; if (!Parse_OutputReg(parseState, &dstReg->Index)) RETURN_ERROR; } else if (parseState->isStateProgram && token[0] == 'c' && parseState->isStateProgram) { /* absolute program parameter register */ /* Only valid for vertex state programs */ dstReg->File = PROGRAM_ENV_PARAM; if (!Parse_AbsParamReg(parseState, &dstReg->Index)) RETURN_ERROR; } else { RETURN_ERROR1("Bad destination register name"); } /* Parse optional write mask */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '.') { /* got a mask */ GLint k = 0; if (!Parse_String(parseState, ".")) RETURN_ERROR; if (!Parse_Token(parseState, token)) RETURN_ERROR; dstReg->WriteMask[0] = GL_FALSE; dstReg->WriteMask[1] = GL_FALSE; dstReg->WriteMask[2] = GL_FALSE; dstReg->WriteMask[3] = GL_FALSE; if (token[k] == 'x') { dstReg->WriteMask[0] = GL_TRUE; k++; } if (token[k] == 'y') { dstReg->WriteMask[1] = GL_TRUE; k++; } if (token[k] == 'z') { dstReg->WriteMask[2] = GL_TRUE; k++; } if (token[k] == 'w') { dstReg->WriteMask[3] = GL_TRUE; k++; } if (k == 0) { RETURN_ERROR1("Bad writemask character"); } return GL_TRUE; } else { dstReg->WriteMask[0] = GL_TRUE; dstReg->WriteMask[1] = GL_TRUE; dstReg->WriteMask[2] = GL_TRUE; dstReg->WriteMask[3] = GL_TRUE; return GL_TRUE; } }
/** * The PRINT instruction is Mesa-specific and is meant as a debugging aid for * the vertex program developer. * The NV_vertex_program extension grammar is modified as follows: * * <instruction> ::= <ARL-instruction> * | ... * | <PRINT-instruction> * * <PRINT-instruction> ::= "PRINT" <string literal> * | "PRINT" <string literal> "," <srcReg> * | "PRINT" <string literal> "," <dstReg> */ static GLboolean Parse_PrintInstruction(struct parse_state *parseState, struct vp_instruction *inst) { const GLubyte *str; GLubyte *msg; GLuint len; GLubyte token[100]; struct vp_src_register *srcReg = &inst->SrcReg[0]; inst->Opcode = VP_OPCODE_PRINT; inst->StringPos = parseState->curLine - parseState->start; /* The first argument is a literal string 'just like this' */ if (!Parse_String(parseState, "'")) RETURN_ERROR; str = parseState->pos; for (len = 0; str[len] != '\''; len++) /* find closing quote */ ; parseState->pos += len + 1; msg = _mesa_malloc(len + 1); _mesa_memcpy(msg, str, len); msg[len] = 0; inst->Data = msg; /* comma */ if (Parse_String(parseState, ",")) { /* The second argument is a register name */ if (!Peek_Token(parseState, token)) RETURN_ERROR; srcReg->RelAddr = GL_FALSE; srcReg->Negate = GL_FALSE; srcReg->Swizzle[0] = 0; srcReg->Swizzle[1] = 1; srcReg->Swizzle[2] = 2; srcReg->Swizzle[3] = 3; /* Register can be R<n>, c[n], c[n +/- offset], a named vertex attrib, * or an o[n] output register. */ if (token[0] == 'R') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &srcReg->Index)) RETURN_ERROR; } else if (token[0] == 'c') { srcReg->File = PROGRAM_ENV_PARAM; if (!Parse_ParamReg(parseState, srcReg)) RETURN_ERROR; } else if (token[0] == 'v') { srcReg->File = PROGRAM_INPUT; if (!Parse_AttribReg(parseState, &srcReg->Index)) RETURN_ERROR; } else if (token[0] == 'o') { srcReg->File = PROGRAM_OUTPUT; if (!Parse_OutputReg(parseState, &srcReg->Index)) RETURN_ERROR; } else { RETURN_ERROR2("Bad source register name", token); } } else { srcReg->File = 0; } /* semicolon */ if (!Parse_String(parseState, ";")) RETURN_ERROR; return GL_TRUE; }
static GLboolean Parse_SwizzleSrcReg(struct parse_state *parseState, struct prog_src_register *srcReg) { GLubyte token[100]; GLint idx; srcReg->RelAddr = GL_FALSE; /* check for '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-') { (void) Parse_String(parseState, "-"); srcReg->NegateBase = NEGATE_XYZW; if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { srcReg->NegateBase = NEGATE_NONE; } /* Src reg can be R<n>, c[n], c[n +/- offset], or a named vertex attrib */ if (token[0] == 'R') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (token[0] == 'c') { if (!Parse_ParamReg(parseState, srcReg)) RETURN_ERROR; } else if (token[0] == 'v') { srcReg->File = PROGRAM_INPUT; if (!Parse_AttribReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else { RETURN_ERROR2("Bad source register name", token); } /* init swizzle fields */ srcReg->Swizzle = SWIZZLE_NOOP; /* Look for optional swizzle suffix */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '.') { (void) Parse_String(parseState, "."); /* consume . */ if (!Parse_Token(parseState, token)) RETURN_ERROR; if (token[1] == 0) { /* single letter swizzle */ if (token[0] == 'x') srcReg->Swizzle = SWIZZLE_XXXX; else if (token[0] == 'y') srcReg->Swizzle = SWIZZLE_YYYY; else if (token[0] == 'z') srcReg->Swizzle = SWIZZLE_ZZZZ; else if (token[0] == 'w') srcReg->Swizzle = SWIZZLE_WWWW; else RETURN_ERROR1("Expected x, y, z, or w"); } else { /* 2, 3 or 4-component swizzle */ GLint k; srcReg->Swizzle = 0; for (k = 0; token[k] && k < 5; k++) { if (token[k] == 'x') srcReg->Swizzle |= 0 << (k*3); else if (token[k] == 'y') srcReg->Swizzle |= 1 << (k*3); else if (token[k] == 'z') srcReg->Swizzle |= 2 << (k*3); else if (token[k] == 'w') srcReg->Swizzle |= 3 << (k*3); else RETURN_ERROR; } if (k >= 5) RETURN_ERROR; } } return GL_TRUE; }
/** * Parse a vector source (register, constant, etc): * <vectorSrc> ::= <absVectorSrc> * | <baseVectorSrc> * <absVectorSrc> ::= <negate> "|" <baseVectorSrc> "|" */ static GLboolean Parse_VectorSrc(struct parse_state *parseState, struct prog_src_register *srcReg) { GLfloat sign = 1.0F; GLubyte token[100]; GLint idx; GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. */ if (Parse_String(parseState, "-")) sign = -1.0F; else if (Parse_String(parseState, "+")) sign = +1.0F; if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) negateBase = NEGATE_NONE; else negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; negateAbs = NEGATE_NONE; negateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; } srcReg->Negate = srcReg->Abs ? negateAbs : negateBase; /* This should be the real src vector/register name */ if (!Peek_Token(parseState, token)) RETURN_ERROR; /* Src reg can be Rn, Hn, f[n], p[n], a named parameter, a scalar * literal or vector literal. */ if (token[0] == 'R' || token[0] == 'H') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (token[0] == 'f') { /* XXX this might be an identifier! */ srcReg->File = PROGRAM_INPUT; if (!Parse_FragReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (token[0] == 'p') { /* XXX this might be an identifier! */ srcReg->File = PROGRAM_LOCAL_PARAM; if (!Parse_ProgramParamReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (IsLetter(token[0])){ GLubyte ident[100]; GLint paramIndex; if (!Parse_Identifier(parseState, ident)) RETURN_ERROR; paramIndex = _mesa_lookup_parameter_index(parseState->parameters, -1, (const char *) ident); if (paramIndex < 0) { RETURN_ERROR2("Undefined constant or parameter: ", ident); } srcReg->File = PROGRAM_NAMED_PARAM; srcReg->Index = paramIndex; } else if (IsDigit(token[0]) || token[0] == '-' || token[0] == '+' || token[0] == '.'){ /* literal scalar constant */ GLfloat values[4]; GLuint paramIndex; if (!Parse_ScalarConstant(parseState, values)) RETURN_ERROR; paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4, NULL); srcReg->File = PROGRAM_NAMED_PARAM; srcReg->Index = paramIndex; } else if (token[0] == '{'){ /* literal vector constant */ GLfloat values[4]; GLuint paramIndex; (void) Parse_String(parseState, "{"); if (!Parse_VectorConstant(parseState, values)) RETURN_ERROR; paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4, NULL); srcReg->File = PROGRAM_NAMED_PARAM; srcReg->Index = paramIndex; } else { RETURN_ERROR2("Invalid source register name", token); } /* init swizzle fields */ srcReg->Swizzle = SWIZZLE_NOOP; /* Look for optional swizzle suffix */ if (Parse_String(parseState, ".")) { GLuint swz[4]; if (!Parse_Token(parseState, token)) RETURN_ERROR; if (!Parse_SwizzleSuffix(token, swz)) RETURN_ERROR1("Invalid swizzle suffix"); srcReg->Swizzle = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]); } /* Finish absolute value */ if (srcReg->Abs && !Parse_String(parseState, "|")) { RETURN_ERROR1("Expected |"); } return GL_TRUE; }
static GLboolean Parse_MaskedDstReg(struct parse_state *parseState, struct prog_dst_register *dstReg) { GLubyte token[100]; GLint idx; /* Dst reg can be R<n>, H<n>, o[n], RC or HC */ if (!Peek_Token(parseState, token)) RETURN_ERROR; if (strcmp((const char *) token, "RC") == 0 || strcmp((const char *) token, "HC") == 0) { /* a write-only register */ dstReg->File = PROGRAM_WRITE_ONLY; if (!Parse_DummyReg(parseState, &idx)) RETURN_ERROR; dstReg->Index = idx; } else if (token[0] == 'R' || token[0] == 'H') { /* a temporary register */ dstReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &idx)) RETURN_ERROR; dstReg->Index = idx; } else if (token[0] == 'o') { /* an output register */ dstReg->File = PROGRAM_OUTPUT; if (!Parse_OutputReg(parseState, &idx)) RETURN_ERROR; dstReg->Index = idx; } else { RETURN_ERROR1("Invalid destination register name"); } /* Parse optional write mask */ if (Parse_String(parseState, ".")) { /* got a mask */ GLint k = 0; if (!Parse_Token(parseState, token)) /* get xyzw writemask */ RETURN_ERROR; dstReg->WriteMask = 0; if (token[k] == 'x') { dstReg->WriteMask |= WRITEMASK_X; k++; } if (token[k] == 'y') { dstReg->WriteMask |= WRITEMASK_Y; k++; } if (token[k] == 'z') { dstReg->WriteMask |= WRITEMASK_Z; k++; } if (token[k] == 'w') { dstReg->WriteMask |= WRITEMASK_W; k++; } if (k == 0) { RETURN_ERROR1("Invalid writemask character"); } } else { dstReg->WriteMask = WRITEMASK_XYZW; } /* optional condition code mask */ if (Parse_String(parseState, "(")) { /* ("EQ" | "GE" | "GT" | "LE" | "LT" | "NE" | "TR" | "FL".x|y|z|w) */ /* ("EQ" | "GE" | "GT" | "LE" | "LT" | "NE" | "TR" | "FL".[xyzw]) */ if (!Parse_CondCodeMask(parseState, dstReg)) RETURN_ERROR; if (!Parse_String(parseState, ")")) /* consume ")" */ RETURN_ERROR1("Expected )"); return GL_TRUE; } else { /* no cond code mask */ dstReg->CondMask = COND_TR; dstReg->CondSwizzle = SWIZZLE_NOOP; return GL_TRUE; } }
static GLboolean Parse_ScalarSrcReg(struct parse_state *parseState, struct prog_src_register *srcReg) { GLubyte token[100]; GLfloat sign = 1.0F; GLboolean needSuffix = GL_TRUE; GLint idx; GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. */ if (Parse_String(parseState, "-")) sign = -1.0F; else if (Parse_String(parseState, "+")) sign = +1.0F; if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) negateBase = NEGATE_NONE; else negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; negateAbs = NEGATE_NONE; negateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; } srcReg->Negate = srcReg->Abs ? negateAbs : negateBase; if (!Peek_Token(parseState, token)) RETURN_ERROR; /* Src reg can be R<n>, H<n> or a named fragment attrib */ if (token[0] == 'R' || token[0] == 'H') { srcReg->File = PROGRAM_TEMPORARY; if (!Parse_TempReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (token[0] == 'f') { srcReg->File = PROGRAM_INPUT; if (!Parse_FragReg(parseState, &idx)) RETURN_ERROR; srcReg->Index = idx; } else if (token[0] == '{') { /* vector literal */ GLfloat values[4]; GLuint paramIndex; (void) Parse_String(parseState, "{"); if (!Parse_VectorConstant(parseState, values)) RETURN_ERROR; paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4, NULL); srcReg->File = PROGRAM_NAMED_PARAM; srcReg->Index = paramIndex; } else if (IsLetter(token[0])){ /* named param/constant */ GLubyte ident[100]; GLint paramIndex; if (!Parse_Identifier(parseState, ident)) RETURN_ERROR; paramIndex = _mesa_lookup_parameter_index(parseState->parameters, -1, (const char *) ident); if (paramIndex < 0) { RETURN_ERROR2("Undefined constant or parameter: ", ident); } srcReg->File = PROGRAM_NAMED_PARAM; srcReg->Index = paramIndex; } else if (IsDigit(token[0])) { /* scalar literal */ GLfloat values[4]; GLuint paramIndex; if (!Parse_ScalarConstant(parseState, values)) RETURN_ERROR; paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4, NULL); srcReg->Index = paramIndex; srcReg->File = PROGRAM_NAMED_PARAM; needSuffix = GL_FALSE; } else { RETURN_ERROR2("Invalid scalar source argument", token); } srcReg->Swizzle = 0; if (needSuffix) { /* parse .[xyzw] suffix */ if (!Parse_String(parseState, ".")) RETURN_ERROR1("Expected ."); if (!Parse_Token(parseState, token)) RETURN_ERROR; if (token[0] == 'x' && token[1] == 0) { srcReg->Swizzle = 0; } else if (token[0] == 'y' && token[1] == 0) { srcReg->Swizzle = 1; } else if (token[0] == 'z' && token[1] == 0) { srcReg->Swizzle = 2; } else if (token[0] == 'w' && token[1] == 0) { srcReg->Swizzle = 3; } else { RETURN_ERROR1("Invalid scalar source suffix"); } } /* Finish absolute value */ if (srcReg->Abs && !Parse_String(parseState, "|")) { RETURN_ERROR1("Expected |"); } return GL_TRUE; }