3 # Copyright 2022 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 # Optimized using spirv-opt with the following arguments:
26 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
30 SHADER vertex variant_vertex_shader PASSTHROUGH
32 # variant_fragment_shader is derived from the following GLSL:
34 # #define _int_0 _GLF_uniform_int_values[0]
35 # #define _int_1 _GLF_uniform_int_values[1]
36 # #define _int_64 _GLF_uniform_int_values[2]
38 # precision highp float;
39 # precision highp int;
41 # // Contents of _GLF_uniform_int_values: [0, 1, 64]
42 # layout(set = 0, binding = 0) uniform buf0
44 # int _GLF_uniform_int_values[3];
47 # // Contents of injectionSwitch: [0.0, 1.0]
48 # layout(set = 0, binding = 1) uniform buf1
50 # vec2 injectionSwitch;
53 # layout(location = 0) out vec4 _GLF_color;
58 # if(injectionSwitch.x > injectionSwitch.y)
67 # // Iterates twice but has no effect.
68 # for(int i = 1; i < findLSB(8); i++)
76 # if(injectionSwitch.x > injectionSwitch.y)
82 # if(gl_FragCoord.y < 0.0)
96 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
100 # _GLF_color = vec4(_int_0);
103 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
106 ; Generator: Khronos Glslang Reference Front End; 10
110 %1 = OpExtInstImport "GLSL.std.450"
111 OpMemoryModel Logical GLSL450
112 OpEntryPoint Fragment %4 "main" %59 %89
113 OpExecutionMode %4 OriginUpperLeft
117 OpMemberName %8 0 "injectionSwitch"
119 OpName %59 "gl_FragCoord"
121 OpMemberName %78 0 "_GLF_uniform_int_values"
123 OpName %89 "_GLF_color"
124 OpMemberDecorate %8 0 Offset 0
126 OpDecorate %10 DescriptorSet 0
127 OpDecorate %10 Binding 1
128 OpDecorate %41 RelaxedPrecision
129 OpDecorate %59 BuiltIn FragCoord
130 OpDecorate %77 ArrayStride 16
131 OpMemberDecorate %78 0 Offset 0
133 OpDecorate %80 DescriptorSet 0
134 OpDecorate %80 Binding 0
135 OpDecorate %89 Location 0
137 %3 = OpTypeFunction %2
139 %7 = OpTypeVector %6 2
141 %9 = OpTypePointer Uniform %8
142 %10 = OpVariable %9 Uniform
144 %12 = OpConstant %11 0
146 %14 = OpConstant %13 0
147 %15 = OpTypePointer Uniform %6
148 %18 = OpConstant %13 1
150 %33 = OpConstant %11 1
151 %40 = OpConstant %11 8
152 %57 = OpTypeVector %6 4
153 %58 = OpTypePointer Input %57
154 %59 = OpVariable %58 Input
155 %60 = OpTypePointer Input %6
156 %63 = OpConstant %6 0
157 %73 = OpConstant %11 64
158 %76 = OpConstant %13 3
159 %77 = OpTypeArray %11 %76
160 %78 = OpTypeStruct %77
161 %79 = OpTypePointer Uniform %78
162 %80 = OpVariable %79 Uniform
163 %81 = OpConstant %11 2
164 %82 = OpTypePointer Uniform %11
165 %88 = OpTypePointer Output %57
166 %89 = OpVariable %88 Output
167 %4 = OpFunction %2 None %3
169 OpSelectionMerge %108 None
172 %16 = OpAccessChain %15 %10 %12 %14
174 %19 = OpAccessChain %15 %10 %12 %18
176 %22 = OpFOrdGreaterThan %21 %17 %20
177 OpSelectionMerge %24 None
178 OpBranchConditional %22 %23 %24
184 %116 = OpPhi %11 %12 %24 %71 %31
185 OpLoopMerge %30 %31 None
188 %114 = OpPhi %11 %33 %28 %69 %37
189 %41 = OpExtInst %11 %1 FindILsb %40
190 %42 = OpSLessThan %21 %114 %41
191 OpLoopMerge %36 %37 None
192 OpBranchConditional %42 %35 %36
194 %45 = OpSLessThan %21 %114 %116
195 OpSelectionMerge %47 None
196 OpBranchConditional %45 %46 %47
200 OpSelectionMerge %55 None
201 OpBranchConditional %22 %54 %56
205 %61 = OpAccessChain %60 %59 %18
207 %64 = OpFOrdLessThan %21 %62 %63
208 OpSelectionMerge %66 None
209 OpBranchConditional %64 %65 %66
217 %69 = OpIAdd %11 %114 %33
220 %71 = OpIAdd %11 %116 %33
223 %74 = OpSLessThan %21 %71 %73
224 OpBranchConditional %74 %28 %30
226 %83 = OpAccessChain %82 %80 %12 %81
228 %85 = OpIEqual %21 %71 %84
229 OpSelectionMerge %87 None
230 OpBranchConditional %85 %86 %103
232 %90 = OpAccessChain %82 %80 %12 %33
234 %92 = OpConvertSToF %6 %91
235 %93 = OpAccessChain %82 %80 %12 %12
237 %95 = OpConvertSToF %6 %94
238 %102 = OpCompositeConstruct %57 %92 %95 %95 %92
242 %104 = OpAccessChain %82 %80 %12 %12
243 %105 = OpLoad %11 %104
244 %106 = OpConvertSToF %6 %105
245 %107 = OpCompositeConstruct %57 %106 %106 %106 %106
255 # uniforms for variant
258 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
261 # _GLF_uniform_int_values
262 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
266 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
268 PIPELINE graphics variant_pipeline
269 ATTACH variant_vertex_shader
270 ATTACH variant_fragment_shader
271 FRAMEBUFFER_SIZE 32 32
272 BIND BUFFER variant_framebuffer AS color LOCATION 0
273 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
274 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
276 CLEAR_COLOR variant_pipeline 0 0 0 255
278 CLEAR variant_pipeline
279 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
281 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255