X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fshader%2Fnvvertparse.c;h=f5e2df267081dbe2cc41cbe4e2c22c1142b9298b;hb=73137997e23ff6c11;hp=ecfe8ec334fbaaa25487cc5df3f2b1840966ff51;hpb=d6272e06172f7ac7a0d6e8062e8ffba33e1ab3ba;p=mesa.git diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c index ecfe8ec334f..f5e2df26708 100644 --- a/src/mesa/shader/nvvertparse.c +++ b/src/mesa/shader/nvvertparse.c @@ -37,15 +37,14 @@ * including any use thereof or modifications thereto. */ -#include "glheader.h" -#include "context.h" -#include "hash.h" -#include "imports.h" -#include "macros.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/context.h" +#include "main/imports.h" +#include "main/macros.h" #include "nvprogram.h" #include "nvvertparse.h" -#include "program_instruction.h" +#include "prog_instruction.h" +#include "prog_print.h" #include "program.h" @@ -642,12 +641,12 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct prog_src_register *sr RETURN_ERROR; if (token[0] == '-') { (void) Parse_String(parseState, "-"); - srcReg->NegateBase = NEGATE_XYZW; + srcReg->Negate = NEGATE_XYZW; if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; } /* Src reg can be R, c[n], c[n +/- offset], or a named vertex attrib */ @@ -686,13 +685,13 @@ Parse_SwizzleSrcReg(struct parse_state *parseState, struct prog_src_register *sr if (token[1] == 0) { /* single letter swizzle */ if (token[0] == 'x') - srcReg->Swizzle = MAKE_SWIZZLE4(0, 0, 0, 0); + srcReg->Swizzle = SWIZZLE_XXXX; else if (token[0] == 'y') - srcReg->Swizzle = MAKE_SWIZZLE4(1, 1, 1, 1); + srcReg->Swizzle = SWIZZLE_YYYY; else if (token[0] == 'z') - srcReg->Swizzle = MAKE_SWIZZLE4(2, 2, 2, 2); + srcReg->Swizzle = SWIZZLE_ZZZZ; else if (token[0] == 'w') - srcReg->Swizzle = MAKE_SWIZZLE4(3, 3, 3, 3); + srcReg->Swizzle = SWIZZLE_WWWW; else RETURN_ERROR1("Expected x, y, z, or w"); } @@ -735,13 +734,13 @@ Parse_ScalarSrcReg(struct parse_state *parseState, struct prog_src_register *src if (!Peek_Token(parseState, token)) RETURN_ERROR; if (token[0] == '-') { - srcReg->NegateBase = NEGATE_XYZW; + srcReg->Negate = NEGATE_XYZW; (void) Parse_String(parseState, "-"); /* consume '-' */ if (!Peek_Token(parseState, token)) RETURN_ERROR; } else { - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; } /* Src reg can be R, c[n], c[n +/- offset], or a named vertex attrib */ @@ -801,7 +800,6 @@ Parse_UnaryOpInstruction(struct parse_state *parseState, RETURN_ERROR1("ABS illegal for vertex program 1.0"); inst->Opcode = opcode; - inst->StringPos = parseState->curLine - parseState->start; /* dest reg */ if (!Parse_MaskedDstReg(parseState, &inst->DstReg)) @@ -834,7 +832,6 @@ Parse_BiOpInstruction(struct parse_state *parseState, RETURN_ERROR1("SUB illegal for vertex program 1.0"); inst->Opcode = opcode; - inst->StringPos = parseState->curLine - parseState->start; /* dest reg */ if (!Parse_MaskedDstReg(parseState, &inst->DstReg)) @@ -882,7 +879,6 @@ Parse_TriOpInstruction(struct parse_state *parseState, enum prog_opcode opcode) { inst->Opcode = opcode; - inst->StringPos = parseState->curLine - parseState->start; /* dest reg */ if (!Parse_MaskedDstReg(parseState, &inst->DstReg)) @@ -953,7 +949,6 @@ Parse_ScalarInstruction(struct parse_state *parseState, RETURN_ERROR1("RCC illegal for vertex program 1.0"); inst->Opcode = opcode; - inst->StringPos = parseState->curLine - parseState->start; /* dest reg */ if (!Parse_MaskedDstReg(parseState, &inst->DstReg)) @@ -979,7 +974,6 @@ static GLboolean Parse_AddressInstruction(struct parse_state *parseState, struct prog_instruction *inst) { inst->Opcode = OPCODE_ARL; - inst->StringPos = parseState->curLine - parseState->start; /* Make ARB_vp backends happy */ inst->DstReg.File = PROGRAM_ADDRESS; @@ -1012,7 +1006,6 @@ Parse_EndInstruction(struct parse_state *parseState, struct prog_instruction *in GLubyte token[100]; inst->Opcode = OPCODE_END; - inst->StringPos = parseState->curLine - parseState->start; /* this should fail! */ if (Parse_Token(parseState, token)) @@ -1046,7 +1039,6 @@ Parse_PrintInstruction(struct parse_state *parseState, struct prog_instruction * GLint idx; inst->Opcode = OPCODE_PRINT; - inst->StringPos = parseState->curLine - parseState->start; /* The first argument is a literal string 'just like this' */ if (!Parse_String(parseState, "'")) @@ -1070,7 +1062,7 @@ Parse_PrintInstruction(struct parse_state *parseState, struct prog_instruction * RETURN_ERROR; srcReg->RelAddr = GL_FALSE; - srcReg->NegateBase = NEGATE_NONE; + srcReg->Negate = NEGATE_NONE; srcReg->Swizzle = SWIZZLE_NOOP; /* Register can be R, c[n], c[n +/- offset], a named vertex attrib, @@ -1380,8 +1372,7 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget, _mesa_free(programString); return; /* out of memory */ } - _mesa_memcpy(newInst, instBuffer, - parseState.numInst * sizeof(struct prog_instruction)); + _mesa_copy_instructions(newInst, instBuffer, parseState.numInst); /* install the program */ program->Base.Target = target; @@ -1404,7 +1395,7 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget, #ifdef DEBUG_foo _mesa_printf("--- glLoadProgramNV result ---\n"); - _mesa_print_nv_vertex_program(program); + _mesa_fprint_program_opt(stdout, &program->Base, PROG_PRINT_NV, 0); _mesa_printf("------------------------------\n"); #endif } @@ -1420,161 +1411,6 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget, } -static void -PrintSrcReg(const struct prog_src_register *src) -{ - static const char comps[5] = "xyzw"; - if (src->NegateBase) - _mesa_printf("-"); - if (src->RelAddr) { - if (src->Index > 0) - _mesa_printf("c[A0.x + %d]", src->Index); - else if (src->Index < 0) - _mesa_printf("c[A0.x - %d]", -src->Index); - else - _mesa_printf("c[A0.x]"); - } - else if (src->File == PROGRAM_OUTPUT) { - _mesa_printf("o[%s]", OutputRegisters[src->Index]); - } - else if (src->File == PROGRAM_INPUT) { - _mesa_printf("v[%s]", InputRegisters[src->Index]); - } - else if (src->File == PROGRAM_ENV_PARAM) { - _mesa_printf("c[%d]", src->Index); - } - else { - ASSERT(src->File == PROGRAM_TEMPORARY); - _mesa_printf("R%d", src->Index); - } - - 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)]); - } -} - - -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_INPUT) { - _mesa_printf("v[%s]", InputRegisters[dst->Index]); - } - else if (dst->File == PROGRAM_ENV_PARAM) { - _mesa_printf("c[%d]", dst->Index); - } - else { - ASSERT(dst->File == PROGRAM_TEMPORARY); - _mesa_printf("R%d", dst->Index); - } - - 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"); - } -} - - -/** - * Print a single NVIDIA vertex program instruction. - */ -void -_mesa_print_nv_vertex_instruction(const struct prog_instruction *inst) -{ - GLuint i, n; - - switch (inst->Opcode) { - case OPCODE_MOV: - case OPCODE_LIT: - case OPCODE_RCP: - case OPCODE_RSQ: - case OPCODE_EXP: - case OPCODE_LOG: - case OPCODE_RCC: - case OPCODE_ABS: - case OPCODE_MUL: - case OPCODE_ADD: - case OPCODE_DP3: - case OPCODE_DP4: - case OPCODE_DST: - case OPCODE_MIN: - case OPCODE_MAX: - case OPCODE_SLT: - case OPCODE_SGE: - case OPCODE_DPH: - case OPCODE_SUB: - case OPCODE_MAD: - _mesa_printf("%s ", _mesa_opcode_string(inst->Opcode)); - PrintDstReg(&inst->DstReg); - _mesa_printf(", "); - n = _mesa_num_inst_src_regs(inst->Opcode); - for (i = 0; i < n; i++) { - PrintSrcReg(&inst->SrcReg[i]); - if (i + 1 < n) - _mesa_printf(", "); - } - _mesa_printf(";\n"); - break; - case OPCODE_ARL: - _mesa_printf("ARL A0.x, "); - PrintSrcReg(&inst->SrcReg[0]); - _mesa_printf(";\n"); - break; - case OPCODE_PRINT: - _mesa_printf("PRINT '%s'", inst->Data); - if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { - _mesa_printf(", "); - PrintSrcReg(&inst->SrcReg[0]); - _mesa_printf(";\n"); - } - else { - _mesa_printf("\n"); - } - break; - case OPCODE_END: - _mesa_printf("END\n"); - break; - default: - _mesa_printf("BAD INSTRUCTION\n"); - } -} - - -/** - * Print (unparse) the given vertex program. Just for debugging. - */ -void -_mesa_print_nv_vertex_program(const struct gl_vertex_program *program) -{ - const struct prog_instruction *inst; - - for (inst = program->Base.Instructions; ; inst++) { - _mesa_print_nv_vertex_instruction(inst); - if (inst->Opcode == OPCODE_END) - return; - } -} - - const char * _mesa_nv_vertex_input_register_name(GLuint i) {