📄 program.c
字号:
inst->SrcReg[1].Swizzle = SWIZZLE_NOOP; inst->SrcReg[2].File = PROGRAM_UNDEFINED; inst->SrcReg[2].Swizzle = SWIZZLE_NOOP; inst->DstReg.File = PROGRAM_UNDEFINED; inst->DstReg.WriteMask = WRITEMASK_XYZW; inst->DstReg.CondMask = COND_TR; inst->DstReg.CondSwizzle = SWIZZLE_NOOP; inst->SaturateMode = SATURATE_OFF; inst->Precision = FLOAT32;}/** * Basic info about each instruction */struct instruction_info{ enum prog_opcode Opcode; const char *Name; GLuint NumSrcRegs;};/** * Instruction info * \note Opcode should equal array index! */static const struct instruction_info InstInfo[MAX_OPCODE] = { { OPCODE_ABS, "ABS", 1 }, { OPCODE_ADD, "ADD", 2 }, { OPCODE_ARA, "ARA", 1 }, { OPCODE_ARL, "ARL", 1 }, { OPCODE_ARL_NV, "ARL", 1 }, { OPCODE_ARR, "ARL", 1 }, { OPCODE_BRA, "BRA", 1 }, { OPCODE_CAL, "CAL", 1 }, { OPCODE_CMP, "CMP", 3 }, { OPCODE_COS, "COS", 1 }, { OPCODE_DDX, "DDX", 1 }, { OPCODE_DDY, "DDY", 1 }, { OPCODE_DP3, "DP3", 2 }, { OPCODE_DP4, "DP4", 2 }, { OPCODE_DPH, "DPH", 2 }, { OPCODE_DST, "DST", 2 }, { OPCODE_END, "END", 0 }, { OPCODE_EX2, "EX2", 1 }, { OPCODE_EXP, "EXP", 1 }, { OPCODE_FLR, "FLR", 1 }, { OPCODE_FRC, "FRC", 1 }, { OPCODE_KIL, "KIL", 1 }, { OPCODE_KIL_NV, "KIL", 0 }, { OPCODE_LG2, "LG2", 1 }, { OPCODE_LIT, "LIT", 1 }, { OPCODE_LOG, "LOG", 1 }, { OPCODE_LRP, "LRP", 3 }, { OPCODE_MAD, "MAD", 3 }, { OPCODE_MAX, "MAX", 2 }, { OPCODE_MIN, "MIN", 2 }, { OPCODE_MOV, "MOV", 1 }, { OPCODE_MUL, "MUL", 2 }, { OPCODE_PK2H, "PK2H", 1 }, { OPCODE_PK2US, "PK2US", 1 }, { OPCODE_PK4B, "PK4B", 1 }, { OPCODE_PK4UB, "PK4UB", 1 }, { OPCODE_POW, "POW", 2 }, { OPCODE_POPA, "POPA", 0 }, { OPCODE_PRINT, "PRINT", 1 }, { OPCODE_PUSHA, "PUSHA", 0 }, { OPCODE_RCC, "RCC", 1 }, { OPCODE_RCP, "RCP", 1 }, { OPCODE_RET, "RET", 1 }, { OPCODE_RFL, "RFL", 1 }, { OPCODE_RSQ, "RSQ", 1 }, { OPCODE_SCS, "SCS", 1 }, { OPCODE_SEQ, "SEQ", 2 }, { OPCODE_SFL, "SFL", 0 }, { OPCODE_SGE, "SGE", 2 }, { OPCODE_SGT, "SGT", 2 }, { OPCODE_SIN, "SIN", 1 }, { OPCODE_SLE, "SLE", 2 }, { OPCODE_SLT, "SLT", 2 }, { OPCODE_SNE, "SNE", 2 }, { OPCODE_SSG, "SSG", 1 }, { OPCODE_STR, "STR", 0 }, { OPCODE_SUB, "SUB", 2 }, { OPCODE_SWZ, "SWZ", 1 }, { OPCODE_TEX, "TEX", 1 }, { OPCODE_TXB, "TXB", 1 }, { OPCODE_TXD, "TXD", 3 }, { OPCODE_TXL, "TXL", 1 }, { OPCODE_TXP, "TXP", 1 }, { OPCODE_TXP_NV, "TXP", 1 }, { OPCODE_UP2H, "UP2H", 1 }, { OPCODE_UP2US, "UP2US", 1 }, { OPCODE_UP4B, "UP4B", 1 }, { OPCODE_UP4UB, "UP4UB", 1 }, { OPCODE_X2D, "X2D", 3 }, { OPCODE_XPD, "XPD", 2 }};/** * Return the number of src registers for the given instruction/opcode. */GLuint_mesa_num_inst_src_regs(enum prog_opcode opcode){ GLuint i;#ifdef DEBUG for (i = 0; i < MAX_OPCODE; i++) { ASSERT(i == InstInfo[i].Opcode); }#endif for (i = 0; i < MAX_OPCODE; i++) { if (InstInfo[i].Opcode == opcode) { return InstInfo[i].NumSrcRegs; } } _mesa_problem(NULL, "invalid opcode in _mesa_num_inst_src_regs"); return 0;}/** * Return string name for given program opcode. */const char *_mesa_opcode_string(enum prog_opcode opcode){ ASSERT(opcode < MAX_OPCODE); return InstInfo[opcode].Name;}/** * Return string name for given program/register file. */static const char *program_file_string(enum register_file f){ switch (f) { case PROGRAM_TEMPORARY: return "TEMP"; case PROGRAM_LOCAL_PARAM: return "LOCAL"; case PROGRAM_ENV_PARAM: return "ENV"; case PROGRAM_STATE_VAR: return "STATE"; case PROGRAM_INPUT: return "INPUT"; case PROGRAM_OUTPUT: return "OUTPUT"; case PROGRAM_NAMED_PARAM: return "NAMED"; case PROGRAM_CONSTANT: return "CONST"; case PROGRAM_WRITE_ONLY: return "WRITE_ONLY"; case PROGRAM_ADDRESS: return "ADDR"; default: return "!unkown!"; }}/** * Return a string representation of the given swizzle word. * If extended is true, use extended (comma-separated) format. */static const char *swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended){ static const char swz[] = "xyzw01"; static char s[20]; GLuint i = 0; if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0) return ""; /* no swizzle/negation */ if (!extended) s[i++] = '.'; if (negateBase & 0x1) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 0)]; if (extended) { s[i++] = ','; } if (negateBase & 0x2) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 1)]; if (extended) { s[i++] = ','; } if (negateBase & 0x4) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 2)]; if (extended) { s[i++] = ','; } if (negateBase & 0x8) s[i++] = '-'; s[i++] = swz[GET_SWZ(swizzle, 3)]; s[i] = 0; return s;}static const char *writemask_string(GLuint writeMask){ static char s[10]; GLuint i = 0; if (writeMask == WRITEMASK_XYZW) return ""; s[i++] = '.'; if (writeMask & WRITEMASK_X) s[i++] = 'x'; if (writeMask & WRITEMASK_Y) s[i++] = 'y'; if (writeMask & WRITEMASK_Z) s[i++] = 'z'; if (writeMask & WRITEMASK_W) s[i++] = 'w'; s[i] = 0; return s;}static voidprint_dst_reg(const struct prog_dst_register *dstReg){ _mesa_printf(" %s[%d]%s", program_file_string((enum register_file) dstReg->File), dstReg->Index, writemask_string(dstReg->WriteMask));}static voidprint_src_reg(const struct prog_src_register *srcReg){ _mesa_printf("%s[%d]%s", program_file_string((enum register_file) srcReg->File), srcReg->Index, swizzle_string(srcReg->Swizzle, srcReg->NegateBase, GL_FALSE));}/** * Print a single vertex/fragment program instruction. */void_mesa_print_instruction(const struct prog_instruction *inst){ switch (inst->Opcode) { case OPCODE_PRINT: _mesa_printf("PRINT '%s'", inst->Data); if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { _mesa_printf(", "); _mesa_printf("%s[%d]%s", program_file_string((enum register_file) inst->SrcReg[0].File), inst->SrcReg[0].Index, swizzle_string(inst->SrcReg[0].Swizzle, inst->SrcReg[0].NegateBase, GL_FALSE)); } _mesa_printf(";\n"); break; case OPCODE_SWZ: _mesa_printf("SWZ"); if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); print_dst_reg(&inst->DstReg); _mesa_printf("%s[%d], %s;\n", program_file_string((enum register_file) inst->SrcReg[0].File), inst->SrcReg[0].Index, swizzle_string(inst->SrcReg[0].Swizzle, inst->SrcReg[0].NegateBase, GL_TRUE)); break; case OPCODE_TEX: case OPCODE_TXP: case OPCODE_TXB: _mesa_printf("%s", _mesa_opcode_string(inst->Opcode)); if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); _mesa_printf(" "); print_dst_reg(&inst->DstReg); _mesa_printf(", "); print_src_reg(&inst->SrcReg[0]); _mesa_printf(", texture[%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_CUBE_INDEX: _mesa_printf("CUBE"); break; case TEXTURE_RECT_INDEX: _mesa_printf("RECT"); break; default: ; } _mesa_printf("\n"); break; case OPCODE_ARL: _mesa_printf("ARL addr.x, "); print_src_reg(&inst->SrcReg[0]); _mesa_printf(";\n"); break; /* XXX may need for other special-case instructions */ default: /* typical alu instruction */ { const GLuint numRegs = _mesa_num_inst_src_regs(inst->Opcode); GLuint j; _mesa_printf("%s", _mesa_opcode_string(inst->Opcode)); /* frag prog only */ if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); if (inst->DstReg.File != PROGRAM_UNDEFINED) { _mesa_printf(" %s[%d]%s", program_file_string((enum register_file) inst->DstReg.File), inst->DstReg.Index, writemask_string(inst->DstReg.WriteMask)); } if (numRegs > 0) _mesa_printf(", "); for (j = 0; j < numRegs; j++) { print_src_reg(inst->SrcReg + j); if (j + 1 < numRegs) _mesa_printf(", "); } _mesa_printf(";\n"); } }}/** * Print a vertx/fragment program to stdout. * XXX this function could be greatly improved. */void_mesa_print_program(const struct program *prog){ GLuint i; for (i = 0; i < prog->NumInstructions; i++) { _mesa_printf("%3d: ", i); _mesa_print_instruction(prog->Instructions + i); }}/** * Print all of a program's parameters. */void_mesa_print_program_parameters(GLcontext *ctx, const struct program *prog){ GLint i; _mesa_printf("NumInstructions=%d\n", prog->NumInstructions); _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries); _mesa_printf("NumParameters=%d\n", prog->NumParameters); _mesa_printf("NumAttributes=%d\n", prog->NumAttributes); _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs); _mesa_load_state_parameters(ctx, prog->Parameters); #if 0 _mesa_printf("Local Params:\n"); for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){ const GLfloat *p = prog->LocalParams[i]; _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]); }#endif for (i = 0; i < prog->Parameters->NumParameters; i++){ struct program_parameter *param = prog->Parameters->Parameters + i; const GLfloat *v = prog->Parameters->ParameterValues[i]; _mesa_printf("param[%d] %s = {%.3f, %.3f, %.3f, %.3f};\n", i, param->Name, v[0], v[1], v[2], v[3]); }}/**********************************************************************//* API functions *//**********************************************************************//** * Bind a program (make it current) * \note Called from the GL API dispatcher by both glBindProgramNV * and glBindProgramARB. */void GLAPIENTRY_mesa_BindProgram(GLenum target, GLuint id){ struct program *prog; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); FLUSH_VERTICES(ctx, _NEW_PROGRAM); if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */ (ctx->Extensions.NV_vertex_program || ctx->Extensions.ARB_vertex_program)) { /*** Vertex program binding ***/ struct vertex_program *curProg = ctx->VertexProgram.Current; if (curProg->Base.Id == id) { /* binding same program - no change */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -