~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/compiler/glsl/tests/varyings_test.cpp

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Intel Corporation
3
 
 *
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:
10
 
 *
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
13
 
 * Software.
14
 
 *
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.
22
 
 */
23
 
#include <gtest/gtest.h>
24
 
#include "util/compiler.h"
25
 
#include "main/macros.h"
26
 
#include "util/ralloc.h"
27
 
#include "ir.h"
28
 
#include "util/hash_table.h"
29
 
 
30
 
/**
31
 
 * \file varyings_test.cpp
32
 
 *
33
 
 * Test various aspects of linking shader stage inputs and outputs.
34
 
 */
35
 
 
36
 
namespace linker {
37
 
void
38
 
populate_consumer_input_sets(void *mem_ctx, exec_list *ir,
39
 
                             hash_table *consumer_inputs,
40
 
                             hash_table *consumer_interface_inputs,
41
 
                             ir_variable *consumer_inputs_with_locations[VARYING_SLOT_MAX]);
42
 
 
43
 
ir_variable *
44
 
get_matching_input(void *mem_ctx,
45
 
                   const ir_variable *output_var,
46
 
                   hash_table *consumer_inputs,
47
 
                   hash_table *consumer_interface_inputs,
48
 
                   ir_variable *consumer_inputs_with_locations[VARYING_SLOT_MAX]);
49
 
}
50
 
 
51
 
class link_varyings : public ::testing::Test {
52
 
public:
53
 
   virtual void SetUp();
54
 
   virtual void TearDown();
55
 
 
56
 
   char *interface_field_name(const glsl_type *iface, unsigned field = 0)
57
 
   {
58
 
      return ralloc_asprintf(mem_ctx,
59
 
                             "%s.%s",
60
 
                             iface->name,
61
 
                             iface->fields.structure[field].name);
62
 
   }
63
 
 
64
 
   void *mem_ctx;
65
 
   exec_list ir;
66
 
   hash_table *consumer_inputs;
67
 
   hash_table *consumer_interface_inputs;
68
 
 
69
 
   const glsl_type *simple_interface;
70
 
   ir_variable *junk[VARYING_SLOT_TESS_MAX];
71
 
};
72
 
 
73
 
void
74
 
link_varyings::SetUp()
75
 
{
76
 
   glsl_type_singleton_init_or_ref();
77
 
 
78
 
   this->mem_ctx = ralloc_context(NULL);
79
 
   this->ir.make_empty();
80
 
 
81
 
   this->consumer_inputs =
82
 
         _mesa_hash_table_create(NULL, _mesa_hash_string,
83
 
                                 _mesa_key_string_equal);
84
 
 
85
 
   this->consumer_interface_inputs =
86
 
         _mesa_hash_table_create(NULL, _mesa_hash_string,
87
 
                                 _mesa_key_string_equal);
88
 
 
89
 
   /* Needs to happen after glsl type initialization */
90
 
   static const glsl_struct_field f[] = {
91
 
      glsl_struct_field(glsl_type::vec(4), "v")
92
 
   };
93
 
 
94
 
   this->simple_interface =
95
 
      glsl_type::get_interface_instance(f,
96
 
                                        ARRAY_SIZE(f),
97
 
                                        GLSL_INTERFACE_PACKING_STD140,
98
 
                                        false,
99
 
                                        "simple_interface");
100
 
}
101
 
 
102
 
void
103
 
link_varyings::TearDown()
104
 
{
105
 
   ralloc_free(this->mem_ctx);
106
 
   this->mem_ctx = NULL;
107
 
 
108
 
   _mesa_hash_table_destroy(this->consumer_inputs, NULL);
109
 
   this->consumer_inputs = NULL;
110
 
   _mesa_hash_table_destroy(this->consumer_interface_inputs, NULL);
111
 
   this->consumer_interface_inputs = NULL;
112
 
 
113
 
   glsl_type_singleton_decref();
114
 
}
115
 
 
116
 
TEST_F(link_varyings, single_simple_input)
117
 
{
118
 
   ir_variable *const v =
119
 
      new(mem_ctx) ir_variable(glsl_type::vec(4),
120
 
                               "a",
121
 
                               ir_var_shader_in);
122
 
 
123
 
 
124
 
   ir.push_tail(v);
125
 
 
126
 
   linker::populate_consumer_input_sets(mem_ctx,
127
 
                                        &ir,
128
 
                                        consumer_inputs,
129
 
                                        consumer_interface_inputs,
130
 
                                        junk);
131
 
 
132
 
   hash_entry *entry = _mesa_hash_table_search(consumer_inputs, "a");
133
 
   EXPECT_EQ((void *) v, entry->data);
134
 
   EXPECT_EQ(1u, consumer_inputs->entries);
135
 
   EXPECT_TRUE(consumer_interface_inputs->entries == 0);
136
 
}
137
 
 
138
 
TEST_F(link_varyings, gl_ClipDistance)
139
 
{
140
 
   const glsl_type *const array_8_of_float =
141
 
      glsl_type::get_array_instance(glsl_type::vec(1), 8);
142
 
 
143
 
   ir_variable *const clipdistance =
144
 
      new(mem_ctx) ir_variable(array_8_of_float,
145
 
                               "gl_ClipDistance",
146
 
                               ir_var_shader_in);
147
 
 
148
 
   clipdistance->data.explicit_location = true;
149
 
   clipdistance->data.location = VARYING_SLOT_CLIP_DIST0;
150
 
   clipdistance->data.explicit_index = 0;
151
 
 
152
 
   ir.push_tail(clipdistance);
153
 
 
154
 
   linker::populate_consumer_input_sets(mem_ctx,
155
 
                                        &ir,
156
 
                                        consumer_inputs,
157
 
                                        consumer_interface_inputs,
158
 
                                        junk);
159
 
 
160
 
   EXPECT_EQ(clipdistance, junk[VARYING_SLOT_CLIP_DIST0]);
161
 
   EXPECT_TRUE(consumer_inputs->entries == 0);
162
 
   EXPECT_TRUE(consumer_interface_inputs->entries == 0);
163
 
}
164
 
 
165
 
TEST_F(link_varyings, gl_CullDistance)
166
 
{
167
 
   const glsl_type *const array_8_of_float =
168
 
      glsl_type::get_array_instance(glsl_type::vec(1), 8);
169
 
 
170
 
   ir_variable *const culldistance =
171
 
      new(mem_ctx) ir_variable(array_8_of_float,
172
 
                               "gl_CullDistance",
173
 
                               ir_var_shader_in);
174
 
 
175
 
   culldistance->data.explicit_location = true;
176
 
   culldistance->data.location = VARYING_SLOT_CULL_DIST0;
177
 
   culldistance->data.explicit_index = 0;
178
 
 
179
 
   ir.push_tail(culldistance);
180
 
 
181
 
   linker::populate_consumer_input_sets(mem_ctx,
182
 
                                        &ir,
183
 
                                        consumer_inputs,
184
 
                                        consumer_interface_inputs,
185
 
                                        junk);
186
 
 
187
 
   EXPECT_EQ(culldistance, junk[VARYING_SLOT_CULL_DIST0]);
188
 
   EXPECT_TRUE(consumer_inputs->entries == 0);
189
 
   EXPECT_TRUE(consumer_interface_inputs->entries == 0);
190
 
}
191
 
 
192
 
TEST_F(link_varyings, single_interface_input)
193
 
{
194
 
   ir_variable *const v =
195
 
      new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
196
 
                               simple_interface->fields.structure[0].name,
197
 
                               ir_var_shader_in);
198
 
 
199
 
   v->init_interface_type(simple_interface);
200
 
 
201
 
   ir.push_tail(v);
202
 
 
203
 
   linker::populate_consumer_input_sets(mem_ctx,
204
 
                                        &ir,
205
 
                                        consumer_inputs,
206
 
                                        consumer_interface_inputs,
207
 
                                        junk);
208
 
   char *const full_name = interface_field_name(simple_interface);
209
 
 
210
 
   hash_entry *entry = _mesa_hash_table_search(consumer_interface_inputs,
211
 
                                               full_name);
212
 
   EXPECT_EQ((void *) v, entry->data);
213
 
   EXPECT_EQ(1u, consumer_interface_inputs->entries);
214
 
   EXPECT_TRUE(consumer_inputs->entries == 0);
215
 
}
216
 
 
217
 
TEST_F(link_varyings, one_interface_and_one_simple_input)
218
 
{
219
 
   ir_variable *const v =
220
 
      new(mem_ctx) ir_variable(glsl_type::vec(4),
221
 
                               "a",
222
 
                               ir_var_shader_in);
223
 
 
224
 
 
225
 
   ir.push_tail(v);
226
 
 
227
 
   ir_variable *const iface =
228
 
      new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
229
 
                               simple_interface->fields.structure[0].name,
230
 
                               ir_var_shader_in);
231
 
 
232
 
   iface->init_interface_type(simple_interface);
233
 
 
234
 
   ir.push_tail(iface);
235
 
 
236
 
   linker::populate_consumer_input_sets(mem_ctx,
237
 
                                        &ir,
238
 
                                        consumer_inputs,
239
 
                                        consumer_interface_inputs,
240
 
                                        junk);
241
 
 
242
 
   char *const iface_field_name = interface_field_name(simple_interface);
243
 
 
244
 
   hash_entry *entry = _mesa_hash_table_search(consumer_interface_inputs,
245
 
                                               iface_field_name);
246
 
   EXPECT_EQ((void *) iface, entry->data);
247
 
   EXPECT_EQ(1u, consumer_interface_inputs->entries);
248
 
 
249
 
   entry = _mesa_hash_table_search(consumer_inputs, "a");
250
 
   EXPECT_EQ((void *) v, entry->data);
251
 
   EXPECT_EQ(1u, consumer_inputs->entries);
252
 
}
253
 
 
254
 
TEST_F(link_varyings, interface_field_doesnt_match_noninterface)
255
 
{
256
 
   char *const iface_field_name = interface_field_name(simple_interface);
257
 
 
258
 
   /* The input shader has a single input variable name "a.v"
259
 
    */
260
 
   ir_variable *const in_v =
261
 
      new(mem_ctx) ir_variable(glsl_type::vec(4),
262
 
                               iface_field_name,
263
 
                               ir_var_shader_in);
264
 
 
265
 
   ir.push_tail(in_v);
266
 
 
267
 
   linker::populate_consumer_input_sets(mem_ctx,
268
 
                                        &ir,
269
 
                                        consumer_inputs,
270
 
                                        consumer_interface_inputs,
271
 
                                        junk);
272
 
 
273
 
   /* Create an output variable, "v", that is part of an interface block named
274
 
    * "a".  They should not match.
275
 
    */
276
 
   ir_variable *const out_v =
277
 
      new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
278
 
                               simple_interface->fields.structure[0].name,
279
 
                               ir_var_shader_in);
280
 
 
281
 
   out_v->init_interface_type(simple_interface);
282
 
 
283
 
   ir_variable *const match =
284
 
      linker::get_matching_input(mem_ctx,
285
 
                                 out_v,
286
 
                                 consumer_inputs,
287
 
                                 consumer_interface_inputs,
288
 
                                 junk);
289
 
 
290
 
   EXPECT_EQ(NULL, match);
291
 
}
292
 
 
293
 
TEST_F(link_varyings, interface_field_doesnt_match_noninterface_vice_versa)
294
 
{
295
 
   char *const iface_field_name = interface_field_name(simple_interface);
296
 
 
297
 
   /* In input shader has a single variable, "v", that is part of an interface
298
 
    * block named "a".
299
 
    */
300
 
   ir_variable *const in_v =
301
 
      new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
302
 
                               simple_interface->fields.structure[0].name,
303
 
                               ir_var_shader_in);
304
 
 
305
 
   in_v->init_interface_type(simple_interface);
306
 
 
307
 
   ir.push_tail(in_v);
308
 
 
309
 
   linker::populate_consumer_input_sets(mem_ctx,
310
 
                                        &ir,
311
 
                                        consumer_inputs,
312
 
                                        consumer_interface_inputs,
313
 
                                        junk);
314
 
 
315
 
   /* Create an output variable "a.v".  They should not match.
316
 
    */
317
 
   ir_variable *const out_v =
318
 
      new(mem_ctx) ir_variable(glsl_type::vec(4),
319
 
                               iface_field_name,
320
 
                               ir_var_shader_out);
321
 
 
322
 
   ir_variable *const match =
323
 
      linker::get_matching_input(mem_ctx,
324
 
                                 out_v,
325
 
                                 consumer_inputs,
326
 
                                 consumer_interface_inputs,
327
 
                                 junk);
328
 
 
329
 
   EXPECT_EQ(NULL, match);
330
 
}