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# #define _int_10 _GLF_uniform_int_values[0]
29# #define _int_1 _GLF_uniform_int_values[1]
30# #define _int_0 _GLF_uniform_int_values[2]
31#
32# precision highp int;
33# precision highp float;
34#
35# // Contents of _GLF_uniform_int_values: [10, 1, 0]
36# layout(set = 0, binding = 0) uniform buf0
37# {
38#     int _GLF_uniform_int_values[3];
39# };
40# layout(location = 0) out vec4 _GLF_color;
41#
42# void main()
43# {
44#     int i = _int_1;
45#
46#     do
47#     {
48#         switch(i)
49#         {
50#             // This case is never his because i starts from one.
51#             case 0:
52#                 if(bitCount(findMSB(_int_1)) > 1)
53#                 {
54#                     // This would cause an infinite loop, but it's never executed.
55#                     continue;
56#                 }
57#         }
58#         i++;
59#     }
60#     while((i < _int_10));
61#
62#     // Always true.
63#     if(i == _int_10)
64#     {
65#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
66#     }
67#     else
68#     {
69#         _GLF_color = vec4(_int_0);
70#     }
71# }
72SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
73; SPIR-V
74; Version: 1.0
75; Generator: Khronos Glslang Reference Front End; 10
76; Bound: 72
77; Schema: 0
78               OpCapability Shader
79          %1 = OpExtInstImport "GLSL.std.450"
80               OpMemoryModel Logical GLSL450
81               OpEntryPoint Fragment %4 "main" %52
82               OpExecutionMode %4 OriginUpperLeft
83               OpSource ESSL 320
84               OpName %4 "main"
85               OpName %8 "i"
86               OpName %12 "buf0"
87               OpMemberName %12 0 "_GLF_uniform_int_values"
88               OpName %14 ""
89               OpName %52 "_GLF_color"
90               OpDecorate %11 ArrayStride 16
91               OpMemberDecorate %12 0 Offset 0
92               OpDecorate %12 Block
93               OpDecorate %14 DescriptorSet 0
94               OpDecorate %14 Binding 0
95               OpDecorate %30 RelaxedPrecision
96               OpDecorate %52 Location 0
97          %2 = OpTypeVoid
98          %3 = OpTypeFunction %2
99          %6 = OpTypeInt 32 1
100          %7 = OpTypePointer Function %6
101          %9 = OpTypeInt 32 0
102         %10 = OpConstant %9 3
103         %11 = OpTypeArray %6 %10
104         %12 = OpTypeStruct %11
105         %13 = OpTypePointer Uniform %12
106         %14 = OpVariable %13 Uniform
107         %15 = OpConstant %6 0
108         %16 = OpConstant %6 1
109         %17 = OpTypePointer Uniform %6
110         %31 = OpTypeBool
111         %49 = OpTypeFloat 32
112         %50 = OpTypeVector %49 4
113         %51 = OpTypePointer Output %50
114         %52 = OpVariable %51 Output
115         %56 = OpConstant %6 2
116          %4 = OpFunction %2 None %3
117          %5 = OpLabel
118          %8 = OpVariable %7 Function
119         %18 = OpAccessChain %17 %14 %15 %16
120         %19 = OpLoad %6 %18
121               OpStore %8 %19
122               OpBranch %20
123         %20 = OpLabel
124               OpLoopMerge %22 %23 None
125               OpBranch %21
126         %21 = OpLabel
127         %24 = OpLoad %6 %8
128               OpSelectionMerge %26 None
129               OpSwitch %24 %26 0 %25
130         %25 = OpLabel
131         %27 = OpAccessChain %17 %14 %15 %16
132         %28 = OpLoad %6 %27
133         %29 = OpExtInst %6 %1 FindSMsb %28
134         %30 = OpBitCount %6 %29
135         %32 = OpSGreaterThan %31 %30 %16
136               OpSelectionMerge %34 None
137               OpBranchConditional %32 %33 %34
138         %33 = OpLabel
139               OpBranch %23
140         %34 = OpLabel
141               OpBranch %26
142         %26 = OpLabel
143         %37 = OpLoad %6 %8
144         %38 = OpIAdd %6 %37 %16
145               OpStore %8 %38
146               OpBranch %23
147         %23 = OpLabel
148         %39 = OpLoad %6 %8
149         %40 = OpAccessChain %17 %14 %15 %15
150         %41 = OpLoad %6 %40
151         %42 = OpSLessThan %31 %39 %41
152               OpBranchConditional %42 %20 %22
153         %22 = OpLabel
154         %43 = OpLoad %6 %8
155         %44 = OpAccessChain %17 %14 %15 %15
156         %45 = OpLoad %6 %44
157         %46 = OpIEqual %31 %43 %45
158               OpSelectionMerge %48 None
159               OpBranchConditional %46 %47 %67
160         %47 = OpLabel
161         %53 = OpAccessChain %17 %14 %15 %16
162         %54 = OpLoad %6 %53
163         %55 = OpConvertSToF %49 %54
164         %57 = OpAccessChain %17 %14 %15 %56
165         %58 = OpLoad %6 %57
166         %59 = OpConvertSToF %49 %58
167         %60 = OpAccessChain %17 %14 %15 %56
168         %61 = OpLoad %6 %60
169         %62 = OpConvertSToF %49 %61
170         %63 = OpAccessChain %17 %14 %15 %16
171         %64 = OpLoad %6 %63
172         %65 = OpConvertSToF %49 %64
173         %66 = OpCompositeConstruct %50 %55 %59 %62 %65
174               OpStore %52 %66
175               OpBranch %48
176         %67 = OpLabel
177         %68 = OpAccessChain %17 %14 %15 %56
178         %69 = OpLoad %6 %68
179         %70 = OpConvertSToF %49 %69
180         %71 = OpCompositeConstruct %50 %70 %70 %70 %70
181               OpStore %52 %71
182               OpBranch %48
183         %48 = OpLabel
184               OpReturn
185               OpFunctionEnd
186END
187
188# uniforms for variant
189
190# _GLF_uniform_int_values
191BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
192 10 1 0
193END
194
195BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
196
197PIPELINE graphics variant_pipeline
198  ATTACH variant_vertex_shader
199  ATTACH variant_fragment_shader
200  FRAMEBUFFER_SIZE 256 256
201  BIND BUFFER variant_framebuffer AS color LOCATION 0
202  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
203END
204CLEAR_COLOR variant_pipeline 0 0 0 255
205
206CLEAR variant_pipeline
207RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
208
209EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
210