• 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
24# Optimized using spirv-opt with the following arguments:
25# '-O'
26# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
27
28
29
30SHADER vertex variant_vertex_shader PASSTHROUGH
31
32# variant_fragment_shader is derived from the following GLSL:
33# #version 320 es
34# #define _int_0 _GLF_uniform_int_values[0]
35# #define _int_1 _GLF_uniform_int_values[1]
36# #define _int_6 _GLF_uniform_int_values[2]
37# #define _int_2 _GLF_uniform_int_values[3]
38# #define _int_3 _GLF_uniform_int_values[4]
39# #define _int_5 _GLF_uniform_int_values[5]
40#
41# precision highp int;
42# precision highp float;
43#
44# // Contents of _GLF_uniform_int_values: [0, 1, 6, 2, 3, 5]
45# layout(set = 0, binding = 0) uniform buf0
46# {
47#     int _GLF_uniform_int_values[6];
48# };
49#
50# layout(location = 0) out vec4 _GLF_color;
51#
52# int func0(int x)
53# {
54#     for(int i = _int_0; i < _int_5; i++)
55#     {
56#         // This function is only called with x = 0,
57#         // therefore the second iteration always returns 1.
58#         if(x == _int_1)
59#         {
60#             return _int_1;
61#         }
62#
63#         x++;
64#     }
65#
66#     // This part of the function is never executed because
67#     // the loop above always returns one.
68#
69#     // Always true.
70#     if(gl_FragCoord.x > 0.0)
71#     {
72#         return -1;
73#     }
74#
75#     // Never executed.
76#     return 2;
77# }
78#
79# int func1()
80# {
81#     // Always true.
82#     if(gl_FragCoord.y > 0.0)
83#     {
84#         // Always true.
85#         if(gl_FragCoord.y > length(vec3(0)))
86#         {
87#             return func0(_int_0);
88#         }
89#
90#         // Never executed.
91#         if(gl_FragCoord.x > 0.0)
92#         {
93#             _GLF_color = vec4(_int_0);
94#         }
95#
96#         // Never executed.
97#         if(func0(_int_6) > _int_0)
98#         {
99#             return _int_2;
100#         }
101#     }
102#
103#     // Never executed.
104#     return _int_3;
105# }
106#
107# void main()
108# {
109#     // Always true.
110#     if(func1() == _int_1)
111#     {
112#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
113#     }
114#     else
115#     {
116#         _GLF_color = vec4(_int_0);
117#     }
118# }
119SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
120; SPIR-V
121; Version: 1.0
122; Generator: Khronos Glslang Reference Front End; 10
123; Bound: 288
124; Schema: 0
125               OpCapability Shader
126          %1 = OpExtInstImport "GLSL.std.450"
127               OpMemoryModel Logical GLSL450
128               OpEntryPoint Fragment %4 "main" %54 %90
129               OpExecutionMode %4 OriginUpperLeft
130               OpSource ESSL 320
131               OpName %4 "main"
132               OpName %19 "buf0"
133               OpMemberName %19 0 "_GLF_uniform_int_values"
134               OpName %21 ""
135               OpName %54 "gl_FragCoord"
136               OpName %90 "_GLF_color"
137               OpDecorate %18 ArrayStride 16
138               OpMemberDecorate %19 0 Offset 0
139               OpDecorate %19 Block
140               OpDecorate %21 DescriptorSet 0
141               OpDecorate %21 Binding 0
142               OpDecorate %54 BuiltIn FragCoord
143               OpDecorate %90 Location 0
144          %2 = OpTypeVoid
145          %3 = OpTypeFunction %2
146          %6 = OpTypeInt 32 1
147         %16 = OpTypeInt 32 0
148         %17 = OpConstant %16 6
149         %18 = OpTypeArray %6 %17
150         %19 = OpTypeStruct %18
151         %20 = OpTypePointer Uniform %19
152         %21 = OpVariable %20 Uniform
153         %22 = OpConstant %6 0
154         %23 = OpTypePointer Uniform %6
155         %32 = OpConstant %6 5
156         %35 = OpTypeBool
157         %38 = OpConstant %6 1
158         %51 = OpTypeFloat 32
159         %52 = OpTypeVector %51 4
160         %53 = OpTypePointer Input %52
161         %54 = OpVariable %53 Input
162         %55 = OpConstant %16 0
163         %56 = OpTypePointer Input %51
164         %59 = OpConstant %51 0
165         %63 = OpConstant %6 -1
166         %65 = OpConstant %6 2
167         %68 = OpConstant %16 1
168         %89 = OpTypePointer Output %52
169         %90 = OpVariable %89 Output
170        %104 = OpConstant %6 3
171        %108 = OpConstant %6 4
172        %141 = OpConstantFalse %35
173        %144 = OpConstantTrue %35
174        %279 = OpUndef %6
175          %4 = OpFunction %2 None %3
176          %5 = OpLabel
177               OpSelectionMerge %193 None
178               OpSwitch %55 %158
179        %158 = OpLabel
180        %159 = OpAccessChain %56 %54 %68
181        %160 = OpLoad %51 %159
182        %161 = OpFOrdGreaterThan %35 %160 %59
183               OpSelectionMerge %190 None
184               OpBranchConditional %161 %162 %190
185        %162 = OpLabel
186               OpSelectionMerge %170 None
187               OpBranchConditional %161 %166 %170
188        %166 = OpLabel
189        %167 = OpAccessChain %23 %21 %22 %22
190        %168 = OpLoad %6 %167
191               OpSelectionMerge %231 None
192               OpSwitch %55 %200
193        %200 = OpLabel
194               OpBranch %203
195        %203 = OpLabel
196        %281 = OpPhi %6 %168 %200 %219 %220
197        %280 = OpPhi %6 %168 %200 %222 %220
198        %206 = OpAccessChain %23 %21 %22 %32
199        %207 = OpLoad %6 %206
200        %208 = OpSLessThan %35 %280 %207
201               OpLoopMerge %223 %220 None
202               OpBranchConditional %208 %209 %223
203        %209 = OpLabel
204        %211 = OpAccessChain %23 %21 %22 %38
205        %212 = OpLoad %6 %211
206        %213 = OpIEqual %35 %281 %212
207               OpSelectionMerge %217 None
208               OpBranchConditional %213 %214 %217
209        %214 = OpLabel
210               OpBranch %223
211        %217 = OpLabel
212        %219 = OpIAdd %6 %281 %38
213               OpBranch %220
214        %220 = OpLabel
215        %222 = OpIAdd %6 %280 %38
216               OpBranch %203
217        %223 = OpLabel
218        %285 = OpPhi %6 %279 %203 %212 %214
219        %282 = OpPhi %35 %141 %203 %144 %214
220               OpSelectionMerge %225 None
221               OpBranchConditional %282 %231 %225
222        %225 = OpLabel
223        %226 = OpAccessChain %56 %54 %55
224        %227 = OpLoad %51 %226
225        %228 = OpFOrdGreaterThan %35 %227 %59
226               OpSelectionMerge %230 None
227               OpBranchConditional %228 %229 %230
228        %229 = OpLabel
229               OpBranch %231
230        %230 = OpLabel
231               OpBranch %231
232        %231 = OpLabel
233        %284 = OpPhi %6 %285 %223 %63 %229 %65 %230
234               OpBranch %193
235        %170 = OpLabel
236        %171 = OpAccessChain %56 %54 %55
237        %172 = OpLoad %51 %171
238        %173 = OpFOrdGreaterThan %35 %172 %59
239               OpSelectionMerge %179 None
240               OpBranchConditional %173 %174 %179
241        %174 = OpLabel
242        %175 = OpAccessChain %23 %21 %22 %22
243        %176 = OpLoad %6 %175
244        %177 = OpConvertSToF %51 %176
245        %178 = OpCompositeConstruct %52 %177 %177 %177 %177
246               OpStore %90 %178
247               OpBranch %179
248        %179 = OpLabel
249        %180 = OpAccessChain %23 %21 %22 %65
250        %181 = OpLoad %6 %180
251               OpSelectionMerge %269 None
252               OpSwitch %55 %238
253        %238 = OpLabel
254        %239 = OpAccessChain %23 %21 %22 %22
255        %240 = OpLoad %6 %239
256               OpBranch %241
257        %241 = OpLabel
258        %272 = OpPhi %6 %181 %238 %257 %258
259        %271 = OpPhi %6 %240 %238 %260 %258
260        %244 = OpAccessChain %23 %21 %22 %32
261        %245 = OpLoad %6 %244
262        %246 = OpSLessThan %35 %271 %245
263               OpLoopMerge %261 %258 None
264               OpBranchConditional %246 %247 %261
265        %247 = OpLabel
266        %249 = OpAccessChain %23 %21 %22 %38
267        %250 = OpLoad %6 %249
268        %251 = OpIEqual %35 %272 %250
269               OpSelectionMerge %255 None
270               OpBranchConditional %251 %252 %255
271        %252 = OpLabel
272               OpBranch %261
273        %255 = OpLabel
274        %257 = OpIAdd %6 %272 %38
275               OpBranch %258
276        %258 = OpLabel
277        %260 = OpIAdd %6 %271 %38
278               OpBranch %241
279        %261 = OpLabel
280        %276 = OpPhi %6 %279 %241 %250 %252
281        %273 = OpPhi %35 %141 %241 %144 %252
282               OpSelectionMerge %263 None
283               OpBranchConditional %273 %269 %263
284        %263 = OpLabel
285               OpSelectionMerge %268 None
286               OpBranchConditional %173 %267 %268
287        %267 = OpLabel
288               OpBranch %269
289        %268 = OpLabel
290               OpBranch %269
291        %269 = OpLabel
292        %275 = OpPhi %6 %276 %261 %63 %267 %65 %268
293        %185 = OpSGreaterThan %35 %275 %240
294               OpSelectionMerge %189 None
295               OpBranchConditional %185 %186 %189
296        %186 = OpLabel
297        %187 = OpAccessChain %23 %21 %22 %104
298        %188 = OpLoad %6 %187
299               OpBranch %193
300        %189 = OpLabel
301               OpBranch %190
302        %190 = OpLabel
303        %191 = OpAccessChain %23 %21 %22 %108
304        %192 = OpLoad %6 %191
305               OpBranch %193
306        %193 = OpLabel
307        %287 = OpPhi %6 %284 %231 %188 %186 %192 %190
308        %114 = OpAccessChain %23 %21 %22 %38
309        %115 = OpLoad %6 %114
310        %116 = OpIEqual %35 %287 %115
311               OpSelectionMerge %118 None
312               OpBranchConditional %116 %117 %132
313        %117 = OpLabel
314        %121 = OpConvertSToF %51 %115
315        %122 = OpAccessChain %23 %21 %22 %22
316        %123 = OpLoad %6 %122
317        %124 = OpConvertSToF %51 %123
318        %131 = OpCompositeConstruct %52 %121 %124 %124 %121
319               OpStore %90 %131
320               OpBranch %118
321        %132 = OpLabel
322        %133 = OpAccessChain %23 %21 %22 %22
323        %134 = OpLoad %6 %133
324        %135 = OpConvertSToF %51 %134
325        %136 = OpCompositeConstruct %52 %135 %135 %135 %135
326               OpStore %90 %136
327               OpBranch %118
328        %118 = OpLabel
329               OpReturn
330               OpFunctionEnd
331END
332
333# uniforms for variant
334
335# _GLF_uniform_int_values
336BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
337 0 1 6 2 3 5
338END
339
340BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
341
342PIPELINE graphics variant_pipeline
343  ATTACH variant_vertex_shader
344  ATTACH variant_fragment_shader
345  FRAMEBUFFER_SIZE 256 256
346  BIND BUFFER variant_framebuffer AS color LOCATION 0
347  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
348END
349CLEAR_COLOR variant_pipeline 0 0 0 255
350
351CLEAR variant_pipeline
352RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
353
354EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
355