diff options
author | Ian Romanick <[email protected]> | 2013-10-22 15:10:16 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2013-10-22 15:23:30 -0700 |
commit | 1eee0a9f016a1049869f4677f5919186ee3785a2 (patch) | |
tree | d6a7aae0ddc0498999bbba56d908b3e51b72aa8c | |
parent | cf8b14ce6dc8e6c741005fa76cfda046e1618ea4 (diff) |
glsl/tests: Unit test vertex shader in / out with link_invalidate_variable_locations
Validates:
- ir_variable::explicit_location should not be modified.
- If ir_variable::explicit_location is not set, ir_variable::location,
ir_variable::location_frac, and
ir_variable::is_unmatched_generic_inout must be reset to 0.
- If ir_variable::explicit_location is set, ir_variable::location
should not be modified. ir_variable::location_frac, and
ir_variable::is_unmatched_generic_inout must be reset to 0.
Previous unit tests have shown that all non-generic inputs / outputs
have explicit_location set.
v2: Split the link_invalidate_variable_locations interface change out to
a separate patch. Remove the vertex_in_builtin_without_explicit and
vertex_out_builtin_without_explicit tests. There was a lot of good
discussion about this on the mailing list to which I refer the
interested reader. Both changes suggested by Paul.
http://lists.freedesktop.org/archives/mesa-dev/2013-October/046652.html
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
-rw-r--r-- | src/glsl/Makefile.am | 1 | ||||
-rw-r--r-- | src/glsl/tests/invalidate_locations_test.cpp | 208 |
2 files changed, 209 insertions, 0 deletions
diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am index 80949fb2741..b9ed5b62b53 100644 --- a/src/glsl/Makefile.am +++ b/src/glsl/Makefile.am @@ -60,6 +60,7 @@ tests_general_ir_test_SOURCES = \ $(top_srcdir)/src/mesa/program/symbol_table.c \ $(GLSL_SRCDIR)/standalone_scaffolding.cpp \ tests/builtin_variable_test.cpp \ + tests/invalidate_locations_test.cpp \ tests/general_ir_test.cpp tests_general_ir_test_CFLAGS = \ $(PTHREAD_CFLAGS) diff --git a/src/glsl/tests/invalidate_locations_test.cpp b/src/glsl/tests/invalidate_locations_test.cpp new file mode 100644 index 00000000000..cded1d5e8c7 --- /dev/null +++ b/src/glsl/tests/invalidate_locations_test.cpp @@ -0,0 +1,208 @@ +/* + * 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 "linker.h" + +/** + * \file varyings_test.cpp + * + * Test various aspects of linking shader stage inputs and outputs. + */ + +class invalidate_locations : public ::testing::Test { +public: + virtual void SetUp(); + virtual void TearDown(); + + void *mem_ctx; + exec_list ir; +}; + +void +invalidate_locations::SetUp() +{ + this->mem_ctx = ralloc_context(NULL); + this->ir.make_empty(); +} + +void +invalidate_locations::TearDown() +{ + ralloc_free(this->mem_ctx); + this->mem_ctx = NULL; +} + +TEST_F(invalidate_locations, simple_vertex_in_generic) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "a", + ir_var_shader_in); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VERT_ATTRIB_GENERIC0; + var->location_frac = 2; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(-1, var->location); + EXPECT_EQ(0u, var->location_frac); + EXPECT_FALSE(var->explicit_location); + EXPECT_TRUE(var->is_unmatched_generic_inout); +} + +TEST_F(invalidate_locations, explicit_location_vertex_in_generic) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "a", + ir_var_shader_in); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VERT_ATTRIB_GENERIC0; + var->explicit_location = true; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(VERT_ATTRIB_GENERIC0, var->location); + EXPECT_EQ(0u, var->location_frac); + EXPECT_TRUE(var->explicit_location); + EXPECT_FALSE(var->is_unmatched_generic_inout); +} + +TEST_F(invalidate_locations, explicit_location_frac_vertex_in_generic) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "a", + ir_var_shader_in); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VERT_ATTRIB_GENERIC0; + var->location_frac = 2; + var->explicit_location = true; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(VERT_ATTRIB_GENERIC0, var->location); + EXPECT_EQ(2u, var->location_frac); + EXPECT_TRUE(var->explicit_location); + EXPECT_FALSE(var->is_unmatched_generic_inout); +} + +TEST_F(invalidate_locations, vertex_in_builtin) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "gl_Vertex", + ir_var_shader_in); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VERT_ATTRIB_POS; + var->explicit_location = true; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(VERT_ATTRIB_POS, var->location); + EXPECT_EQ(0u, var->location_frac); + EXPECT_TRUE(var->explicit_location); + EXPECT_FALSE(var->is_unmatched_generic_inout); +} + +TEST_F(invalidate_locations, simple_vertex_out_generic) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "a", + ir_var_shader_out); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VARYING_SLOT_VAR0; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(-1, var->location); + EXPECT_EQ(0u, var->location_frac); + EXPECT_FALSE(var->explicit_location); + EXPECT_TRUE(var->is_unmatched_generic_inout); +} + +TEST_F(invalidate_locations, vertex_out_builtin) +{ + ir_variable *const var = + new(mem_ctx) ir_variable(glsl_type::vec(4), + "gl_FrontColor", + ir_var_shader_out); + + EXPECT_FALSE(var->explicit_location); + EXPECT_EQ(-1, var->location); + + var->location = VARYING_SLOT_COL0; + var->explicit_location = true; + + ir.push_tail(var); + + link_invalidate_variable_locations(&ir, + VERT_ATTRIB_GENERIC0, + VARYING_SLOT_VAR0); + + EXPECT_EQ(VARYING_SLOT_COL0, var->location); + EXPECT_EQ(0u, var->location_frac); + EXPECT_TRUE(var->explicit_location); + EXPECT_FALSE(var->is_unmatched_generic_inout); +} |