mesa: Prefix main includes with dir to avoid conflicts.
[mesa.git] / src / mesa / shader / slang / slang_simplify.c
index 87b117874fd803da4b1c4383d987d4fbd73727de..d5997283a879d0a936a3f6f61593bed28f44dcdc 100644 (file)
  * \author Michal Krol
  */
 
-#include "imports.h"
-#include "macros.h"
-#include "get.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/get.h"
 #include "slang_compile.h"
 #include "slang_codegen.h"
 #include "slang_simplify.h"
 #include "slang_print.h"
 
 
+#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS     0x8DFD
+#endif
+#ifndef GL_MAX_VERTEX_UNIFORM_VECTORS
+#define GL_MAX_VERTEX_UNIFORM_VECTORS       0x8DFB
+#endif
+#ifndef GL_MAX_VARYING_VECTORS
+#define GL_MAX_VARYING_VECTORS              0x8DFC
+#endif
 
 
 /**
@@ -63,6 +72,11 @@ _slang_lookup_constant(const char *name)
       { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS },
       { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS },
       { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS },
+#if FEATURE_es2_glsl
+      { "gl_MaxVertexUniformVectors", GL_MAX_VERTEX_UNIFORM_VECTORS },
+      { "gl_MaxVaryingVectors", GL_MAX_VARYING_VECTORS },
+      { "gl_MaxFragmentUniformVectors", GL_MAX_FRAGMENT_UNIFORM_VECTORS },
+#endif
       { NULL, 0 }
    };
    GLuint i;
@@ -70,7 +84,7 @@ _slang_lookup_constant(const char *name)
    for (i = 0; info[i].Name; i++) {
       if (strcmp(info[i].Name, name) == 0) {
          /* found */
-         GLint value = -1.0;
+         GLint value = -1;
          _mesa_GetIntegerv(info[i].Token, &value);
          ASSERT(value >= 0);  /* sanity check that glGetFloatv worked */
          return value;
@@ -104,7 +118,7 @@ _slang_simplify(slang_operation *oper,
          oper->literal[0] =
          oper->literal[1] =
          oper->literal[2] =
-         oper->literal[3] = value;
+         oper->literal[3] = (GLfloat) value;
          oper->type = SLANG_OPER_LITERAL_INT;
          return;
       }
@@ -263,8 +277,6 @@ _slang_simplify(slang_operation *oper,
       /* vec2(flt, flt) constructor */
       if (oper->type == SLANG_OPER_CALL) {
          if (strcmp((char *) oper->a_id, "vec2") == 0) {
-            printf("SIMPLIFY vec2 constructor scope = %p\n",
-                   (void*) oper->locals);
             oper->literal[0] = oper->children[0].literal[0];
             oper->literal[1] = oper->children[1].literal[0];
             oper->literal[2] = oper->literal[1];
@@ -277,6 +289,26 @@ _slang_simplify(slang_operation *oper,
          }
       }
    }
+
+   if (oper->num_children == 1 && isFloat[0]) {
+      /* vec2/3/4(flt, flt) constructor */
+      if (oper->type == SLANG_OPER_CALL) {
+         const char *func = (const char *) oper->a_id;
+         if (strncmp(func, "vec", 3) == 0 && func[3] >= '2' && func[3] <= '4') {
+            oper->literal[0] =
+            oper->literal[1] =
+            oper->literal[2] =
+            oper->literal[3] = oper->children[0].literal[0];
+            oper->literal_size = func[3] - '0';
+            assert(oper->literal_size >= 2);
+            assert(oper->literal_size <= 4);
+            slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */
+            oper->type = SLANG_OPER_LITERAL_FLOAT;
+            assert(oper->num_children == 0);
+            return;
+         }
+      }
+   }
 }
 
 
@@ -302,6 +334,10 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
    if (dbg) printf("Adapt %d args to %d parameters\n",
                    callOper->num_children, numParams);
 
+   /* Only try adapting for constructors */
+   if (fun->kind != SLANG_FUNC_CONSTRUCTOR)
+      return GL_FALSE;
+
    if (callOper->num_children != numParams) {
       /* number of arguments doesn't match number of parameters */
 
@@ -352,7 +388,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
                                        &origArg);
                   callOper->children[i + j].children[1].type
                      = SLANG_OPER_LITERAL_INT;
-                  callOper->children[i + j].children[1].literal[0] = j;
+                  callOper->children[i + j].children[1].literal[0] = (GLfloat) j;
                }
 
             }
@@ -366,11 +402,11 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
       }
    }
 
-   if (callOper->num_children < numParams) {
+   if (callOper->num_children < (GLuint) numParams) {
       /* still not enough args for all params */
       return GL_FALSE;
    }
-   else if (callOper->num_children > numParams) {
+   else if (callOper->num_children > (GLuint) numParams) {
       /* now too many arguments */
       /* XXX this isn't always an error, see spec */
       return GL_FALSE;
@@ -406,7 +442,7 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
          slang_operation *child = slang_operation_new(1);
 
          slang_operation_copy(child, &callOper->children[i]);
-         child->locals->outer_scope = callOper->locals;
+         child->locals->outer_scope = callOper->children[i].locals;
 
          callOper->children[i].type = SLANG_OPER_CALL;
          callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName);