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:
35 # #define _int_1 _GLF_uniform_int_values[0]
36 # #define _int_0 _GLF_uniform_int_values[1]
37 # #define _float_1_0 _GLF_uniform_float_values[0]
38 # #define _float_0_0 _GLF_uniform_float_values[1]
40 # precision highp float;
41 # precision highp int;
43 # // Contents of _GLF_uniform_float_values: [1.0, 0.0]
44 # layout(set = 0, binding = 0) uniform buf0
46 # float _GLF_uniform_float_values[2];
49 # // Contents of _GLF_uniform_int_values: [1, 0]
50 # layout(set = 0, binding = 1) uniform buf1
52 # int _GLF_uniform_int_values[2];
55 # layout(location = 0) out vec4 _GLF_color;
57 # bool func(vec2 v0, vec4 v1)
60 # if(v1.y > _float_1_0)
66 # if(v0.x > ((gl_FragCoord.y < _float_0_0) ? v1.z : 4.3))
71 # // Always returns here.
77 # vec2 v0 = vec3(1.0, 7014.7640, 1.0) * mat2x3(1.0, -1.0, 1.0, _float_1_0, _float_1_0, _float_1_0);
78 # _GLF_color = vec4(_int_0);
80 # for(int i = 0; i < 5; i++)
83 # if(func(v0, vec4[5](vec4(1), vec4(_int_1), vec4(_int_1), vec4(_int_1), vec4(_int_1))[i]))
85 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
89 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
92 ; Generator: Khronos Glslang Reference Front End; 10
96 %1 = OpExtInstImport "GLSL.std.450"
97 OpMemoryModel Logical GLSL450
98 OpEntryPoint Fragment %4 "main" %41 %83
99 OpExecutionMode %4 OriginUpperLeft
103 OpMemberName %24 0 "_GLF_uniform_float_values"
105 OpName %41 "gl_FragCoord"
106 OpName %83 "_GLF_color"
108 OpMemberName %85 0 "_GLF_uniform_int_values"
110 OpName %128 "indexable"
111 OpDecorate %23 ArrayStride 16
112 OpMemberDecorate %24 0 Offset 0
114 OpDecorate %26 DescriptorSet 0
115 OpDecorate %26 Binding 0
116 OpDecorate %41 BuiltIn FragCoord
117 OpDecorate %83 Location 0
118 OpDecorate %84 ArrayStride 16
119 OpMemberDecorate %85 0 Offset 0
121 OpDecorate %87 DescriptorSet 0
122 OpDecorate %87 Binding 1
124 %3 = OpTypeFunction %2
126 %7 = OpTypeVector %6 2
127 %9 = OpTypeVector %6 4
128 %10 = OpTypePointer Function %9
131 %18 = OpConstant %17 1
132 %22 = OpConstant %17 2
133 %23 = OpTypeArray %6 %22
134 %24 = OpTypeStruct %23
135 %25 = OpTypePointer Uniform %24
136 %26 = OpVariable %25 Uniform
138 %28 = OpConstant %27 0
139 %29 = OpTypePointer Uniform %6
140 %35 = OpConstantTrue %11
141 %37 = OpConstant %17 0
142 %40 = OpTypePointer Input %9
143 %41 = OpVariable %40 Input
144 %42 = OpTypePointer Input %6
145 %45 = OpConstant %27 1
146 %55 = OpConstant %6 4.30000019
147 %60 = OpConstantFalse %11
148 %65 = OpTypeVector %6 3
149 %66 = OpConstant %6 1
150 %67 = OpConstant %6 7014.76416
151 %68 = OpConstantComposite %65 %66 %67 %66
152 %69 = OpConstant %6 -1
153 %76 = OpTypeMatrix %65 2
154 %82 = OpTypePointer Output %9
155 %83 = OpVariable %82 Output
156 %84 = OpTypeArray %27 %22
157 %85 = OpTypeStruct %84
158 %86 = OpTypePointer Uniform %85
159 %87 = OpVariable %86 Uniform
160 %88 = OpTypePointer Uniform %27
161 %101 = OpConstant %27 5
162 %103 = OpConstantComposite %9 %66 %66 %66 %66
163 %120 = OpConstant %17 5
164 %121 = OpTypeArray %9 %120
165 %127 = OpTypePointer Function %121
166 %195 = OpConstantComposite %65 %66 %69 %66
167 %4 = OpFunction %2 None %3
169 %128 = OpVariable %127 Function
170 %70 = OpAccessChain %29 %26 %28 %28
172 %79 = OpCompositeConstruct %65 %71 %71 %71
173 %80 = OpCompositeConstruct %76 %195 %79
174 %81 = OpVectorTimesMatrix %7 %68 %80
175 %89 = OpAccessChain %88 %87 %28 %45
177 %91 = OpConvertSToF %6 %90
178 %92 = OpCompositeConstruct %9 %91 %91 %91 %91
182 %189 = OpPhi %27 %28 %5 %148 %98
183 %102 = OpSLessThan %11 %189 %101
184 OpLoopMerge %97 %98 None
185 OpBranchConditional %102 %96 %97
187 %104 = OpAccessChain %88 %87 %28 %28
188 %105 = OpLoad %27 %104
189 %106 = OpConvertSToF %6 %105
190 %107 = OpCompositeConstruct %9 %106 %106 %106 %106
191 %122 = OpCompositeConstruct %121 %103 %107 %107 %107 %107
193 %129 = OpAccessChain %10 %128 %189
194 %130 = OpLoad %9 %129
195 OpSelectionMerge %184 None
198 %162 = OpCompositeExtract %6 %130 1
199 %165 = OpFOrdGreaterThan %11 %162 %71
200 OpSelectionMerge %167 None
201 OpBranchConditional %165 %166 %167
205 %169 = OpCompositeExtract %6 %81 0
206 %170 = OpAccessChain %42 %41 %18
207 %171 = OpLoad %6 %170
208 %172 = OpAccessChain %29 %26 %28 %45
209 %173 = OpLoad %6 %172
210 %174 = OpFOrdLessThan %11 %171 %173
211 OpSelectionMerge %179 None
212 OpBranchConditional %174 %175 %178
214 %177 = OpCompositeExtract %6 %130 2
219 %190 = OpPhi %6 %177 %175 %55 %178
220 %181 = OpFOrdGreaterThan %11 %169 %190
221 OpSelectionMerge %183 None
222 OpBranchConditional %181 %182 %183
228 %191 = OpPhi %11 %35 %166 %60 %182 %35 %183
229 OpSelectionMerge %133 None
230 OpBranchConditional %191 %132 %133
232 %146 = OpCompositeConstruct %9 %106 %91 %91 %106
238 %148 = OpIAdd %27 %189 %45
245 # uniforms for variant
247 # _GLF_uniform_int_values
248 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
251 # _GLF_uniform_float_values
252 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
256 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
258 PIPELINE graphics variant_pipeline
259 ATTACH variant_vertex_shader
260 ATTACH variant_fragment_shader
261 FRAMEBUFFER_SIZE 32 32
262 BIND BUFFER variant_framebuffer AS color LOCATION 0
263 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
264 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
266 CLEAR_COLOR variant_pipeline 0 0 0 255
268 CLEAR variant_pipeline
269 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
271 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255