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:
29 # #define _GLF_MAKE_IN_BOUNDS_INT(IDX, SZ) clamp(IDX, 0, SZ - 1)
31 # #define _int_1 _GLF_uniform_int_values[0]
32 # #define _int_16 _GLF_uniform_int_values[1]
33 # #define _int_128 _GLF_uniform_int_values[2]
34 # #define _int_0 _GLF_uniform_int_values[3]
36 # precision highp float;
37 # precision highp int;
39 # // Contents of _GLF_uniform_int_values: [1, 16, 128, 0]
40 # layout(set = 0, binding = 0) uniform buf0
42 # int _GLF_uniform_int_values[4];
45 # const int _GLF_global_loop_bound = 10;
46 # int _GLF_global_loop_count = 0;
48 # layout(location = 0) out vec4 _GLF_color;
50 # int arr[128] = int[128](1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
57 # _GLF_global_loop_count++;
62 # if(arr[_GLF_MAKE_IN_BOUNDS_INT(_int_1, 128)] == _int_1)
68 # if(arr[_GLF_MAKE_IN_BOUNDS_INT(_int_1, 128)] == _int_1)
70 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
72 # _GLF_global_loop_count ++;
78 # if(arr[_GLF_MAKE_IN_BOUNDS_INT(_int_1, 128)] == _int_1)
86 # arr[_GLF_MAKE_IN_BOUNDS_INT(_int_16, 128)] = _int_0;
90 # if(arr[_GLF_MAKE_IN_BOUNDS_INT(clamp(int(gl_FragCoord.y), _int_0, _int_128 - _int_1), 128)] == _int_0)
95 # while(_GLF_global_loop_count < _GLF_global_loop_bound);
97 # if(arr[_GLF_MAKE_IN_BOUNDS_INT(_int_16, 128)] == _int_1)
99 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
103 # _GLF_color = vec4(_int_0);
106 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
109 ; Generator: Khronos Glslang Reference Front End; 10
113 %1 = OpExtInstImport "GLSL.std.450"
114 OpMemoryModel Logical GLSL450
115 OpEntryPoint Fragment %4 "main" %93 %130
116 OpExecutionMode %4 OriginUpperLeft
119 OpName %8 "_GLF_global_loop_count"
123 OpMemberName %27 0 "_GLF_uniform_int_values"
125 OpName %93 "gl_FragCoord"
126 OpName %130 "_GLF_color"
127 OpDecorate %26 ArrayStride 16
128 OpMemberDecorate %27 0 Offset 0
130 OpDecorate %29 DescriptorSet 0
131 OpDecorate %29 Binding 0
132 OpDecorate %93 BuiltIn FragCoord
133 OpDecorate %130 Location 0
135 %3 = OpTypeFunction %2
137 %7 = OpTypePointer Private %6
138 %8 = OpVariable %7 Private
141 %11 = OpConstant %10 128
142 %12 = OpTypeArray %6 %11
143 %13 = OpTypePointer Private %12
144 %14 = OpVariable %13 Private
145 %15 = OpConstant %6 1
146 %16 = OpConstantComposite %12 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15 %15
147 %23 = OpTypePointer Function %6
148 %25 = OpConstant %10 4
149 %26 = OpTypeArray %6 %25
150 %27 = OpTypeStruct %26
151 %28 = OpTypePointer Uniform %27
152 %29 = OpVariable %28 Uniform
153 %30 = OpTypePointer Uniform %6
154 %33 = OpConstant %6 127
156 %61 = OpConstant %6 10
157 %86 = OpConstant %6 3
159 %91 = OpTypeVector %90 4
160 %92 = OpTypePointer Input %91
161 %93 = OpVariable %92 Input
162 %94 = OpConstant %10 1
163 %95 = OpTypePointer Input %90
164 %101 = OpConstant %6 2
165 %129 = OpTypePointer Output %91
166 %130 = OpVariable %129 Output
167 %4 = OpFunction %2 None %3
169 %24 = OpVariable %23 Function
174 OpLoopMerge %19 %20 None
178 %22 = OpIAdd %6 %21 %15
181 %31 = OpAccessChain %30 %29 %9 %9
183 %34 = OpExtInst %6 %1 SClamp %32 %9 %33
184 %35 = OpAccessChain %7 %14 %34
186 %37 = OpAccessChain %30 %29 %9 %9
188 %40 = OpIEqual %39 %36 %38
189 OpSelectionMerge %42 None
190 OpBranchConditional %40 %41 %42
193 %44 = OpIAdd %6 %43 %15
197 %45 = OpAccessChain %30 %29 %9 %9
199 %47 = OpExtInst %6 %1 SClamp %46 %9 %33
200 %48 = OpAccessChain %7 %14 %47
202 %50 = OpAccessChain %30 %29 %9 %9
204 %52 = OpIEqual %39 %49 %51
205 OpSelectionMerge %54 None
206 OpBranchConditional %52 %53 %54
210 OpLoopMerge %57 %58 None
214 %62 = OpSLessThan %39 %60 %61
215 OpBranchConditional %62 %56 %57
218 %64 = OpIAdd %6 %63 %15
225 %66 = OpIAdd %6 %65 %15
229 %67 = OpAccessChain %30 %29 %9 %9
231 %69 = OpExtInst %6 %1 SClamp %68 %9 %33
232 %70 = OpAccessChain %7 %14 %69
234 %72 = OpAccessChain %30 %29 %9 %9
236 %74 = OpIEqual %39 %71 %73
237 OpSelectionMerge %76 None
238 OpBranchConditional %74 %75 %76
241 %78 = OpIAdd %6 %77 %15
246 %80 = OpIEqual %39 %79 %9
247 OpSelectionMerge %82 None
248 OpBranchConditional %80 %81 %82
250 %83 = OpAccessChain %30 %29 %9 %15
252 %85 = OpExtInst %6 %1 SClamp %84 %9 %33
253 %87 = OpAccessChain %30 %29 %9 %86
255 %89 = OpAccessChain %7 %14 %85
259 %96 = OpAccessChain %95 %93 %94
261 %98 = OpConvertFToS %6 %97
262 %99 = OpAccessChain %30 %29 %9 %86
264 %102 = OpAccessChain %30 %29 %9 %101
265 %103 = OpLoad %6 %102
266 %104 = OpAccessChain %30 %29 %9 %9
267 %105 = OpLoad %6 %104
268 %106 = OpISub %6 %103 %105
269 %107 = OpExtInst %6 %1 SClamp %98 %100 %106
270 %108 = OpExtInst %6 %1 SClamp %107 %9 %33
271 %109 = OpAccessChain %7 %14 %108
272 %110 = OpLoad %6 %109
273 %111 = OpAccessChain %30 %29 %9 %86
274 %112 = OpLoad %6 %111
275 %113 = OpIEqual %39 %110 %112
276 OpSelectionMerge %115 None
277 OpBranchConditional %113 %114 %115
284 %118 = OpSLessThan %39 %117 %61
285 OpBranchConditional %118 %17 %19
287 %119 = OpAccessChain %30 %29 %9 %15
288 %120 = OpLoad %6 %119
289 %121 = OpExtInst %6 %1 SClamp %120 %9 %33
290 %122 = OpAccessChain %7 %14 %121
291 %123 = OpLoad %6 %122
292 %124 = OpAccessChain %30 %29 %9 %9
293 %125 = OpLoad %6 %124
294 %126 = OpIEqual %39 %123 %125
295 OpSelectionMerge %128 None
296 OpBranchConditional %126 %127 %144
298 %131 = OpAccessChain %30 %29 %9 %9
299 %132 = OpLoad %6 %131
300 %133 = OpConvertSToF %90 %132
301 %134 = OpAccessChain %30 %29 %9 %86
302 %135 = OpLoad %6 %134
303 %136 = OpConvertSToF %90 %135
304 %137 = OpAccessChain %30 %29 %9 %86
305 %138 = OpLoad %6 %137
306 %139 = OpConvertSToF %90 %138
307 %140 = OpAccessChain %30 %29 %9 %9
308 %141 = OpLoad %6 %140
309 %142 = OpConvertSToF %90 %141
310 %143 = OpCompositeConstruct %91 %133 %136 %139 %142
314 %145 = OpAccessChain %30 %29 %9 %86
315 %146 = OpLoad %6 %145
316 %147 = OpConvertSToF %90 %146
317 %148 = OpCompositeConstruct %91 %147 %147 %147 %147
325 # uniforms for variant
327 # _GLF_uniform_int_values
328 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
332 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
334 PIPELINE graphics variant_pipeline
335 ATTACH variant_vertex_shader
336 ATTACH variant_fragment_shader
337 FRAMEBUFFER_SIZE 16 16
338 BIND BUFFER variant_framebuffer AS color LOCATION 0
339 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
341 CLEAR_COLOR variant_pipeline 0 0 0 255
343 CLEAR variant_pipeline
344 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
346 EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255