1 // GENERATED FILE - DO NOT EDIT.
2 // Generated by generate_tests.py
3 //
4 // Copyright (c) 2022 Google LLC.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17
18 #include "../diff_test_utils.h"
19
20 #include "gtest/gtest.h"
21
22 namespace spvtools {
23 namespace diff {
24 namespace {
25
26 // Test for multiple entry points with the same execution model.
27 constexpr char kSrc[] = R"( OpCapability Shader
28 %1 = OpExtInstImport "GLSL.std.450"
29 OpMemoryModel Logical GLSL450
30 OpEntryPoint Vertex %4 "main1" %8 %10
31 OpEntryPoint Vertex %12 "main2" %13 %14 %15
32 OpSource ESSL 310
33 OpName %4 "main1"
34 OpName %12 "main2"
35 OpName %8 "v"
36 OpName %10 "a"
37 OpName %13 "v"
38 OpName %14 "a"
39 OpName %15 "b"
40 OpDecorate %8 Location 0
41 OpDecorate %10 Location 0
42 OpDecorate %13 Location 0
43 OpDecorate %14 Location 0
44 OpDecorate %15 Location 1
45 %2 = OpTypeVoid
46 %3 = OpTypeFunction %2
47 %6 = OpTypeFloat 32
48
49 %7 = OpTypePointer Output %6
50 %9 = OpTypePointer Input %6
51 %8 = OpVariable %7 Output
52 %10 = OpVariable %9 Input
53 %13 = OpVariable %7 Output
54 %14 = OpVariable %9 Input
55 %15 = OpVariable %9 Input
56
57 %4 = OpFunction %2 None %3
58 %5 = OpLabel
59 %11 = OpLoad %6 %10
60 OpStore %8 %11
61 OpReturn
62 OpFunctionEnd
63
64 %12 = OpFunction %2 None %3
65 %16 = OpLabel
66 %17 = OpLoad %6 %14
67 %18 = OpLoad %6 %15
68 %19 = OpFAdd %6 %17 %18
69 OpStore %13 %19
70 OpReturn
71 OpFunctionEnd)";
72 constexpr char kDst[] = R"( OpCapability Shader
73 %1 = OpExtInstImport "GLSL.std.450"
74 OpMemoryModel Logical GLSL450
75 OpEntryPoint Vertex %4 "main2" %13 %14 %15
76 OpEntryPoint Vertex %12 "main1" %8 %10
77 OpSource ESSL 310
78 OpName %12 "main1"
79 OpName %4 "main2"
80 OpName %8 "v"
81 OpName %10 "a"
82 OpName %13 "v"
83 OpName %14 "a"
84 OpName %15 "b"
85 OpDecorate %8 Location 0
86 OpDecorate %10 Location 0
87 OpDecorate %13 Location 0
88 OpDecorate %14 Location 0
89 OpDecorate %15 Location 1
90 %2 = OpTypeVoid
91 %3 = OpTypeFunction %2
92 %6 = OpTypeFloat 32
93
94 %7 = OpTypePointer Output %6
95 %9 = OpTypePointer Input %6
96 %8 = OpVariable %7 Output
97 %10 = OpVariable %9 Input
98 %13 = OpVariable %7 Output
99 %14 = OpVariable %9 Input
100 %15 = OpVariable %9 Input
101
102 %4 = OpFunction %2 None %3
103 %16 = OpLabel
104 %17 = OpLoad %6 %14
105 %18 = OpLoad %6 %15
106 %19 = OpFAdd %6 %17 %18
107 OpStore %13 %19
108 OpReturn
109 OpFunctionEnd
110
111 %12 = OpFunction %2 None %3
112 %5 = OpLabel
113 %11 = OpLoad %6 %10
114 OpStore %8 %11
115 OpReturn
116 OpFunctionEnd
117 )";
118
TEST(DiffTest,MultipleSameEntryPoints)119 TEST(DiffTest, MultipleSameEntryPoints) {
120 constexpr char kDiff[] = R"( ; SPIR-V
121 ; Version: 1.6
122 ; Generator: Khronos SPIR-V Tools Assembler; 0
123 ; Bound: 20
124 ; Schema: 0
125 OpCapability Shader
126 %1 = OpExtInstImport "GLSL.std.450"
127 OpMemoryModel Logical GLSL450
128 OpEntryPoint Vertex %4 "main1" %8 %10
129 OpEntryPoint Vertex %12 "main2" %13 %14 %15
130 OpSource ESSL 310
131 OpName %4 "main1"
132 OpName %12 "main2"
133 OpName %8 "v"
134 OpName %10 "a"
135 OpName %13 "v"
136 OpName %14 "a"
137 OpName %15 "b"
138 OpDecorate %8 Location 0
139 OpDecorate %10 Location 0
140 OpDecorate %13 Location 0
141 OpDecorate %14 Location 0
142 OpDecorate %15 Location 1
143 %2 = OpTypeVoid
144 %3 = OpTypeFunction %2
145 %6 = OpTypeFloat 32
146 %7 = OpTypePointer Output %6
147 %9 = OpTypePointer Input %6
148 %8 = OpVariable %7 Output
149 %10 = OpVariable %9 Input
150 %13 = OpVariable %7 Output
151 %14 = OpVariable %9 Input
152 %15 = OpVariable %9 Input
153 %4 = OpFunction %2 None %3
154 %5 = OpLabel
155 %11 = OpLoad %6 %10
156 OpStore %8 %11
157 OpReturn
158 OpFunctionEnd
159 %12 = OpFunction %2 None %3
160 %16 = OpLabel
161 %17 = OpLoad %6 %14
162 %18 = OpLoad %6 %15
163 %19 = OpFAdd %6 %17 %18
164 OpStore %13 %19
165 OpReturn
166 OpFunctionEnd
167 )";
168 Options options;
169 DoStringDiffTest(kSrc, kDst, kDiff, options);
170 }
171
TEST(DiffTest,MultipleSameEntryPointsNoDebug)172 TEST(DiffTest, MultipleSameEntryPointsNoDebug) {
173 constexpr char kSrcNoDebug[] = R"( OpCapability Shader
174 %1 = OpExtInstImport "GLSL.std.450"
175 OpMemoryModel Logical GLSL450
176 OpEntryPoint Vertex %4 "main1" %8 %10
177 OpEntryPoint Vertex %12 "main2" %13 %14 %15
178 OpSource ESSL 310
179 OpDecorate %8 Location 0
180 OpDecorate %10 Location 0
181 OpDecorate %13 Location 0
182 OpDecorate %14 Location 0
183 OpDecorate %15 Location 1
184 %2 = OpTypeVoid
185 %3 = OpTypeFunction %2
186 %6 = OpTypeFloat 32
187
188 %7 = OpTypePointer Output %6
189 %9 = OpTypePointer Input %6
190 %8 = OpVariable %7 Output
191 %10 = OpVariable %9 Input
192 %13 = OpVariable %7 Output
193 %14 = OpVariable %9 Input
194 %15 = OpVariable %9 Input
195
196 %4 = OpFunction %2 None %3
197 %5 = OpLabel
198 %11 = OpLoad %6 %10
199 OpStore %8 %11
200 OpReturn
201 OpFunctionEnd
202
203 %12 = OpFunction %2 None %3
204 %16 = OpLabel
205 %17 = OpLoad %6 %14
206 %18 = OpLoad %6 %15
207 %19 = OpFAdd %6 %17 %18
208 OpStore %13 %19
209 OpReturn
210 OpFunctionEnd
211 )";
212 constexpr char kDstNoDebug[] = R"( OpCapability Shader
213 %1 = OpExtInstImport "GLSL.std.450"
214 OpMemoryModel Logical GLSL450
215 OpEntryPoint Vertex %4 "main2" %13 %14 %15
216 OpEntryPoint Vertex %12 "main1" %8 %10
217 OpSource ESSL 310
218 OpDecorate %8 Location 0
219 OpDecorate %10 Location 0
220 OpDecorate %13 Location 0
221 OpDecorate %14 Location 0
222 OpDecorate %15 Location 1
223 %2 = OpTypeVoid
224 %3 = OpTypeFunction %2
225 %6 = OpTypeFloat 32
226
227 %7 = OpTypePointer Output %6
228 %9 = OpTypePointer Input %6
229 %8 = OpVariable %7 Output
230 %10 = OpVariable %9 Input
231 %13 = OpVariable %7 Output
232 %14 = OpVariable %9 Input
233 %15 = OpVariable %9 Input
234
235 %4 = OpFunction %2 None %3
236 %16 = OpLabel
237 %17 = OpLoad %6 %14
238 %18 = OpLoad %6 %15
239 %19 = OpFAdd %6 %17 %18
240 OpStore %13 %19
241 OpReturn
242 OpFunctionEnd
243
244 %12 = OpFunction %2 None %3
245 %5 = OpLabel
246 %11 = OpLoad %6 %10
247 OpStore %8 %11
248 OpReturn
249 OpFunctionEnd
250 )";
251 constexpr char kDiff[] = R"( ; SPIR-V
252 ; Version: 1.6
253 ; Generator: Khronos SPIR-V Tools Assembler; 0
254 ; Bound: 20
255 ; Schema: 0
256 OpCapability Shader
257 %1 = OpExtInstImport "GLSL.std.450"
258 OpMemoryModel Logical GLSL450
259 OpEntryPoint Vertex %4 "main1" %8 %10
260 OpEntryPoint Vertex %12 "main2" %13 %14 %15
261 OpSource ESSL 310
262 OpDecorate %8 Location 0
263 OpDecorate %10 Location 0
264 OpDecorate %13 Location 0
265 OpDecorate %14 Location 0
266 OpDecorate %15 Location 1
267 %2 = OpTypeVoid
268 %3 = OpTypeFunction %2
269 %6 = OpTypeFloat 32
270 %7 = OpTypePointer Output %6
271 %9 = OpTypePointer Input %6
272 %8 = OpVariable %7 Output
273 %10 = OpVariable %9 Input
274 %13 = OpVariable %7 Output
275 %14 = OpVariable %9 Input
276 %15 = OpVariable %9 Input
277 %4 = OpFunction %2 None %3
278 %5 = OpLabel
279 %11 = OpLoad %6 %10
280 OpStore %8 %11
281 OpReturn
282 OpFunctionEnd
283 %12 = OpFunction %2 None %3
284 %16 = OpLabel
285 %17 = OpLoad %6 %14
286 %18 = OpLoad %6 %15
287 %19 = OpFAdd %6 %17 %18
288 OpStore %13 %19
289 OpReturn
290 OpFunctionEnd
291 )";
292 Options options;
293 DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
294 }
295
TEST(DiffTest,MultipleSameEntryPointsDumpIds)296 TEST(DiffTest, MultipleSameEntryPointsDumpIds) {
297 constexpr char kDiff[] = R"( ; SPIR-V
298 ; Version: 1.6
299 ; Generator: Khronos SPIR-V Tools Assembler; 0
300 ; Bound: 20
301 ; Schema: 0
302 OpCapability Shader
303 %1 = OpExtInstImport "GLSL.std.450"
304 OpMemoryModel Logical GLSL450
305 OpEntryPoint Vertex %4 "main1" %8 %10
306 OpEntryPoint Vertex %12 "main2" %13 %14 %15
307 OpSource ESSL 310
308 OpName %4 "main1"
309 OpName %12 "main2"
310 OpName %8 "v"
311 OpName %10 "a"
312 OpName %13 "v"
313 OpName %14 "a"
314 OpName %15 "b"
315 OpDecorate %8 Location 0
316 OpDecorate %10 Location 0
317 OpDecorate %13 Location 0
318 OpDecorate %14 Location 0
319 OpDecorate %15 Location 1
320 %2 = OpTypeVoid
321 %3 = OpTypeFunction %2
322 %6 = OpTypeFloat 32
323 %7 = OpTypePointer Output %6
324 %9 = OpTypePointer Input %6
325 %8 = OpVariable %7 Output
326 %10 = OpVariable %9 Input
327 %13 = OpVariable %7 Output
328 %14 = OpVariable %9 Input
329 %15 = OpVariable %9 Input
330 %4 = OpFunction %2 None %3
331 %5 = OpLabel
332 %11 = OpLoad %6 %10
333 OpStore %8 %11
334 OpReturn
335 OpFunctionEnd
336 %12 = OpFunction %2 None %3
337 %16 = OpLabel
338 %17 = OpLoad %6 %14
339 %18 = OpLoad %6 %15
340 %19 = OpFAdd %6 %17 %18
341 OpStore %13 %19
342 OpReturn
343 OpFunctionEnd
344 Src -> Dst
345 1 -> 1 [ExtInstImport]
346 2 -> 2 [TypeVoid]
347 3 -> 3 [TypeFunction]
348 4 -> 12 [Function]
349 5 -> 5 [Label]
350 6 -> 6 [TypeFloat]
351 7 -> 7 [TypePointer]
352 8 -> 8 [Variable]
353 9 -> 9 [TypePointer]
354 10 -> 10 [Variable]
355 11 -> 11 [Load]
356 12 -> 4 [Function]
357 13 -> 13 [Variable]
358 14 -> 14 [Variable]
359 15 -> 15 [Variable]
360 16 -> 16 [Label]
361 17 -> 17 [Load]
362 18 -> 18 [Load]
363 19 -> 19 [FAdd]
364 )";
365 Options options;
366 options.dump_id_map = true;
367 DoStringDiffTest(kSrc, kDst, kDiff, options);
368 }
369
370 } // namespace
371 } // namespace diff
372 } // namespace spvtools
373