1#!amber
2
3# Copyright 2020 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17
18# A test for a bug found by the GraphicsFuzz project.
19
20# Short description: Equivalent shaders, one that uses null for 0 and an Unroll annotation
21
22# The test passes because both shaders render the same image.
23
24SHADER vertex reference_vertex_shader PASSTHROUGH
25
26SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
27; SPIR-V
28; Version: 1.0
29; Generator: Khronos Glslang Reference Front End; 7
30; Bound: 295
31; Schema: 0
32               OpCapability Shader
33          %1 = OpExtInstImport "GLSL.std.450"
34               OpMemoryModel Logical GLSL450
35               OpEntryPoint Fragment %4 "main" %165 %180
36               OpExecutionMode %4 OriginUpperLeft
37               OpSource ESSL 320
38               OpName %4 "main"
39               OpName %165 "gl_FragCoord"
40               OpName %168 "buf0"
41               OpMemberName %168 0 "resolution"
42               OpName %170 ""
43               OpName %180 "_GLF_color"
44               OpDecorate %165 BuiltIn FragCoord
45               OpMemberDecorate %168 0 Offset 0
46               OpDecorate %168 Block
47               OpDecorate %170 DescriptorSet 0
48               OpDecorate %170 Binding 0
49               OpDecorate %180 Location 0
50          %2 = OpTypeVoid
51          %3 = OpTypeFunction %2
52          %6 = OpTypeFloat 32
53          %7 = OpTypeVector %6 2
54          %9 = OpTypeVector %6 4
55         %10 = OpTypePointer Function %9
56         %11 = OpTypeBool
57         %21 = OpTypeInt 32 0
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
64         %71 = OpConstant %6 1
65         %72 = OpConstantComposite %9 %70 %70 %71 %71
66         %73 = OpTypeInt 32 1
67         %76 = OpConstant %73 0
68         %83 = OpConstant %73 8
69         %85 = OpConstant %21 8
70         %86 = OpTypeArray %9 %85
71         %87 = OpConstant %6 4
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
76         %92 = OpConstant %6 8
77         %93 = OpConstantComposite %9 %88 %87 %87 %92
78         %94 = OpConstant %6 6
79         %95 = OpConstant %6 2
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
123          %5 = OpLabel
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
135               OpBranch %205
136        %205 = OpLabel
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
142        %209 = OpLabel
143               OpStore %199 %103
144        %212 = OpAccessChain %10 %199 %289
145        %213 = OpLoad %9 %212
146               OpSelectionMerge %277 None
147               OpSwitch %22 %242
148        %242 = OpLabel
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
154        %248 = OpLabel
155               OpBranch %277
156        %249 = OpLabel
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
162        %255 = OpLabel
163               OpBranch %277
164        %256 = OpLabel
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
170        %265 = OpLabel
171               OpBranch %277
172        %266 = OpLabel
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
178        %275 = OpLabel
179               OpBranch %277
180        %276 = OpLabel
181               OpBranch %277
182        %277 = OpLabel
183        %291 = OpPhi %11 %31 %248 %31 %255 %31 %265 %31 %275 %66 %276
184               OpSelectionMerge %232 None
185               OpBranchConditional %291 %215 %232
186        %215 = OpLabel
187               OpStore %200 %103
188        %217 = OpAccessChain %23 %200 %289 %22
189        %218 = OpLoad %6 %217
190        %219 = OpConvertFToS %73 %218
191               OpStore %201 %103
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
200               OpStore %202 %133
201        %230 = OpAccessChain %10 %202 %229
202        %231 = OpLoad %9 %230
203               OpBranch %232
204        %232 = OpLabel
205        %294 = OpPhi %9 %290 %277 %231 %215
206               OpBranch %233
207        %233 = OpLabel
208        %235 = OpIAdd %73 %289 %158
209               OpBranch %205
210        %236 = OpLabel
211               OpStore %180 %290
212               OpReturn
213               OpFunctionEnd
214END
215
216# uniforms for reference
217
218# resolution
219BUFFER reference_resolution DATA_TYPE vec2<float> DATA
220 256.0 256.0
221END
222
223BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
224
225PIPELINE 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
231END
232CLEAR_COLOR reference_pipeline 0 0 0 255
233
234CLEAR reference_pipeline
235RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
236
237
238SHADER vertex variant_vertex_shader PASSTHROUGH
239
240SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
241; SPIR-V
242; Version: 1.0
243; Generator: Khronos Glslang Reference Front End; 7
244; Bound: 426
245; Schema: 0
246               OpCapability Shader
247          %1 = OpExtInstImport "GLSL.std.450"
248               OpMemoryModel Logical GLSL450
249               OpEntryPoint Fragment %4 "main" %165 %180
250               OpExecutionMode %4 OriginUpperLeft
251               OpSource ESSL 320
252               OpName %4 "main"
253               OpName %165 "gl_FragCoord"
254               OpName %168 "buf0"
255               OpMemberName %168 0 "resolution"
256               OpName %170 ""
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
264          %2 = OpTypeVoid
265          %3 = OpTypeFunction %2
266          %6 = OpTypeFloat 32
267          %7 = OpTypeVector %6 2
268          %9 = OpTypeVector %6 4
269         %10 = OpTypePointer Function %9
270         %11 = OpTypeBool
271         %21 = OpTypeInt 32 0
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
280         %73 = OpTypeInt 32 1
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
338          %5 = OpLabel
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
350               OpBranch %205
351        %205 = OpLabel
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
357        %209 = OpLabel
358               OpStore %199 %103
359        %212 = OpAccessChain %10 %199 %289
360        %213 = OpLoad %9 %212
361               OpSelectionMerge %277 None
362               OpSwitch %22 %242
363        %242 = OpLabel
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
369        %248 = OpLabel
370               OpBranch %277
371        %249 = OpLabel
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
377        %255 = OpLabel
378               OpBranch %277
379        %256 = OpLabel
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
385        %265 = OpLabel
386               OpBranch %277
387        %266 = OpLabel
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
393        %275 = OpLabel
394               OpBranch %277
395        %276 = OpLabel
396               OpBranch %277
397        %277 = OpLabel
398        %291 = OpPhi %11 %31 %248 %31 %255 %31 %265 %31 %275 %66 %276
399               OpSelectionMerge %232 None
400               OpBranchConditional %291 %215 %232
401        %215 = OpLabel
402               OpStore %200 %103
403        %217 = OpAccessChain %23 %200 %289 %22
404        %218 = OpLoad %6 %217
405        %219 = OpConvertFToS %73 %218
406               OpStore %201 %103
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
415               OpStore %202 %133
416        %230 = OpAccessChain %10 %202 %229
417        %231 = OpLoad %9 %230
418               OpBranch %232
419        %232 = OpLabel
420        %294 = OpPhi %9 %290 %277 %231 %215
421               OpBranch %233
422        %233 = OpLabel
423        %235 = OpIAdd %73 %289 %158
424               OpBranch %205
425        %236 = OpLabel
426               OpStore %180 %290
427               OpReturn
428               OpFunctionEnd
429END
430
431# uniforms for variant
432
433# resolution
434BUFFER variant_resolution DATA_TYPE vec2<float> DATA
435 256.0 256.0
436END
437
438BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
439
440PIPELINE 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
446END
447CLEAR_COLOR variant_pipeline 0 0 0 255
448
449CLEAR variant_pipeline
450RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
451
452EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005
453