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 "main/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 this->mem_ctx
= ralloc_context(NULL
);
50 this->ir
.make_empty();
54 invalidate_locations::TearDown()
56 ralloc_free(this->mem_ctx
);
60 TEST_F(invalidate_locations
, simple_vertex_in_generic
)
62 ir_variable
*const var
=
63 new(mem_ctx
) ir_variable(glsl_type::vec(4),
67 EXPECT_FALSE(var
->data
.explicit_location
);
68 EXPECT_EQ(-1, var
->data
.location
);
70 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
71 var
->data
.location_frac
= 2;
75 link_invalidate_variable_locations(&ir
);
77 EXPECT_EQ(-1, var
->data
.location
);
78 EXPECT_EQ(0u, var
->data
.location_frac
);
79 EXPECT_FALSE(var
->data
.explicit_location
);
80 EXPECT_TRUE(var
->data
.is_unmatched_generic_inout
);
83 TEST_F(invalidate_locations
, explicit_location_vertex_in_generic
)
85 ir_variable
*const var
=
86 new(mem_ctx
) ir_variable(glsl_type::vec(4),
90 EXPECT_FALSE(var
->data
.explicit_location
);
91 EXPECT_EQ(-1, var
->data
.location
);
93 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
94 var
->data
.explicit_location
= true;
98 link_invalidate_variable_locations(&ir
);
100 EXPECT_EQ(VERT_ATTRIB_GENERIC0
, var
->data
.location
);
101 EXPECT_EQ(0u, var
->data
.location_frac
);
102 EXPECT_TRUE(var
->data
.explicit_location
);
103 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
106 TEST_F(invalidate_locations
, explicit_location_frac_vertex_in_generic
)
108 ir_variable
*const var
=
109 new(mem_ctx
) ir_variable(glsl_type::vec(4),
113 EXPECT_FALSE(var
->data
.explicit_location
);
114 EXPECT_EQ(-1, var
->data
.location
);
116 var
->data
.location
= VERT_ATTRIB_GENERIC0
;
117 var
->data
.location_frac
= 2;
118 var
->data
.explicit_location
= true;
122 link_invalidate_variable_locations(&ir
);
124 EXPECT_EQ(VERT_ATTRIB_GENERIC0
, var
->data
.location
);
125 EXPECT_EQ(2u, var
->data
.location_frac
);
126 EXPECT_TRUE(var
->data
.explicit_location
);
127 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
130 TEST_F(invalidate_locations
, vertex_in_builtin
)
132 ir_variable
*const var
=
133 new(mem_ctx
) ir_variable(glsl_type::vec(4),
137 EXPECT_FALSE(var
->data
.explicit_location
);
138 EXPECT_EQ(-1, var
->data
.location
);
140 var
->data
.location
= VERT_ATTRIB_POS
;
141 var
->data
.explicit_location
= true;
145 link_invalidate_variable_locations(&ir
);
147 EXPECT_EQ(VERT_ATTRIB_POS
, var
->data
.location
);
148 EXPECT_EQ(0u, var
->data
.location_frac
);
149 EXPECT_TRUE(var
->data
.explicit_location
);
150 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);
153 TEST_F(invalidate_locations
, simple_vertex_out_generic
)
155 ir_variable
*const var
=
156 new(mem_ctx
) ir_variable(glsl_type::vec(4),
160 EXPECT_FALSE(var
->data
.explicit_location
);
161 EXPECT_EQ(-1, var
->data
.location
);
163 var
->data
.location
= VARYING_SLOT_VAR0
;
167 link_invalidate_variable_locations(&ir
);
169 EXPECT_EQ(-1, var
->data
.location
);
170 EXPECT_EQ(0u, var
->data
.location_frac
);
171 EXPECT_FALSE(var
->data
.explicit_location
);
172 EXPECT_TRUE(var
->data
.is_unmatched_generic_inout
);
175 TEST_F(invalidate_locations
, vertex_out_builtin
)
177 ir_variable
*const var
=
178 new(mem_ctx
) ir_variable(glsl_type::vec(4),
182 EXPECT_FALSE(var
->data
.explicit_location
);
183 EXPECT_EQ(-1, var
->data
.location
);
185 var
->data
.location
= VARYING_SLOT_COL0
;
186 var
->data
.explicit_location
= true;
190 link_invalidate_variable_locations(&ir
);
192 EXPECT_EQ(VARYING_SLOT_COL0
, var
->data
.location
);
193 EXPECT_EQ(0u, var
->data
.location_frac
);
194 EXPECT_TRUE(var
->data
.explicit_location
);
195 EXPECT_FALSE(var
->data
.is_unmatched_generic_inout
);