r600g,radeonsi: add a bunch of useful queries for the HUD
[mesa.git] / src / glsl / tests / builtin_variable_test.cpp
index 4dbccdcdf068aac27a7b1b9645bd70abf1c70ba0..3fdfce57d4f34ee25d27c0e6af89d0eb0317974e 100644 (file)
@@ -65,9 +65,10 @@ common_builtin::SetUp()
 
    this->shader = rzalloc(this->mem_ctx, gl_shader);
    this->shader->Type = this->shader_type;
+   this->shader->Stage = _mesa_shader_enum_to_shader_stage(this->shader_type);
 
    this->state =
-      new(mem_ctx) _mesa_glsl_parse_state(&this->ctx, this->shader->Type,
+      new(mem_ctx) _mesa_glsl_parse_state(&this->ctx, this->shader->Stage,
                                           this->shader);
 
    _mesa_glsl_initialize_types(this->state);
@@ -110,11 +111,11 @@ common_builtin::uniforms_and_system_values_dont_have_explicit_location()
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_uniform && var->mode != ir_var_system_value)
+      if (var->data.mode != ir_var_uniform && var->data.mode != ir_var_system_value)
          continue;
 
-      EXPECT_FALSE(var->explicit_location);
-      EXPECT_EQ(-1, var->location);
+      EXPECT_FALSE(var->data.explicit_location);
+      EXPECT_EQ(-1, var->data.location);
    }
 }
 
@@ -124,12 +125,12 @@ common_builtin::constants_are_constant()
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_auto)
+      if (var->data.mode != ir_var_auto)
          continue;
 
-      EXPECT_FALSE(var->explicit_location);
-      EXPECT_EQ(-1, var->location);
-      EXPECT_TRUE(var->read_only);
+      EXPECT_FALSE(var->data.explicit_location);
+      EXPECT_EQ(-1, var->data.location);
+      EXPECT_TRUE(var->data.read_only);
    }
 }
 
@@ -139,7 +140,7 @@ common_builtin::no_invalid_variable_modes()
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      switch (var->mode) {
+      switch (var->data.mode) {
       case ir_var_auto:
       case ir_var_uniform:
       case ir_var_shader_in:
@@ -149,7 +150,7 @@ common_builtin::no_invalid_variable_modes()
 
       default:
          ADD_FAILURE() << "Built-in variable " << var->name
-                       << " has an invalid mode " << int(var->mode);
+                       << " has an invalid mode " << int(var->data.mode);
          break;
       }
    }
@@ -176,13 +177,13 @@ TEST_F(vertex_builtin, inputs_have_explicit_location)
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_shader_in)
+      if (var->data.mode != ir_var_shader_in)
          continue;
 
-      EXPECT_TRUE(var->explicit_location);
-      EXPECT_NE(-1, var->location);
-      EXPECT_GT(VERT_ATTRIB_GENERIC0, var->location);
-      EXPECT_EQ(0u, var->location_frac);
+      EXPECT_TRUE(var->data.explicit_location);
+      EXPECT_NE(-1, var->data.location);
+      EXPECT_GT(VERT_ATTRIB_GENERIC0, var->data.location);
+      EXPECT_EQ(0u, var->data.location_frac);
    }
 }
 
@@ -191,20 +192,20 @@ TEST_F(vertex_builtin, outputs_have_explicit_location)
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_shader_out)
+      if (var->data.mode != ir_var_shader_out)
          continue;
 
-      EXPECT_TRUE(var->explicit_location);
-      EXPECT_NE(-1, var->location);
-      EXPECT_GT(VARYING_SLOT_VAR0, var->location);
-      EXPECT_EQ(0u, var->location_frac);
+      EXPECT_TRUE(var->data.explicit_location);
+      EXPECT_NE(-1, var->data.location);
+      EXPECT_GT(VARYING_SLOT_VAR0, var->data.location);
+      EXPECT_EQ(0u, var->data.location_frac);
 
       /* Several varyings only exist in the fragment shader.  Be sure that no
        * outputs with these locations exist.
        */
-      EXPECT_NE(VARYING_SLOT_PNTC, var->location);
-      EXPECT_NE(VARYING_SLOT_FACE, var->location);
-      EXPECT_NE(VARYING_SLOT_PRIMITIVE_ID, var->location);
+      EXPECT_NE(VARYING_SLOT_PNTC, var->data.location);
+      EXPECT_NE(VARYING_SLOT_FACE, var->data.location);
+      EXPECT_NE(VARYING_SLOT_PRIMITIVE_ID, var->data.location);
    }
 }
 
@@ -244,18 +245,18 @@ TEST_F(fragment_builtin, inputs_have_explicit_location)
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_shader_in)
+      if (var->data.mode != ir_var_shader_in)
         continue;
 
-      EXPECT_TRUE(var->explicit_location);
-      EXPECT_NE(-1, var->location);
-      EXPECT_GT(VARYING_SLOT_VAR0, var->location);
-      EXPECT_EQ(0u, var->location_frac);
+      EXPECT_TRUE(var->data.explicit_location);
+      EXPECT_NE(-1, var->data.location);
+      EXPECT_GT(VARYING_SLOT_VAR0, var->data.location);
+      EXPECT_EQ(0u, var->data.location_frac);
 
       /* Several varyings only exist in the vertex / geometry shader.  Be sure
        * that no inputs with these locations exist.
        */
-      EXPECT_TRUE(_mesa_varying_slot_in_fs((gl_varying_slot) var->location));
+      EXPECT_TRUE(_mesa_varying_slot_in_fs((gl_varying_slot) var->data.location));
    }
 }
 
@@ -264,18 +265,18 @@ TEST_F(fragment_builtin, outputs_have_explicit_location)
    foreach_list(node, &this->ir) {
       ir_variable *const var = ((ir_instruction *) node)->as_variable();
 
-      if (var->mode != ir_var_shader_out)
+      if (var->data.mode != ir_var_shader_out)
         continue;
 
-      EXPECT_TRUE(var->explicit_location);
-      EXPECT_NE(-1, var->location);
+      EXPECT_TRUE(var->data.explicit_location);
+      EXPECT_NE(-1, var->data.location);
 
       /* gl_FragData[] has location FRAG_RESULT_DATA0.  Locations beyond that
        * are invalid.
        */
-      EXPECT_GE(FRAG_RESULT_DATA0, var->location);
+      EXPECT_GE(FRAG_RESULT_DATA0, var->data.location);
 
-      EXPECT_EQ(0u, var->location_frac);
+      EXPECT_EQ(0u, var->data.location_frac);
    }
 }
 
@@ -293,3 +294,101 @@ TEST_F(fragment_builtin, no_invalid_variable_modes)
 {
    common_builtin::no_invalid_variable_modes();
 }
+
+/********************************************************************/
+
+class geometry_builtin : public common_builtin {
+public:
+   geometry_builtin()
+      : common_builtin(GL_GEOMETRY_SHADER)
+   {
+      /* empty */
+   }
+};
+
+TEST_F(geometry_builtin, names_start_with_gl)
+{
+   common_builtin::names_start_with_gl();
+}
+
+TEST_F(geometry_builtin, inputs_have_explicit_location)
+{
+   foreach_list(node, &this->ir) {
+      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+      if (var->data.mode != ir_var_shader_in)
+        continue;
+
+      if (var->is_interface_instance()) {
+         EXPECT_STREQ("gl_in", var->name);
+         EXPECT_FALSE(var->data.explicit_location);
+         EXPECT_EQ(-1, var->data.location);
+
+         ASSERT_TRUE(var->type->is_array());
+
+         const glsl_type *const instance_type = var->type->fields.array;
+
+         for (unsigned i = 0; i < instance_type->length; i++) {
+            const glsl_struct_field *const input =
+               &instance_type->fields.structure[i];
+
+            string_starts_with_prefix(input->name, "gl_");
+            EXPECT_NE(-1, input->location);
+            EXPECT_GT(VARYING_SLOT_VAR0, input->location);
+
+            /* Several varyings only exist in the fragment shader.  Be sure
+             * that no inputs with these locations exist.
+             */
+            EXPECT_NE(VARYING_SLOT_PNTC, input->location);
+            EXPECT_NE(VARYING_SLOT_FACE, input->location);
+         }
+      } else {
+         EXPECT_TRUE(var->data.explicit_location);
+         EXPECT_NE(-1, var->data.location);
+         EXPECT_GT(VARYING_SLOT_VAR0, var->data.location);
+         EXPECT_EQ(0u, var->data.location_frac);
+      }
+
+      /* Several varyings only exist in the fragment shader.  Be sure that no
+       * inputs with these locations exist.
+       */
+      EXPECT_NE(VARYING_SLOT_PNTC, var->data.location);
+      EXPECT_NE(VARYING_SLOT_FACE, var->data.location);
+   }
+}
+
+TEST_F(geometry_builtin, outputs_have_explicit_location)
+{
+   foreach_list(node, &this->ir) {
+      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+      if (var->data.mode != ir_var_shader_out)
+        continue;
+
+      EXPECT_TRUE(var->data.explicit_location);
+      EXPECT_NE(-1, var->data.location);
+      EXPECT_GT(VARYING_SLOT_VAR0, var->data.location);
+      EXPECT_EQ(0u, var->data.location_frac);
+
+      /* Several varyings only exist in the fragment shader.  Be sure that no
+       * outputs with these locations exist.
+       */
+      EXPECT_NE(VARYING_SLOT_PNTC, var->data.location);
+      EXPECT_NE(VARYING_SLOT_FACE, var->data.location);
+   }
+}
+
+TEST_F(geometry_builtin, uniforms_and_system_values_dont_have_explicit_location)
+{
+   common_builtin::uniforms_and_system_values_dont_have_explicit_location();
+}
+
+TEST_F(geometry_builtin, constants_are_constant)
+{
+   common_builtin::constants_are_constant();
+}
+
+TEST_F(geometry_builtin, no_invalid_variable_modes)
+{
+   common_builtin::no_invalid_variable_modes();
+}