[Mesa-dev] [PATCH 4/6] glsl/tests: Verify geometry shader built-ins generated by _mesa_glsl_initialize_variables

Ian Romanick idr at freedesktop.org
Fri Oct 11 20:18:39 CEST 2013


From: Ian Romanick <ian.d.romanick at intel.com>

Checks that the variables generated meet certain criteria.

 - Geometry shader inputs have an explicit location.

 - Geometry shader outputs have an explicit location.

 - Fragment shader-only varying locations are not used.

 - Geometry shader uniforms and system values don't have an explicit
   location.

 - Geometry shader constants don't have an explicit location and are
   read-only.

 - No other kinds of geometry variables exist.

It does not verify that an specific variables exist.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Paul Berry <stereotype441 at gmail.com>
---
 src/glsl/tests/builtin_variable_test.cpp | 98 ++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/src/glsl/tests/builtin_variable_test.cpp b/src/glsl/tests/builtin_variable_test.cpp
index 37c8f25..41a6922 100644
--- a/src/glsl/tests/builtin_variable_test.cpp
+++ b/src/glsl/tests/builtin_variable_test.cpp
@@ -309,3 +309,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->mode != ir_var_shader_in)
+	 continue;
+
+      if (var->is_interface_instance()) {
+         EXPECT_STREQ("gl_in", var->name);
+         EXPECT_FALSE(var->explicit_location);
+         EXPECT_EQ(-1, var->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->explicit_location);
+         EXPECT_NE(-1, var->location);
+         EXPECT_GT(VARYING_SLOT_VAR0, var->location);
+         EXPECT_EQ(0u, var->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->location);
+      EXPECT_NE(VARYING_SLOT_FACE, var->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->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);
+
+      /* 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);
+   }
+}
+
+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();
+}
-- 
1.8.1.4



More information about the mesa-dev mailing list