⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_atifragshader.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/** * Execute the given fragment shader. * NOTE: we do everything in single-precision floating point * \param ctx - rendering context * \param shader - the shader to execute * \param machine - virtual machine state * \param span - the SWspan we're operating on * \param column - which pixel [i] we're operating on in the span */static voidexecute_shader(GLcontext *ctx, const struct ati_fragment_shader *shader,	       struct atifs_machine *machine, const SWspan *span,               GLuint column){   GLuint pc;   struct atifs_instruction *inst;   struct atifs_setupinst *texinst;   GLint optype;   GLuint i;   GLint j, pass;   GLint dstreg;   GLfloat src[2][3][4];   GLfloat zeros[4] = { 0.0, 0.0, 0.0, 0.0 };   GLfloat ones[4] = { 1.0, 1.0, 1.0, 1.0 };   GLfloat dst[2][4], *dstp;   for (pass = 0; pass < shader->NumPasses; pass++) {      if (pass > 0)	 finish_pass(machine);      for (j = 0; j < MAX_NUM_FRAGMENT_REGISTERS_ATI; j++) {	 texinst = &shader->SetupInst[pass][j];	 if (texinst->Opcode == ATI_FRAGMENT_SHADER_PASS_OP)	    handle_pass_op(machine, texinst, span, column, j);	 else if (texinst->Opcode == ATI_FRAGMENT_SHADER_SAMPLE_OP)	    handle_sample_op(ctx, machine, texinst, span, column, j);      }      for (pc = 0; pc < shader->numArithInstr[pass]; pc++) {	 inst = &shader->Instructions[pass][pc];	 /* setup the source registers for color and alpha ops */	 for (optype = 0; optype < 2; optype++) { 	    for (i = 0; i < inst->ArgCount[optype]; i++) {	       GLint index = inst->SrcReg[optype][i].Index;	       if (index >= GL_REG_0_ATI && index <= GL_REG_5_ATI)		  SETUP_SRC_REG(optype, i,				machine->Registers[index - GL_REG_0_ATI]);	       else if (index >= GL_CON_0_ATI && index <= GL_CON_7_ATI) {		  if (shader->LocalConstDef & (1 << (index - GL_CON_0_ATI))) {		     SETUP_SRC_REG(optype, i,				shader->Constants[index - GL_CON_0_ATI]);		  } else {		     SETUP_SRC_REG(optype, i,				ctx->ATIFragmentShader.GlobalConstants[index - GL_CON_0_ATI]);		  }	       }	       else if (index == GL_ONE)		  SETUP_SRC_REG(optype, i, ones);	       else if (index == GL_ZERO)		  SETUP_SRC_REG(optype, i, zeros);	       else if (index == GL_PRIMARY_COLOR_EXT)		  SETUP_SRC_REG(optype, i,				machine->Inputs[ATI_FS_INPUT_PRIMARY]);	       else if (index == GL_SECONDARY_INTERPOLATOR_ATI)		  SETUP_SRC_REG(optype, i,				machine->Inputs[ATI_FS_INPUT_SECONDARY]);	       apply_src_rep(optype, inst->SrcReg[optype][i].argRep,			     src[optype][i]);	       apply_src_mod(optype, inst->SrcReg[optype][i].argMod,			     src[optype][i]);	    }	 }	 /* Execute the operations - color then alpha */	 for (optype = 0; optype < 2; optype++) {	    if (inst->Opcode[optype]) {	       switch (inst->Opcode[optype]) {	       case GL_ADD_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   src[optype][0][i] + src[optype][1][i];		     }		  else		     dst[optype][3] = src[optype][0][3] + src[optype][1][3];		  break;	       case GL_SUB_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   src[optype][0][i] - src[optype][1][i];		     }		  else		     dst[optype][3] = src[optype][0][3] - src[optype][1][3];		  break;	       case GL_MUL_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   src[optype][0][i] * src[optype][1][i];		     }		  else		     dst[optype][3] = src[optype][0][3] * src[optype][1][3];		  break;	       case GL_MAD_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   src[optype][0][i] * src[optype][1][i] +			   src[optype][2][i];		     }		  else		     dst[optype][3] =			src[optype][0][3] * src[optype][1][3] +			src[optype][2][3];		  break;	       case GL_LERP_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   src[optype][0][i] * src[optype][1][i] + (1 -								    src								    [optype]								    [0][i]) *			   src[optype][2][i];		     }		  else		     dst[optype][3] =			src[optype][0][3] * src[optype][1][3] + (1 -								 src[optype]								 [0][3]) *			src[optype][2][3];		  break;	       case GL_MOV_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] = src[optype][0][i];		     }		  else		     dst[optype][3] = src[optype][0][3];		  break;	       case GL_CND_ATI:		  if (!optype) {		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   (src[optype][2][i] >			    0.5) ? src[optype][0][i] : src[optype][1][i];		     }		  }		  else {		     dst[optype][3] =			(src[optype][2][3] >			 0.5) ? src[optype][0][3] : src[optype][1][3];		  }		  break;	       case GL_CND0_ATI:		  if (!optype)		     for (i = 0; i < 3; i++) {			dst[optype][i] =			   (src[optype][2][i] >=			    0) ? src[optype][0][i] : src[optype][1][i];		     }		  else {		     dst[optype][3] =			(src[optype][2][3] >=			 0) ? src[optype][0][3] : src[optype][1][3];		  }		  break;	       case GL_DOT2_ADD_ATI:		  {		     GLfloat result;		     /* DOT 2 always uses the source from the color op */		     /* could save recalculation of dot products for alpha inst */		     result = src[0][0][0] * src[0][1][0] +			src[0][0][1] * src[0][1][1] + src[0][2][2];		     if (!optype) {			for (i = 0; i < 3; i++) {			   dst[optype][i] = result;			}		     }		     else			dst[optype][3] = result;		  }		  break;	       case GL_DOT3_ATI:		  {		     GLfloat result;		     /* DOT 3 always uses the source from the color op */		     result = src[0][0][0] * src[0][1][0] +			src[0][0][1] * src[0][1][1] +			src[0][0][2] * src[0][1][2];		     if (!optype) {			for (i = 0; i < 3; i++) {			   dst[optype][i] = result;			}		     }		     else			dst[optype][3] = result;		  }		  break;	       case GL_DOT4_ATI:		  {		     GLfloat result;		     /* DOT 4 always uses the source from the color op */		     result = src[0][0][0] * src[0][1][0] +			src[0][0][1] * src[0][1][1] +			src[0][0][2] * src[0][1][2] +			src[0][0][3] * src[0][1][3];		     if (!optype) {			for (i = 0; i < 3; i++) {			   dst[optype][i] = result;			}		     }		     else			dst[optype][3] = result;		  }		  break;	       }	    }	 }	 /* write out the destination registers */	 for (optype = 0; optype < 2; optype++) {	    if (inst->Opcode[optype]) {	       dstreg = inst->DstReg[optype].Index;	       dstp = machine->Registers[dstreg - GL_REG_0_ATI];	       if ((optype == 0) || ((inst->Opcode[1] != GL_DOT2_ADD_ATI) &&		  (inst->Opcode[1] != GL_DOT3_ATI) && (inst->Opcode[1] != GL_DOT4_ATI)))	          write_dst_addr(optype, inst->DstReg[optype].dstMod,			      inst->DstReg[optype].dstMask, dst[optype],			      dstp);	       else		  write_dst_addr(1, inst->DstReg[0].dstMod, 0, dst[1], dstp);	    }	 }      }   }}/** * Init fragment shader virtual machine state. */static voidinit_machine(GLcontext * ctx, struct atifs_machine *machine,	     const struct ati_fragment_shader *shader,	     const SWspan *span, GLuint col){   GLfloat (*inputs)[4] = machine->Inputs;   GLint i, j;   for (i = 0; i < 6; i++) {      for (j = 0; j < 4; j++)	 machine->Registers[i][j] = 0.0;   }   COPY_4V(inputs[ATI_FS_INPUT_PRIMARY], span->array->attribs[FRAG_ATTRIB_COL0][col]);   COPY_4V(inputs[ATI_FS_INPUT_SECONDARY], span->array->attribs[FRAG_ATTRIB_COL1][col]);}/** * Execute the current ATI shader program, operating on the given span. */void_swrast_exec_fragment_shader(GLcontext * ctx, SWspan *span){   const struct ati_fragment_shader *shader = ctx->ATIFragmentShader.Current;   struct atifs_machine machine;   GLuint i;   /* incoming colors should be floats */   ASSERT(span->array->ChanType == GL_FLOAT);   ctx->_CurrentProgram = GL_FRAGMENT_SHADER_ATI;   for (i = 0; i < span->end; i++) {      if (span->array->mask[i]) {	 init_machine(ctx, &machine, shader, span, i);	 execute_shader(ctx, shader, &machine, span, i);         /* store result color */	 {	    const GLfloat *colOut = machine.Registers[0];            /*fprintf(stderr,"outputs %f %f %f %f\n",              colOut[0], colOut[1], colOut[2], colOut[3]); */            COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], colOut);	 }      }   }   ctx->_CurrentProgram = 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -