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 NIR 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 gl_FragCoord.x * (1.0 / 256.0),
36 (int(gl_FragCoord.x) ^ int(gl_FragCoord.y)) * (1.0 / 256.0),
37 gl_FragCoord.y * (1.0 / 256.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:
59 # #define _int_1 _GLF_uniform_int_values[0]
60 # #define _int_0 _GLF_uniform_int_values[1]
61 # #define _float_1_0 _GLF_uniform_float_values[0]
63 # precision highp float;
64 # precision highp int;
66 # // Contents of _GLF_uniform_float_values: 1.0
67 # layout(set = 0, binding = 0) uniform buf0
69 # float _GLF_uniform_float_values[1];
71 # // Contents of _GLF_uniform_int_values: [1, 0]
72 # layout(set = 0, binding = 1) uniform buf1
74 # int _GLF_uniform_int_values[2];
77 # layout(location = 0) out vec4 _GLF_color;
78 # layout(set = 0, binding = 2) uniform sampler2D tex;
82 # const float arr[9] = float[9](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
83 # vec2 coord = gl_FragCoord.xy;
84 # vec4 res = vec4(_int_1, _int_0, _int_0, _int_1);
86 # for (int i = 0; i < 3; i++)
88 # for (int j = 0; j < 3; j++)
90 # int a = clamp(i + j, 0, 9);
91 # // f0 and f1 are guaranteed to get the value 0.0.
92 # float f0 = clamp(arr[a], arr[a], arr[a]);
93 # float f1 = clamp(arr[a], arr[a], arr[a]);
94 # // v0 = (0, 0, 0, 0) due to f0 being zero.
96 # // v1, v2, v3, v4 all become (0, 0, 0, 0) due to multiplication by zero.
97 # vec4 v1 = texture(tex, vec2(i)) * f1;
98 # vec4 v2 = texture(tex, coord) * arr[a];
99 # vec4 v3 = texture(tex, coord) * arr[a];
100 # vec4 v4 = texture(tex, coord + vec2(i - _int_1, j - _int_1)) * arr[a];
102 # // v5 becomes (0, 0, 0, 0) since the min function picks v2.
103 # vec4 v5 = min(vec4(1.0), v2);
104 # // v6 also becomes (0, 0, 0, 0) because both v3 and v5 are zero vectors.
105 # vec4 v6 = min(v3, v5);
107 # // The min chain simplifies to min(vec4(1.0), vec4(0.0)) which results
108 # // in zero vector. Thus the += operation has no effect.
109 # res += min(min(min(v0, v1), v6) + vec4(_float_1_0), v4);
113 # // res is originally red, and it has only zero vector added to it, so the
114 # // output color will be red too.
117 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
120 ; Generator: Khronos Glslang Reference Front End; 10
124 %1 = OpExtInstImport "GLSL.std.450"
125 OpMemoryModel Logical GLSL450
126 OpEntryPoint Fragment %4 "main" %12 %186
127 OpExecutionMode %4 OriginUpperLeft
131 OpName %12 "gl_FragCoord"
134 OpMemberName %21 0 "_GLF_uniform_int_values"
140 OpName %73 "indexable"
141 OpName %77 "indexable"
142 OpName %81 "indexable"
144 OpName %87 "indexable"
145 OpName %91 "indexable"
146 OpName %95 "indexable"
151 OpName %119 "indexable"
153 OpName %128 "indexable"
155 OpName %149 "indexable"
159 OpMemberName %169 0 "_GLF_uniform_float_values"
161 OpName %186 "_GLF_color"
162 OpDecorate %12 BuiltIn FragCoord
163 OpDecorate %20 ArrayStride 16
164 OpMemberDecorate %21 0 Offset 0
166 OpDecorate %23 DescriptorSet 0
167 OpDecorate %23 Binding 1
168 OpDecorate %106 RelaxedPrecision
169 OpDecorate %106 DescriptorSet 0
170 OpDecorate %106 Binding 2
171 OpDecorate %107 RelaxedPrecision
172 OpDecorate %109 RelaxedPrecision
173 OpDecorate %110 RelaxedPrecision
174 OpDecorate %111 RelaxedPrecision
175 OpDecorate %115 RelaxedPrecision
176 OpDecorate %117 RelaxedPrecision
177 OpDecorate %124 RelaxedPrecision
178 OpDecorate %126 RelaxedPrecision
179 OpDecorate %133 RelaxedPrecision
180 OpDecorate %147 RelaxedPrecision
181 OpDecorate %168 ArrayStride 16
182 OpMemberDecorate %169 0 Offset 0
183 OpDecorate %169 Block
184 OpDecorate %171 DescriptorSet 0
185 OpDecorate %171 Binding 0
186 OpDecorate %186 Location 0
188 %3 = OpTypeFunction %2
190 %7 = OpTypeVector %6 2
191 %8 = OpTypePointer Function %7
192 %10 = OpTypeVector %6 4
193 %11 = OpTypePointer Input %10
194 %12 = OpVariable %11 Input
195 %15 = OpTypePointer Function %10
198 %19 = OpConstant %18 2
199 %20 = OpTypeArray %17 %19
200 %21 = OpTypeStruct %20
201 %22 = OpTypePointer Uniform %21
202 %23 = OpVariable %22 Uniform
203 %24 = OpConstant %17 0
204 %25 = OpTypePointer Uniform %17
205 %29 = OpConstant %17 1
206 %40 = OpTypePointer Function %17
207 %48 = OpConstant %17 3
209 %63 = OpConstant %17 9
210 %65 = OpTypePointer Function %6
211 %67 = OpConstant %18 9
212 %68 = OpTypeArray %6 %67
213 %69 = OpConstant %6 0
214 %70 = OpConstantComposite %68 %69 %69 %69 %69 %69 %69 %69 %69 %69
215 %72 = OpTypePointer Function %68
216 %103 = OpTypeImage %6 2D 0 0 0 1 Unknown
217 %104 = OpTypeSampledImage %103
218 %105 = OpTypePointer UniformConstant %104
219 %106 = OpVariable %105 UniformConstant
220 %154 = OpConstant %6 1
221 %155 = OpConstantComposite %10 %154 %154 %154 %154
222 %167 = OpConstant %18 1
223 %168 = OpTypeArray %6 %167
224 %169 = OpTypeStruct %168
225 %170 = OpTypePointer Uniform %169
226 %171 = OpVariable %170 Uniform
227 %172 = OpTypePointer Uniform %6
228 %185 = OpTypePointer Output %10
229 %186 = OpVariable %185 Output
230 %4 = OpFunction %2 None %3
232 %9 = OpVariable %8 Function
233 %16 = OpVariable %15 Function
234 %41 = OpVariable %40 Function
235 %51 = OpVariable %40 Function
236 %59 = OpVariable %40 Function
237 %66 = OpVariable %65 Function
238 %73 = OpVariable %72 Function
239 %77 = OpVariable %72 Function
240 %81 = OpVariable %72 Function
241 %85 = OpVariable %65 Function
242 %87 = OpVariable %72 Function
243 %91 = OpVariable %72 Function
244 %95 = OpVariable %72 Function
245 %99 = OpVariable %15 Function
246 %102 = OpVariable %15 Function
247 %114 = OpVariable %15 Function
248 %119 = OpVariable %72 Function
249 %123 = OpVariable %15 Function
250 %128 = OpVariable %72 Function
251 %132 = OpVariable %15 Function
252 %149 = OpVariable %72 Function
253 %153 = OpVariable %15 Function
254 %158 = OpVariable %15 Function
256 %14 = OpVectorShuffle %7 %13 %13 0 1
258 %26 = OpAccessChain %25 %23 %24 %24
260 %28 = OpConvertSToF %6 %27
261 %30 = OpAccessChain %25 %23 %24 %29
263 %32 = OpConvertSToF %6 %31
264 %33 = OpAccessChain %25 %23 %24 %29
266 %35 = OpConvertSToF %6 %34
267 %36 = OpAccessChain %25 %23 %24 %24
269 %38 = OpConvertSToF %6 %37
270 %39 = OpCompositeConstruct %10 %28 %32 %35 %38
275 OpLoopMerge %44 %45 None
279 %50 = OpSLessThan %49 %47 %48
280 OpBranchConditional %50 %43 %44
285 OpLoopMerge %54 %55 None
289 %58 = OpSLessThan %49 %57 %48
290 OpBranchConditional %58 %53 %54
294 %62 = OpIAdd %17 %60 %61
295 %64 = OpExtInst %17 %1 SClamp %62 %24 %63
299 %74 = OpAccessChain %65 %73 %71
303 %78 = OpAccessChain %65 %77 %76
307 %82 = OpAccessChain %65 %81 %80
309 %84 = OpExtInst %6 %1 FClamp %75 %79 %83
313 %88 = OpAccessChain %65 %87 %86
317 %92 = OpAccessChain %65 %91 %90
321 %96 = OpAccessChain %65 %95 %94
323 %98 = OpExtInst %6 %1 FClamp %89 %93 %97
326 %101 = OpCompositeConstruct %10 %100 %100 %100 %100
328 %107 = OpLoad %104 %106
329 %108 = OpLoad %17 %41
330 %109 = OpConvertSToF %6 %108
331 %110 = OpCompositeConstruct %7 %109 %109
332 %111 = OpImageSampleImplicitLod %10 %107 %110
334 %113 = OpVectorTimesScalar %10 %111 %112
336 %115 = OpLoad %104 %106
338 %117 = OpImageSampleImplicitLod %10 %115 %116
339 %118 = OpLoad %17 %59
341 %120 = OpAccessChain %65 %119 %118
342 %121 = OpLoad %6 %120
343 %122 = OpVectorTimesScalar %10 %117 %121
345 %124 = OpLoad %104 %106
347 %126 = OpImageSampleImplicitLod %10 %124 %125
348 %127 = OpLoad %17 %59
350 %129 = OpAccessChain %65 %128 %127
351 %130 = OpLoad %6 %129
352 %131 = OpVectorTimesScalar %10 %126 %130
354 %133 = OpLoad %104 %106
356 %135 = OpLoad %17 %41
357 %136 = OpAccessChain %25 %23 %24 %24
358 %137 = OpLoad %17 %136
359 %138 = OpISub %17 %135 %137
360 %139 = OpConvertSToF %6 %138
361 %140 = OpLoad %17 %51
362 %141 = OpAccessChain %25 %23 %24 %24
363 %142 = OpLoad %17 %141
364 %143 = OpISub %17 %140 %142
365 %144 = OpConvertSToF %6 %143
366 %145 = OpCompositeConstruct %7 %139 %144
367 %146 = OpFAdd %7 %134 %145
368 %147 = OpImageSampleImplicitLod %10 %133 %146
369 %148 = OpLoad %17 %59
371 %150 = OpAccessChain %65 %149 %148
372 %151 = OpLoad %6 %150
373 %152 = OpVectorTimesScalar %10 %147 %151
375 %156 = OpLoad %10 %114
376 %157 = OpExtInst %10 %1 FMin %155 %156
378 %159 = OpLoad %10 %123
379 %160 = OpLoad %10 %153
380 %161 = OpExtInst %10 %1 FMin %159 %160
382 %162 = OpLoad %10 %99
383 %163 = OpLoad %10 %102
384 %164 = OpExtInst %10 %1 FMin %162 %163
385 %165 = OpLoad %10 %158
386 %166 = OpExtInst %10 %1 FMin %164 %165
387 %173 = OpAccessChain %172 %171 %24 %24
388 %174 = OpLoad %6 %173
389 %175 = OpCompositeConstruct %10 %174 %174 %174 %174
390 %176 = OpFAdd %10 %166 %175
391 %177 = OpLoad %10 %132
392 %178 = OpExtInst %10 %1 FMin %176 %177
393 %179 = OpLoad %10 %16
394 %180 = OpFAdd %10 %179 %178
398 %181 = OpLoad %17 %51
399 %182 = OpIAdd %17 %181 %29
405 %183 = OpLoad %17 %41
406 %184 = OpIAdd %17 %183 %29
410 %187 = OpLoad %10 %16
416 # uniforms for variant
421 # _GLF_uniform_int_values
422 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
425 # _GLF_uniform_float_values
426 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
430 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
432 PIPELINE graphics variant_pipeline
433 ATTACH variant_vertex_shader
434 ATTACH variant_fragment_shader
435 FRAMEBUFFER_SIZE 256 256
436 BIND BUFFER variant_framebuffer AS color LOCATION 0
437 BIND BUFFER default_texture AS combined_image_sampler SAMPLER variant_tex DESCRIPTOR_SET 0 BINDING 2
438 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
439 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
441 CLEAR_COLOR variant_pipeline 0 0 0 255
443 CLEAR variant_pipeline
444 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
446 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255