• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Tests a diff where the dst shader doesn't have OpExtImport while the
27 // src shader does (and uses OpExtInst).  This test ensures that when matching,
28 // the OpExtImport instruction from the correct module is referenced.
29 constexpr char kSrc[] = R"(               OpCapability Shader
30           %1 = OpExtInstImport "GLSL.std.450"
31                OpMemoryModel Logical GLSL450
32                OpEntryPoint Fragment %4 "main" %9 %11
33                OpExecutionMode %4 OriginUpperLeft
34                OpSource ESSL 310
35                OpName %4 "main"
36                OpName %9 "color"
37                OpName %11 "v"
38                OpDecorate %9 RelaxedPrecision
39                OpDecorate %9 Location 0
40                OpDecorate %11 RelaxedPrecision
41                OpDecorate %11 Location 0
42                OpDecorate %12 RelaxedPrecision
43                OpDecorate %13 RelaxedPrecision
44                OpDecorate %14 RelaxedPrecision
45           %2 = OpTypeVoid
46           %3 = OpTypeFunction %2
47           %6 = OpTypeFloat 32
48           %7 = OpTypeVector %6 4
49           %8 = OpTypePointer Output %7
50           %9 = OpVariable %8 Output
51          %10 = OpTypePointer Input %6
52          %11 = OpVariable %10 Input
53           %4 = OpFunction %2 None %3
54           %5 = OpLabel
55          %12 = OpLoad %6 %11
56          %13 = OpExtInst %6 %1 Log2 %12
57          %14 = OpCompositeConstruct %7 %13 %13 %13 %13
58                OpStore %9 %14
59                OpReturn
60                OpFunctionEnd
61 )";
62 constexpr char kDst[] = R"(               OpCapability Shader
63                OpMemoryModel Logical GLSL450
64                OpEntryPoint Fragment %4 "main" %9 %11
65                OpExecutionMode %4 OriginUpperLeft
66                OpSource ESSL 310
67                OpName %4 "main"
68                OpName %9 "color"
69                OpName %11 "v"
70                OpDecorate %9 RelaxedPrecision
71                OpDecorate %9 Location 0
72                OpDecorate %11 RelaxedPrecision
73                OpDecorate %11 Location 0
74                OpDecorate %12 RelaxedPrecision
75                OpDecorate %13 RelaxedPrecision
76           %2 = OpTypeVoid
77           %3 = OpTypeFunction %2
78           %6 = OpTypeFloat 32
79           %7 = OpTypeVector %6 4
80           %8 = OpTypePointer Output %7
81           %9 = OpVariable %8 Output
82          %10 = OpTypePointer Input %6
83          %11 = OpVariable %10 Input
84           %4 = OpFunction %2 None %3
85           %5 = OpLabel
86          %12 = OpLoad %6 %11
87          %13 = OpCompositeConstruct %7 %12 %12 %12 %12
88                OpStore %9 %13
89                OpReturn
90                OpFunctionEnd
91 
92 )";
93 
TEST(DiffTest,OpextinstInSrcOnly)94 TEST(DiffTest, OpextinstInSrcOnly) {
95   constexpr char kDiff[] = R"( ; SPIR-V
96  ; Version: 1.6
97  ; Generator: Khronos SPIR-V Tools Assembler; 0
98  ; Bound: 15
99  ; Schema: 0
100  OpCapability Shader
101 -%1 = OpExtInstImport "GLSL.std.450"
102  OpMemoryModel Logical GLSL450
103  OpEntryPoint Fragment %4 "main" %9 %11
104  OpExecutionMode %4 OriginUpperLeft
105  OpSource ESSL 310
106  OpName %4 "main"
107  OpName %9 "color"
108  OpName %11 "v"
109  OpDecorate %9 RelaxedPrecision
110  OpDecorate %9 Location 0
111  OpDecorate %11 RelaxedPrecision
112  OpDecorate %11 Location 0
113  OpDecorate %12 RelaxedPrecision
114 -OpDecorate %13 RelaxedPrecision
115  OpDecorate %14 RelaxedPrecision
116  %2 = OpTypeVoid
117  %3 = OpTypeFunction %2
118  %6 = OpTypeFloat 32
119  %7 = OpTypeVector %6 4
120  %8 = OpTypePointer Output %7
121  %9 = OpVariable %8 Output
122  %10 = OpTypePointer Input %6
123  %11 = OpVariable %10 Input
124  %4 = OpFunction %2 None %3
125  %5 = OpLabel
126  %12 = OpLoad %6 %11
127 -%13 = OpExtInst %6 %1 Log2 %12
128 -%14 = OpCompositeConstruct %7 %13 %13 %13 %13
129 +%14 = OpCompositeConstruct %7 %12 %12 %12 %12
130  OpStore %9 %14
131  OpReturn
132  OpFunctionEnd
133 )";
134   Options options;
135   DoStringDiffTest(kSrc, kDst, kDiff, options);
136 }
137 
TEST(DiffTest,OpextinstInSrcOnlyNoDebug)138 TEST(DiffTest, OpextinstInSrcOnlyNoDebug) {
139   constexpr char kSrcNoDebug[] = R"(               OpCapability Shader
140           %1 = OpExtInstImport "GLSL.std.450"
141                OpMemoryModel Logical GLSL450
142                OpEntryPoint Fragment %4 "main" %9 %11
143                OpExecutionMode %4 OriginUpperLeft
144                OpSource ESSL 310
145                OpDecorate %9 RelaxedPrecision
146                OpDecorate %9 Location 0
147                OpDecorate %11 RelaxedPrecision
148                OpDecorate %11 Location 0
149                OpDecorate %12 RelaxedPrecision
150                OpDecorate %13 RelaxedPrecision
151                OpDecorate %14 RelaxedPrecision
152           %2 = OpTypeVoid
153           %3 = OpTypeFunction %2
154           %6 = OpTypeFloat 32
155           %7 = OpTypeVector %6 4
156           %8 = OpTypePointer Output %7
157           %9 = OpVariable %8 Output
158          %10 = OpTypePointer Input %6
159          %11 = OpVariable %10 Input
160           %4 = OpFunction %2 None %3
161           %5 = OpLabel
162          %12 = OpLoad %6 %11
163          %13 = OpExtInst %6 %1 Log2 %12
164          %14 = OpCompositeConstruct %7 %13 %13 %13 %13
165                OpStore %9 %14
166                OpReturn
167                OpFunctionEnd
168 
169 )";
170   constexpr char kDstNoDebug[] = R"(               OpCapability Shader
171                OpMemoryModel Logical GLSL450
172                OpEntryPoint Fragment %4 "main" %9 %11
173                OpExecutionMode %4 OriginUpperLeft
174                OpSource ESSL 310
175                OpDecorate %9 RelaxedPrecision
176                OpDecorate %9 Location 0
177                OpDecorate %11 RelaxedPrecision
178                OpDecorate %11 Location 0
179                OpDecorate %12 RelaxedPrecision
180                OpDecorate %13 RelaxedPrecision
181           %2 = OpTypeVoid
182           %3 = OpTypeFunction %2
183           %6 = OpTypeFloat 32
184           %7 = OpTypeVector %6 4
185           %8 = OpTypePointer Output %7
186           %9 = OpVariable %8 Output
187          %10 = OpTypePointer Input %6
188          %11 = OpVariable %10 Input
189           %4 = OpFunction %2 None %3
190           %5 = OpLabel
191          %12 = OpLoad %6 %11
192          %13 = OpCompositeConstruct %7 %12 %12 %12 %12
193                OpStore %9 %13
194                OpReturn
195                OpFunctionEnd
196 
197 )";
198   constexpr char kDiff[] = R"( ; SPIR-V
199  ; Version: 1.6
200  ; Generator: Khronos SPIR-V Tools Assembler; 0
201  ; Bound: 15
202  ; Schema: 0
203  OpCapability Shader
204 -%1 = OpExtInstImport "GLSL.std.450"
205  OpMemoryModel Logical GLSL450
206  OpEntryPoint Fragment %4 "main" %9 %11
207  OpExecutionMode %4 OriginUpperLeft
208  OpSource ESSL 310
209  OpDecorate %9 RelaxedPrecision
210  OpDecorate %9 Location 0
211  OpDecorate %11 RelaxedPrecision
212  OpDecorate %11 Location 0
213  OpDecorate %12 RelaxedPrecision
214 -OpDecorate %13 RelaxedPrecision
215  OpDecorate %14 RelaxedPrecision
216  %2 = OpTypeVoid
217  %3 = OpTypeFunction %2
218  %6 = OpTypeFloat 32
219  %7 = OpTypeVector %6 4
220  %8 = OpTypePointer Output %7
221  %9 = OpVariable %8 Output
222  %10 = OpTypePointer Input %6
223  %11 = OpVariable %10 Input
224  %4 = OpFunction %2 None %3
225  %5 = OpLabel
226  %12 = OpLoad %6 %11
227 -%13 = OpExtInst %6 %1 Log2 %12
228 -%14 = OpCompositeConstruct %7 %13 %13 %13 %13
229 +%14 = OpCompositeConstruct %7 %12 %12 %12 %12
230  OpStore %9 %14
231  OpReturn
232  OpFunctionEnd
233 )";
234   Options options;
235   DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
236 }
237 
238 }  // namespace
239 }  // namespace diff
240 }  // namespace spvtools
241