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 // Basic test for spirv-diff
27 constexpr char kSrc[] = R"(; SPIR-V
28 ; Version: 1.0
29 ; Generator: Google ANGLE Shader Compiler; 0
30 ; Bound: 27
31 ; Schema: 0
32 OpCapability Shader
33 OpMemoryModel Logical GLSL450
34 OpEntryPoint Vertex %22 "main" %4 %14 %19
35 OpSource GLSL 450
36 OpName %4 "_ua_position"
37 OpName %14 "ANGLEXfbPosition"
38 OpName %17 "gl_PerVertex"
39 OpMemberName %17 0 "gl_Position"
40 OpMemberName %17 1 "gl_PointSize"
41 OpMemberName %17 2 "gl_ClipDistance"
42 OpMemberName %17 3 "gl_CullDistance"
43 OpName %19 ""
44 OpName %22 "main"
45 OpDecorate %4 Location 0
46 OpDecorate %14 Location 0
47 OpMemberDecorate %17 1 RelaxedPrecision
48 OpMemberDecorate %17 0 BuiltIn Position
49 OpMemberDecorate %17 1 BuiltIn PointSize
50 OpMemberDecorate %17 2 BuiltIn ClipDistance
51 OpMemberDecorate %17 3 BuiltIn CullDistance
52 OpDecorate %17 Block
53 %1 = OpTypeFloat 32
54 %2 = OpTypeVector %1 4
55 %5 = OpTypeInt 32 0
56 %6 = OpTypeInt 32 1
57 %15 = OpConstant %5 8
58 %16 = OpTypeArray %1 %15
59 %17 = OpTypeStruct %2 %1 %16 %16
60 %20 = OpTypeVoid
61 %25 = OpConstant %6 0
62 %3 = OpTypePointer Input %2
63 %13 = OpTypePointer Output %2
64 %18 = OpTypePointer Output %17
65 %21 = OpTypeFunction %20
66 %4 = OpVariable %3 Input
67 %14 = OpVariable %13 Output
68 %19 = OpVariable %18 Output
69 %22 = OpFunction %20 None %21
70 %23 = OpLabel
71 %24 = OpLoad %2 %4
72 %26 = OpAccessChain %13 %19 %25
73 OpStore %26 %24
74 OpReturn
75 OpFunctionEnd)";
76 constexpr char kDst[] = R"(; SPIR-V
77 ; Version: 1.0
78 ; Generator: Khronos Glslang Reference Front End; 10
79 ; Bound: 28
80 ; Schema: 0
81 OpCapability Shader
82 %1 = OpExtInstImport "GLSL.std.450"
83 OpMemoryModel Logical GLSL450
84 OpEntryPoint Vertex %4 "main" %13 %17 %27
85 OpSource GLSL 450
86 OpName %4 "main"
87 OpName %11 "gl_PerVertex"
88 OpMemberName %11 0 "gl_Position"
89 OpMemberName %11 1 "gl_PointSize"
90 OpMemberName %11 2 "gl_ClipDistance"
91 OpMemberName %11 3 "gl_CullDistance"
92 OpName %13 ""
93 OpName %17 "_ua_position"
94 OpName %27 "ANGLEXfbPosition"
95 OpMemberDecorate %11 0 BuiltIn Position
96 OpMemberDecorate %11 1 BuiltIn PointSize
97 OpMemberDecorate %11 2 BuiltIn ClipDistance
98 OpMemberDecorate %11 3 BuiltIn CullDistance
99 OpDecorate %11 Block
100 OpDecorate %17 Location 0
101 OpDecorate %27 Location 0
102 %2 = OpTypeVoid
103 %3 = OpTypeFunction %2
104 %6 = OpTypeFloat 32
105 %7 = OpTypeVector %6 4
106 %8 = OpTypeInt 32 0
107 %9 = OpConstant %8 1
108 %10 = OpTypeArray %6 %9
109 %11 = OpTypeStruct %7 %6 %10 %10
110 %12 = OpTypePointer Output %11
111 %13 = OpVariable %12 Output
112 %14 = OpTypeInt 32 1
113 %15 = OpConstant %14 0
114 %16 = OpTypePointer Input %7
115 %17 = OpVariable %16 Input
116 %19 = OpTypePointer Output %7
117 %27 = OpVariable %19 Output
118 %4 = OpFunction %2 None %3
119 %5 = OpLabel
120 %18 = OpLoad %7 %17
121 %20 = OpAccessChain %19 %13 %15
122 OpStore %20 %18
123 OpReturn
124 OpFunctionEnd
125 )";
126
TEST(DiffTest,Basic)127 TEST(DiffTest, Basic) {
128 constexpr char kDiff[] = R"( ; SPIR-V
129 ; Version: 1.6
130 ; Generator: Khronos SPIR-V Tools Assembler; 0
131 -; Bound: 27
132 +; Bound: 36
133 ; Schema: 0
134 OpCapability Shader
135 +%27 = OpExtInstImport "GLSL.std.450"
136 OpMemoryModel Logical GLSL450
137 -OpEntryPoint Vertex %22 "main" %4 %14 %19
138 +OpEntryPoint Vertex %22 "main" %19 %4 %14
139 OpSource GLSL 450
140 OpName %4 "_ua_position"
141 OpName %14 "ANGLEXfbPosition"
142 OpName %17 "gl_PerVertex"
143 OpMemberName %17 0 "gl_Position"
144 OpMemberName %17 1 "gl_PointSize"
145 OpMemberName %17 2 "gl_ClipDistance"
146 OpMemberName %17 3 "gl_CullDistance"
147 OpName %19 ""
148 OpName %22 "main"
149 OpDecorate %4 Location 0
150 OpDecorate %14 Location 0
151 -OpMemberDecorate %17 1 RelaxedPrecision
152 OpMemberDecorate %17 0 BuiltIn Position
153 OpMemberDecorate %17 1 BuiltIn PointSize
154 OpMemberDecorate %17 2 BuiltIn ClipDistance
155 OpMemberDecorate %17 3 BuiltIn CullDistance
156 OpDecorate %17 Block
157 %1 = OpTypeFloat 32
158 %2 = OpTypeVector %1 4
159 %5 = OpTypeInt 32 0
160 %6 = OpTypeInt 32 1
161 -%15 = OpConstant %5 8
162 -%16 = OpTypeArray %1 %15
163 -%17 = OpTypeStruct %2 %1 %16 %16
164 +%17 = OpTypeStruct %2 %1 %29 %29
165 +%28 = OpConstant %5 1
166 +%29 = OpTypeArray %1 %28
167 %20 = OpTypeVoid
168 %25 = OpConstant %6 0
169 %3 = OpTypePointer Input %2
170 %13 = OpTypePointer Output %2
171 %18 = OpTypePointer Output %17
172 %21 = OpTypeFunction %20
173 %4 = OpVariable %3 Input
174 %14 = OpVariable %13 Output
175 %19 = OpVariable %18 Output
176 %22 = OpFunction %20 None %21
177 %23 = OpLabel
178 %24 = OpLoad %2 %4
179 %26 = OpAccessChain %13 %19 %25
180 OpStore %26 %24
181 OpReturn
182 OpFunctionEnd
183 )";
184 Options options;
185 DoStringDiffTest(kSrc, kDst, kDiff, options);
186 }
187
TEST(DiffTest,BasicNoDebug)188 TEST(DiffTest, BasicNoDebug) {
189 constexpr char kSrcNoDebug[] = R"(; SPIR-V
190 ; Version: 1.0
191 ; Generator: Google ANGLE Shader Compiler; 0
192 ; Bound: 27
193 ; Schema: 0
194 OpCapability Shader
195 OpMemoryModel Logical GLSL450
196 OpEntryPoint Vertex %22 "main" %4 %14 %19
197 OpSource GLSL 450
198 OpDecorate %4 Location 0
199 OpDecorate %14 Location 0
200 OpMemberDecorate %17 1 RelaxedPrecision
201 OpMemberDecorate %17 0 BuiltIn Position
202 OpMemberDecorate %17 1 BuiltIn PointSize
203 OpMemberDecorate %17 2 BuiltIn ClipDistance
204 OpMemberDecorate %17 3 BuiltIn CullDistance
205 OpDecorate %17 Block
206 %1 = OpTypeFloat 32
207 %2 = OpTypeVector %1 4
208 %5 = OpTypeInt 32 0
209 %6 = OpTypeInt 32 1
210 %15 = OpConstant %5 8
211 %16 = OpTypeArray %1 %15
212 %17 = OpTypeStruct %2 %1 %16 %16
213 %20 = OpTypeVoid
214 %25 = OpConstant %6 0
215 %3 = OpTypePointer Input %2
216 %13 = OpTypePointer Output %2
217 %18 = OpTypePointer Output %17
218 %21 = OpTypeFunction %20
219 %4 = OpVariable %3 Input
220 %14 = OpVariable %13 Output
221 %19 = OpVariable %18 Output
222 %22 = OpFunction %20 None %21
223 %23 = OpLabel
224 %24 = OpLoad %2 %4
225 %26 = OpAccessChain %13 %19 %25
226 OpStore %26 %24
227 OpReturn
228 OpFunctionEnd
229 )";
230 constexpr char kDstNoDebug[] = R"(; SPIR-V
231 ; Version: 1.0
232 ; Generator: Khronos Glslang Reference Front End; 10
233 ; Bound: 28
234 ; Schema: 0
235 OpCapability Shader
236 %1 = OpExtInstImport "GLSL.std.450"
237 OpMemoryModel Logical GLSL450
238 OpEntryPoint Vertex %4 "main" %13 %17 %27
239 OpSource GLSL 450
240 OpMemberDecorate %11 0 BuiltIn Position
241 OpMemberDecorate %11 1 BuiltIn PointSize
242 OpMemberDecorate %11 2 BuiltIn ClipDistance
243 OpMemberDecorate %11 3 BuiltIn CullDistance
244 OpDecorate %11 Block
245 OpDecorate %17 Location 0
246 OpDecorate %27 Location 0
247 %2 = OpTypeVoid
248 %3 = OpTypeFunction %2
249 %6 = OpTypeFloat 32
250 %7 = OpTypeVector %6 4
251 %8 = OpTypeInt 32 0
252 %9 = OpConstant %8 1
253 %10 = OpTypeArray %6 %9
254 %11 = OpTypeStruct %7 %6 %10 %10
255 %12 = OpTypePointer Output %11
256 %13 = OpVariable %12 Output
257 %14 = OpTypeInt 32 1
258 %15 = OpConstant %14 0
259 %16 = OpTypePointer Input %7
260 %17 = OpVariable %16 Input
261 %19 = OpTypePointer Output %7
262 %27 = OpVariable %19 Output
263 %4 = OpFunction %2 None %3
264 %5 = OpLabel
265 %18 = OpLoad %7 %17
266 %20 = OpAccessChain %19 %13 %15
267 OpStore %20 %18
268 OpReturn
269 OpFunctionEnd
270 )";
271 constexpr char kDiff[] = R"( ; SPIR-V
272 ; Version: 1.6
273 ; Generator: Khronos SPIR-V Tools Assembler; 0
274 -; Bound: 27
275 +; Bound: 36
276 ; Schema: 0
277 OpCapability Shader
278 +%27 = OpExtInstImport "GLSL.std.450"
279 OpMemoryModel Logical GLSL450
280 -OpEntryPoint Vertex %22 "main" %4 %14 %19
281 +OpEntryPoint Vertex %22 "main" %19 %4 %14
282 OpSource GLSL 450
283 OpDecorate %4 Location 0
284 OpDecorate %14 Location 0
285 -OpMemberDecorate %17 1 RelaxedPrecision
286 OpMemberDecorate %17 0 BuiltIn Position
287 OpMemberDecorate %17 1 BuiltIn PointSize
288 OpMemberDecorate %17 2 BuiltIn ClipDistance
289 OpMemberDecorate %17 3 BuiltIn CullDistance
290 OpDecorate %17 Block
291 %1 = OpTypeFloat 32
292 %2 = OpTypeVector %1 4
293 %5 = OpTypeInt 32 0
294 %6 = OpTypeInt 32 1
295 -%15 = OpConstant %5 8
296 -%16 = OpTypeArray %1 %15
297 -%17 = OpTypeStruct %2 %1 %16 %16
298 +%17 = OpTypeStruct %2 %1 %29 %29
299 +%28 = OpConstant %5 1
300 +%29 = OpTypeArray %1 %28
301 %20 = OpTypeVoid
302 %25 = OpConstant %6 0
303 %3 = OpTypePointer Input %2
304 %13 = OpTypePointer Output %2
305 %18 = OpTypePointer Output %17
306 %21 = OpTypeFunction %20
307 %4 = OpVariable %3 Input
308 %14 = OpVariable %13 Output
309 %19 = OpVariable %18 Output
310 %22 = OpFunction %20 None %21
311 %23 = OpLabel
312 %24 = OpLoad %2 %4
313 %26 = OpAccessChain %13 %19 %25
314 OpStore %26 %24
315 OpReturn
316 OpFunctionEnd
317 )";
318 Options options;
319 DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
320 }
321
TEST(DiffTest,BasicDumpIds)322 TEST(DiffTest, BasicDumpIds) {
323 constexpr char kDiff[] = R"( ; SPIR-V
324 ; Version: 1.6
325 ; Generator: Khronos SPIR-V Tools Assembler; 0
326 -; Bound: 27
327 +; Bound: 36
328 ; Schema: 0
329 OpCapability Shader
330 +%27 = OpExtInstImport "GLSL.std.450"
331 OpMemoryModel Logical GLSL450
332 -OpEntryPoint Vertex %22 "main" %4 %14 %19
333 +OpEntryPoint Vertex %22 "main" %19 %4 %14
334 OpSource GLSL 450
335 OpName %4 "_ua_position"
336 OpName %14 "ANGLEXfbPosition"
337 OpName %17 "gl_PerVertex"
338 OpMemberName %17 0 "gl_Position"
339 OpMemberName %17 1 "gl_PointSize"
340 OpMemberName %17 2 "gl_ClipDistance"
341 OpMemberName %17 3 "gl_CullDistance"
342 OpName %19 ""
343 OpName %22 "main"
344 OpDecorate %4 Location 0
345 OpDecorate %14 Location 0
346 -OpMemberDecorate %17 1 RelaxedPrecision
347 OpMemberDecorate %17 0 BuiltIn Position
348 OpMemberDecorate %17 1 BuiltIn PointSize
349 OpMemberDecorate %17 2 BuiltIn ClipDistance
350 OpMemberDecorate %17 3 BuiltIn CullDistance
351 OpDecorate %17 Block
352 %1 = OpTypeFloat 32
353 %2 = OpTypeVector %1 4
354 %5 = OpTypeInt 32 0
355 %6 = OpTypeInt 32 1
356 -%15 = OpConstant %5 8
357 -%16 = OpTypeArray %1 %15
358 -%17 = OpTypeStruct %2 %1 %16 %16
359 +%17 = OpTypeStruct %2 %1 %29 %29
360 +%28 = OpConstant %5 1
361 +%29 = OpTypeArray %1 %28
362 %20 = OpTypeVoid
363 %25 = OpConstant %6 0
364 %3 = OpTypePointer Input %2
365 %13 = OpTypePointer Output %2
366 %18 = OpTypePointer Output %17
367 %21 = OpTypeFunction %20
368 %4 = OpVariable %3 Input
369 %14 = OpVariable %13 Output
370 %19 = OpVariable %18 Output
371 %22 = OpFunction %20 None %21
372 %23 = OpLabel
373 %24 = OpLoad %2 %4
374 %26 = OpAccessChain %13 %19 %25
375 OpStore %26 %24
376 OpReturn
377 OpFunctionEnd
378 Src -> Dst
379 1 -> 6 [TypeFloat]
380 2 -> 7 [TypeVector]
381 3 -> 16 [TypePointer]
382 4 -> 17 [Variable]
383 5 -> 8 [TypeInt]
384 6 -> 14 [TypeInt]
385 13 -> 19 [TypePointer]
386 14 -> 27 [Variable]
387 15 -> 34 [Constant]
388 16 -> 35 [TypeArray]
389 17 -> 11 [TypeStruct]
390 18 -> 12 [TypePointer]
391 19 -> 13 [Variable]
392 20 -> 2 [TypeVoid]
393 21 -> 3 [TypeFunction]
394 22 -> 4 [Function]
395 23 -> 5 [Label]
396 24 -> 18 [Load]
397 25 -> 15 [Constant]
398 26 -> 20 [AccessChain]
399 )";
400 Options options;
401 options.dump_id_map = true;
402 DoStringDiffTest(kSrc, kDst, kDiff, options);
403 }
404
405 } // namespace
406 } // namespace diff
407 } // namespace spvtools
408