X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fshader%2Fnvfragparse.c;h=0fd55524abf19e03807a5342f12491ed4ddd55ae;hb=84445273ed554ea6fa65c894bbe098eb3f3d1230;hp=20e47813729a91caf0e526542c265a36031b5ee7;hpb=4af0d940a35536f096a9289470af0268a79402b3;p=mesa.git diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index 20e47813729..0fd55524abf 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -43,6 +43,7 @@ #include "main/macros.h" #include "program.h" #include "prog_parameter.h" +#include "prog_print.h" #include "prog_instruction.h" #include "nvfragparse.h" @@ -384,16 +385,6 @@ static const char *InputRegisters[MAX_NV_FRAGMENT_PROGRAM_INPUTS + 1] = { "TEX0", "TEX1", "TEX2", "TEX3", "TEX4", "TEX5", "TEX6", "TEX7", NULL }; -static const char *OutputRegisters[MAX_NV_FRAGMENT_PROGRAM_OUTPUTS + 1] = { - "COLR", "COLH", - /* These are only allows for register combiners */ - /* - "TEX0", "TEX1", "TEX2", "TEX3", - */ - "DEPR", NULL -}; - - /**********************************************************************/ @@ -828,7 +819,6 @@ static GLboolean Parse_OutputReg(struct parse_state *parseState, GLint *outputRegNum) { GLubyte token[100]; - GLint j; /* Match "o[" */ if (!Parse_String(parseState, "o[")) @@ -839,19 +829,19 @@ Parse_OutputReg(struct parse_state *parseState, GLint *outputRegNum) RETURN_ERROR; /* try to match an output register name */ - for (j = 0; OutputRegisters[j]; j++) { - if (_mesa_strcmp((const char *) token, OutputRegisters[j]) == 0) { - static GLuint bothColors = (1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_COLH); - *outputRegNum = j; - parseState->outputsWritten |= (1 << j); - if ((parseState->outputsWritten & bothColors) == bothColors) { - RETURN_ERROR1("Illegal to write to both o[COLR] and o[COLH]"); - } - break; - } + if (_mesa_strcmp((char *) token, "COLR") == 0 || + _mesa_strcmp((char *) token, "COLH") == 0) { + /* note that we don't distinguish between COLR and COLH */ + *outputRegNum = FRAG_RESULT_COLOR; + parseState->outputsWritten |= (1 << FRAG_RESULT_COLOR); + } + else if (_mesa_strcmp((char *) token, "DEPR") == 0) { + *outputRegNum = FRAG_RESULT_DEPTH; + parseState->outputsWritten |= (1 << FRAG_RESULT_DEPTH); } - if (!OutputRegisters[j]) + else { RETURN_ERROR1("Invalid output register name"); + } /* Match ']' */ if (!Parse_String(parseState, "]")) @@ -967,6 +957,7 @@ Parse_VectorSrc(struct parse_state *parseState, GLfloat sign = 1.0F; GLubyte token[100]; GLint idx; + GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. @@ -978,21 +969,23 @@ Parse_VectorSrc(struct parse_state *parseState, if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; - srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE; + negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) - srcReg->NegateBase = NEGATE_XYZW; + negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; else - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; - srcReg->NegateAbs = GL_FALSE; - srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; + 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; @@ -1093,6 +1086,7 @@ Parse_ScalarSrcReg(struct parse_state *parseState, GLfloat sign = 1.0F; GLboolean needSuffix = GL_TRUE; GLint idx; + GLuint negateBase, negateAbs; /* * First, take care of +/- and absolute value stuff. @@ -1104,21 +1098,23 @@ Parse_ScalarSrcReg(struct parse_state *parseState, if (Parse_String(parseState, "|")) { srcReg->Abs = GL_TRUE; - srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE; + negateAbs = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; if (Parse_String(parseState, "-")) - srcReg->NegateBase = NEGATE_XYZW; + negateBase = NEGATE_XYZW; else if (Parse_String(parseState, "+")) - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; else - srcReg->NegateBase = NEGATE_NONE; + negateBase = NEGATE_NONE; } else { srcReg->Abs = GL_FALSE; - srcReg->NegateAbs = GL_FALSE; - srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; + negateAbs = NEGATE_NONE; + negateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE; } + srcReg->Negate = srcReg->Abs ? negateAbs : negateBase; + if (!Peek_Token(parseState, token)) RETURN_ERROR; @@ -1257,9 +1253,8 @@ Parse_PrintInstruction(struct parse_state *parseState, } inst->SrcReg[0].Swizzle = SWIZZLE_NOOP; - inst->SrcReg[0].NegateBase = NEGATE_NONE; inst->SrcReg[0].Abs = GL_FALSE; - inst->SrcReg[0].NegateAbs = GL_FALSE; + inst->SrcReg[0].Negate = NEGATE_NONE; return GL_TRUE; } @@ -1318,8 +1313,6 @@ Parse_InstructionSequence(struct parse_state *parseState, } else if (Parse_String(parseState, "END")) { inst->Opcode = OPCODE_END; - inst->StringPos = parseState->curLine - parseState->start; - assert(inst->StringPos >= 0); parseState->numInst++; if (Parse_Token(parseState, token)) { RETURN_ERROR1("Code after END opcode."); @@ -1346,8 +1339,6 @@ Parse_InstructionSequence(struct parse_state *parseState, inst->SaturateMode = (instMatch.suffixes & (_S)) ? SATURATE_ZERO_ONE : SATURATE_OFF; inst->CondUpdate = (instMatch.suffixes & (_C)) ? GL_TRUE : GL_FALSE; - inst->StringPos = parseState->curLine - parseState->start; - assert(inst->StringPos >= 0); /* * parse the input and output operands @@ -1570,7 +1561,7 @@ _mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum dstTarget, #ifdef DEBUG_foo _mesa_printf("--- glLoadProgramNV(%d) result ---\n", program->Base.Id); - _mesa_print_nv_fragment_program(program); + _mesa_fprint_program_opt(stdout, &program->Base, PROG_PRINT_NV, 0); _mesa_printf("----------------------------------\n"); #endif } @@ -1582,243 +1573,6 @@ _mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum dstTarget, } -static void -PrintSrcReg(const struct gl_fragment_program *program, - const struct prog_src_register *src) -{ - static const char comps[5] = "xyzw"; - - if (src->NegateAbs) { - _mesa_printf("-"); - } - if (src->Abs) { - _mesa_printf("|"); - } - if (src->NegateBase) { - _mesa_printf("-"); - } - if (src->File == PROGRAM_NAMED_PARAM) { - if (program->Base.Parameters->Parameters[src->Index].Type - == PROGRAM_CONSTANT) { - const GLfloat *v; - v = program->Base.Parameters->ParameterValues[src->Index]; - _mesa_printf("{%g, %g, %g, %g}", v[0], v[1], v[2], v[3]); - } - else { - ASSERT(program->Base.Parameters->Parameters[src->Index].Type - == PROGRAM_NAMED_PARAM); - _mesa_printf("%s", program->Base.Parameters->Parameters[src->Index].Name); - } - } - else if (src->File == PROGRAM_OUTPUT) { - _mesa_printf("o[%s]", OutputRegisters[src->Index]); - } - else if (src->File == PROGRAM_INPUT) { - _mesa_printf("f[%s]", InputRegisters[src->Index]); - } - else if (src->File == PROGRAM_LOCAL_PARAM) { - _mesa_printf("p[%d]", src->Index); - } - else if (src->File == PROGRAM_TEMPORARY) { - if (src->Index >= 32) - _mesa_printf("H%d", src->Index); - else - _mesa_printf("R%d", src->Index); - } - else if (src->File == PROGRAM_WRITE_ONLY) { - _mesa_printf("%cC", "HR"[src->Index]); - } - else { - _mesa_problem(NULL, "Invalid fragment register %d", src->Index); - return; - } - if (GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 1) && - GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 2) && - GET_SWZ(src->Swizzle, 0) == GET_SWZ(src->Swizzle, 3)) { - _mesa_printf(".%c", comps[GET_SWZ(src->Swizzle, 0)]); - } - else if (src->Swizzle != SWIZZLE_NOOP) { - _mesa_printf(".%c%c%c%c", - comps[GET_SWZ(src->Swizzle, 0)], - comps[GET_SWZ(src->Swizzle, 1)], - comps[GET_SWZ(src->Swizzle, 2)], - comps[GET_SWZ(src->Swizzle, 3)]); - } - if (src->Abs) { - _mesa_printf("|"); - } -} - -static void -PrintTextureSrc(const struct prog_instruction *inst) -{ - _mesa_printf("TEX%d, ", inst->TexSrcUnit); - switch (inst->TexSrcTarget) { - case TEXTURE_1D_INDEX: - _mesa_printf("1D"); - break; - case TEXTURE_2D_INDEX: - _mesa_printf("2D"); - break; - case TEXTURE_3D_INDEX: - _mesa_printf("3D"); - break; - case TEXTURE_RECT_INDEX: - _mesa_printf("RECT"); - break; - case TEXTURE_CUBE_INDEX: - _mesa_printf("CUBE"); - break; - default: - _mesa_problem(NULL, "Invalid textue target in PrintTextureSrc"); - } -} - -static void -PrintCondCode(const struct prog_dst_register *dst) -{ - static const char *comps = "xyzw"; - static const char *ccString[] = { - "??", "GT", "EQ", "LT", "UN", "GE", "LE", "NE", "TR", "FL", "??" - }; - - _mesa_printf("%s", ccString[dst->CondMask]); - if (GET_SWZ(dst->CondSwizzle, 0) == GET_SWZ(dst->CondSwizzle, 1) && - GET_SWZ(dst->CondSwizzle, 0) == GET_SWZ(dst->CondSwizzle, 2) && - GET_SWZ(dst->CondSwizzle, 0) == GET_SWZ(dst->CondSwizzle, 3)) { - _mesa_printf(".%c", comps[GET_SWZ(dst->CondSwizzle, 0)]); - } - else if (dst->CondSwizzle != SWIZZLE_NOOP) { - _mesa_printf(".%c%c%c%c", - comps[GET_SWZ(dst->CondSwizzle, 0)], - comps[GET_SWZ(dst->CondSwizzle, 1)], - comps[GET_SWZ(dst->CondSwizzle, 2)], - comps[GET_SWZ(dst->CondSwizzle, 3)]); - } -} - - -static void -PrintDstReg(const struct prog_dst_register *dst) -{ - if (dst->File == PROGRAM_OUTPUT) { - _mesa_printf("o[%s]", OutputRegisters[dst->Index]); - } - else if (dst->File == PROGRAM_TEMPORARY) { - if (dst->Index >= 32) - _mesa_printf("H%d", dst->Index); - else - _mesa_printf("R%d", dst->Index); - } - else if (dst->File == PROGRAM_LOCAL_PARAM) { - _mesa_printf("p[%d]", dst->Index); - } - else if (dst->File == PROGRAM_WRITE_ONLY) { - _mesa_printf("%cC", "HR"[dst->Index]); - } - else { - _mesa_printf("???"); - } - - if (dst->WriteMask != 0 && dst->WriteMask != WRITEMASK_XYZW) { - _mesa_printf("."); - if (dst->WriteMask & WRITEMASK_X) - _mesa_printf("x"); - if (dst->WriteMask & WRITEMASK_Y) - _mesa_printf("y"); - if (dst->WriteMask & WRITEMASK_Z) - _mesa_printf("z"); - if (dst->WriteMask & WRITEMASK_W) - _mesa_printf("w"); - } - - if (dst->CondMask != COND_TR || - dst->CondSwizzle != SWIZZLE_NOOP) { - _mesa_printf(" ("); - PrintCondCode(dst); - _mesa_printf(")"); - } -} - - -/** - * Print (unparse) the given vertex program. Just for debugging. - */ -void -_mesa_print_nv_fragment_program(const struct gl_fragment_program *program) -{ - const struct prog_instruction *inst; - - for (inst = program->Base.Instructions; inst->Opcode != OPCODE_END; inst++) { - int i; - for (i = 0; Instructions[i].name; i++) { - if (inst->Opcode == Instructions[i].opcode) { - /* print instruction name */ - _mesa_printf("%s", Instructions[i].name); - if (inst->Precision == FLOAT16) - _mesa_printf("H"); - else if (inst->Precision == FIXED12) - _mesa_printf("X"); - if (inst->CondUpdate) - _mesa_printf("C"); - if (inst->SaturateMode == SATURATE_ZERO_ONE) - _mesa_printf("_SAT"); - _mesa_printf(" "); - - if (Instructions[i].inputs == INPUT_CC) { - PrintCondCode(&inst->DstReg); - } - else if (Instructions[i].outputs == OUTPUT_V || - Instructions[i].outputs == OUTPUT_S) { - /* print dest register */ - PrintDstReg(&inst->DstReg); - _mesa_printf(", "); - } - - /* print source register(s) */ - if (Instructions[i].inputs == INPUT_1V || - Instructions[i].inputs == INPUT_1S) { - PrintSrcReg(program, &inst->SrcReg[0]); - } - else if (Instructions[i].inputs == INPUT_2V || - Instructions[i].inputs == INPUT_2S) { - PrintSrcReg(program, &inst->SrcReg[0]); - _mesa_printf(", "); - PrintSrcReg(program, &inst->SrcReg[1]); - } - else if (Instructions[i].inputs == INPUT_3V) { - PrintSrcReg(program, &inst->SrcReg[0]); - _mesa_printf(", "); - PrintSrcReg(program, &inst->SrcReg[1]); - _mesa_printf(", "); - PrintSrcReg(program, &inst->SrcReg[2]); - } - else if (Instructions[i].inputs == INPUT_1V_T) { - PrintSrcReg(program, &inst->SrcReg[0]); - _mesa_printf(", "); - PrintTextureSrc(inst); - } - else if (Instructions[i].inputs == INPUT_3V_T) { - PrintSrcReg(program, &inst->SrcReg[0]); - _mesa_printf(", "); - PrintSrcReg(program, &inst->SrcReg[1]); - _mesa_printf(", "); - PrintSrcReg(program, &inst->SrcReg[2]); - _mesa_printf(", "); - PrintTextureSrc(inst); - } - _mesa_printf(";\n"); - break; - } - } - if (!Instructions[i].name) { - _mesa_printf("Invalid opcode %d\n", inst->Opcode); - } - } - _mesa_printf("END\n"); -} - - const char * _mesa_nv_fragment_input_register_name(GLuint i) { @@ -1826,10 +1580,3 @@ _mesa_nv_fragment_input_register_name(GLuint i) return InputRegisters[i]; } - -const char * -_mesa_nv_fragment_output_register_name(GLuint i) -{ - ASSERT(i < MAX_NV_FRAGMENT_PROGRAM_OUTPUTS); - return OutputRegisters[i]; -}