glsl2: Add support for non-float constants in Mesa IR.
authorEric Anholt <eric@anholt.net>
Sat, 26 Jun 2010 00:50:25 +0000 (17:50 -0700)
committerEric Anholt <eric@anholt.net>
Sat, 26 Jun 2010 01:01:20 +0000 (18:01 -0700)
Fixes glsl-vs-vec4-indexing-4.

src/mesa/shader/ir_to_mesa.cpp

index f28f5fcbfcbda56c3b19f545828795c0a51b75ad..99ec55a0d851286b712f94ce0a3a0e19826978a3 100644 (file)
@@ -980,22 +980,41 @@ void
 ir_to_mesa_visitor::visit(ir_constant *ir)
 {
    ir_to_mesa_src_reg src_reg;
+   GLfloat stack_vals[4];
+   GLfloat *values = stack_vals;
+   unsigned int i;
 
-   assert(ir->type->base_type == GLSL_TYPE_FLOAT ||
-         ir->type->base_type == GLSL_TYPE_UINT ||
-         ir->type->base_type == GLSL_TYPE_INT ||
-         ir->type->base_type == GLSL_TYPE_BOOL);
-
-   if (ir->type->base_type == GLSL_TYPE_FLOAT &&
-       !ir->type->is_matrix() && !ir->type->is_array()) {
-      src_reg.file = PROGRAM_CONSTANT;
-      src_reg.index =
-        _mesa_add_unnamed_constant(this->prog->Parameters,
-                                   &ir->value.f[0], ir->type->vector_elements,
-                                   &src_reg.swizzle);
-   } else {
-      assert(!"FINISHME: non-float constants");
+   if (ir->type->is_matrix() || ir->type->is_array()) {
+      assert(!"FINISHME: array/matrix constants");
    }
+
+   src_reg.file = PROGRAM_CONSTANT;
+   switch (ir->type->base_type) {
+   case GLSL_TYPE_FLOAT:
+      values = &ir->value.f[0];
+      break;
+   case GLSL_TYPE_UINT:
+      for (i = 0; i < ir->type->vector_elements; i++) {
+        values[i] = ir->value.u[i];
+      }
+      break;
+   case GLSL_TYPE_INT:
+      for (i = 0; i < ir->type->vector_elements; i++) {
+        values[i] = ir->value.i[i];
+      }
+      break;
+   case GLSL_TYPE_BOOL:
+      for (i = 0; i < ir->type->vector_elements; i++) {
+        values[i] = ir->value.b[i];
+      }
+      break;
+   default:
+      assert(!"Non-float/uint/int/bool constant");
+   }
+
+   src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters,
+                                             values, ir->type->vector_elements,
+                                             &src_reg.swizzle);
    src_reg.reladdr = false;
    src_reg.negate = 0;