egl: rename _eglMatchDriver() to _eglInitializeDisplay()
[mesa.git] / src / mesa / program / prog_execute.c
index d336c51ca20b3573b1214d814980e4a05c25c628..956b84a20d6496c7c9ebe61f592ff27c0b0fc9c6 100644 (file)
 
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 #include "prog_execute.h"
 #include "prog_instruction.h"
 #include "prog_parameter.h"
@@ -117,11 +119,13 @@ get_src_register_pointer(const struct prog_src_register *source,
       /* Fallthrough */
    case PROGRAM_CONSTANT:
       /* Fallthrough */
-   case PROGRAM_UNIFORM:
+   case PROGRAM_UNIFORM: {
       if (reg >= (GLint) prog->Parameters->NumParameters)
          return ZeroVec;
-      return (GLfloat *) prog->Parameters->ParameterValues[reg];
 
+      unsigned pvo = prog->Parameters->ParameterValueOffset[reg];
+      return (GLfloat *) prog->Parameters->ParameterValues + pvo;
+   }
    case PROGRAM_SYSTEM_VALUE:
       assert(reg < (GLint) ARRAY_SIZE(machine->SystemValues));
       return machine->SystemValues[reg];
@@ -200,12 +204,6 @@ fetch_vector4(const struct prog_src_register *source,
       result[3] = src[GET_SWZ(source->Swizzle, 3)];
    }
 
-   if (source->Abs) {
-      result[0] = fabsf(result[0]);
-      result[1] = fabsf(result[1]);
-      result[2] = fabsf(result[2]);
-      result[3] = fabsf(result[3]);
-   }
    if (source->Negate) {
       assert(source->Negate == NEGATE_XYZW);
       result[0] = -result[0];
@@ -215,10 +213,10 @@ fetch_vector4(const struct prog_src_register *source,
    }
 
 #ifdef NAN_CHECK
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
-   assert(!IS_INF_OR_NAN(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
+   assert(!util_is_inf_or_nan(result[0]));
 #endif
 }
 
@@ -228,8 +226,7 @@ fetch_vector4(const struct prog_src_register *source,
  * XXX this currently only works for fragment program input attribs.
  */
 static void
-fetch_vector4_deriv(struct gl_context * ctx,
-                    const struct prog_src_register *source,
+fetch_vector4_deriv(const struct prog_src_register *source,
                     const struct gl_program_machine *machine,
                     char xOrY, GLfloat result[4])
 {
@@ -258,12 +255,6 @@ fetch_vector4_deriv(struct gl_context * ctx,
       result[2] = deriv[GET_SWZ(source->Swizzle, 2)];
       result[3] = deriv[GET_SWZ(source->Swizzle, 3)];
       
-      if (source->Abs) {
-         result[0] = fabsf(result[0]);
-         result[1] = fabsf(result[1]);
-         result[2] = fabsf(result[2]);
-         result[3] = fabsf(result[3]);
-      }
       if (source->Negate) {
          assert(source->Negate == NEGATE_XYZW);
          result[0] = -result[0];
@@ -289,9 +280,6 @@ fetch_vector1(const struct prog_src_register *source,
 
    result[0] = src[GET_SWZ(source->Swizzle, 0)];
 
-   if (source->Abs) {
-      result[0] = fabsf(result[0]);
-   }
    if (source->Negate) {
       result[0] = -result[0];
    }
@@ -344,9 +332,9 @@ store_vector4(const struct prog_instruction *inst,
 
 #if 0
    if (value[0] > 1.0e10 ||
-       IS_INF_OR_NAN(value[0]) ||
-       IS_INF_OR_NAN(value[1]) ||
-       IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
+       util_is_inf_or_nan(value[0]) ||
+       util_is_inf_or_nan(value[1]) ||
+       util_is_inf_or_nan(value[2]) || util_is_inf_or_nan(value[3]))
       printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
 #endif
 
@@ -359,10 +347,10 @@ store_vector4(const struct prog_instruction *inst,
    }
 
 #ifdef NAN_CHECK
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
-   assert(!IS_INF_OR_NAN(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
+   assert(!util_is_inf_or_nan(value[0]));
 #endif
 
    if (writeMask & WRITEMASK_X)
@@ -389,7 +377,7 @@ _mesa_execute_program(struct gl_context * ctx,
                       const struct gl_program *program,
                       struct gl_program_machine *machine)
 {
-   const GLuint numInst = program->NumInstructions;
+   const GLuint numInst = program->arb.NumInstructions;
    const GLuint maxExec = 65536;
    GLuint pc, numExec = 0;
 
@@ -407,7 +395,7 @@ _mesa_execute_program(struct gl_context * ctx,
    }
 
    for (pc = 0; pc < numInst; pc++) {
-      const struct prog_instruction *inst = program->Instructions + pc;
+      const struct prog_instruction *inst = program->arb.Instructions + pc;
 
       if (DEBUG_PROG) {
          _mesa_print_instruction(inst);
@@ -446,7 +434,7 @@ _mesa_execute_program(struct gl_context * ctx,
          {
             GLfloat t[4];
             fetch_vector4(&inst->SrcReg[0], machine, t);
-            machine->AddressReg[0][0] = IFLOOR(t[0]);
+            machine->AddressReg[0][0] = util_ifloor(t[0]);
             if (DEBUG_PROG) {
                printf("ARL %d\n", machine->AddressReg[0][0]);
             }
@@ -454,12 +442,12 @@ _mesa_execute_program(struct gl_context * ctx,
          break;
       case OPCODE_BGNLOOP:
          /* no-op */
-         assert(program->Instructions[inst->BranchTarget].Opcode
+         assert(program->arb.Instructions[inst->BranchTarget].Opcode
                 == OPCODE_ENDLOOP);
          break;
       case OPCODE_ENDLOOP:
          /* subtract 1 here since pc is incremented by for(pc) loop */
-         assert(program->Instructions[inst->BranchTarget].Opcode
+         assert(program->arb.Instructions[inst->BranchTarget].Opcode
                 == OPCODE_BGNLOOP);
          pc = inst->BranchTarget - 1;   /* go to matching BNGLOOP */
          break;
@@ -468,14 +456,14 @@ _mesa_execute_program(struct gl_context * ctx,
       case OPCODE_ENDSUB:      /* end subroutine */
          break;
       case OPCODE_BRK:         /* break out of loop (conditional) */
-         assert(program->Instructions[inst->BranchTarget].Opcode
+         assert(program->arb.Instructions[inst->BranchTarget].Opcode
                 == OPCODE_ENDLOOP);
          /* break out of loop */
          /* pc++ at end of for-loop will put us after the ENDLOOP inst */
          pc = inst->BranchTarget;
          break;
       case OPCODE_CONT:        /* continue loop (conditional) */
-         assert(program->Instructions[inst->BranchTarget].Opcode
+         assert(program->arb.Instructions[inst->BranchTarget].Opcode
                 == OPCODE_ENDLOOP);
          /* continue at ENDLOOP */
          /* Subtract 1 here since we'll do pc++ at end of for-loop */
@@ -522,16 +510,14 @@ _mesa_execute_program(struct gl_context * ctx,
       case OPCODE_DDX:         /* Partial derivative with respect to X */
          {
             GLfloat result[4];
-            fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
-                                'X', result);
+            fetch_vector4_deriv(&inst->SrcReg[0], machine, 'X', result);
             store_vector4(inst, machine, result);
          }
          break;
       case OPCODE_DDY:         /* Partial derivative with respect to Y */
          {
             GLfloat result[4];
-            fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
-                                'Y', result);
+            fetch_vector4_deriv(&inst->SrcReg[0], machine, 'Y', result);
             store_vector4(inst, machine, result);
          }
          break;
@@ -628,7 +614,7 @@ _mesa_execute_program(struct gl_context * ctx,
             fetch_vector1(&inst->SrcReg[0], machine, a);
             val = exp2f(a[0]);
             /*
-            if (IS_INF_OR_NAN(val))
+            if (util_is_inf_or_nan(val))
                val = 1.0e10;
             */
             result[0] = result[1] = result[2] = result[3] = val;
@@ -660,16 +646,14 @@ _mesa_execute_program(struct gl_context * ctx,
       case OPCODE_IF:
          {
             GLboolean cond;
-            assert(program->Instructions[inst->BranchTarget].Opcode
+            assert(program->arb.Instructions[inst->BranchTarget].Opcode
                    == OPCODE_ELSE ||
-                   program->Instructions[inst->BranchTarget].Opcode
+                   program->arb.Instructions[inst->BranchTarget].Opcode
                    == OPCODE_ENDIF);
             /* eval condition */
-            if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
-               GLfloat a[4];
-               fetch_vector1(&inst->SrcReg[0], machine, a);
-               cond = (a[0] != 0.0F);
-            }
+            GLfloat a[4];
+            fetch_vector1(&inst->SrcReg[0], machine, a);
+            cond = (a[0] != 0.0F);
             if (DEBUG_PROG) {
                printf("IF: %d\n", cond);
             }
@@ -686,7 +670,7 @@ _mesa_execute_program(struct gl_context * ctx,
          break;
       case OPCODE_ELSE:
          /* goto ENDIF */
-         assert(program->Instructions[inst->BranchTarget].Opcode
+         assert(program->arb.Instructions[inst->BranchTarget].Opcode
                 == OPCODE_ENDIF);
          assert(inst->BranchTarget >= 0);
          pc = inst->BranchTarget;
@@ -760,7 +744,7 @@ _mesa_execute_program(struct gl_context * ctx,
             fetch_vector1(&inst->SrcReg[0], machine, t);
             abs_t0 = fabsf(t[0]);
             if (abs_t0 != 0.0F) {
-               if (IS_INF_OR_NAN(abs_t0))
+               if (util_is_inf_or_nan(abs_t0))
                {
                   SET_POS_INFINITY(q[0]);
                   q[1] = 1.0F;
@@ -947,7 +931,7 @@ _mesa_execute_program(struct gl_context * ctx,
             if (DEBUG_PROG) {
                if (a[0] == 0)
                   printf("RCP(0)\n");
-               else if (IS_INF_OR_NAN(a[0]))
+               else if (util_is_inf_or_nan(a[0]))
                   printf("RCP(inf)\n");
             }
             result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
@@ -984,24 +968,6 @@ _mesa_execute_program(struct gl_context * ctx,
             store_vector4(inst, machine, result);
          }
          break;
-      case OPCODE_SEQ:         /* set on equal */
-         {
-            GLfloat a[4], b[4], result[4];
-            fetch_vector4(&inst->SrcReg[0], machine, a);
-            fetch_vector4(&inst->SrcReg[1], machine, b);
-            result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
-            result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
-            result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
-            result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
-            store_vector4(inst, machine, result);
-            if (DEBUG_PROG) {
-               printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
-                      result[0], result[1], result[2], result[3],
-                      a[0], a[1], a[2], a[3],
-                      b[0], b[1], b[2], b[3]);
-            }
-         }
-         break;
       case OPCODE_SGE:         /* set on greater or equal */
          {
             GLfloat a[4], b[4], result[4];
@@ -1020,24 +986,6 @@ _mesa_execute_program(struct gl_context * ctx,
             }
          }
          break;
-      case OPCODE_SGT:         /* set on greater */
-         {
-            GLfloat a[4], b[4], result[4];
-            fetch_vector4(&inst->SrcReg[0], machine, a);
-            fetch_vector4(&inst->SrcReg[1], machine, b);
-            result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
-            result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
-            result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
-            result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
-            store_vector4(inst, machine, result);
-            if (DEBUG_PROG) {
-               printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
-                      result[0], result[1], result[2], result[3],
-                      a[0], a[1], a[2], a[3],
-                      b[0], b[1], b[2], b[3]);
-            }
-         }
-         break;
       case OPCODE_SIN:
          {
             GLfloat a[4], result[4];
@@ -1047,24 +995,6 @@ _mesa_execute_program(struct gl_context * ctx,
             store_vector4(inst, machine, result);
          }
          break;
-      case OPCODE_SLE:         /* set on less or equal */
-         {
-            GLfloat a[4], b[4], result[4];
-            fetch_vector4(&inst->SrcReg[0], machine, a);
-            fetch_vector4(&inst->SrcReg[1], machine, b);
-            result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
-            result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
-            result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
-            result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
-            store_vector4(inst, machine, result);
-            if (DEBUG_PROG) {
-               printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
-                      result[0], result[1], result[2], result[3],
-                      a[0], a[1], a[2], a[3],
-                      b[0], b[1], b[2], b[3]);
-            }
-         }
-         break;
       case OPCODE_SLT:         /* set on less */
          {
             GLfloat a[4], b[4], result[4];
@@ -1083,24 +1013,6 @@ _mesa_execute_program(struct gl_context * ctx,
             }
          }
          break;
-      case OPCODE_SNE:         /* set on not equal */
-         {
-            GLfloat a[4], b[4], result[4];
-            fetch_vector4(&inst->SrcReg[0], machine, a);
-            fetch_vector4(&inst->SrcReg[1], machine, b);
-            result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
-            result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
-            result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
-            result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
-            store_vector4(inst, machine, result);
-            if (DEBUG_PROG) {
-               printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
-                      result[0], result[1], result[2], result[3],
-                      a[0], a[1], a[2], a[3],
-                      b[0], b[1], b[2], b[3]);
-            }
-         }
-         break;
       case OPCODE_SSG:         /* set sign (-1, 0 or +1) */
          {
             GLfloat a[4], result[4];
@@ -1203,7 +1115,7 @@ _mesa_execute_program(struct gl_context * ctx,
             store_vector4(inst, machine, color);
          }
          break;
-      case OPCODE_TXD:         /* GL_NV_fragment_program only */
+      case OPCODE_TXD:
          /* Texture lookup w/ partial derivatives for LOD */
          {
             GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
@@ -1253,26 +1165,6 @@ _mesa_execute_program(struct gl_context * ctx,
             store_vector4(inst, machine, color);
          }
          break;
-      case OPCODE_TXP_NV:      /* GL_NV_fragment_program only */
-         /* Texture lookup w/ projective divide, as above, but do not
-          * do the divide by w if sampling from a cube map.
-          */
-         {
-            GLfloat texcoord[4], color[4];
-
-            fetch_vector4(&inst->SrcReg[0], machine, texcoord);
-            if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
-                texcoord[3] != 0.0F) {
-               texcoord[0] /= texcoord[3];
-               texcoord[1] /= texcoord[3];
-               texcoord[2] /= texcoord[3];
-            }
-
-            fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
-
-            store_vector4(inst, machine, color);
-         }
-         break;
       case OPCODE_TRUNC:       /* truncate toward zero */
          {
             GLfloat a[4], result[4];