Merge vk-gl-cts/vulkan-cts-1.2.6 into vk-gl-cts/vulkan-cts-1.2.7
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / cov-min-nested-loop-same-value-for-variables.amber
1 #!amber
2
3 # Copyright 2021 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 coverage-gap found by the GraphicsFuzz project.
19
20 # Short description: A fragment shader that covers specific NIR code paths
21
22 # The test passes because the shader always writes red.
23
24 SHADER vertex texgen_vert PASSTHROUGH
25
26 SHADER fragment texgen_frag GLSL
27 #version 430
28 precision highp float;
29
30 layout(location = 0) out vec4 _GLF_color;
31
32 void main()
33 {
34  _GLF_color = vec4(
35  floor(gl_FragCoord.x) * (1.0 / 255.0),
36  (int(gl_FragCoord.x) ^ int(gl_FragCoord.y)) * (1.0 / 255.0),
37  floor(gl_FragCoord.y) * (1.0 / 255.0),
38  1.0);
39 }
40 END
41 BUFFER default_texture FORMAT B8G8R8A8_UNORM
42
43 PIPELINE graphics texgen_pipeline
44   ATTACH texgen_vert
45   ATTACH texgen_frag
46   FRAMEBUFFER_SIZE 256 256
47   BIND BUFFER default_texture AS color LOCATION 0
48 END
49
50 CLEAR_COLOR texgen_pipeline 0 0 0 255
51 CLEAR texgen_pipeline
52 RUN texgen_pipeline DRAW_RECT POS 0 0  SIZE 256 256
53
54 SHADER vertex variant_vertex_shader PASSTHROUGH
55
56 # variant_fragment_shader is derived from the following GLSL:
57 # #version 320 es
58 #
59 # #define _int_1 _GLF_uniform_int_values[0]
60 # #define _int_0 _GLF_uniform_int_values[1]
61 # #define _float_1_0 _GLF_uniform_float_values[0]
62 #
63 # precision highp float;
64 # precision highp int;
65 #
66 # // Contents of _GLF_uniform_float_values: 1.0
67 # layout(set = 0, binding = 0) uniform buf0
68 # {
69 #     float _GLF_uniform_float_values[1];
70 # };
71 # // Contents of _GLF_uniform_int_values: [1, 0]
72 # layout(set = 0, binding = 1) uniform buf1
73 # {
74 #     int _GLF_uniform_int_values[2];
75 # };
76 #
77 # layout(location = 0) out vec4 _GLF_color;
78 # layout(set = 0, binding = 2) uniform sampler2D tex;
79 #
80 # void main()
81 # {
82 #     const float arr[9] = float[9](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
83 #     vec2 coord = gl_FragCoord.xy;
84 #     vec4 res = vec4(_int_1, _int_0, _int_0, _int_1);
85 #
86 #     for (int i = 0; i < 3; i++)
87 #     {
88 #         for (int j = 0; j < 3; j++)
89 #         {
90 #             int a = clamp(i + j, 0, 9);
91 #             // f0 and f1 are guaranteed to get the value 0.0.
92 #             float f0 = clamp(arr[a], arr[a], arr[a]);
93 #             float f1 = clamp(arr[a], arr[a], arr[a]);
94 #             // v0 = (0, 0, 0, 0) due to f0 being zero.
95 #             vec4 v0 = vec4(f0);
96 #             // v1, v2, v3, v4 all become (0, 0, 0, 0) due to multiplication by zero.
97 #             vec4 v1 = texture(tex, vec2(i)) * f1;
98 #             vec4 v2 = texture(tex, coord) * arr[a];
99 #             vec4 v3 = texture(tex, coord) * arr[a];
100 #             vec4 v4 = texture(tex, coord + vec2(i - _int_1, j - _int_1)) * arr[a];
101 #
102 #             // v5 becomes (0, 0, 0, 0) since the min function picks v2.
103 #             vec4 v5 = min(vec4(1.0), v2);
104 #             // v6 also becomes (0, 0, 0, 0) because both v3 and v5 are zero vectors.
105 #             vec4 v6 = min(v3, v5);
106 #
107 #             // The min chain simplifies to min(vec4(1.0), vec4(0.0)) which results
108 #             // in zero vector. Thus the += operation has no effect.
109 #             res += min(min(min(v0, v1), v6) + vec4(_float_1_0), v4);
110 #         }
111 #     }
112 #
113 #     // res is originally red, and it has only zero vector added to it, so the
114 #     // output color will be red too.
115 #     _GLF_color = res;
116 # }
117 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
118 ; SPIR-V
119 ; Version: 1.0
120 ; Generator: Khronos Glslang Reference Front End; 10
121 ; Bound: 188
122 ; Schema: 0
123                OpCapability Shader
124           %1 = OpExtInstImport "GLSL.std.450"
125                OpMemoryModel Logical GLSL450
126                OpEntryPoint Fragment %4 "main" %12 %186
127                OpExecutionMode %4 OriginUpperLeft
128                OpSource ESSL 320
129                OpName %4 "main"
130                OpName %9 "coord"
131                OpName %12 "gl_FragCoord"
132                OpName %16 "res"
133                OpName %21 "buf1"
134                OpMemberName %21 0 "_GLF_uniform_int_values"
135                OpName %23 ""
136                OpName %41 "i"
137                OpName %51 "j"
138                OpName %59 "a"
139                OpName %66 "f0"
140                OpName %73 "indexable"
141                OpName %77 "indexable"
142                OpName %81 "indexable"
143                OpName %85 "f1"
144                OpName %87 "indexable"
145                OpName %91 "indexable"
146                OpName %95 "indexable"
147                OpName %99 "v0"
148                OpName %102 "v1"
149                OpName %106 "tex"
150                OpName %114 "v2"
151                OpName %119 "indexable"
152                OpName %123 "v3"
153                OpName %128 "indexable"
154                OpName %132 "v4"
155                OpName %149 "indexable"
156                OpName %153 "v5"
157                OpName %158 "v6"
158                OpName %169 "buf0"
159                OpMemberName %169 0 "_GLF_uniform_float_values"
160                OpName %171 ""
161                OpName %186 "_GLF_color"
162                OpDecorate %12 BuiltIn FragCoord
163                OpDecorate %20 ArrayStride 16
164                OpMemberDecorate %21 0 Offset 0
165                OpDecorate %21 Block
166                OpDecorate %23 DescriptorSet 0
167                OpDecorate %23 Binding 1
168                OpDecorate %106 RelaxedPrecision
169                OpDecorate %106 DescriptorSet 0
170                OpDecorate %106 Binding 2
171                OpDecorate %107 RelaxedPrecision
172                OpDecorate %109 RelaxedPrecision
173                OpDecorate %110 RelaxedPrecision
174                OpDecorate %111 RelaxedPrecision
175                OpDecorate %115 RelaxedPrecision
176                OpDecorate %117 RelaxedPrecision
177                OpDecorate %124 RelaxedPrecision
178                OpDecorate %126 RelaxedPrecision
179                OpDecorate %133 RelaxedPrecision
180                OpDecorate %147 RelaxedPrecision
181                OpDecorate %168 ArrayStride 16
182                OpMemberDecorate %169 0 Offset 0
183                OpDecorate %169 Block
184                OpDecorate %171 DescriptorSet 0
185                OpDecorate %171 Binding 0
186                OpDecorate %186 Location 0
187           %2 = OpTypeVoid
188           %3 = OpTypeFunction %2
189           %6 = OpTypeFloat 32
190           %7 = OpTypeVector %6 2
191           %8 = OpTypePointer Function %7
192          %10 = OpTypeVector %6 4
193          %11 = OpTypePointer Input %10
194          %12 = OpVariable %11 Input
195          %15 = OpTypePointer Function %10
196          %17 = OpTypeInt 32 1
197          %18 = OpTypeInt 32 0
198          %19 = OpConstant %18 2
199          %20 = OpTypeArray %17 %19
200          %21 = OpTypeStruct %20
201          %22 = OpTypePointer Uniform %21
202          %23 = OpVariable %22 Uniform
203          %24 = OpConstant %17 0
204          %25 = OpTypePointer Uniform %17
205          %29 = OpConstant %17 1
206          %40 = OpTypePointer Function %17
207          %48 = OpConstant %17 3
208          %49 = OpTypeBool
209          %63 = OpConstant %17 9
210          %65 = OpTypePointer Function %6
211          %67 = OpConstant %18 9
212          %68 = OpTypeArray %6 %67
213          %69 = OpConstant %6 0
214          %70 = OpConstantComposite %68 %69 %69 %69 %69 %69 %69 %69 %69 %69
215          %72 = OpTypePointer Function %68
216         %103 = OpTypeImage %6 2D 0 0 0 1 Unknown
217         %104 = OpTypeSampledImage %103
218         %105 = OpTypePointer UniformConstant %104
219         %106 = OpVariable %105 UniformConstant
220         %154 = OpConstant %6 1
221         %155 = OpConstantComposite %10 %154 %154 %154 %154
222         %167 = OpConstant %18 1
223         %168 = OpTypeArray %6 %167
224         %169 = OpTypeStruct %168
225         %170 = OpTypePointer Uniform %169
226         %171 = OpVariable %170 Uniform
227         %172 = OpTypePointer Uniform %6
228         %185 = OpTypePointer Output %10
229         %186 = OpVariable %185 Output
230           %4 = OpFunction %2 None %3
231           %5 = OpLabel
232           %9 = OpVariable %8 Function
233          %16 = OpVariable %15 Function
234          %41 = OpVariable %40 Function
235          %51 = OpVariable %40 Function
236          %59 = OpVariable %40 Function
237          %66 = OpVariable %65 Function
238          %73 = OpVariable %72 Function
239          %77 = OpVariable %72 Function
240          %81 = OpVariable %72 Function
241          %85 = OpVariable %65 Function
242          %87 = OpVariable %72 Function
243          %91 = OpVariable %72 Function
244          %95 = OpVariable %72 Function
245          %99 = OpVariable %15 Function
246         %102 = OpVariable %15 Function
247         %114 = OpVariable %15 Function
248         %119 = OpVariable %72 Function
249         %123 = OpVariable %15 Function
250         %128 = OpVariable %72 Function
251         %132 = OpVariable %15 Function
252         %149 = OpVariable %72 Function
253         %153 = OpVariable %15 Function
254         %158 = OpVariable %15 Function
255          %13 = OpLoad %10 %12
256          %14 = OpVectorShuffle %7 %13 %13 0 1
257                OpStore %9 %14
258          %26 = OpAccessChain %25 %23 %24 %24
259          %27 = OpLoad %17 %26
260          %28 = OpConvertSToF %6 %27
261          %30 = OpAccessChain %25 %23 %24 %29
262          %31 = OpLoad %17 %30
263          %32 = OpConvertSToF %6 %31
264          %33 = OpAccessChain %25 %23 %24 %29
265          %34 = OpLoad %17 %33
266          %35 = OpConvertSToF %6 %34
267          %36 = OpAccessChain %25 %23 %24 %24
268          %37 = OpLoad %17 %36
269          %38 = OpConvertSToF %6 %37
270          %39 = OpCompositeConstruct %10 %28 %32 %35 %38
271                OpStore %16 %39
272                OpStore %41 %24
273                OpBranch %42
274          %42 = OpLabel
275                OpLoopMerge %44 %45 None
276                OpBranch %46
277          %46 = OpLabel
278          %47 = OpLoad %17 %41
279          %50 = OpSLessThan %49 %47 %48
280                OpBranchConditional %50 %43 %44
281          %43 = OpLabel
282                OpStore %51 %24
283                OpBranch %52
284          %52 = OpLabel
285                OpLoopMerge %54 %55 None
286                OpBranch %56
287          %56 = OpLabel
288          %57 = OpLoad %17 %51
289          %58 = OpSLessThan %49 %57 %48
290                OpBranchConditional %58 %53 %54
291          %53 = OpLabel
292          %60 = OpLoad %17 %41
293          %61 = OpLoad %17 %51
294          %62 = OpIAdd %17 %60 %61
295          %64 = OpExtInst %17 %1 SClamp %62 %24 %63
296                OpStore %59 %64
297          %71 = OpLoad %17 %59
298                OpStore %73 %70
299          %74 = OpAccessChain %65 %73 %71
300          %75 = OpLoad %6 %74
301          %76 = OpLoad %17 %59
302                OpStore %77 %70
303          %78 = OpAccessChain %65 %77 %76
304          %79 = OpLoad %6 %78
305          %80 = OpLoad %17 %59
306                OpStore %81 %70
307          %82 = OpAccessChain %65 %81 %80
308          %83 = OpLoad %6 %82
309          %84 = OpExtInst %6 %1 FClamp %75 %79 %83
310                OpStore %66 %84
311          %86 = OpLoad %17 %59
312                OpStore %87 %70
313          %88 = OpAccessChain %65 %87 %86
314          %89 = OpLoad %6 %88
315          %90 = OpLoad %17 %59
316                OpStore %91 %70
317          %92 = OpAccessChain %65 %91 %90
318          %93 = OpLoad %6 %92
319          %94 = OpLoad %17 %59
320                OpStore %95 %70
321          %96 = OpAccessChain %65 %95 %94
322          %97 = OpLoad %6 %96
323          %98 = OpExtInst %6 %1 FClamp %89 %93 %97
324                OpStore %85 %98
325         %100 = OpLoad %6 %66
326         %101 = OpCompositeConstruct %10 %100 %100 %100 %100
327                OpStore %99 %101
328         %107 = OpLoad %104 %106
329         %108 = OpLoad %17 %41
330         %109 = OpConvertSToF %6 %108
331         %110 = OpCompositeConstruct %7 %109 %109
332         %111 = OpImageSampleImplicitLod %10 %107 %110
333         %112 = OpLoad %6 %85
334         %113 = OpVectorTimesScalar %10 %111 %112
335                OpStore %102 %113
336         %115 = OpLoad %104 %106
337         %116 = OpLoad %7 %9
338         %117 = OpImageSampleImplicitLod %10 %115 %116
339         %118 = OpLoad %17 %59
340                OpStore %119 %70
341         %120 = OpAccessChain %65 %119 %118
342         %121 = OpLoad %6 %120
343         %122 = OpVectorTimesScalar %10 %117 %121
344                OpStore %114 %122
345         %124 = OpLoad %104 %106
346         %125 = OpLoad %7 %9
347         %126 = OpImageSampleImplicitLod %10 %124 %125
348         %127 = OpLoad %17 %59
349                OpStore %128 %70
350         %129 = OpAccessChain %65 %128 %127
351         %130 = OpLoad %6 %129
352         %131 = OpVectorTimesScalar %10 %126 %130
353                OpStore %123 %131
354         %133 = OpLoad %104 %106
355         %134 = OpLoad %7 %9
356         %135 = OpLoad %17 %41
357         %136 = OpAccessChain %25 %23 %24 %24
358         %137 = OpLoad %17 %136
359         %138 = OpISub %17 %135 %137
360         %139 = OpConvertSToF %6 %138
361         %140 = OpLoad %17 %51
362         %141 = OpAccessChain %25 %23 %24 %24
363         %142 = OpLoad %17 %141
364         %143 = OpISub %17 %140 %142
365         %144 = OpConvertSToF %6 %143
366         %145 = OpCompositeConstruct %7 %139 %144
367         %146 = OpFAdd %7 %134 %145
368         %147 = OpImageSampleImplicitLod %10 %133 %146
369         %148 = OpLoad %17 %59
370                OpStore %149 %70
371         %150 = OpAccessChain %65 %149 %148
372         %151 = OpLoad %6 %150
373         %152 = OpVectorTimesScalar %10 %147 %151
374                OpStore %132 %152
375         %156 = OpLoad %10 %114
376         %157 = OpExtInst %10 %1 FMin %155 %156
377                OpStore %153 %157
378         %159 = OpLoad %10 %123
379         %160 = OpLoad %10 %153
380         %161 = OpExtInst %10 %1 FMin %159 %160
381                OpStore %158 %161
382         %162 = OpLoad %10 %99
383         %163 = OpLoad %10 %102
384         %164 = OpExtInst %10 %1 FMin %162 %163
385         %165 = OpLoad %10 %158
386         %166 = OpExtInst %10 %1 FMin %164 %165
387         %173 = OpAccessChain %172 %171 %24 %24
388         %174 = OpLoad %6 %173
389         %175 = OpCompositeConstruct %10 %174 %174 %174 %174
390         %176 = OpFAdd %10 %166 %175
391         %177 = OpLoad %10 %132
392         %178 = OpExtInst %10 %1 FMin %176 %177
393         %179 = OpLoad %10 %16
394         %180 = OpFAdd %10 %179 %178
395                OpStore %16 %180
396                OpBranch %55
397          %55 = OpLabel
398         %181 = OpLoad %17 %51
399         %182 = OpIAdd %17 %181 %29
400                OpStore %51 %182
401                OpBranch %52
402          %54 = OpLabel
403                OpBranch %45
404          %45 = OpLabel
405         %183 = OpLoad %17 %41
406         %184 = OpIAdd %17 %183 %29
407                OpStore %41 %184
408                OpBranch %42
409          %44 = OpLabel
410         %187 = OpLoad %10 %16
411                OpStore %186 %187
412                OpReturn
413                OpFunctionEnd
414 END
415
416 # uniforms for variant
417
418 # tex
419 SAMPLER variant_tex
420
421 # _GLF_uniform_int_values
422 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
423  1 0
424 END
425 # _GLF_uniform_float_values
426 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
427  1.0
428 END
429
430 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
431
432 PIPELINE graphics variant_pipeline
433   ATTACH variant_vertex_shader
434   ATTACH variant_fragment_shader
435   FRAMEBUFFER_SIZE 256 256
436   BIND BUFFER variant_framebuffer AS color LOCATION 0
437   BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_tex DESCRIPTOR_SET 0 BINDING 2
438   BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
439   BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
440 END
441 CLEAR_COLOR variant_pipeline 0 0 0 255
442
443 CLEAR variant_pipeline
444 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
445
446 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255