2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 #include <gtest/gtest.h>
24 #include "util/compiler.h"
25 #include "main/mtypes.h"
26 #include "main/macros.h"
27 #include "util/ralloc.h"
32 * \file varyings_test.cpp
34 * Test various aspects of linking shader stage inputs and outputs.
37 class invalidate_locations
: public ::testing::Test
{
40 virtual void TearDown();
47 invalidate_locations::SetUp()
49 glsl_type_singleton_init_or_ref();
51 this->mem_ctx
= ralloc_context(NULL
);
52 this->ir
.make_empty();
56 invalidate_locations::TearDown()
58 ralloc_free(this->mem_ctx
);
61 glsl_type_singleton_decref();
64 TEST_F(invalidate_locations
, simple_vertex_in_generic
)
66 ir_variable
*const var
=
67 new(mem_ctx
) ir_variable(glsl_type::vec(4),
71 EXPECT_FALSE(var
->data
.explicit_location
);
72 EXPECT_EQ(-1, var
->data
.location
);
74 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
75 var
->data
.location_frac
= 2;
79 link_invalidate_variable_locations(&ir
);
81 EXPECT_EQ(-1, var
->data
.location
);
82 EXPECT_EQ(0u, var
->data
.location_frac
);
83 EXPECT_FALSE(var
->data
.explicit_location
);
84 EXPECT_TRUE(var
->data
.is_unmatched_generic_inout
);
87 TEST_F(invalidate_locations
, explicit_location_vertex_in_generic
)
89 ir_variable
*const var
=
90 new(mem_ctx
) ir_variable(glsl_type::vec(4),
94 EXPECT_FALSE(var
->data
.explicit_location
);
95 EXPECT_EQ(-1, var
->data
.location
);
97 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
98 var
->data
.explicit_location
= true;
102 link_invalidate_variable_locations(&ir
);
104 EXPECT_EQ(VERT_ATTRIB_GENERIC0
, var
->data
.location
);
105 EXPECT_EQ(0u, var
->data
.location_frac
);
106 EXPECT_TRUE(var
->data
.explicit_location
);
107 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
110 TEST_F(invalidate_locations
, explicit_location_frac_vertex_in_generic
)
112 ir_variable
*const var
=
113 new(mem_ctx
) ir_variable(glsl_type::vec(4),
117 EXPECT_FALSE(var
->data
.explicit_location
);
118 EXPECT_EQ(-1, var
->data
.location
);
120 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
121 var
->data
.location_frac
= 2;
122 var
->data
.explicit_location
= true;
126 link_invalidate_variable_locations(&ir
);
128 EXPECT_EQ(VERT_ATTRIB_GENERIC0
, var
->data
.location
);
129 EXPECT_EQ(2u, var
->data
.location_frac
);
130 EXPECT_TRUE(var
->data
.explicit_location
);
131 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
134 TEST_F(invalidate_locations
, vertex_in_builtin
)
136 ir_variable
*const var
=
137 new(mem_ctx
) ir_variable(glsl_type::vec(4),
141 EXPECT_FALSE(var
->data
.explicit_location
);
142 EXPECT_EQ(-1, var
->data
.location
);
144 var
->data
.location
= VERT_ATTRIB_POS
;
145 var
->data
.explicit_location
= true;
149 link_invalidate_variable_locations(&ir
);
151 EXPECT_EQ(VERT_ATTRIB_POS
, var
->data
.location
);
152 EXPECT_EQ(0u, var
->data
.location_frac
);
153 EXPECT_TRUE(var
->data
.explicit_location
);
154 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
157 TEST_F(invalidate_locations
, simple_vertex_out_generic
)
159 ir_variable
*const var
=
160 new(mem_ctx
) ir_variable(glsl_type::vec(4),
164 EXPECT_FALSE(var
->data
.explicit_location
);
165 EXPECT_EQ(-1, var
->data
.location
);
167 var
->data
.location
= VARYING_SLOT_VAR0
;
171 link_invalidate_variable_locations(&ir
);
173 EXPECT_EQ(-1, var
->data
.location
);
174 EXPECT_EQ(0u, var
->data
.location_frac
);
175 EXPECT_FALSE(var
->data
.explicit_location
);
176 EXPECT_TRUE(var
->data
.is_unmatched_generic_inout
);
179 TEST_F(invalidate_locations
, vertex_out_builtin
)
181 ir_variable
*const var
=
182 new(mem_ctx
) ir_variable(glsl_type::vec(4),
186 EXPECT_FALSE(var
->data
.explicit_location
);
187 EXPECT_EQ(-1, var
->data
.location
);
189 var
->data
.location
= VARYING_SLOT_COL0
;
190 var
->data
.explicit_location
= true;
194 link_invalidate_variable_locations(&ir
);
196 EXPECT_EQ(VARYING_SLOT_COL0
, var
->data
.location
);
197 EXPECT_EQ(0u, var
->data
.location_frac
);
198 EXPECT_TRUE(var
->data
.explicit_location
);
199 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);