summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2013-10-02 15:44:14 -0700
committerIan Romanick <[email protected]>2014-05-02 07:19:39 -0700
commitba7195d126ce20bf74a27725224662aaca4d90ef (patch)
treefe252be251a3c086b65a7e363a5e6b12e8f015f6 /src
parent8f5852bd2b91df7b259e5aeafb6a62a4268ca4c4 (diff)
glsl/tests: Add first simple tests of populate_consumer_input_sets
Four initial tests: * Create an IR list with a single input variable and verify that variable is the only thing in the hash tables. * Same as the previous test, but use a built-in variable (gl_ClipDistance) with an explicit location set. * Create an IR list with a single input variable from an interface block and verify that variable is the only thing in the hash tables. * Create an IR list with a single input variable and a single input variable from an interface block. Verify that each is the only thing in the proper hash tables. Signed-off-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/Makefile.am3
-rw-r--r--src/glsl/tests/varyings_test.cpp246
2 files changed, 248 insertions, 1 deletions
diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
index 534eaa38536..e12ba956d7a 100644
--- a/src/glsl/Makefile.am
+++ b/src/glsl/Makefile.am
@@ -61,7 +61,8 @@ tests_general_ir_test_SOURCES = \
$(GLSL_SRCDIR)/standalone_scaffolding.cpp \
tests/builtin_variable_test.cpp \
tests/invalidate_locations_test.cpp \
- tests/general_ir_test.cpp
+ tests/general_ir_test.cpp \
+ tests/varyings_test.cpp
tests_general_ir_test_CFLAGS = \
$(PTHREAD_CFLAGS)
tests_general_ir_test_LDADD = \
diff --git a/src/glsl/tests/varyings_test.cpp b/src/glsl/tests/varyings_test.cpp
new file mode 100644
index 00000000000..ab47fcf59d8
--- /dev/null
+++ b/src/glsl/tests/varyings_test.cpp
@@ -0,0 +1,246 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include <gtest/gtest.h>
+#include "main/compiler.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "ralloc.h"
+#include "ir.h"
+#include "program/hash_table.h"
+
+/**
+ * \file varyings_test.cpp
+ *
+ * Test various aspects of linking shader stage inputs and outputs.
+ */
+
+namespace linker {
+void
+populate_consumer_input_sets(void *mem_ctx, exec_list *ir,
+ hash_table *consumer_inputs,
+ hash_table *consumer_interface_inputs);
+}
+
+class link_varyings : public ::testing::Test {
+public:
+ link_varyings();
+
+ virtual void SetUp();
+ virtual void TearDown();
+
+ char *interface_field_name(const glsl_type *iface, unsigned field = 0)
+ {
+ return ralloc_asprintf(mem_ctx,
+ "%s.%s",
+ simple_interface->name,
+ simple_interface->fields.structure[field].name);
+ }
+
+ void *mem_ctx;
+ exec_list ir;
+ hash_table *consumer_inputs;
+ hash_table *consumer_interface_inputs;
+
+ const glsl_type *simple_interface;
+};
+
+link_varyings::link_varyings()
+{
+ static const glsl_struct_field f[] = {
+ {
+ glsl_type::vec(4),
+ "v",
+ false
+ }
+ };
+
+ this->simple_interface =
+ glsl_type::get_interface_instance(f,
+ ARRAY_SIZE(f),
+ GLSL_INTERFACE_PACKING_STD140,
+ "simple_interface");
+}
+
+void
+link_varyings::SetUp()
+{
+ this->mem_ctx = ralloc_context(NULL);
+ this->ir.make_empty();
+
+ this->consumer_inputs
+ = hash_table_ctor(0, hash_table_string_hash, hash_table_string_compare);
+
+ this->consumer_interface_inputs
+ = hash_table_ctor(0, hash_table_string_hash, hash_table_string_compare);
+}
+
+void
+link_varyings::TearDown()
+{
+ ralloc_free(this->mem_ctx);
+ this->mem_ctx = NULL;
+
+ hash_table_dtor(this->consumer_inputs);
+ this->consumer_inputs = NULL;
+ hash_table_dtor(this->consumer_interface_inputs);
+ this->consumer_interface_inputs = NULL;
+}
+
+/**
+ * Hash table callback function that counts the elements in the table
+ *
+ * \sa num_elements
+ */
+static void
+ht_count_callback(const void *, void *, void *closure)
+{
+ unsigned int *counter = (unsigned int *) closure;
+
+ (*counter)++;
+}
+
+/**
+ * Helper function to count the number of elements in a hash table.
+ */
+static unsigned
+num_elements(hash_table *ht)
+{
+ unsigned int counter = 0;
+
+ hash_table_call_foreach(ht, ht_count_callback, (void *) &counter);
+
+ return counter;
+}
+
+/**
+ * Helper function to determine whether a hash table is empty.
+ */
+static bool
+is_empty(hash_table *ht)
+{
+ return num_elements(ht) == 0;
+}
+
+TEST_F(link_varyings, single_simple_input)
+{
+ ir_variable *const v =
+ new(mem_ctx) ir_variable(glsl_type::vec(4),
+ "a",
+ ir_var_shader_in);
+
+
+ ir.push_tail(v);
+
+ linker::populate_consumer_input_sets(mem_ctx,
+ &ir,
+ consumer_inputs,
+ consumer_interface_inputs);
+
+ EXPECT_EQ((void *) v, hash_table_find(consumer_inputs, "a"));
+ EXPECT_EQ(1u, num_elements(consumer_inputs));
+ EXPECT_TRUE(is_empty(consumer_interface_inputs));
+}
+
+TEST_F(link_varyings, gl_ClipDistance)
+{
+ const glsl_type *const array_8_of_float =
+ glsl_type::get_array_instance(glsl_type::vec(1), 8);
+
+ ir_variable *const clipdistance =
+ new(mem_ctx) ir_variable(array_8_of_float,
+ "gl_ClipDistance",
+ ir_var_shader_in);
+
+ clipdistance->explicit_location = true;
+ clipdistance->location = VARYING_SLOT_CLIP_DIST0;
+ clipdistance->explicit_index = 0;
+
+ ir.push_tail(clipdistance);
+
+ linker::populate_consumer_input_sets(mem_ctx,
+ &ir,
+ consumer_inputs,
+ consumer_interface_inputs);
+
+ EXPECT_EQ((void *) clipdistance,
+ hash_table_find(consumer_inputs, "gl_ClipDistance"));
+ EXPECT_EQ(1u, num_elements(consumer_inputs));
+ EXPECT_TRUE(is_empty(consumer_interface_inputs));
+}
+
+TEST_F(link_varyings, single_interface_input)
+{
+ ir_variable *const v =
+ new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
+ simple_interface->fields.structure[0].name,
+ ir_var_shader_in);
+
+ v->interface_type = simple_interface;
+
+ ir.push_tail(v);
+
+ linker::populate_consumer_input_sets(mem_ctx,
+ &ir,
+ consumer_inputs,
+ consumer_interface_inputs);
+
+ char *const full_name = interface_field_name(simple_interface);
+
+ EXPECT_EQ((void *) v, hash_table_find(consumer_interface_inputs, full_name));
+ EXPECT_EQ(1u, num_elements(consumer_interface_inputs));
+ EXPECT_TRUE(is_empty(consumer_inputs));
+}
+
+TEST_F(link_varyings, one_interface_and_one_simple_input)
+{
+ ir_variable *const v =
+ new(mem_ctx) ir_variable(glsl_type::vec(4),
+ "a",
+ ir_var_shader_in);
+
+
+ ir.push_tail(v);
+
+ ir_variable *const iface =
+ new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
+ simple_interface->fields.structure[0].name,
+ ir_var_shader_in);
+
+ iface->interface_type = simple_interface;
+
+ ir.push_tail(iface);
+
+ linker::populate_consumer_input_sets(mem_ctx,
+ &ir,
+ consumer_inputs,
+ consumer_interface_inputs);
+
+ char *const iface_field_name = interface_field_name(simple_interface);
+
+ EXPECT_EQ((void *) iface, hash_table_find(consumer_interface_inputs,
+ iface_field_name));
+ EXPECT_EQ(1u, num_elements(consumer_interface_inputs));
+
+ EXPECT_EQ((void *) v, hash_table_find(consumer_inputs, "a"));
+ EXPECT_EQ(1u, num_elements(consumer_inputs));
+}