r300: move some more function to generic
[mesa.git] / src / mesa / shader / slang / slang_codegen.c
index e7b2bad8c2493af856d232f78a80c3e19de0f3e1..d23ae4d8cb599e6cff3f2b0eb66e65693b108ab7 100644 (file)
@@ -413,6 +413,9 @@ static slang_asm_info AsmInfo[] = {
    { "vec4_multiply", IR_MUL, 1, 2 },
    { "vec4_dot", IR_DOT4, 1, 2 },
    { "vec3_dot", IR_DOT3, 1, 2 },
+   { "vec2_dot", IR_DOT2, 1, 2 },
+   { "vec3_nrm", IR_NRM3, 1, 1 },
+   { "vec4_nrm", IR_NRM4, 1, 1 },
    { "vec3_cross", IR_CROSS, 1, 2 },
    { "vec4_lrp", IR_LRP, 1, 3 },
    { "vec4_min", IR_MIN, 1, 2 },
@@ -477,7 +480,6 @@ new_node3(slang_ir_opcode op,
       n->Children[0] = c0;
       n->Children[1] = c1;
       n->Children[2] = c2;
-      n->Writemask = WRITEMASK_XYZW;
       n->InstLocation = -1;
    }
    return n;
@@ -1598,19 +1600,6 @@ resolve_swizzle(const slang_operation *oper)
 }
 
 
-/**
- * As above, but produce a writemask.
- */
-static GLuint
-resolve_writemask(slang_assemble_ctx *A, const slang_operation *oper)
-{
-   GLuint swizzle = resolve_swizzle(oper);
-   GLuint writemask, swizzleOut;
-   swizzle_to_writemask(A, swizzle, &writemask, &swizzleOut);
-   return writemask;
-}
-
-
 /**
  * Recursively descend through swizzle nodes to find the node's storage info.
  */
@@ -1674,14 +1663,11 @@ _slang_gen_asm(slang_assemble_ctx *A, slang_operation *oper,
       /* Setup n->Store to be a particular location.  Otherwise, storage
        * for the result (a temporary) will be allocated later.
        */
-      GLuint writemask = WRITEMASK_XYZW;
       slang_operation *dest_oper;
       slang_ir_node *n0;
 
       dest_oper = &oper->children[0];
 
-      writemask = resolve_writemask(A, dest_oper);
-
       n0 = _slang_gen_operation(A, dest_oper);
       if (!n0)
          return NULL;
@@ -3061,7 +3047,6 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
             rhs = _slang_gen_swizzle(rhs, newSwizzle);
          }
          n = new_node2(IR_COPY, lhs, rhs);
-         n->Writemask = writemask;
          return n;
       }
       else {
@@ -3218,8 +3203,6 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
                                         SWIZZLE_NIL,
                                         SWIZZLE_NIL);
          n = _slang_gen_swizzle(n, swizzle);
-         /*n->Store = _slang_clone_ir_storage_swz(n->Store, */
-         n->Writemask = WRITEMASK_X << index;
       }
       assert(n->Store);
       return n;
@@ -3253,7 +3236,7 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
       index = _slang_gen_operation(A, &oper->children[1]);
       if (array && index) {
          /* bounds check */
-         GLint constIndex = 0;
+         GLint constIndex = -1;
          if (index->Opcode == IR_FLOAT) {
             constIndex = (int) index->Value[0];
             if (constIndex < 0 || constIndex >= arrayLen) {
@@ -3705,11 +3688,6 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
       const GLint totalSize = array_size(size, var->array_len);
       const GLuint swizzle = _slang_var_swizzle(totalSize, 0);
 
-      if (var->initializer) {
-         slang_info_log_error(A->log, "illegal initializer for uniform '%s'", varName);
-         return GL_FALSE;
-      }
-
       if (prog) {
          /* user-defined uniform */
          if (datatype == GL_NONE) {
@@ -3717,7 +3695,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
                /* temporary work-around */
                GLenum datatype = GL_FLOAT;
                GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
-                                                    totalSize, datatype);
+                                                    totalSize, datatype, NULL);
                store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
                                                  totalSize, swizzle);
 
@@ -3734,6 +3712,12 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
                 * "f.a"  (GL_FLOAT_VEC3)
                 * "f.b"  (GL_FLOAT_VEC4)
                 */
+
+               if (var->initializer) {
+                  slang_info_log_error(A->log,
+                     "unsupported initializer for uniform '%s'", varName);
+                  return GL_FALSE;
+               }
             }
             else {
                slang_info_log_error(A->log,
@@ -3743,8 +3727,25 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
             }
          }
          else {
-            GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
-                                                 totalSize, datatype);
+            GLint uniformLoc;
+            const GLfloat *initialValues = NULL;
+            if (var->initializer) {
+               _slang_simplify(var->initializer, &A->space, A->atoms);
+               if (var->initializer->type == SLANG_OPER_LITERAL_FLOAT ||
+                   var->initializer->type == SLANG_OPER_LITERAL_INT) {
+                  /* simple float/vector initializer */
+                  initialValues = var->initializer->literal;
+               }
+               else {
+                  /* complex initializer */
+                  slang_info_log_error(A->log,
+                     "unsupported initializer for uniform '%s'", varName);
+                  return GL_FALSE;
+               }
+            }
+
+            uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
+                                           totalSize, datatype, initialValues);
             store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
                                               totalSize, swizzle);
          }