Implement debugger callback, etc for vertex programs. Misc clean-ups.
[mesa.git] / src / mesa / swrast / s_nvfragprog.c
index 5700b1e78469c1b0378f65d92e05a5585640ecf1..9fef97c6f83347c69c37b26223ba9f8c681d263a 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: s_nvfragprog.c,v 1.15 2003/04/11 01:20:15 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
  * Version:  5.1
@@ -496,6 +494,12 @@ init_machine_deriv( GLcontext *ctx,
          }
       }
    }
+
+   /* init condition codes */
+   dMachine->CondCodes[0] = COND_EQ;
+   dMachine->CondCodes[1] = COND_EQ;
+   dMachine->CondCodes[2] = COND_EQ;
+   dMachine->CondCodes[3] = COND_EQ;
 }
 
 
@@ -523,6 +527,14 @@ execute_program( GLcontext *ctx,
 
    for (pc = 0; pc < maxInst; pc++) {
       const struct fp_instruction *inst = program->Instructions + pc;
+
+      if (ctx->FragmentProgram.CallbackEnabled &&
+          ctx->FragmentProgram.Callback) {
+         ctx->FragmentProgram.CurrentPosition = inst->StringPos;
+         ctx->FragmentProgram.Callback(program->Base.Target,
+                                       ctx->FragmentProgram.CallbackData);
+      }
+
       switch (inst->Opcode) {
          case FP_OPCODE_ADD:
             {
@@ -556,6 +568,7 @@ execute_program( GLcontext *ctx,
                    * Finally, find the difference in the register values for
                    * the original and derivative runs.
                    */
+                  fetch_vector4( &inst->SrcReg[0], machine, program, a);
                   init_machine_deriv(ctx, machine, program, span,
                                      'X', &dMachine);
                   execute_program(ctx, program, pc, &dMachine, span, column);
@@ -575,6 +588,7 @@ execute_program( GLcontext *ctx,
                if (!fetch_vector4_deriv(&inst->SrcReg[0], span, 'Y', result)) {
                   init_machine_deriv(ctx, machine, program, span,
                                      'Y', &dMachine);
+                  fetch_vector4( &inst->SrcReg[0], machine, program, a);
                   execute_program(ctx, program, pc, &dMachine, span, column);
                   fetch_vector4( &inst->SrcReg[0], &dMachine, program, aNext );
                   result[0] = aNext[0] - a[0];
@@ -659,8 +673,9 @@ execute_program( GLcontext *ctx,
                if (test_cc(machine->CondCodes[swizzle[0]], condMask) ||
                    test_cc(machine->CondCodes[swizzle[1]], condMask) ||
                    test_cc(machine->CondCodes[swizzle[2]], condMask) ||
-                   test_cc(machine->CondCodes[swizzle[3]], condMask))
+                   test_cc(machine->CondCodes[swizzle[3]], condMask)) {
                   return GL_FALSE;
+               }
             }
             break;
          case FP_OPCODE_LG2:  /* log base 2 */
@@ -1098,8 +1113,12 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
               const struct fragment_program *program,
               const struct sw_span *span, GLuint col )
 {
+   GLuint inputsRead = program->InputsRead;
    GLuint j, u;
 
+   if (ctx->FragmentProgram.CallbackEnabled)
+      inputsRead = ~0;
+
    /* Clear temporary registers */
    _mesa_bzero(machine->Registers + FP_TEMP_REG_START,
                MAX_NV_FRAGMENT_PROGRAM_TEMPS * 4 * sizeof(GLfloat));
@@ -1111,28 +1130,28 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
    }
 
    /* Load input registers */
-   if (program->InputsRead & (1 << FRAG_ATTRIB_WPOS)) {
+   if (inputsRead & (1 << FRAG_ATTRIB_WPOS)) {
       GLfloat *wpos = machine->Registers[FP_INPUT_REG_START+FRAG_ATTRIB_WPOS];
       wpos[0] = span->x + col;
       wpos[1] = span->y;
       wpos[2] = (GLfloat) span->array->z[col] / ctx->DepthMaxF;
       wpos[3] = span->w + col * span->dwdx;
    }
-   if (program->InputsRead & (1 << FRAG_ATTRIB_COL0)) {
+   if (inputsRead & (1 << FRAG_ATTRIB_COL0)) {
       GLfloat *col0 = machine->Registers[FP_INPUT_REG_START+FRAG_ATTRIB_COL0];
       col0[0] = CHAN_TO_FLOAT(span->array->rgba[col][RCOMP]);
       col0[1] = CHAN_TO_FLOAT(span->array->rgba[col][GCOMP]);
       col0[2] = CHAN_TO_FLOAT(span->array->rgba[col][BCOMP]);
       col0[3] = CHAN_TO_FLOAT(span->array->rgba[col][ACOMP]);
    }
-   if (program->InputsRead & (1 << FRAG_ATTRIB_COL1)) {
+   if (inputsRead & (1 << FRAG_ATTRIB_COL1)) {
       GLfloat *col1 = machine->Registers[FP_INPUT_REG_START+FRAG_ATTRIB_COL1];
       col1[0] = CHAN_TO_FLOAT(span->array->spec[col][RCOMP]);
       col1[1] = CHAN_TO_FLOAT(span->array->spec[col][GCOMP]);
       col1[2] = CHAN_TO_FLOAT(span->array->spec[col][BCOMP]);
       col1[3] = CHAN_TO_FLOAT(span->array->spec[col][ACOMP]);
    }
-   if (program->InputsRead & (1 << FRAG_ATTRIB_FOGC)) {
+   if (inputsRead & (1 << FRAG_ATTRIB_FOGC)) {
       GLfloat *fogc = machine->Registers[FP_INPUT_REG_START+FRAG_ATTRIB_FOGC];
       fogc[0] = span->array->fog[col];
       fogc[1] = 0.0F;
@@ -1140,13 +1159,19 @@ init_machine( GLcontext *ctx, struct fp_machine *machine,
       fogc[3] = 0.0F;
    }
    for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) {
-      if (program->InputsRead & (1 << (FRAG_ATTRIB_TEX0 + u))) {
+      if (inputsRead & (1 << (FRAG_ATTRIB_TEX0 + u))) {
          GLfloat *tex = machine->Registers[FP_INPUT_REG_START+FRAG_ATTRIB_TEX0+u];
-         ASSERT(ctx->Texture._EnabledCoordUnits & (1 << u));
+         /*ASSERT(ctx->Texture._EnabledCoordUnits & (1 << u));*/
          COPY_4V(tex, span->array->texcoords[u][col]);
-         ASSERT(tex[0] != 0 || tex[1] != 0 || tex[2] != 0);
+         /*ASSERT(tex[0] != 0 || tex[1] != 0 || tex[2] != 0);*/
       }
    }
+
+   /* init condition codes */
+   machine->CondCodes[0] = COND_EQ;
+   machine->CondCodes[1] = COND_EQ;
+   machine->CondCodes[2] = COND_EQ;
+   machine->CondCodes[3] = COND_EQ;
 }
 
 
@@ -1156,14 +1181,17 @@ _swrast_exec_nv_fragment_program( GLcontext *ctx, struct sw_span *span )
    const struct fragment_program *program = ctx->FragmentProgram.Current;
    GLuint i;
 
+   ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */
+
    for (i = 0; i < span->end; i++) {
       if (span->array->mask[i]) {
          init_machine(ctx, &ctx->FragmentProgram.Machine,
                       ctx->FragmentProgram.Current, span, i);
 
          if (!execute_program(ctx, program, ~0,
-                              &ctx->FragmentProgram.Machine, span, i))
+                              &ctx->FragmentProgram.Machine, span, i)) {
             span->array->mask[i] = GL_FALSE;  /* killed fragment */
+         }
 
          /* Store output registers */
          {
@@ -1175,9 +1203,11 @@ _swrast_exec_nv_fragment_program( GLcontext *ctx, struct sw_span *span )
             UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], colOut[3]);
          }
          /* depth value */
-         if (ctx->FragmentProgram.Current->OutputsWritten & 2)
+         if (program->OutputsWritten & (1 << FRAG_OUTPUT_DEPR))
             span->array->z[i] = IROUND(ctx->FragmentProgram.Machine.Registers[FP_OUTPUT_REG_START + 2][0] * ctx->DepthMaxF);
       }
    }
+
+   ctx->_CurrentProgram = 0;
 }