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 variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # #define _int_0 _GLF_uniform_int_values[0]
29 # #define _int_1 _GLF_uniform_int_values[1]
30 # #define _int_32 _GLF_uniform_int_values[2]
31 # #define _float_0_0 _GLF_uniform_float_values[0]
33 # precision highp float;
34 # precision highp int;
36 # // Contents of _GLF_uniform_int_values: [0, 1, 32]
37 # layout(set = 0, binding = 0) uniform buf0
39 # int _GLF_uniform_int_values[3];
42 # // Contents of _GLF_uniform_float_values: 0.0
43 # layout(set = 0, binding = 1) uniform buf1
45 # float _GLF_uniform_float_values[1];
48 # layout(location = 0) out vec4 _GLF_color;
50 # // Contents of resolution: [32.0, 32.0]
51 # layout(push_constant) uniform buf_push
56 # int func(float a, float b)
61 # for(int i = 0; i < 2; i ++)
65 # // Always true, keeping c incremented at the
67 # if(mod(float(d), b) > _float_0_0)
72 # // Returns when c is 32.
89 # if(func(resolution.x, resolution.y) == _int_32)
91 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
95 # _GLF_color = vec4(_int_0);
98 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
101 ; Generator: Khronos Glslang Reference Front End; 10
105 %1 = OpExtInstImport "GLSL.std.450"
106 OpMemoryModel Logical GLSL450
107 OpEntryPoint Fragment %4 "main" %99
108 OpExecutionMode %4 OriginUpperLeft
111 OpName %12 "func(f1;f1;"
116 OpMemberName %19 0 "_GLF_uniform_int_values"
121 OpMemberName %52 0 "_GLF_uniform_float_values"
123 OpName %80 "buf_push"
124 OpMemberName %80 0 "resolution"
128 OpName %99 "_GLF_color"
129 OpDecorate %18 ArrayStride 16
130 OpMemberDecorate %19 0 Offset 0
132 OpDecorate %21 DescriptorSet 0
133 OpDecorate %21 Binding 0
134 OpDecorate %51 ArrayStride 16
135 OpMemberDecorate %52 0 Offset 0
137 OpDecorate %54 DescriptorSet 0
138 OpDecorate %54 Binding 1
139 OpMemberDecorate %80 0 Offset 0
141 OpDecorate %99 Location 0
143 %3 = OpTypeFunction %2
145 %7 = OpTypePointer Function %6
147 %9 = OpTypeFunction %8 %7 %7
148 %14 = OpTypePointer Function %8
150 %17 = OpConstant %16 3
151 %18 = OpTypeArray %8 %17
152 %19 = OpTypeStruct %18
153 %20 = OpTypePointer Uniform %19
154 %21 = OpVariable %20 Uniform
155 %22 = OpConstant %8 0
156 %23 = OpConstant %8 1
157 %24 = OpTypePointer Uniform %8
158 %35 = OpConstant %8 2
160 %44 = OpConstant %8 110
161 %50 = OpConstant %16 1
162 %51 = OpTypeArray %6 %50
163 %52 = OpTypeStruct %51
164 %53 = OpTypePointer Uniform %52
165 %54 = OpVariable %53 Uniform
166 %55 = OpTypePointer Uniform %6
167 %79 = OpTypeVector %6 2
168 %80 = OpTypeStruct %79
169 %81 = OpTypePointer PushConstant %80
170 %82 = OpVariable %81 PushConstant
171 %84 = OpConstant %16 0
172 %85 = OpTypePointer PushConstant %6
173 %97 = OpTypeVector %6 4
174 %98 = OpTypePointer Output %97
175 %99 = OpVariable %98 Output
176 %4 = OpFunction %2 None %3
178 %83 = OpVariable %7 Function
179 %88 = OpVariable %7 Function
180 %86 = OpAccessChain %85 %82 %22 %84
183 %89 = OpAccessChain %85 %82 %22 %50
186 %91 = OpFunctionCall %8 %12 %83 %88
187 %92 = OpAccessChain %24 %21 %22 %35
189 %94 = OpIEqual %36 %91 %93
190 OpSelectionMerge %96 None
191 OpBranchConditional %94 %95 %113
193 %100 = OpAccessChain %24 %21 %22 %23
194 %101 = OpLoad %8 %100
195 %102 = OpConvertSToF %6 %101
196 %103 = OpAccessChain %24 %21 %22 %22
197 %104 = OpLoad %8 %103
198 %105 = OpConvertSToF %6 %104
199 %106 = OpAccessChain %24 %21 %22 %22
200 %107 = OpLoad %8 %106
201 %108 = OpConvertSToF %6 %107
202 %109 = OpAccessChain %24 %21 %22 %23
203 %110 = OpLoad %8 %109
204 %111 = OpConvertSToF %6 %110
205 %112 = OpCompositeConstruct %97 %102 %105 %108 %111
209 %114 = OpAccessChain %24 %21 %22 %22
210 %115 = OpLoad %8 %114
211 %116 = OpConvertSToF %6 %115
212 %117 = OpCompositeConstruct %97 %116 %116 %116 %116
218 %12 = OpFunction %8 None %9
219 %10 = OpFunctionParameter %7
220 %11 = OpFunctionParameter %7
222 %15 = OpVariable %14 Function
223 %27 = OpVariable %14 Function
224 %28 = OpVariable %14 Function
225 %25 = OpAccessChain %24 %21 %22 %23
232 OpLoopMerge %31 %32 None
236 %37 = OpSLessThan %36 %34 %35
237 OpBranchConditional %37 %30 %31
241 OpLoopMerge %40 %41 None
245 %45 = OpSLessThan %36 %43 %44
246 OpBranchConditional %45 %39 %40
249 %47 = OpConvertSToF %6 %46
251 %49 = OpFMod %6 %47 %48
252 %56 = OpAccessChain %55 %54 %22 %22
254 %58 = OpFOrdGreaterThan %36 %49 %57
255 OpSelectionMerge %60 None
256 OpBranchConditional %58 %59 %60
259 %62 = OpIAdd %8 %61 %23
264 %64 = OpConvertSToF %6 %63
266 %66 = OpFOrdGreaterThanEqual %36 %64 %65
267 OpSelectionMerge %68 None
268 OpBranchConditional %66 %67 %68
274 %72 = OpIAdd %8 %71 %23
283 %74 = OpIAdd %8 %73 %23
287 %75 = OpAccessChain %24 %21 %22 %22
293 # uniforms for variant
296 BUFFER variant_resolution DATA_TYPE vec2<float> STD140 DATA
299 # _GLF_uniform_float_values
300 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
303 # _GLF_uniform_int_values
304 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
308 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
310 PIPELINE graphics variant_pipeline
311 ATTACH variant_vertex_shader
312 ATTACH variant_fragment_shader
313 FRAMEBUFFER_SIZE 256 256
314 BIND BUFFER variant_framebuffer AS color LOCATION 0
315 BIND BUFFER variant_resolution AS push_constant
316 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
317 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
319 CLEAR_COLOR variant_pipeline 0 0 0 255
321 CLEAR variant_pipeline
322 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
324 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255