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 multiple entry points. The entry points have different
27 // execution models and so can be trivially matched.
28 constexpr char kSrc[] = R"( OpCapability Shader
29 %1 = OpExtInstImport "GLSL.std.450"
30 OpMemoryModel Logical GLSL450
31 OpEntryPoint Vertex %mainv "mainv" %vo %a
32 OpEntryPoint Fragment %mainf "mainf" %color %vi
33 OpExecutionMode %mainf OriginUpperLeft
34 OpSource ESSL 310
35 OpName %mainv "mainv"
36 OpName %mainf "mainf"
37 OpName %a "a"
38 OpName %vo "v"
39 OpName %vi "v"
40 OpName %color "color"
41 OpDecorate %a Location 0
42 OpDecorate %vo Location 0
43 OpDecorate %vi Location 0
44 OpDecorate %color Location 0
45 OpDecorate %color RelaxedPrecision
46 OpDecorate %vi RelaxedPrecision
47 OpDecorate %12 RelaxedPrecision
48 OpDecorate %13 RelaxedPrecision
49
50 %void = OpTypeVoid
51 %3 = OpTypeFunction %void
52 %float = OpTypeFloat 32
53 %v4float = OpTypeVector %float 4
54
55 %_ptr_Input_float = OpTypePointer Input %float
56 %a = OpVariable %_ptr_Input_float Input
57 %_ptr_Output_float = OpTypePointer Output %float
58 %vo = OpVariable %_ptr_Output_float Output
59 %vi = OpVariable %_ptr_Input_float Input
60 %_ptr_Output_v4float = OpTypePointer Output %v4float
61 %color = OpVariable %_ptr_Output_v4float Output
62
63 %mainv = OpFunction %void None %3
64 %5 = OpLabel
65 %11 = OpLoad %float %a
66 OpStore %vo %11
67 OpReturn
68 OpFunctionEnd
69
70 %mainf = OpFunction %void None %3
71 %6 = OpLabel
72 %12 = OpLoad %float %vi
73 %13 = OpCompositeConstruct %v4float %12 %12 %12 %12
74 OpStore %color %13
75 OpReturn
76 OpFunctionEnd)";
77 constexpr char kDst[] = R"( OpCapability Shader
78 %1 = OpExtInstImport "GLSL.std.450"
79 OpMemoryModel Logical GLSL450
80 OpEntryPoint Fragment %frag "frag" %vi %color
81 OpEntryPoint Vertex %vert "vert" %a %vo
82 OpExecutionMode %frag OriginUpperLeft
83 OpSource ESSL 310
84 OpName %frag "frag"
85 OpName %vert "vert"
86 OpName %vo "v"
87 OpName %a "a"
88 OpName %color "color"
89 OpName %vi "v"
90 OpDecorate %vi Location 0
91 OpDecorate %color Location 0
92 OpDecorate %a Location 0
93 OpDecorate %vo Location 0
94 OpDecorate %color RelaxedPrecision
95 OpDecorate %vi RelaxedPrecision
96 OpDecorate %14 RelaxedPrecision
97 OpDecorate %17 RelaxedPrecision
98
99 %float = OpTypeFloat 32
100 %v4float = OpTypeVector %float 4
101 %void = OpTypeVoid
102 %3 = OpTypeFunction %void
103
104 %_ptr_Output_float = OpTypePointer Output %float
105 %vo = OpVariable %_ptr_Output_float Output
106 %_ptr_Input_float = OpTypePointer Input %float
107 %a = OpVariable %_ptr_Input_float Input
108 %vi = OpVariable %_ptr_Input_float Input
109 %_ptr_Output_v4float = OpTypePointer Output %v4float
110 %color = OpVariable %_ptr_Output_v4float Output
111
112 %frag = OpFunction %void None %3
113 %7 = OpLabel
114 %14 = OpLoad %float %vi
115 %17 = OpCompositeConstruct %v4float %14 %14 %14 %14
116 OpStore %color %17
117 OpReturn
118 OpFunctionEnd
119
120 %vert = OpFunction %void None %3
121 %8 = OpLabel
122 %13 = OpLoad %float %a
123 OpStore %vo %13
124 OpReturn
125 OpFunctionEnd
126 )";
127
TEST(DiffTest,MultipleDifferentEntryPoints)128 TEST(DiffTest, MultipleDifferentEntryPoints) {
129 constexpr char kDiff[] = R"( ; SPIR-V
130 ; Version: 1.6
131 ; Generator: Khronos SPIR-V Tools Assembler; 0
132 ; Bound: 20
133 ; Schema: 0
134 OpCapability Shader
135 %1 = OpExtInstImport "GLSL.std.450"
136 OpMemoryModel Logical GLSL450
137 -OpEntryPoint Vertex %2 "mainv" %4 %7
138 +OpEntryPoint Vertex %2 "vert" %7 %4
139 -OpEntryPoint Fragment %8 "mainf" %9 %10
140 +OpEntryPoint Fragment %8 "frag" %10 %9
141 OpExecutionMode %8 OriginUpperLeft
142 OpSource ESSL 310
143 -OpName %2 "mainv"
144 +OpName %2 "vert"
145 -OpName %8 "mainf"
146 +OpName %8 "frag"
147 OpName %7 "a"
148 OpName %4 "v"
149 OpName %10 "v"
150 OpName %9 "color"
151 OpDecorate %7 Location 0
152 OpDecorate %4 Location 0
153 OpDecorate %10 Location 0
154 OpDecorate %9 Location 0
155 OpDecorate %9 RelaxedPrecision
156 OpDecorate %10 RelaxedPrecision
157 OpDecorate %12 RelaxedPrecision
158 OpDecorate %13 RelaxedPrecision
159 %14 = OpTypeVoid
160 %3 = OpTypeFunction %14
161 %15 = OpTypeFloat 32
162 %16 = OpTypeVector %15 4
163 %17 = OpTypePointer Input %15
164 %7 = OpVariable %17 Input
165 %18 = OpTypePointer Output %15
166 %4 = OpVariable %18 Output
167 %10 = OpVariable %17 Input
168 %19 = OpTypePointer Output %16
169 %9 = OpVariable %19 Output
170 %2 = OpFunction %14 None %3
171 %5 = OpLabel
172 %11 = OpLoad %15 %7
173 OpStore %4 %11
174 OpReturn
175 OpFunctionEnd
176 %8 = OpFunction %14 None %3
177 %6 = OpLabel
178 %12 = OpLoad %15 %10
179 %13 = OpCompositeConstruct %16 %12 %12 %12 %12
180 OpStore %9 %13
181 OpReturn
182 OpFunctionEnd
183 )";
184 Options options;
185 DoStringDiffTest(kSrc, kDst, kDiff, options);
186 }
187
TEST(DiffTest,MultipleDifferentEntryPointsNoDebug)188 TEST(DiffTest, MultipleDifferentEntryPointsNoDebug) {
189 constexpr char kSrcNoDebug[] = R"( OpCapability Shader
190 %1 = OpExtInstImport "GLSL.std.450"
191 OpMemoryModel Logical GLSL450
192 OpEntryPoint Vertex %mainv "mainv" %vo %a
193 OpEntryPoint Fragment %mainf "mainf" %color %vi
194 OpExecutionMode %mainf OriginUpperLeft
195 OpSource ESSL 310
196 OpDecorate %a Location 0
197 OpDecorate %vo Location 0
198 OpDecorate %vi Location 0
199 OpDecorate %color Location 0
200 OpDecorate %color RelaxedPrecision
201 OpDecorate %vi RelaxedPrecision
202 OpDecorate %12 RelaxedPrecision
203 OpDecorate %13 RelaxedPrecision
204
205 %void = OpTypeVoid
206 %3 = OpTypeFunction %void
207 %float = OpTypeFloat 32
208 %v4float = OpTypeVector %float 4
209
210 %_ptr_Input_float = OpTypePointer Input %float
211 %a = OpVariable %_ptr_Input_float Input
212 %_ptr_Output_float = OpTypePointer Output %float
213 %vo = OpVariable %_ptr_Output_float Output
214 %vi = OpVariable %_ptr_Input_float Input
215 %_ptr_Output_v4float = OpTypePointer Output %v4float
216 %color = OpVariable %_ptr_Output_v4float Output
217
218 %mainv = OpFunction %void None %3
219 %5 = OpLabel
220 %11 = OpLoad %float %a
221 OpStore %vo %11
222 OpReturn
223 OpFunctionEnd
224
225 %mainf = OpFunction %void None %3
226 %6 = OpLabel
227 %12 = OpLoad %float %vi
228 %13 = OpCompositeConstruct %v4float %12 %12 %12 %12
229 OpStore %color %13
230 OpReturn
231 OpFunctionEnd
232 )";
233 constexpr char kDstNoDebug[] = R"( OpCapability Shader
234 %1 = OpExtInstImport "GLSL.std.450"
235 OpMemoryModel Logical GLSL450
236 OpEntryPoint Fragment %frag "frag" %vi %color
237 OpEntryPoint Vertex %vert "vert" %a %vo
238 OpExecutionMode %frag OriginUpperLeft
239 OpSource ESSL 310
240 OpDecorate %vi Location 0
241 OpDecorate %color Location 0
242 OpDecorate %a Location 0
243 OpDecorate %vo Location 0
244 OpDecorate %color RelaxedPrecision
245 OpDecorate %vi RelaxedPrecision
246 OpDecorate %14 RelaxedPrecision
247 OpDecorate %17 RelaxedPrecision
248
249 %float = OpTypeFloat 32
250 %v4float = OpTypeVector %float 4
251 %void = OpTypeVoid
252 %3 = OpTypeFunction %void
253
254 %_ptr_Output_float = OpTypePointer Output %float
255 %vo = OpVariable %_ptr_Output_float Output
256 %_ptr_Input_float = OpTypePointer Input %float
257 %a = OpVariable %_ptr_Input_float Input
258 %vi = OpVariable %_ptr_Input_float Input
259 %_ptr_Output_v4float = OpTypePointer Output %v4float
260 %color = OpVariable %_ptr_Output_v4float Output
261
262 %frag = OpFunction %void None %3
263 %7 = OpLabel
264 %14 = OpLoad %float %vi
265 %17 = OpCompositeConstruct %v4float %14 %14 %14 %14
266 OpStore %color %17
267 OpReturn
268 OpFunctionEnd
269
270 %vert = OpFunction %void None %3
271 %8 = OpLabel
272 %13 = OpLoad %float %a
273 OpStore %vo %13
274 OpReturn
275 OpFunctionEnd
276 )";
277 constexpr char kDiff[] = R"( ; SPIR-V
278 ; Version: 1.6
279 ; Generator: Khronos SPIR-V Tools Assembler; 0
280 ; Bound: 20
281 ; Schema: 0
282 OpCapability Shader
283 %1 = OpExtInstImport "GLSL.std.450"
284 OpMemoryModel Logical GLSL450
285 -OpEntryPoint Vertex %2 "mainv" %4 %7
286 +OpEntryPoint Vertex %2 "vert" %7 %4
287 -OpEntryPoint Fragment %8 "mainf" %9 %10
288 +OpEntryPoint Fragment %8 "frag" %10 %9
289 OpExecutionMode %8 OriginUpperLeft
290 OpSource ESSL 310
291 OpDecorate %7 Location 0
292 OpDecorate %4 Location 0
293 OpDecorate %10 Location 0
294 OpDecorate %9 Location 0
295 OpDecorate %9 RelaxedPrecision
296 OpDecorate %10 RelaxedPrecision
297 OpDecorate %12 RelaxedPrecision
298 OpDecorate %13 RelaxedPrecision
299 %14 = OpTypeVoid
300 %3 = OpTypeFunction %14
301 %15 = OpTypeFloat 32
302 %16 = OpTypeVector %15 4
303 %17 = OpTypePointer Input %15
304 %7 = OpVariable %17 Input
305 %18 = OpTypePointer Output %15
306 %4 = OpVariable %18 Output
307 %10 = OpVariable %17 Input
308 %19 = OpTypePointer Output %16
309 %9 = OpVariable %19 Output
310 %2 = OpFunction %14 None %3
311 %5 = OpLabel
312 %11 = OpLoad %15 %7
313 OpStore %4 %11
314 OpReturn
315 OpFunctionEnd
316 %8 = OpFunction %14 None %3
317 %6 = OpLabel
318 %12 = OpLoad %15 %10
319 %13 = OpCompositeConstruct %16 %12 %12 %12 %12
320 OpStore %9 %13
321 OpReturn
322 OpFunctionEnd
323 )";
324 Options options;
325 DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
326 }
327
328 } // namespace
329 } // namespace diff
330 } // namespace spvtools
331