nv50: fix build-predicate function
[mesa.git] / src / mesa / slang / slang_builtin.c
index 610e793c1d96d874c79dc0a99aef3461af006c93..a7e0efcb7b5d375c3b15268a48cef12749078759 100644 (file)
@@ -399,7 +399,7 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field,
    }
 
    if (isMatrix) {
-      /* load all four columns of matrix */
+      /* load all four rows (or columns) of matrix */
       GLint pos[4];
       GLuint j;
       for (j = 0; j < 4; j++) {
@@ -489,9 +489,26 @@ emit_statevars(const char *name, int array_len,
          tokens[0] = STATE_TEXGEN;
          tokens[2] = STATE_TEXGEN_OBJECT_Q;
       }
+      else if (strcmp(name, "gl_TextureMatrix") == 0) {
+         tokens[0] = STATE_TEXTURE_MATRIX;
+         tokens[4] = STATE_MATRIX_TRANSPOSE;
+      }
+      else if (strcmp(name, "gl_TextureMatrixInverse") == 0) {
+         tokens[0] = STATE_TEXTURE_MATRIX;
+         tokens[4] = STATE_MATRIX_INVTRANS;
+      }
+      else if (strcmp(name, "gl_TextureMatrixTranspose") == 0) {
+         tokens[0] = STATE_TEXTURE_MATRIX;
+         tokens[4] = 0;
+      }
+      else if (strcmp(name, "gl_TextureMatrixInverseTranspose") == 0) {
+         tokens[0] = STATE_TEXTURE_MATRIX;
+         tokens[4] = STATE_MATRIX_INVERSE;
+      }
       else {
          return -1; /* invalid array name */
       }
+      /* emit state vars for each array element */
       for (i = 0; i < array_len; i++) {
          GLint p;
          tokens[1] = i;
@@ -513,6 +530,19 @@ emit_statevars(const char *name, int array_len,
       }
       return pos;
    }
+   else if (type->type == SLANG_SPEC_MAT4) {
+      /* unroll/emit 4 array rows (or columns) */
+      slang_type_specifier vec4;
+      GLint i, p, pos = -1;
+      vec4.type = SLANG_SPEC_VEC4;
+      for (i = 0; i < 4; i++) {
+         tokens[2] = tokens[3] = i; /* row[i] (or column[i]) of matrix */
+         p = emit_statevars(NULL, 0, &vec4, tokens, paramList);
+         if (pos == -1)
+            pos = p;
+      }
+      return pos;
+   }
    else {
       GLint pos;
       assert(type->type == SLANG_SPEC_VEC4 ||
@@ -726,36 +756,48 @@ struct input_info
    GLuint Attrib;
    GLenum Type;
    GLuint Swizzle;
+   GLboolean Array;
 };
 
 /** Predefined vertex shader inputs/attributes */
 static const struct input_info vertInputs[] = {
-   { "gl_Vertex", VERT_ATTRIB_POS, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_Normal", VERT_ATTRIB_NORMAL, GL_FLOAT_VEC3, SWIZZLE_NOOP },
-   { "gl_Color", VERT_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_FogCoord", VERT_ATTRIB_FOG, GL_FLOAT, SWIZZLE_XXXX },
-   { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { NULL, 0, GL_NONE, SWIZZLE_NOOP }
+   { "gl_Vertex", VERT_ATTRIB_POS, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_Normal", VERT_ATTRIB_NORMAL, GL_FLOAT_VEC3, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_Color", VERT_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_SecondaryColor", VERT_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_FogCoord", VERT_ATTRIB_FOG, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE },
+   { "gl_MultiTexCoord0", VERT_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord1", VERT_ATTRIB_TEX1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord2", VERT_ATTRIB_TEX2, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord3", VERT_ATTRIB_TEX3, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord4", VERT_ATTRIB_TEX4, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord5", VERT_ATTRIB_TEX5, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord6", VERT_ATTRIB_TEX6, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_MultiTexCoord7", VERT_ATTRIB_TEX7, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE }
+};
+
+static const struct input_info geomInputs[] = {
+   { "gl_PrimitiveIDIn", GEOM_ATTRIB_PRIMITIVE_ID, GL_FLOAT, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_FrontColorIn", GEOM_ATTRIB_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_BackColorIn", GEOM_ATTRIB_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_FrontSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_BackSecondaryColorIn", GEOM_ATTRIB_SECONDARY_COLOR1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_TexCoordIn", GEOM_ATTRIB_TEX_COORD, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_FogFragCoordIn", GEOM_ATTRIB_FOG_FRAG_COORD, GL_FLOAT, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_PositionIn", GEOM_ATTRIB_POSITION, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_ClipVertexIn", GEOM_ATTRIB_CLIP_VERTEX, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_TRUE },
+   { "gl_PointSizeIn", GEOM_ATTRIB_POINT_SIZE, GL_FLOAT, SWIZZLE_NOOP, GL_TRUE }
 };
 
 /** Predefined fragment shader inputs */
 static const struct input_info fragInputs[] = {
-   { "gl_FragCoord", FRAG_ATTRIB_WPOS, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_Color", FRAG_ATTRIB_COL0, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_SecondaryColor", FRAG_ATTRIB_COL1, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_TexCoord", FRAG_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP },
-   { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, GL_FLOAT, SWIZZLE_XXXX },
-   { "gl_FrontFacing", FRAG_ATTRIB_FACE, GL_FLOAT, SWIZZLE_XXXX },
-   { "gl_PointCoord", FRAG_ATTRIB_PNTC, GL_FLOAT_VEC2, SWIZZLE_XYZW },
-   { NULL, 0, GL_NONE, SWIZZLE_NOOP }
+   { "gl_FragCoord", FRAG_ATTRIB_WPOS, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_Color", FRAG_ATTRIB_COL0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_SecondaryColor", FRAG_ATTRIB_COL1, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_TexCoord", FRAG_ATTRIB_TEX0, GL_FLOAT_VEC4, SWIZZLE_NOOP, GL_FALSE },
+   { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE },
+   { "gl_FrontFacing", FRAG_ATTRIB_FACE, GL_FLOAT, SWIZZLE_XXXX, GL_FALSE },
+   { "gl_PointCoord", FRAG_ATTRIB_PNTC, GL_FLOAT_VEC2, SWIZZLE_XYZW, GL_FALSE }
 };
 
 
@@ -766,19 +808,25 @@ static const struct input_info fragInputs[] = {
  * XXX return size too
  */
 GLint
-_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
+_slang_input_index(const char *name, GLenum target, GLuint *swizzleOut,
+                   GLboolean *is_array)
 {
    const struct input_info *inputs;
-   GLuint i;
+   GLuint i, n;
 
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB:
       inputs = vertInputs;
+      n = Elements(vertInputs);
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
       inputs = fragInputs;
+      n = Elements(fragInputs);
+      break;
+   case MESA_GEOMETRY_PROGRAM:
+      inputs = geomInputs;
+      n = Elements(geomInputs);
       break;
-   /* XXX geom program */
    default:
       _mesa_problem(NULL, "bad target in _slang_input_index");
       return -1;
@@ -786,10 +834,12 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
 
    ASSERT(MAX_TEXTURE_COORD_UNITS == 8); /* if this fails, fix vertInputs above */
 
-   for (i = 0; inputs[i].Name; i++) {
+   for (i = 0; i < n; i++) {
       if (strcmp(inputs[i].Name, name) == 0) {
          /* found */
          *swizzleOut = inputs[i].Swizzle;
+         if (is_array)
+            *is_array = inputs[i].Array;
          return inputs[i].Attrib;
       }
    }
@@ -805,7 +855,7 @@ _slang_vert_attrib_name(GLuint attrib)
 {
    GLuint i;
    assert(attrib < VERT_ATTRIB_GENERIC0);
-   for (i = 0; vertInputs[i].Name; i++) {
+   for (i = 0; Elements(vertInputs); i++) {
       if (vertInputs[i].Attrib == attrib)
          return vertInputs[i].Name;
    }
@@ -822,7 +872,7 @@ _slang_vert_attrib_type(GLuint attrib)
 {
    GLuint i;
    assert(attrib < VERT_ATTRIB_GENERIC0);
-   for (i = 0; vertInputs[i].Name; i++) {
+   for (i = 0; Elements(vertInputs); i++) {
       if (vertInputs[i].Attrib == attrib)
          return vertInputs[i].Type;
    }
@@ -850,44 +900,62 @@ static const struct output_info vertOutputs[] = {
    { "gl_BackSecondaryColor", VERT_RESULT_BFC1, GL_FLOAT_VEC4 },
    { "gl_TexCoord", VERT_RESULT_TEX0, GL_FLOAT_VEC4 },
    { "gl_FogFragCoord", VERT_RESULT_FOGC, GL_FLOAT },
-   { "gl_PointSize", VERT_RESULT_PSIZ, GL_FLOAT },
-   { NULL, 0, GL_NONE }
+   { "gl_PointSize", VERT_RESULT_PSIZ, GL_FLOAT }
+};
+
+/** Predefined geometry shader outputs */
+static const struct output_info geomOutputs[] = {
+   { "gl_Position", GEOM_RESULT_POS, GL_FLOAT_VEC4 },
+   { "gl_FrontColor", GEOM_RESULT_COL0, GL_FLOAT_VEC4  },
+   { "gl_BackColor", GEOM_RESULT_COL1, GL_FLOAT_VEC4  },
+   { "gl_FrontSecondaryColor", GEOM_RESULT_SCOL0, GL_FLOAT_VEC4  },
+   { "gl_BackSecondaryColor", GEOM_RESULT_SCOL1, GL_FLOAT_VEC4  },
+   { "gl_TexCoord", GEOM_RESULT_TEX0, GL_FLOAT_VEC4  },
+   { "gl_FogFragCoord", GEOM_RESULT_FOGC, GL_FLOAT  },
+   { "gl_ClipVertex", GEOM_RESULT_CLPV, GL_FLOAT_VEC4  },
+   { "gl_PointSize", GEOM_RESULT_PSIZ, GL_FLOAT  },
+   { "gl_PrimitiveID", GEOM_RESULT_PRID, GL_FLOAT  },
+   { "gl_Layer", GEOM_RESULT_LAYR, GL_FLOAT  }
 };
 
 /** Predefined fragment shader outputs */
 static const struct output_info fragOutputs[] = {
    { "gl_FragColor", FRAG_RESULT_COLOR, GL_FLOAT_VEC4 },
    { "gl_FragDepth", FRAG_RESULT_DEPTH, GL_FLOAT },
-   { "gl_FragData", FRAG_RESULT_DATA0, GL_FLOAT_VEC4 },
-   { NULL, 0, GL_NONE }
+   { "gl_FragData", FRAG_RESULT_DATA0, GL_FLOAT_VEC4 }
 };
 
 
 /**
- * Return the VERT_RESULT_* or FRAG_RESULT_* value that corresponds to
- * a vertex or fragment program output variable.  Return -1 for an invalid
+ * Return the VERT_RESULT_*, GEOM_RESULT_* or FRAG_RESULT_* value that corresponds
+ * to a vertex or fragment program output variable.  Return -1 for an invalid
  * output name.
  */
 GLint
 _slang_output_index(const char *name, GLenum target)
 {
    const struct output_info *outputs;
-   GLuint i;
+   GLuint i, n;
 
    switch (target) {
    case GL_VERTEX_PROGRAM_ARB:
       outputs = vertOutputs;
+      n = Elements(vertOutputs);
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
       outputs = fragOutputs;
+      n = Elements(fragOutputs);
+      break;
+   case MESA_GEOMETRY_PROGRAM:
+      outputs = geomOutputs;
+      n = Elements(geomOutputs);
       break;
-   /* XXX geom program */
    default:
       _mesa_problem(NULL, "bad target in _slang_output_index");
       return -1;
    }
 
-   for (i = 0; outputs[i].Name; i++) {
+   for (i = 0; i < n; i++) {
       if (strcmp(outputs[i].Name, name) == 0) {
          /* found */
          return outputs[i].Attrib;
@@ -910,6 +978,19 @@ _slang_vertex_output_name(gl_vert_result index)
 }
 
 
+/**
+ * Given a GEOM_RESULT_x index, return the corresponding string name.
+ */
+const char *
+_slang_geometry_output_name(gl_geom_result index)
+{
+   if (index < Elements(geomOutputs))
+      return geomOutputs[index].Name;
+   else
+      return NULL;
+}
+
+
 /**
  * Given a FRAG_RESULT_x index, return the corresponding string name.
  */