glsl/serialize: optimize for equal offsets in uniform remap tables
[mesa.git] / src / compiler / glsl / ir_validate.cpp
index df76a7cafd8eb63f844e209c64eaa225efafeed4..d0ffad0bd39b57e42ce07afef0ae8dc41f1406f3 100644 (file)
@@ -36,6 +36,7 @@
 #include "ir.h"
 #include "ir_hierarchical_visitor.h"
 #include "util/hash_table.h"
+#include "util/macros.h"
 #include "util/set.h"
 #include "compiler/glsl_types.h"
 
@@ -45,8 +46,7 @@ class ir_validate : public ir_hierarchical_visitor {
 public:
    ir_validate()
    {
-      this->ir_set = _mesa_set_create(NULL, _mesa_hash_pointer,
-                                      _mesa_key_pointer_equal);
+      this->ir_set = _mesa_pointer_set_create(NULL);
 
       this->current_function = NULL;
 
@@ -126,7 +126,7 @@ ir_validate::visit_enter(class ir_dereference_array *ir)
       abort();
    }
 
-   if (!ir->array_index->type->is_integer()) {
+   if (!ir->array_index->type->is_integer_32()) {
       printf("ir_dereference_array @ %p does not have integer index: %s\n",
              (void *) ir, ir->array_index->type->name);
       abort();
@@ -236,6 +236,14 @@ ir_validate::visit_enter(ir_function_signature *ir)
 ir_visitor_status
 ir_validate::visit_leave(ir_expression *ir)
 {
+   for (unsigned i = ir->num_operands; i < 4; i++) {
+      assert(ir->operands[i] == NULL);
+   }
+
+   for (unsigned i = 0; i < ir->num_operands; i++) {
+      assert(ir->operands[i] != NULL);
+   }
+
    switch (ir->operation) {
    case ir_unop_bit_not:
       assert(ir->operands[0]->type == ir->type);
@@ -477,6 +485,16 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::uvec2_type);
       break;
 
+   case ir_unop_pack_sampler_2x32:
+      assert(ir->type->is_sampler());
+      assert(ir->operands[0]->type == glsl_type::uvec2_type);
+      break;
+
+   case ir_unop_pack_image_2x32:
+      assert(ir->type->is_image());
+      assert(ir->operands[0]->type == glsl_type::uvec2_type);
+      break;
+
    case ir_unop_unpack_snorm_2x16:
    case ir_unop_unpack_unorm_2x16:
    case ir_unop_unpack_half_2x16:
@@ -505,16 +523,26 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::uint64_t_type);
       break;
 
+   case ir_unop_unpack_sampler_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type->is_sampler());
+      break;
+
+   case ir_unop_unpack_image_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type->is_image());
+      break;
+
    case ir_unop_bitfield_reverse:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       break;
 
    case ir_unop_bit_count:
    case ir_unop_find_msb:
    case ir_unop_find_lsb:
       assert(ir->operands[0]->type->vector_elements == ir->type->vector_elements);
-      assert(ir->operands[0]->type->is_integer());
+      assert(ir->operands[0]->type->is_integer_32());
       assert(ir->type->base_type == GLSL_TYPE_INT);
       break;
 
@@ -582,27 +610,10 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->type->base_type == GLSL_TYPE_INT);
       break;
 
-   case ir_unop_ballot:
-      assert(ir->type == glsl_type::uint64_t_type);
-      assert(ir->operands[0]->type == glsl_type::bool_type);
-      break;
-
-   case ir_binop_read_invocation:
-      assert(ir->operands[1]->type == glsl_type::uint_type);
-      /* fall-through */
-   case ir_unop_read_first_invocation:
+   case ir_unop_atan:
+      assert(ir->operands[0]->type->is_float() ||
+             ir->operands[0]->type->is_double());
       assert(ir->type == ir->operands[0]->type);
-      assert(ir->type->is_scalar() || ir->type->is_vector());
-      assert(ir->type->is_float() ||
-             ir->type->base_type == GLSL_TYPE_INT ||
-             ir->type->base_type == GLSL_TYPE_UINT);
-      break;
-
-   case ir_unop_vote_any:
-   case ir_unop_vote_all:
-   case ir_unop_vote_eq:
-      assert(ir->type == glsl_type::bool_type);
-      assert(ir->operands[0]->type == glsl_type::bool_type);
       break;
 
    case ir_binop_add:
@@ -616,6 +627,17 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type->base_type ==
              ir->operands[1]->type->base_type);
 
+      if (ir->operation == ir_binop_mul &&
+          (ir->type->base_type == GLSL_TYPE_UINT64 ||
+           ir->type->base_type == GLSL_TYPE_INT64) &&
+          (ir->operands[0]->type->base_type == GLSL_TYPE_INT ||
+           ir->operands[1]->type->base_type == GLSL_TYPE_INT ||
+           ir->operands[0]->type->base_type == GLSL_TYPE_UINT ||
+           ir->operands[1]->type->base_type == GLSL_TYPE_UINT)) {
+         assert(ir->operands[0]->type == ir->operands[1]->type);
+         break;
+      }
+
       if (ir->operands[0]->type->is_scalar())
         assert(ir->operands[1]->type == ir->type);
       else if (ir->operands[1]->type->is_scalar())
@@ -630,7 +652,7 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_imul_high:
       assert(ir->type == ir->operands[0]->type);
       assert(ir->type == ir->operands[1]->type);
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       break;
 
    case ir_binop_carry:
@@ -641,8 +663,6 @@ ir_validate::visit_leave(ir_expression *ir)
       break;
 
    case ir_binop_less:
-   case ir_binop_greater:
-   case ir_binop_lequal:
    case ir_binop_gequal:
    case ir_binop_equal:
    case ir_binop_nequal:
@@ -671,7 +691,7 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_lshift:
    case ir_binop_rshift:
       assert(ir->operands[0]->type->is_integer_32_64() &&
-             ir->operands[1]->type->is_integer());
+             ir->operands[1]->type->is_integer_32());
       if (ir->operands[0]->type->is_scalar()) {
           assert(ir->operands[1]->type->is_scalar());
       }
@@ -731,7 +751,7 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_vector_extract:
       assert(ir->operands[0]->type->is_vector());
       assert(ir->operands[1]->type->is_scalar()
-             && ir->operands[1]->type->is_integer());
+             && ir->operands[1]->type->is_integer_32());
       break;
 
    case ir_binop_interpolate_at_offset:
@@ -747,6 +767,13 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[1]->type == glsl_type::int_type);
       break;
 
+   case ir_binop_atan2:
+      assert(ir->operands[0]->type->is_float() ||
+             ir->operands[0]->type->is_double());
+      assert(ir->operands[1]->type == ir->operands[0]->type);
+      assert(ir->type == ir->operands[0]->type);
+      break;
+
    case ir_triop_fma:
       assert(ir->type->is_float() ||
              ir->type->is_double());
@@ -772,7 +799,7 @@ ir_validate::visit_leave(ir_expression *ir)
       break;
 
    case ir_triop_bitfield_extract:
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       assert(ir->operands[0]->type == ir->type);
       assert(ir->operands[1]->type == ir->type);
       assert(ir->operands[2]->type == ir->type);
@@ -783,12 +810,12 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[1]->type->is_scalar());
       assert(ir->operands[0]->type->base_type == ir->operands[1]->type->base_type);
       assert(ir->operands[2]->type->is_scalar()
-             && ir->operands[2]->type->is_integer());
+             && ir->operands[2]->type->is_integer_32());
       assert(ir->type == ir->operands[0]->type);
       break;
 
    case ir_quadop_bitfield_insert:
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       assert(ir->operands[0]->type == ir->type);
       assert(ir->operands[1]->type == ir->type);
       assert(ir->operands[2]->type == ir->type);
@@ -1038,7 +1065,8 @@ ir_validate::validate_ir(ir_instruction *ir, void *data)
    _mesa_set_add(ir_set, ir);
 }
 
-void
+#ifdef DEBUG
+static void
 check_node_type(ir_instruction *ir, void *data)
 {
    (void) data;
@@ -1051,6 +1079,7 @@ check_node_type(ir_instruction *ir, void *data)
    if (value != NULL)
       assert(value->type != glsl_type::error_type);
 }
+#endif
 
 void
 validate_ir_tree(exec_list *instructions)