• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LLVM code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28#
29# #define _int_5 _GLF_uniform_int_values[0]
30# #define _int_3 _GLF_uniform_int_values[1]
31# #define _int_4 _GLF_uniform_int_values[2]
32# #define _int_6 _GLF_uniform_int_values[3]
33# #define _int_7 _GLF_uniform_int_values[4]
34# #define _int_8 _GLF_uniform_int_values[5]
35# #define _int_1 _GLF_uniform_int_values[6]
36# #define _int_0 _GLF_uniform_int_values[7]
37# #define _int_2 _GLF_uniform_int_values[8]
38# #define _int_9 _GLF_uniform_int_values[9]
39# #define _int_1065353216 _GLF_uniform_int_values[10]
40#
41# precision highp int;
42# precision highp float;
43#
44# // Contents of _GLF_uniform_int_values: [5, 3, 4, 6, 7, 8, 1, 0, 2, 9, 1065353216]
45# layout(set = 0, binding = 0) uniform buf0
46# {
47#     int _GLF_uniform_int_values[11];
48# };
49#
50# layout(location = 0) out vec4 _GLF_color;
51#
52# void main()
53# {
54#     // a becomes 1065353216.
55#     int a = floatBitsToInt(1.0);
56#     int arr[9] = int[9](_int_1, _int_2, _int_3, _int_4, _int_5, _int_6, _int_7, _int_8, _int_9);
57#
58#     // During the loop only arr[8] changes to zero.
59#     for(int i = 0; i < 5; i ++)
60#     {
61#         for(int j = 0; j < 5; j ++)
62#         {
63#             // a is a large number making the clamp always return 8.
64#             int idx = clamp(a, 0, 8);
65#             // Sets the last array element to zero.
66#             arr[idx] = _int_0;
67#
68#             for(int k = _int_0; k < i; k ++)
69#             {
70#                 for(int l = 0; l < j; l ++)
71#                 {
72#                     // These cases get all hit at some point, but
73#                     // they only affect the last element as idx is
74#                     // always eight. Even that value gets overwritten
75#                     // by zero (see the code above)  and the last
76#                     // iterations don't hit any of these cases making
77#                     // the final value zero.
78#                     switch(a - _int_1065353216)
79#                     {
80#                         case 6:
81#                             arr[idx] += _int_1;
82#                             break;
83#                         case 7:
84#                             arr[idx] += _int_2;
85#                             break;
86#                         case 8:
87#                             arr[idx] += _int_3;
88#                             break;
89#                         case 9:
90#                             arr[idx] += _int_4;
91#                             break;
92#                         case 10:
93#                             arr[idx] += _int_5;
94#                             break;
95#                     }
96#                 }
97#             }
98#             a++;
99#         }
100#     }
101#
102#     int ref[9] = int[9](_int_1, _int_2, _int_3, _int_4, _int_5, _int_6, _int_7, _int_8, _int_0);
103#
104#     _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
105#
106#     // Verify results.
107#     for(int i = _int_0; i < _int_9; i ++)
108#     {
109#         if(arr[i] != ref[i])
110#         {
111#             // Indicate a failure.
112#             _GLF_color = vec4(_int_0);
113#         }
114#     }
115# }
116SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
117; SPIR-V
118; Version: 1.0
119; Generator: Khronos Glslang Reference Front End; 10
120; Bound: 221
121; Schema: 0
122               OpCapability Shader
123          %1 = OpExtInstImport "GLSL.std.450"
124               OpMemoryModel Logical GLSL450
125               OpEntryPoint Fragment %4 "main" %180
126               OpExecutionMode %4 OriginUpperLeft
127               OpSource ESSL 320
128               OpName %4 "main"
129               OpName %8 "a"
130               OpName %16 "arr"
131               OpName %19 "buf0"
132               OpMemberName %19 0 "_GLF_uniform_int_values"
133               OpName %21 ""
134               OpName %51 "i"
135               OpName %60 "j"
136               OpName %68 "idx"
137               OpName %76 "k"
138               OpName %87 "l"
139               OpName %158 "ref"
140               OpName %180 "_GLF_color"
141               OpName %194 "i"
142               OpDecorate %18 ArrayStride 16
143               OpMemberDecorate %19 0 Offset 0
144               OpDecorate %19 Block
145               OpDecorate %21 DescriptorSet 0
146               OpDecorate %21 Binding 0
147               OpDecorate %180 Location 0
148          %2 = OpTypeVoid
149          %3 = OpTypeFunction %2
150          %6 = OpTypeInt 32 1
151          %7 = OpTypePointer Function %6
152          %9 = OpTypeFloat 32
153         %10 = OpConstant %9 1
154         %12 = OpTypeInt 32 0
155         %13 = OpConstant %12 9
156         %14 = OpTypeArray %6 %13
157         %15 = OpTypePointer Function %14
158         %17 = OpConstant %12 11
159         %18 = OpTypeArray %6 %17
160         %19 = OpTypeStruct %18
161         %20 = OpTypePointer Uniform %19
162         %21 = OpVariable %20 Uniform
163         %22 = OpConstant %6 0
164         %23 = OpConstant %6 6
165         %24 = OpTypePointer Uniform %6
166         %27 = OpConstant %6 8
167         %30 = OpConstant %6 1
168         %33 = OpConstant %6 2
169         %38 = OpConstant %6 3
170         %41 = OpConstant %6 4
171         %44 = OpConstant %6 5
172         %47 = OpConstant %6 9
173         %58 = OpTypeBool
174         %72 = OpConstant %6 7
175         %97 = OpConstant %6 10
176        %178 = OpTypeVector %9 4
177        %179 = OpTypePointer Output %178
178        %180 = OpVariable %179 Output
179          %4 = OpFunction %2 None %3
180          %5 = OpLabel
181          %8 = OpVariable %7 Function
182         %16 = OpVariable %15 Function
183         %51 = OpVariable %7 Function
184         %60 = OpVariable %7 Function
185         %68 = OpVariable %7 Function
186         %76 = OpVariable %7 Function
187         %87 = OpVariable %7 Function
188        %158 = OpVariable %15 Function
189        %194 = OpVariable %7 Function
190         %11 = OpBitcast %6 %10
191               OpStore %8 %11
192         %25 = OpAccessChain %24 %21 %22 %23
193         %26 = OpLoad %6 %25
194         %28 = OpAccessChain %24 %21 %22 %27
195         %29 = OpLoad %6 %28
196         %31 = OpAccessChain %24 %21 %22 %30
197         %32 = OpLoad %6 %31
198         %34 = OpAccessChain %24 %21 %22 %33
199         %35 = OpLoad %6 %34
200         %36 = OpAccessChain %24 %21 %22 %22
201         %37 = OpLoad %6 %36
202         %39 = OpAccessChain %24 %21 %22 %38
203         %40 = OpLoad %6 %39
204         %42 = OpAccessChain %24 %21 %22 %41
205         %43 = OpLoad %6 %42
206         %45 = OpAccessChain %24 %21 %22 %44
207         %46 = OpLoad %6 %45
208         %48 = OpAccessChain %24 %21 %22 %47
209         %49 = OpLoad %6 %48
210         %50 = OpCompositeConstruct %14 %26 %29 %32 %35 %37 %40 %43 %46 %49
211               OpStore %16 %50
212               OpStore %51 %22
213               OpBranch %52
214         %52 = OpLabel
215               OpLoopMerge %54 %55 None
216               OpBranch %56
217         %56 = OpLabel
218         %57 = OpLoad %6 %51
219         %59 = OpSLessThan %58 %57 %44
220               OpBranchConditional %59 %53 %54
221         %53 = OpLabel
222               OpStore %60 %22
223               OpBranch %61
224         %61 = OpLabel
225               OpLoopMerge %63 %64 None
226               OpBranch %65
227         %65 = OpLabel
228         %66 = OpLoad %6 %60
229         %67 = OpSLessThan %58 %66 %44
230               OpBranchConditional %67 %62 %63
231         %62 = OpLabel
232         %69 = OpLoad %6 %8
233         %70 = OpExtInst %6 %1 SClamp %69 %22 %27
234               OpStore %68 %70
235         %71 = OpLoad %6 %68
236         %73 = OpAccessChain %24 %21 %22 %72
237         %74 = OpLoad %6 %73
238         %75 = OpAccessChain %7 %16 %71
239               OpStore %75 %74
240         %77 = OpAccessChain %24 %21 %22 %72
241         %78 = OpLoad %6 %77
242               OpStore %76 %78
243               OpBranch %79
244         %79 = OpLabel
245               OpLoopMerge %81 %82 None
246               OpBranch %83
247         %83 = OpLabel
248         %84 = OpLoad %6 %76
249         %85 = OpLoad %6 %51
250         %86 = OpSLessThan %58 %84 %85
251               OpBranchConditional %86 %80 %81
252         %80 = OpLabel
253               OpStore %87 %22
254               OpBranch %88
255         %88 = OpLabel
256               OpLoopMerge %90 %91 None
257               OpBranch %92
258         %92 = OpLabel
259         %93 = OpLoad %6 %87
260         %94 = OpLoad %6 %60
261         %95 = OpSLessThan %58 %93 %94
262               OpBranchConditional %95 %89 %90
263         %89 = OpLabel
264         %96 = OpLoad %6 %8
265         %98 = OpAccessChain %24 %21 %22 %97
266         %99 = OpLoad %6 %98
267        %100 = OpISub %6 %96 %99
268               OpSelectionMerge %106 None
269               OpSwitch %100 %106 6 %101 7 %102 8 %103 9 %104 10 %105
270        %101 = OpLabel
271        %107 = OpLoad %6 %68
272        %108 = OpAccessChain %24 %21 %22 %23
273        %109 = OpLoad %6 %108
274        %110 = OpAccessChain %7 %16 %107
275        %111 = OpLoad %6 %110
276        %112 = OpIAdd %6 %111 %109
277        %113 = OpAccessChain %7 %16 %107
278               OpStore %113 %112
279               OpBranch %106
280        %102 = OpLabel
281        %115 = OpLoad %6 %68
282        %116 = OpAccessChain %24 %21 %22 %27
283        %117 = OpLoad %6 %116
284        %118 = OpAccessChain %7 %16 %115
285        %119 = OpLoad %6 %118
286        %120 = OpIAdd %6 %119 %117
287        %121 = OpAccessChain %7 %16 %115
288               OpStore %121 %120
289               OpBranch %106
290        %103 = OpLabel
291        %123 = OpLoad %6 %68
292        %124 = OpAccessChain %24 %21 %22 %30
293        %125 = OpLoad %6 %124
294        %126 = OpAccessChain %7 %16 %123
295        %127 = OpLoad %6 %126
296        %128 = OpIAdd %6 %127 %125
297        %129 = OpAccessChain %7 %16 %123
298               OpStore %129 %128
299               OpBranch %106
300        %104 = OpLabel
301        %131 = OpLoad %6 %68
302        %132 = OpAccessChain %24 %21 %22 %33
303        %133 = OpLoad %6 %132
304        %134 = OpAccessChain %7 %16 %131
305        %135 = OpLoad %6 %134
306        %136 = OpIAdd %6 %135 %133
307        %137 = OpAccessChain %7 %16 %131
308               OpStore %137 %136
309               OpBranch %106
310        %105 = OpLabel
311        %139 = OpLoad %6 %68
312        %140 = OpAccessChain %24 %21 %22 %22
313        %141 = OpLoad %6 %140
314        %142 = OpAccessChain %7 %16 %139
315        %143 = OpLoad %6 %142
316        %144 = OpIAdd %6 %143 %141
317        %145 = OpAccessChain %7 %16 %139
318               OpStore %145 %144
319               OpBranch %106
320        %106 = OpLabel
321               OpBranch %91
322         %91 = OpLabel
323        %148 = OpLoad %6 %87
324        %149 = OpIAdd %6 %148 %30
325               OpStore %87 %149
326               OpBranch %88
327         %90 = OpLabel
328               OpBranch %82
329         %82 = OpLabel
330        %150 = OpLoad %6 %76
331        %151 = OpIAdd %6 %150 %30
332               OpStore %76 %151
333               OpBranch %79
334         %81 = OpLabel
335        %152 = OpLoad %6 %8
336        %153 = OpIAdd %6 %152 %30
337               OpStore %8 %153
338               OpBranch %64
339         %64 = OpLabel
340        %154 = OpLoad %6 %60
341        %155 = OpIAdd %6 %154 %30
342               OpStore %60 %155
343               OpBranch %61
344         %63 = OpLabel
345               OpBranch %55
346         %55 = OpLabel
347        %156 = OpLoad %6 %51
348        %157 = OpIAdd %6 %156 %30
349               OpStore %51 %157
350               OpBranch %52
351         %54 = OpLabel
352        %159 = OpAccessChain %24 %21 %22 %23
353        %160 = OpLoad %6 %159
354        %161 = OpAccessChain %24 %21 %22 %27
355        %162 = OpLoad %6 %161
356        %163 = OpAccessChain %24 %21 %22 %30
357        %164 = OpLoad %6 %163
358        %165 = OpAccessChain %24 %21 %22 %33
359        %166 = OpLoad %6 %165
360        %167 = OpAccessChain %24 %21 %22 %22
361        %168 = OpLoad %6 %167
362        %169 = OpAccessChain %24 %21 %22 %38
363        %170 = OpLoad %6 %169
364        %171 = OpAccessChain %24 %21 %22 %41
365        %172 = OpLoad %6 %171
366        %173 = OpAccessChain %24 %21 %22 %44
367        %174 = OpLoad %6 %173
368        %175 = OpAccessChain %24 %21 %22 %72
369        %176 = OpLoad %6 %175
370        %177 = OpCompositeConstruct %14 %160 %162 %164 %166 %168 %170 %172 %174 %176
371               OpStore %158 %177
372        %181 = OpAccessChain %24 %21 %22 %23
373        %182 = OpLoad %6 %181
374        %183 = OpConvertSToF %9 %182
375        %184 = OpAccessChain %24 %21 %22 %72
376        %185 = OpLoad %6 %184
377        %186 = OpConvertSToF %9 %185
378        %187 = OpAccessChain %24 %21 %22 %72
379        %188 = OpLoad %6 %187
380        %189 = OpConvertSToF %9 %188
381        %190 = OpAccessChain %24 %21 %22 %23
382        %191 = OpLoad %6 %190
383        %192 = OpConvertSToF %9 %191
384        %193 = OpCompositeConstruct %178 %183 %186 %189 %192
385               OpStore %180 %193
386        %195 = OpAccessChain %24 %21 %22 %72
387        %196 = OpLoad %6 %195
388               OpStore %194 %196
389               OpBranch %197
390        %197 = OpLabel
391               OpLoopMerge %199 %200 None
392               OpBranch %201
393        %201 = OpLabel
394        %202 = OpLoad %6 %194
395        %203 = OpAccessChain %24 %21 %22 %47
396        %204 = OpLoad %6 %203
397        %205 = OpSLessThan %58 %202 %204
398               OpBranchConditional %205 %198 %199
399        %198 = OpLabel
400        %206 = OpLoad %6 %194
401        %207 = OpAccessChain %7 %16 %206
402        %208 = OpLoad %6 %207
403        %209 = OpLoad %6 %194
404        %210 = OpAccessChain %7 %158 %209
405        %211 = OpLoad %6 %210
406        %212 = OpINotEqual %58 %208 %211
407               OpSelectionMerge %214 None
408               OpBranchConditional %212 %213 %214
409        %213 = OpLabel
410        %215 = OpAccessChain %24 %21 %22 %72
411        %216 = OpLoad %6 %215
412        %217 = OpConvertSToF %9 %216
413        %218 = OpCompositeConstruct %178 %217 %217 %217 %217
414               OpStore %180 %218
415               OpBranch %214
416        %214 = OpLabel
417               OpBranch %200
418        %200 = OpLabel
419        %219 = OpLoad %6 %194
420        %220 = OpIAdd %6 %219 %30
421               OpStore %194 %220
422               OpBranch %197
423        %199 = OpLabel
424               OpReturn
425               OpFunctionEnd
426END
427
428# uniforms for variant
429
430# _GLF_uniform_int_values
431BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
432 5 3 4 6 7 8 1 0 2 9 1065353216
433END
434
435BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
436
437PIPELINE graphics variant_pipeline
438  ATTACH variant_vertex_shader
439  ATTACH variant_fragment_shader
440  FRAMEBUFFER_SIZE 16 16
441  BIND BUFFER variant_framebuffer AS color LOCATION 0
442  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
443END
444CLEAR_COLOR variant_pipeline 0 0 0 255
445
446CLEAR variant_pipeline
447RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
448
449EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255
450