3 # Copyright 2020 Google LLC
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # A test for a bug found by the GraphicsFuzz project.
20 # Short description: Equivalent shaders, one that uses null for 0 and an Unroll annotation
22 # The test passes because both shaders render the same image.
24 SHADER vertex reference_vertex_shader PASSTHROUGH
26 SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
29 ; Generator: Khronos Glslang Reference Front End; 7
33 %1 = OpExtInstImport "GLSL.std.450"
34 OpMemoryModel Logical GLSL450
35 OpEntryPoint Fragment %4 "main" %165 %180
36 OpExecutionMode %4 OriginUpperLeft
39 OpName %165 "gl_FragCoord"
41 OpMemberName %168 0 "resolution"
43 OpName %180 "_GLF_color"
44 OpDecorate %165 BuiltIn FragCoord
45 OpMemberDecorate %168 0 Offset 0
47 OpDecorate %170 DescriptorSet 0
48 OpDecorate %170 Binding 0
49 OpDecorate %180 Location 0
51 %3 = OpTypeFunction %2
53 %7 = OpTypeVector %6 2
54 %9 = OpTypeVector %6 4
55 %10 = OpTypePointer Function %9
58 %22 = OpConstant %21 0
59 %23 = OpTypePointer Function %6
60 %31 = OpConstantFalse %11
61 %33 = OpConstant %21 1
62 %66 = OpConstantTrue %11
63 %70 = OpConstant %6 0.5
65 %72 = OpConstantComposite %9 %70 %70 %71 %71
67 %76 = OpConstant %73 0
68 %83 = OpConstant %73 8
69 %85 = OpConstant %21 8
70 %86 = OpTypeArray %9 %85
72 %88 = OpConstant %6 20
73 %89 = OpConstantComposite %9 %87 %87 %88 %87
74 %90 = OpConstantComposite %9 %87 %87 %87 %88
75 %91 = OpConstantComposite %9 %87 %88 %88 %87
77 %93 = OpConstantComposite %9 %88 %87 %87 %92
80 %96 = OpConstantComposite %9 %92 %94 %87 %95
81 %97 = OpConstant %6 12
82 %98 = OpConstantComposite %9 %95 %97 %95 %87
83 %99 = OpConstant %6 16
84 %100 = OpConstantComposite %9 %99 %95 %87 %87
85 %101 = OpConstant %6 22
86 %102 = OpConstantComposite %9 %97 %101 %87 %87
87 %103 = OpConstantComposite %86 %89 %90 %91 %93 %96 %98 %100 %102
88 %108 = OpTypePointer Function %86
89 %115 = OpConstant %21 16
90 %116 = OpTypeArray %9 %115
91 %117 = OpConstant %6 0
92 %118 = OpConstantComposite %9 %117 %117 %117 %71
93 %119 = OpConstantComposite %9 %70 %117 %117 %71
94 %120 = OpConstantComposite %9 %117 %70 %117 %71
95 %121 = OpConstantComposite %9 %70 %70 %117 %71
96 %122 = OpConstantComposite %9 %117 %117 %70 %71
97 %123 = OpConstantComposite %9 %70 %117 %70 %71
98 %124 = OpConstantComposite %9 %117 %70 %70 %71
99 %125 = OpConstantComposite %9 %70 %70 %70 %71
100 %126 = OpConstantComposite %9 %71 %117 %117 %71
101 %127 = OpConstantComposite %9 %117 %71 %117 %71
102 %128 = OpConstantComposite %9 %71 %71 %117 %71
103 %129 = OpConstantComposite %9 %117 %117 %71 %71
104 %130 = OpConstantComposite %9 %71 %117 %71 %71
105 %131 = OpConstantComposite %9 %117 %71 %71 %71
106 %132 = OpConstantComposite %9 %71 %71 %71 %71
107 %133 = OpConstantComposite %116 %118 %119 %120 %121 %122 %123 %124 %125 %118 %126 %127 %128 %129 %130 %131 %132
108 %146 = OpConstant %73 9
109 %149 = OpConstant %73 11
110 %151 = OpConstant %73 16
111 %153 = OpTypePointer Function %116
112 %158 = OpConstant %73 1
113 %164 = OpTypePointer Input %9
114 %165 = OpVariable %164 Input
115 %168 = OpTypeStruct %7
116 %169 = OpTypePointer Uniform %168
117 %170 = OpVariable %169 Uniform
118 %171 = OpTypePointer Uniform %7
119 %176 = OpConstant %6 32
120 %179 = OpTypePointer Output %9
121 %180 = OpVariable %179 Output
122 %4 = OpFunction %2 None %3
124 %199 = OpVariable %108 Function
125 %200 = OpVariable %108 Function
126 %201 = OpVariable %108 Function
127 %202 = OpVariable %153 Function
128 %166 = OpLoad %9 %165
129 %167 = OpVectorShuffle %7 %166 %166 0 1
130 %172 = OpAccessChain %171 %170 %76
131 %173 = OpLoad %7 %172
132 %174 = OpFDiv %7 %167 %173
133 %177 = OpVectorTimesScalar %7 %174 %176
134 %178 = OpExtInst %7 %1 Floor %177
137 %290 = OpPhi %9 %72 %5 %294 %233
138 %289 = OpPhi %73 %76 %5 %235 %233
139 %208 = OpSLessThan %11 %289 %83
140 OpLoopMerge %236 %233 None
141 OpBranchConditional %208 %209 %236
144 %212 = OpAccessChain %10 %199 %289
145 %213 = OpLoad %9 %212
146 OpSelectionMerge %277 None
149 %244 = OpCompositeExtract %6 %178 0
150 %246 = OpCompositeExtract %6 %213 0
151 %247 = OpFOrdLessThan %11 %244 %246
152 OpSelectionMerge %249 None
153 OpBranchConditional %247 %248 %249
157 %251 = OpCompositeExtract %6 %178 1
158 %253 = OpCompositeExtract %6 %213 1
159 %254 = OpFOrdLessThan %11 %251 %253
160 OpSelectionMerge %256 None
161 OpBranchConditional %254 %255 %256
165 %262 = OpCompositeExtract %6 %213 2
166 %263 = OpFAdd %6 %246 %262
167 %264 = OpFOrdGreaterThan %11 %244 %263
168 OpSelectionMerge %266 None
169 OpBranchConditional %264 %265 %266
173 %272 = OpCompositeExtract %6 %213 3
174 %273 = OpFAdd %6 %253 %272
175 %274 = OpFOrdGreaterThan %11 %251 %273
176 OpSelectionMerge %276 None
177 OpBranchConditional %274 %275 %276
183 %291 = OpPhi %11 %31 %248 %31 %255 %31 %265 %31 %275 %66 %276
184 OpSelectionMerge %232 None
185 OpBranchConditional %291 %215 %232
188 %217 = OpAccessChain %23 %200 %289 %22
189 %218 = OpLoad %6 %217
190 %219 = OpConvertFToS %73 %218
192 %221 = OpAccessChain %23 %201 %289 %33
193 %222 = OpLoad %6 %221
194 %223 = OpConvertFToS %73 %222
195 %224 = OpIMul %73 %219 %223
196 %226 = OpIMul %73 %289 %146
197 %227 = OpIAdd %73 %224 %226
198 %228 = OpIAdd %73 %227 %149
199 %229 = OpSMod %73 %228 %151
201 %230 = OpAccessChain %10 %202 %229
202 %231 = OpLoad %9 %230
205 %294 = OpPhi %9 %290 %277 %231 %215
208 %235 = OpIAdd %73 %289 %158
216 # uniforms for reference
219 BUFFER reference_resolution DATA_TYPE vec2<float> DATA
223 BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
225 PIPELINE graphics reference_pipeline
226 ATTACH reference_vertex_shader
227 ATTACH reference_fragment_shader
228 FRAMEBUFFER_SIZE 256 256
229 BIND BUFFER reference_framebuffer AS color LOCATION 0
230 BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
232 CLEAR_COLOR reference_pipeline 0 0 0 255
234 CLEAR reference_pipeline
235 RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
238 SHADER vertex variant_vertex_shader PASSTHROUGH
240 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
243 ; Generator: Khronos Glslang Reference Front End; 7
247 %1 = OpExtInstImport "GLSL.std.450"
248 OpMemoryModel Logical GLSL450
249 OpEntryPoint Fragment %4 "main" %165 %180
250 OpExecutionMode %4 OriginUpperLeft
253 OpName %165 "gl_FragCoord"
255 OpMemberName %168 0 "resolution"
257 OpName %180 "_GLF_color"
258 OpDecorate %165 BuiltIn FragCoord
259 OpMemberDecorate %168 0 Offset 0
260 OpDecorate %168 Block
261 OpDecorate %170 DescriptorSet 0
262 OpDecorate %170 Binding 0
263 OpDecorate %180 Location 0
265 %3 = OpTypeFunction %2
267 %7 = OpTypeVector %6 2
268 %9 = OpTypeVector %6 4
269 %10 = OpTypePointer Function %9
272 %22 = OpConstant %21 0
273 %23 = OpTypePointer Function %6
274 %31 = OpConstantFalse %11
275 %33 = OpConstant %21 1
276 %66 = OpConstantTrue %11
277 %70 = OpConstant %6 0.5
278 %71 = OpConstant %6 1
279 %72 = OpConstantComposite %9 %70 %70 %71 %71
281 %76 = OpConstant %73 0
282 %83 = OpConstant %73 8
283 %85 = OpConstant %21 8
284 %86 = OpTypeArray %9 %85
285 %87 = OpConstant %6 4
286 %88 = OpConstant %6 20
287 %89 = OpConstantComposite %9 %87 %87 %88 %87
288 %90 = OpConstantComposite %9 %87 %87 %87 %88
289 %91 = OpConstantComposite %9 %87 %88 %88 %87
290 %92 = OpConstant %6 8
291 %93 = OpConstantComposite %9 %88 %87 %87 %92
292 %94 = OpConstant %6 6
293 %95 = OpConstant %6 2
294 %96 = OpConstantComposite %9 %92 %94 %87 %95
295 %97 = OpConstant %6 12
296 %98 = OpConstantComposite %9 %95 %97 %95 %87
297 %99 = OpConstant %6 16
298 %100 = OpConstantComposite %9 %99 %95 %87 %87
299 %101 = OpConstant %6 22
300 %102 = OpConstantComposite %9 %97 %101 %87 %87
301 %103 = OpConstantComposite %86 %89 %90 %91 %93 %96 %98 %100 %102
302 %108 = OpTypePointer Function %86
303 %115 = OpConstant %21 16
304 %116 = OpTypeArray %9 %115
305 %117 = OpConstant %6 0
306 %118 = OpConstantComposite %9 %117 %117 %117 %71
307 %119 = OpConstantComposite %9 %70 %117 %117 %71
308 %120 = OpConstantComposite %9 %117 %70 %117 %71
309 %121 = OpConstantComposite %9 %70 %70 %117 %71
310 %122 = OpConstantComposite %9 %117 %117 %70 %71
311 %123 = OpConstantComposite %9 %70 %117 %70 %71
312 %124 = OpConstantComposite %9 %117 %70 %70 %71
313 %125 = OpConstantComposite %9 %70 %70 %70 %71
314 %126 = OpConstantComposite %9 %71 %117 %117 %71
315 %127 = OpConstantComposite %9 %117 %71 %117 %71
316 %128 = OpConstantComposite %9 %71 %71 %117 %71
317 %129 = OpConstantComposite %9 %117 %117 %71 %71
318 %130 = OpConstantComposite %9 %71 %117 %71 %71
319 %131 = OpConstantComposite %9 %117 %71 %71 %71
320 %132 = OpConstantComposite %9 %71 %71 %71 %71
321 %133 = OpConstantComposite %116 %118 %119 %120 %121 %122 %123 %124 %125 %118 %126 %127 %128 %129 %130 %131 %132
322 %146 = OpConstant %73 9
323 %149 = OpConstant %73 11
324 %151 = OpConstant %73 16
325 %153 = OpTypePointer Function %116
326 %158 = OpConstant %73 1
327 %164 = OpTypePointer Input %9
328 %165 = OpVariable %164 Input
329 %168 = OpTypeStruct %7
330 %169 = OpTypePointer Uniform %168
331 %170 = OpVariable %169 Uniform
332 %171 = OpTypePointer Uniform %7
333 %176 = OpConstant %6 32
334 %179 = OpTypePointer Output %9
335 %180 = OpVariable %179 Output
336 %425 = OpConstantNull %73
337 %4 = OpFunction %2 None %3
339 %199 = OpVariable %108 Function
340 %200 = OpVariable %108 Function
341 %201 = OpVariable %108 Function
342 %202 = OpVariable %153 Function
343 %166 = OpLoad %9 %165
344 %167 = OpVectorShuffle %7 %166 %166 0 1
345 %172 = OpAccessChain %171 %170 %76
346 %173 = OpLoad %7 %172
347 %174 = OpFDiv %7 %167 %173
348 %177 = OpVectorTimesScalar %7 %174 %176
349 %178 = OpExtInst %7 %1 Floor %177
352 %290 = OpPhi %9 %72 %5 %294 %233
353 %289 = OpPhi %73 %425 %5 %235 %233
354 %208 = OpSLessThan %11 %289 %83
355 OpLoopMerge %236 %233 Unroll
356 OpBranchConditional %208 %209 %236
359 %212 = OpAccessChain %10 %199 %289
360 %213 = OpLoad %9 %212
361 OpSelectionMerge %277 None
364 %244 = OpCompositeExtract %6 %178 0
365 %246 = OpCompositeExtract %6 %213 0
366 %247 = OpFOrdLessThan %11 %244 %246
367 OpSelectionMerge %249 None
368 OpBranchConditional %247 %248 %249
372 %251 = OpCompositeExtract %6 %178 1
373 %253 = OpCompositeExtract %6 %213 1
374 %254 = OpFOrdLessThan %11 %251 %253
375 OpSelectionMerge %256 None
376 OpBranchConditional %254 %255 %256
380 %262 = OpCompositeExtract %6 %213 2
381 %263 = OpFAdd %6 %246 %262
382 %264 = OpFOrdGreaterThan %11 %244 %263
383 OpSelectionMerge %266 None
384 OpBranchConditional %264 %265 %266
388 %272 = OpCompositeExtract %6 %213 3
389 %273 = OpFAdd %6 %253 %272
390 %274 = OpFOrdGreaterThan %11 %251 %273
391 OpSelectionMerge %276 None
392 OpBranchConditional %274 %275 %276
398 %291 = OpPhi %11 %31 %248 %31 %255 %31 %265 %31 %275 %66 %276
399 OpSelectionMerge %232 None
400 OpBranchConditional %291 %215 %232
403 %217 = OpAccessChain %23 %200 %289 %22
404 %218 = OpLoad %6 %217
405 %219 = OpConvertFToS %73 %218
407 %221 = OpAccessChain %23 %201 %289 %33
408 %222 = OpLoad %6 %221
409 %223 = OpConvertFToS %73 %222
410 %224 = OpIMul %73 %219 %223
411 %226 = OpIMul %73 %289 %146
412 %227 = OpIAdd %73 %224 %226
413 %228 = OpIAdd %73 %227 %149
414 %229 = OpSMod %73 %228 %151
416 %230 = OpAccessChain %10 %202 %229
417 %231 = OpLoad %9 %230
420 %294 = OpPhi %9 %290 %277 %231 %215
423 %235 = OpIAdd %73 %289 %158
431 # uniforms for variant
434 BUFFER variant_resolution DATA_TYPE vec2<float> DATA
438 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
440 PIPELINE graphics variant_pipeline
441 ATTACH variant_vertex_shader
442 ATTACH variant_fragment_shader
443 FRAMEBUFFER_SIZE 256 256
444 BIND BUFFER variant_framebuffer AS color LOCATION 0
445 BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
447 CLEAR_COLOR variant_pipeline 0 0 0 255
449 CLEAR variant_pipeline
450 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
452 EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005