Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / stable-colorgrid-modulo-true-conditional-divided-1.amber
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 GraphicsFuzz.
19
20 # Short description: A fragment shader with true conditional divided by 1
21
22 # The test passes because both shaders render the same image.
23
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-local-multi-store'
26 # '--combine-access-chains'
27 # '--copy-propagate-arrays'
28 # '--scalar-replacement=100'
29 # '--eliminate-dead-code-aggressive'
30 # '--inline-entry-points-exhaustive'
31 # '--private-to-local'
32 # '--eliminate-dead-branches'
33 # '--eliminate-dead-inserts'
34 # '--vector-dce'
35 # '--simplify-instructions'
36 # '--vector-dce'
37 # '--eliminate-local-single-block'
38 # '--eliminate-local-single-block'
39 # '--private-to-local'
40 # '--combine-access-chains'
41 # '--reduce-load-size'
42 # '--ccp'
43 # '--eliminate-dead-branches'
44 # '--merge-blocks'
45 # '--vector-dce'
46 # '--eliminate-local-single-store'
47 # '--redundancy-elimination'
48 # '--inline-entry-points-exhaustive'
49 # '--reduce-load-size'
50 # '--simplify-instructions'
51 # '--eliminate-dead-inserts'
52 # '--eliminate-dead-code-aggressive'
53 # '--if-conversion'
54 # '--eliminate-dead-inserts'
55 # spirv-opt commit hash: 7afbc0c8be3f4dd48a7e521deb18f5c29a6c9892
56
57
58
59 SHADER vertex reference_vertex_shader PASSTHROUGH
60
61 # reference_fragment_shader is derived from the following GLSL:
62 # #version 320 es
63 # precision highp float;
64 #
65 # precision highp int;
66 #
67 # layout(location = 0) out vec4 _GLF_color;
68 #
69 # layout(set = 0, binding = 0) uniform buf0
70 # {
71 #   vec2 resolution;
72 # };
73 # float compute_value(float limit, float thirty_two)
74 # {
75 #   float result = -0.5;
76 #   for (int i = 1; i < 800; i++)
77 #   {
78 #     if ((i % 32) == 0)
79 #     {
80 #       result += 0.4;
81 #     }
82 #     else
83 #     {
84 #       if (mod(float(i), round(thirty_two)) <= 0.01)
85 #       {
86 #         result += 100.0;
87 #       }
88 #     }
89 #     if (float(i) >= limit)
90 #     {
91 #       return result;
92 #     }
93 #   }
94 #   return result;
95 # }
96 # void main()
97 # {
98 #   vec3 c = vec3(7.0, 8.0, 9.0);
99 #   float thirty_two = round(resolution.x / 8.0);
100 #   c.x = compute_value(gl_FragCoord.x, thirty_two);
101 #   c.y = compute_value(gl_FragCoord.y, thirty_two);
102 #   c.z = c.x + c.y;
103 #   for (int i = 0; i < 3; i++)
104 #   {
105 #     if (c[i] >= 1.0)
106 #     {
107 #       c[i] = c[i] * c[i];
108 #     }
109 #   }
110 #   _GLF_color = vec4(normalize(abs(c)), 1.0);
111 # }
112 SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
113 ; SPIR-V
114 ; Version: 1.0
115 ; Generator: Khronos Glslang Reference Front End; 10
116 ; Bound: 154
117 ; Schema: 0
118                OpCapability Shader
119           %1 = OpExtInstImport "GLSL.std.450"
120                OpMemoryModel Logical GLSL450
121                OpEntryPoint Fragment %4 "main" %85 %137
122                OpExecutionMode %4 OriginUpperLeft
123                OpSource ESSL 320
124                OpName %4 "main"
125                OpName %11 "compute_value(f1;f1;"
126                OpName %9 "limit"
127                OpName %10 "thirty_two"
128                OpName %66 "c"
129                OpName %73 "buf0"
130                OpMemberName %73 0 "resolution"
131                OpName %75 ""
132                OpName %85 "gl_FragCoord"
133                OpName %86 "param"
134                OpName %90 "param"
135                OpName %94 "param"
136                OpName %98 "param"
137                OpName %137 "_GLF_color"
138                OpMemberDecorate %73 0 Offset 0
139                OpDecorate %73 Block
140                OpDecorate %75 DescriptorSet 0
141                OpDecorate %75 Binding 0
142                OpDecorate %85 BuiltIn FragCoord
143                OpDecorate %137 Location 0
144           %2 = OpTypeVoid
145           %3 = OpTypeFunction %2
146           %6 = OpTypeFloat 32
147           %7 = OpTypePointer Function %6
148           %8 = OpTypeFunction %6 %7 %7
149          %14 = OpConstant %6 -0.5
150          %15 = OpTypeInt 32 1
151          %18 = OpConstant %15 1
152          %25 = OpConstant %15 800
153          %26 = OpTypeBool
154          %29 = OpConstant %15 32
155          %31 = OpConstant %15 0
156          %35 = OpConstant %6 0.400000006
157          %44 = OpConstant %6 0.00999999978
158          %48 = OpConstant %6 100
159          %64 = OpTypeVector %6 3
160          %65 = OpTypePointer Function %64
161          %67 = OpConstant %6 7
162          %68 = OpConstant %6 8
163          %69 = OpConstant %6 9
164          %70 = OpConstantComposite %64 %67 %68 %69
165          %72 = OpTypeVector %6 2
166          %73 = OpTypeStruct %72
167          %74 = OpTypePointer Uniform %73
168          %75 = OpVariable %74 Uniform
169          %76 = OpTypeInt 32 0
170          %77 = OpConstant %76 0
171          %78 = OpTypePointer Uniform %6
172          %83 = OpTypeVector %6 4
173          %84 = OpTypePointer Input %83
174          %85 = OpVariable %84 Input
175          %87 = OpTypePointer Input %6
176          %95 = OpConstant %76 1
177         %107 = OpConstant %76 2
178         %116 = OpConstant %15 3
179         %121 = OpConstant %6 1
180         %136 = OpTypePointer Output %83
181         %137 = OpVariable %136 Output
182         %153 = OpConstant %6 0.125
183           %4 = OpFunction %2 None %3
184           %5 = OpLabel
185          %66 = OpVariable %65 Function
186          %86 = OpVariable %7 Function
187          %90 = OpVariable %7 Function
188          %94 = OpVariable %7 Function
189          %98 = OpVariable %7 Function
190                OpStore %66 %70
191          %79 = OpAccessChain %78 %75 %31 %77
192          %80 = OpLoad %6 %79
193          %81 = OpFMul %6 %80 %153
194          %82 = OpExtInst %6 %1 Round %81
195          %88 = OpAccessChain %87 %85 %77
196          %89 = OpLoad %6 %88
197                OpStore %86 %89
198                OpStore %90 %82
199          %92 = OpFunctionCall %6 %11 %86 %90
200          %93 = OpAccessChain %7 %66 %77
201                OpStore %93 %92
202          %96 = OpAccessChain %87 %85 %95
203          %97 = OpLoad %6 %96
204                OpStore %94 %97
205                OpStore %98 %82
206         %100 = OpFunctionCall %6 %11 %94 %98
207         %101 = OpAccessChain %7 %66 %95
208                OpStore %101 %100
209         %103 = OpLoad %6 %93
210         %105 = OpLoad %6 %101
211         %106 = OpFAdd %6 %103 %105
212         %108 = OpAccessChain %7 %66 %107
213                OpStore %108 %106
214                OpBranch %110
215         %110 = OpLabel
216         %145 = OpPhi %15 %31 %5 %135 %113
217         %117 = OpSLessThan %26 %145 %116
218                OpLoopMerge %112 %113 None
219                OpBranchConditional %117 %111 %112
220         %111 = OpLabel
221         %119 = OpAccessChain %7 %66 %145
222         %120 = OpLoad %6 %119
223         %122 = OpFOrdGreaterThanEqual %26 %120 %121
224                OpSelectionMerge %124 None
225                OpBranchConditional %122 %123 %124
226         %123 = OpLabel
227         %128 = OpLoad %6 %119
228         %131 = OpLoad %6 %119
229         %132 = OpFMul %6 %128 %131
230                OpStore %119 %132
231                OpBranch %124
232         %124 = OpLabel
233                OpBranch %113
234         %113 = OpLabel
235         %135 = OpIAdd %15 %145 %18
236                OpBranch %110
237         %112 = OpLabel
238         %138 = OpLoad %64 %66
239         %139 = OpExtInst %64 %1 FAbs %138
240         %140 = OpExtInst %64 %1 Normalize %139
241         %141 = OpCompositeExtract %6 %140 0
242         %142 = OpCompositeExtract %6 %140 1
243         %143 = OpCompositeExtract %6 %140 2
244         %144 = OpCompositeConstruct %83 %141 %142 %143 %121
245                OpStore %137 %144
246                OpReturn
247                OpFunctionEnd
248          %11 = OpFunction %6 None %8
249           %9 = OpFunctionParameter %7
250          %10 = OpFunctionParameter %7
251          %12 = OpLabel
252                OpBranch %19
253          %19 = OpLabel
254         %148 = OpPhi %6 %14 %12 %151 %22
255         %147 = OpPhi %15 %18 %12 %60 %22
256          %27 = OpSLessThan %26 %147 %25
257                OpLoopMerge %21 %22 None
258                OpBranchConditional %27 %20 %21
259          %20 = OpLabel
260          %30 = OpSMod %15 %147 %29
261          %32 = OpIEqual %26 %30 %31
262                OpSelectionMerge %34 None
263                OpBranchConditional %32 %33 %38
264          %33 = OpLabel
265          %37 = OpFAdd %6 %148 %35
266                OpBranch %34
267          %38 = OpLabel
268          %40 = OpConvertSToF %6 %147
269          %41 = OpLoad %6 %10
270          %42 = OpExtInst %6 %1 Round %41
271          %43 = OpFMod %6 %40 %42
272          %45 = OpFOrdLessThanEqual %26 %43 %44
273                OpSelectionMerge %47 None
274                OpBranchConditional %45 %46 %47
275          %46 = OpLabel
276          %50 = OpFAdd %6 %148 %48
277                OpBranch %47
278          %47 = OpLabel
279         %152 = OpPhi %6 %148 %38 %50 %46
280                OpBranch %34
281          %34 = OpLabel
282         %151 = OpPhi %6 %37 %33 %152 %47
283          %52 = OpConvertSToF %6 %147
284          %53 = OpLoad %6 %9
285          %54 = OpFOrdGreaterThanEqual %26 %52 %53
286                OpSelectionMerge %56 None
287                OpBranchConditional %54 %55 %56
288          %55 = OpLabel
289                OpReturnValue %151
290          %56 = OpLabel
291                OpBranch %22
292          %22 = OpLabel
293          %60 = OpIAdd %15 %147 %18
294                OpBranch %19
295          %21 = OpLabel
296                OpReturnValue %148
297                OpFunctionEnd
298 END
299
300 # uniforms for reference
301
302 # resolution
303 BUFFER reference_resolution DATA_TYPE vec2<float> DATA
304  256.0 256.0
305 END
306
307 BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
308
309 PIPELINE graphics reference_pipeline
310   ATTACH reference_vertex_shader
311   ATTACH reference_fragment_shader
312   FRAMEBUFFER_SIZE 256 256
313   BIND BUFFER reference_framebuffer AS color LOCATION 0
314   BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
315 END
316 CLEAR_COLOR reference_pipeline 0 0 0 255
317
318 CLEAR reference_pipeline
319 RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
320
321
322 SHADER vertex variant_vertex_shader PASSTHROUGH
323
324 # variant_fragment_shader is derived from the following GLSL:
325 # #version 320 es
326 # precision highp float;
327 #
328 # precision highp int;
329 #
330 # layout(location = 0) out vec4 _GLF_color;
331 #
332 # layout(set = 0, binding = 0) uniform buf0
333 # {
334 #   vec2 resolution;
335 # };
336 # layout(set = 0, binding = 1) uniform buf1
337 # {
338 #   vec2 injectionSwitch; //x == 0.0, y == 1.0
339 # };
340 #
341 # float compute_value(float limit, float thirty_two)
342 # {
343 #   float result = -0.5;
344 #   for (int i = 1; i < 800; i++)
345 #   {
346 #     if ((i % 32) == 0)
347 #     {
348 #       result += 0.4;
349 #     }
350 #     else
351 #     {
352 #       if (mod(float(i), round(thirty_two)) <= 0.01)
353 #       {
354 #         result += 100.0;
355 #       }
356 #     }
357 #     if (float(i) >= limit)
358 #     {
359 #       return result;
360 #     }
361 #   }
362 #   return result;
363 # }
364 # void main()
365 # {
366 #   vec3 c = vec3(7.0, 8.0, 9.0);
367 #   float thirty_two = round(resolution.x / 8.0);
368 #   c.x = compute_value(gl_FragCoord.x, thirty_two);
369 #   c.y = compute_value(gl_FragCoord.y, thirty_two);
370 #   //  Always true, x / 1 = x, end result should be same as the reference result.
371 #   c.z = c.x + (true ? ((c) / 1.0) : (vec3(1.0))).y;
372 #   for (int i = 0; i < 3; i++)
373 #   {
374 #     if (c[i] >= 1.0)
375 #     {
376 #       // Always false.
377 #       if ((injectionSwitch.x > injectionSwitch.y))
378 #       {
379 #         discard;
380 #       }
381 #       c[i] = c[i] * c[i];
382 #     }
383 #   }
384 #   _GLF_color = vec4(normalize(abs(c)), 1.0);
385 # }
386 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
387 ; SPIR-V
388 ; Version: 1.0
389 ; Generator: Khronos Glslang Reference Front End; 10
390 ; Bound: 174
391 ; Schema: 0
392                OpCapability Shader
393           %1 = OpExtInstImport "GLSL.std.450"
394                OpMemoryModel Logical GLSL450
395                OpEntryPoint Fragment %4 "main" %85 %157
396                OpExecutionMode %4 OriginUpperLeft
397                OpSource ESSL 320
398                OpName %4 "main"
399                OpName %11 "compute_value(f1;f1;"
400                OpName %9 "limit"
401                OpName %10 "thirty_two"
402                OpName %66 "c"
403                OpName %73 "buf0"
404                OpMemberName %73 0 "resolution"
405                OpName %75 ""
406                OpName %85 "gl_FragCoord"
407                OpName %86 "param"
408                OpName %90 "param"
409                OpName %94 "param"
410                OpName %98 "param"
411                OpName %134 "buf1"
412                OpMemberName %134 0 "injectionSwitch"
413                OpName %136 ""
414                OpName %157 "_GLF_color"
415                OpMemberDecorate %73 0 Offset 0
416                OpDecorate %73 Block
417                OpDecorate %75 DescriptorSet 0
418                OpDecorate %75 Binding 0
419                OpDecorate %85 BuiltIn FragCoord
420                OpMemberDecorate %134 0 Offset 0
421                OpDecorate %134 Block
422                OpDecorate %136 DescriptorSet 0
423                OpDecorate %136 Binding 1
424                OpDecorate %157 Location 0
425           %2 = OpTypeVoid
426           %3 = OpTypeFunction %2
427           %6 = OpTypeFloat 32
428           %7 = OpTypePointer Function %6
429           %8 = OpTypeFunction %6 %7 %7
430          %14 = OpConstant %6 -0.5
431          %15 = OpTypeInt 32 1
432          %18 = OpConstant %15 1
433          %25 = OpConstant %15 800
434          %26 = OpTypeBool
435          %29 = OpConstant %15 32
436          %31 = OpConstant %15 0
437          %35 = OpConstant %6 0.400000006
438          %44 = OpConstant %6 0.00999999978
439          %48 = OpConstant %6 100
440          %64 = OpTypeVector %6 3
441          %65 = OpTypePointer Function %64
442          %67 = OpConstant %6 7
443          %68 = OpConstant %6 8
444          %69 = OpConstant %6 9
445          %70 = OpConstantComposite %64 %67 %68 %69
446          %72 = OpTypeVector %6 2
447          %73 = OpTypeStruct %72
448          %74 = OpTypePointer Uniform %73
449          %75 = OpVariable %74 Uniform
450          %76 = OpTypeInt 32 0
451          %77 = OpConstant %76 0
452          %78 = OpTypePointer Uniform %6
453          %83 = OpTypeVector %6 4
454          %84 = OpTypePointer Input %83
455          %85 = OpVariable %84 Input
456          %87 = OpTypePointer Input %6
457          %95 = OpConstant %76 1
458         %109 = OpConstant %6 1
459         %117 = OpConstant %76 2
460         %126 = OpConstant %15 3
461         %134 = OpTypeStruct %72
462         %135 = OpTypePointer Uniform %134
463         %136 = OpVariable %135 Uniform
464         %156 = OpTypePointer Output %83
465         %157 = OpVariable %156 Output
466         %173 = OpConstant %6 0.125
467           %4 = OpFunction %2 None %3
468           %5 = OpLabel
469          %66 = OpVariable %65 Function
470          %86 = OpVariable %7 Function
471          %90 = OpVariable %7 Function
472          %94 = OpVariable %7 Function
473          %98 = OpVariable %7 Function
474         %105 = OpVariable %65 Function
475                OpStore %66 %70
476          %79 = OpAccessChain %78 %75 %31 %77
477          %80 = OpLoad %6 %79
478          %81 = OpFMul %6 %80 %173
479          %82 = OpExtInst %6 %1 Round %81
480          %88 = OpAccessChain %87 %85 %77
481          %89 = OpLoad %6 %88
482                OpStore %86 %89
483                OpStore %90 %82
484          %92 = OpFunctionCall %6 %11 %86 %90
485          %93 = OpAccessChain %7 %66 %77
486                OpStore %93 %92
487          %96 = OpAccessChain %87 %85 %95
488          %97 = OpLoad %6 %96
489                OpStore %94 %97
490                OpStore %98 %82
491         %100 = OpFunctionCall %6 %11 %94 %98
492         %101 = OpAccessChain %7 %66 %95
493                OpStore %101 %100
494         %103 = OpLoad %6 %93
495         %108 = OpLoad %64 %66
496                OpStore %105 %108
497         %114 = OpAccessChain %7 %105 %95
498         %115 = OpLoad %6 %114
499         %116 = OpFAdd %6 %103 %115
500         %118 = OpAccessChain %7 %66 %117
501                OpStore %118 %116
502                OpBranch %120
503         %120 = OpLabel
504         %165 = OpPhi %15 %31 %5 %155 %123
505         %127 = OpSLessThan %26 %165 %126
506                OpLoopMerge %122 %123 None
507                OpBranchConditional %127 %121 %122
508         %121 = OpLabel
509         %129 = OpAccessChain %7 %66 %165
510         %130 = OpLoad %6 %129
511         %131 = OpFOrdGreaterThanEqual %26 %130 %109
512                OpSelectionMerge %133 None
513                OpBranchConditional %131 %132 %133
514         %132 = OpLabel
515         %137 = OpAccessChain %78 %136 %31 %77
516         %138 = OpLoad %6 %137
517         %139 = OpAccessChain %78 %136 %31 %95
518         %140 = OpLoad %6 %139
519         %141 = OpFOrdGreaterThan %26 %138 %140
520                OpSelectionMerge %143 None
521                OpBranchConditional %141 %142 %143
522         %142 = OpLabel
523                OpKill
524         %143 = OpLabel
525         %148 = OpLoad %6 %129
526         %151 = OpLoad %6 %129
527         %152 = OpFMul %6 %148 %151
528                OpStore %129 %152
529                OpBranch %133
530         %133 = OpLabel
531                OpBranch %123
532         %123 = OpLabel
533         %155 = OpIAdd %15 %165 %18
534                OpBranch %120
535         %122 = OpLabel
536         %158 = OpLoad %64 %66
537         %159 = OpExtInst %64 %1 FAbs %158
538         %160 = OpExtInst %64 %1 Normalize %159
539         %161 = OpCompositeExtract %6 %160 0
540         %162 = OpCompositeExtract %6 %160 1
541         %163 = OpCompositeExtract %6 %160 2
542         %164 = OpCompositeConstruct %83 %161 %162 %163 %109
543                OpStore %157 %164
544                OpReturn
545                OpFunctionEnd
546          %11 = OpFunction %6 None %8
547           %9 = OpFunctionParameter %7
548          %10 = OpFunctionParameter %7
549          %12 = OpLabel
550                OpBranch %19
551          %19 = OpLabel
552         %168 = OpPhi %6 %14 %12 %171 %22
553         %167 = OpPhi %15 %18 %12 %60 %22
554          %27 = OpSLessThan %26 %167 %25
555                OpLoopMerge %21 %22 None
556                OpBranchConditional %27 %20 %21
557          %20 = OpLabel
558          %30 = OpSMod %15 %167 %29
559          %32 = OpIEqual %26 %30 %31
560                OpSelectionMerge %34 None
561                OpBranchConditional %32 %33 %38
562          %38 = OpLabel
563          %40 = OpConvertSToF %6 %167
564          %41 = OpLoad %6 %10
565          %42 = OpExtInst %6 %1 Round %41
566          %43 = OpFMod %6 %40 %42
567          %45 = OpFOrdLessThanEqual %26 %43 %44
568                OpSelectionMerge %47 None
569                OpBranchConditional %45 %46 %47
570          %46 = OpLabel
571          %50 = OpFAdd %6 %168 %48
572                OpBranch %47
573          %47 = OpLabel
574         %172 = OpPhi %6 %168 %38 %50 %46
575                OpBranch %34
576          %33 = OpLabel
577          %37 = OpFAdd %6 %168 %35
578                OpBranch %34
579          %34 = OpLabel
580         %171 = OpPhi %6 %37 %33 %172 %47
581          %52 = OpConvertSToF %6 %167
582          %53 = OpLoad %6 %9
583          %54 = OpFOrdGreaterThanEqual %26 %52 %53
584                OpSelectionMerge %56 None
585                OpBranchConditional %54 %55 %56
586          %55 = OpLabel
587                OpReturnValue %171
588          %56 = OpLabel
589                OpBranch %22
590          %22 = OpLabel
591          %60 = OpIAdd %15 %167 %18
592                OpBranch %19
593          %21 = OpLabel
594                OpReturnValue %168
595                OpFunctionEnd
596 END
597
598 # uniforms for variant
599
600 # resolution
601 BUFFER variant_resolution DATA_TYPE vec2<float> DATA
602  256.0 256.0
603 END
604 # injectionSwitch
605 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
606  0.0 1.0
607 END
608
609 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
610
611 PIPELINE graphics variant_pipeline
612   ATTACH variant_vertex_shader
613   ATTACH variant_fragment_shader
614   FRAMEBUFFER_SIZE 256 256
615   BIND BUFFER variant_framebuffer AS color LOCATION 0
616   BIND BUFFER variant_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
617   BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
618 END
619 CLEAR_COLOR variant_pipeline 0 0 0 255
620
621 CLEAR variant_pipeline
622 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
623
624 EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005