3 # Copyright 2021 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a coverage-gap found by the GraphicsFuzz project.
20 # Short description: A fragment shader that covers specific LLVM code paths
22 # The test passes because the shader always writes red.
24 SHADER vertex texgen_vert PASSTHROUGH
26 SHADER fragment texgen_frag GLSL
28 precision highp float;
30 layout(location = 0) out vec4 _GLF_color;
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),
41 BUFFER default_texture FORMAT B8G8R8A8_UNORM
43 PIPELINE graphics texgen_pipeline
46 FRAMEBUFFER_SIZE 256 256
47 BIND BUFFER default_texture AS color LOCATION 0
50 CLEAR_COLOR texgen_pipeline 0 0 0 255
52 RUN texgen_pipeline DRAW_RECT POS 0 0 SIZE 256 256
54 SHADER vertex variant_vertex_shader PASSTHROUGH
56 # variant_fragment_shader is derived from the following GLSL:
58 # #define _int_0 _GLF_uniform_int_values[0]
59 # #define _int_1 _GLF_uniform_int_values[1]
60 # #define _int_4 _GLF_uniform_int_values[2]
61 # #define _float_0_0 _GLF_uniform_float_values[0]
62 # #define _float_1_0 _GLF_uniform_float_values[1]
63 # #define _float_255_0 _GLF_uniform_float_values[2]
64 # #define _float_256_0 _GLF_uniform_float_values[3]
66 # precision highp float;
67 # precision highp int;
69 # // Contents of _GLF_uniform_float_values: [0.0, 1.0, 255.0, 256.0]
70 # layout(set = 0, binding = 0) uniform buf0
72 # float _GLF_uniform_float_values[4];
74 # // Contents of _GLF_uniform_int_values: [0, 1, 4]
75 # layout(set = 0, binding = 1) uniform buf1
77 # int _GLF_uniform_int_values[3];
79 # // Contents of one: 1.0
80 # layout(push_constant) uniform buf_push
85 # layout(set = 0, binding = 2) uniform sampler2D tex;
86 # layout(location = 0) out vec4 _GLF_color;
90 # vec2 coord = vec2(_float_0_0);
91 # vec4 texel = texture(tex, coord);
92 # _GLF_color = vec4(_int_0);
94 # for(int i = _int_0; i < int(one); i++)
96 # // Texture has a red channel that changes from zero to one in u direction.
97 # // The first time it's sampled from u = 0 which gives a value of zero.
98 # // The second time the sampled location has chaned to the other edge
99 # // where it samples 1.0 and therefore exits the loop.
100 # while(texel.x < _float_1_0)
102 # for(int i = _int_0; i < _int_1; i ++)
105 # if(gl_FragCoord.y > _float_0_0)
110 # // This branch is never executed.
111 # for(int i = _int_1; i > _int_0; i--)
113 # for(int i = _int_0; i != _int_1; i++)
115 # for(int i = _int_0; i < int(one); i++)
117 # if(gl_FragCoord.y > _float_0_0)
122 # coord = vec2(_float_1_0);
130 # // Jump to the opposite corner of the texture where
131 # // it will sample 1.0 for the red channel.
132 # coord = coord + _float_255_0 / _float_256_0;
133 # for(int i = _int_0; i < _int_1; i ++)
135 # for(int i = _int_1; i != _int_0; i --)
137 # texel = texture(tex, coord);
138 # _GLF_color = vec4(texel.x, _int_0, _int_0, _int_1);
142 # // This does nothing.
143 # for(int i = _int_0; i < _int_1; i ++)
145 # for(int i = _int_0; i != _int_1; i ++)
152 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
155 ; Generator: Khronos Glslang Reference Front End; 10
159 %1 = OpExtInstImport "GLSL.std.450"
160 OpMemoryModel Logical GLSL450
161 OpEntryPoint Fragment %4 "main" %33 %89
162 OpExecutionMode %4 OriginUpperLeft
167 OpMemberName %13 0 "_GLF_uniform_float_values"
171 OpName %33 "_GLF_color"
173 OpMemberName %36 0 "_GLF_uniform_int_values"
176 OpName %54 "buf_push"
177 OpMemberName %54 0 "one"
180 OpName %89 "gl_FragCoord"
188 OpDecorate %12 ArrayStride 16
189 OpMemberDecorate %13 0 Offset 0
191 OpDecorate %15 DescriptorSet 0
192 OpDecorate %15 Binding 0
193 OpDecorate %28 RelaxedPrecision
194 OpDecorate %28 DescriptorSet 0
195 OpDecorate %28 Binding 2
196 OpDecorate %29 RelaxedPrecision
197 OpDecorate %31 RelaxedPrecision
198 OpDecorate %33 Location 0
199 OpDecorate %35 ArrayStride 16
200 OpMemberDecorate %36 0 Offset 0
202 OpDecorate %38 DescriptorSet 0
203 OpDecorate %38 Binding 1
204 OpMemberDecorate %54 0 Offset 0
206 OpDecorate %89 BuiltIn FragCoord
207 OpDecorate %190 RelaxedPrecision
208 OpDecorate %192 RelaxedPrecision
210 %3 = OpTypeFunction %2
212 %7 = OpTypeVector %6 2
213 %8 = OpTypePointer Function %7
215 %11 = OpConstant %10 4
216 %12 = OpTypeArray %6 %11
217 %13 = OpTypeStruct %12
218 %14 = OpTypePointer Uniform %13
219 %15 = OpVariable %14 Uniform
221 %17 = OpConstant %16 0
222 %18 = OpTypePointer Uniform %6
223 %22 = OpTypeVector %6 4
224 %23 = OpTypePointer Function %22
225 %25 = OpTypeImage %6 2D 0 0 0 1 Unknown
226 %26 = OpTypeSampledImage %25
227 %27 = OpTypePointer UniformConstant %26
228 %28 = OpVariable %27 UniformConstant
229 %32 = OpTypePointer Output %22
230 %33 = OpVariable %32 Output
231 %34 = OpConstant %10 3
232 %35 = OpTypeArray %16 %34
233 %36 = OpTypeStruct %35
234 %37 = OpTypePointer Uniform %36
235 %38 = OpVariable %37 Uniform
236 %39 = OpTypePointer Uniform %16
237 %44 = OpTypePointer Function %16
238 %54 = OpTypeStruct %6
239 %55 = OpTypePointer PushConstant %54
240 %56 = OpVariable %55 PushConstant
241 %57 = OpTypePointer PushConstant %6
243 %68 = OpConstant %10 0
244 %69 = OpTypePointer Function %6
245 %72 = OpConstant %16 1
246 %88 = OpTypePointer Input %22
247 %89 = OpVariable %88 Input
248 %90 = OpConstant %10 1
249 %91 = OpTypePointer Input %6
250 %157 = OpConstant %16 2
251 %160 = OpConstant %16 3
252 %4 = OpFunction %2 None %3
254 %9 = OpVariable %8 Function
255 %24 = OpVariable %23 Function
256 %45 = OpVariable %44 Function
257 %76 = OpVariable %44 Function
258 %100 = OpVariable %44 Function
259 %112 = OpVariable %44 Function
260 %124 = OpVariable %44 Function
261 %166 = OpVariable %44 Function
262 %178 = OpVariable %44 Function
263 %209 = OpVariable %44 Function
264 %221 = OpVariable %44 Function
265 %19 = OpAccessChain %18 %15 %17 %17
267 %21 = OpCompositeConstruct %7 %20 %20
271 %31 = OpImageSampleImplicitLod %22 %29 %30
273 %40 = OpAccessChain %39 %38 %17 %17
275 %42 = OpConvertSToF %6 %41
276 %43 = OpCompositeConstruct %22 %42 %42 %42 %42
278 %46 = OpAccessChain %39 %38 %17 %17
283 OpLoopMerge %50 %51 None
287 %58 = OpAccessChain %57 %56 %17
289 %60 = OpConvertFToS %16 %59
290 %62 = OpSLessThan %61 %53 %60
291 OpBranchConditional %62 %49 %50
295 OpLoopMerge %65 %66 None
298 %70 = OpAccessChain %69 %24 %68
300 %73 = OpAccessChain %18 %15 %17 %72
302 %75 = OpFOrdLessThan %61 %71 %74
303 OpBranchConditional %75 %64 %65
305 %77 = OpAccessChain %39 %38 %17 %17
310 OpLoopMerge %81 %82 None
314 %85 = OpAccessChain %39 %38 %17 %72
316 %87 = OpSLessThan %61 %84 %86
317 OpBranchConditional %87 %80 %81
319 %92 = OpAccessChain %91 %89 %90
321 %94 = OpAccessChain %18 %15 %17 %17
323 %96 = OpFOrdGreaterThan %61 %93 %95
324 OpSelectionMerge %98 None
325 OpBranchConditional %96 %97 %99
329 %101 = OpAccessChain %39 %38 %17 %72
330 %102 = OpLoad %16 %101
334 OpLoopMerge %105 %106 None
337 %108 = OpLoad %16 %100
338 %109 = OpAccessChain %39 %38 %17 %17
339 %110 = OpLoad %16 %109
340 %111 = OpSGreaterThan %61 %108 %110
341 OpBranchConditional %111 %104 %105
343 %113 = OpAccessChain %39 %38 %17 %17
344 %114 = OpLoad %16 %113
348 OpLoopMerge %117 %118 None
351 %120 = OpLoad %16 %112
352 %121 = OpAccessChain %39 %38 %17 %72
353 %122 = OpLoad %16 %121
354 %123 = OpINotEqual %61 %120 %122
355 OpBranchConditional %123 %116 %117
357 %125 = OpAccessChain %39 %38 %17 %17
358 %126 = OpLoad %16 %125
362 OpLoopMerge %129 %130 None
365 %132 = OpLoad %16 %124
366 %133 = OpAccessChain %57 %56 %17
367 %134 = OpLoad %6 %133
368 %135 = OpConvertFToS %16 %134
369 %136 = OpSLessThan %61 %132 %135
370 OpBranchConditional %136 %128 %129
372 %137 = OpAccessChain %91 %89 %90
373 %138 = OpLoad %6 %137
374 %139 = OpAccessChain %18 %15 %17 %17
375 %140 = OpLoad %6 %139
376 %141 = OpFOrdGreaterThan %61 %138 %140
377 OpSelectionMerge %143 None
378 OpBranchConditional %141 %142 %144
382 %145 = OpAccessChain %18 %15 %17 %72
383 %146 = OpLoad %6 %145
384 %147 = OpCompositeConstruct %7 %146 %146
390 %148 = OpLoad %16 %124
391 %149 = OpIAdd %16 %148 %72
397 %150 = OpLoad %16 %112
398 %151 = OpIAdd %16 %150 %72
404 %152 = OpLoad %16 %100
405 %153 = OpISub %16 %152 %72
413 %154 = OpLoad %16 %76
414 %155 = OpIAdd %16 %154 %72
419 %158 = OpAccessChain %18 %15 %17 %157
420 %159 = OpLoad %6 %158
421 %161 = OpAccessChain %18 %15 %17 %160
422 %162 = OpLoad %6 %161
423 %163 = OpFDiv %6 %159 %162
424 %164 = OpCompositeConstruct %7 %163 %163
425 %165 = OpFAdd %7 %156 %164
427 %167 = OpAccessChain %39 %38 %17 %17
428 %168 = OpLoad %16 %167
432 OpLoopMerge %171 %172 None
435 %174 = OpLoad %16 %166
436 %175 = OpAccessChain %39 %38 %17 %72
437 %176 = OpLoad %16 %175
438 %177 = OpSLessThan %61 %174 %176
439 OpBranchConditional %177 %170 %171
441 %179 = OpAccessChain %39 %38 %17 %72
442 %180 = OpLoad %16 %179
446 OpLoopMerge %183 %184 None
449 %186 = OpLoad %16 %178
450 %187 = OpAccessChain %39 %38 %17 %17
451 %188 = OpLoad %16 %187
452 %189 = OpINotEqual %61 %186 %188
453 OpBranchConditional %189 %182 %183
455 %190 = OpLoad %26 %28
457 %192 = OpImageSampleImplicitLod %22 %190 %191
459 %193 = OpAccessChain %69 %24 %68
460 %194 = OpLoad %6 %193
461 %195 = OpAccessChain %39 %38 %17 %17
462 %196 = OpLoad %16 %195
463 %197 = OpConvertSToF %6 %196
464 %198 = OpAccessChain %39 %38 %17 %17
465 %199 = OpLoad %16 %198
466 %200 = OpConvertSToF %6 %199
467 %201 = OpAccessChain %39 %38 %17 %72
468 %202 = OpLoad %16 %201
469 %203 = OpConvertSToF %6 %202
470 %204 = OpCompositeConstruct %22 %194 %197 %200 %203
474 %205 = OpLoad %16 %178
475 %206 = OpISub %16 %205 %72
481 %207 = OpLoad %16 %166
482 %208 = OpIAdd %16 %207 %72
486 %210 = OpAccessChain %39 %38 %17 %17
487 %211 = OpLoad %16 %210
491 OpLoopMerge %214 %215 None
494 %217 = OpLoad %16 %209
495 %218 = OpAccessChain %39 %38 %17 %72
496 %219 = OpLoad %16 %218
497 %220 = OpSLessThan %61 %217 %219
498 OpBranchConditional %220 %213 %214
500 %222 = OpAccessChain %39 %38 %17 %17
501 %223 = OpLoad %16 %222
505 OpLoopMerge %226 %227 None
508 %229 = OpLoad %16 %221
509 %230 = OpAccessChain %39 %38 %17 %72
510 %231 = OpLoad %16 %230
511 %232 = OpINotEqual %61 %229 %231
512 OpBranchConditional %232 %225 %226
516 %233 = OpLoad %16 %221
517 %234 = OpIAdd %16 %233 %72
523 %235 = OpLoad %16 %209
524 %236 = OpIAdd %16 %235 %72
534 %237 = OpLoad %16 %45
535 %238 = OpIAdd %16 %237 %72
543 # uniforms for variant
549 BUFFER variant_one DATA_TYPE float STD140 DATA
552 # _GLF_uniform_int_values
553 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
556 # _GLF_uniform_float_values
557 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
561 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
563 PIPELINE graphics variant_pipeline
564 ATTACH variant_vertex_shader
565 ATTACH variant_fragment_shader
566 FRAMEBUFFER_SIZE 256 256
567 BIND BUFFER variant_framebuffer AS color LOCATION 0
568 BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_tex DESCRIPTOR_SET 0 BINDING 2
569 BIND BUFFER variant_one AS push_constant
570 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
571 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
573 CLEAR_COLOR variant_pipeline 0 0 0 255
575 CLEAR variant_pipeline
576 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
578 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255