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:
25 # '--copy-propagate-arrays'
26 # '--eliminate-local-multi-store'
28 # '--eliminate-local-single-block'
29 # '--eliminate-dead-inserts'
30 # '--redundancy-elimination'
31 # '--eliminate-local-single-store'
32 # '--eliminate-dead-code-aggressive'
33 # '--eliminate-dead-code-aggressive'
34 # '--redundancy-elimination'
35 # '--scalar-replacement=100'
36 # '--eliminate-local-multi-store'
37 # '--inline-entry-points-exhaustive'
38 # '--eliminate-dead-branches'
40 # '--eliminate-dead-branches'
43 # '--copy-propagate-arrays'
44 # '--combine-access-chains'
46 # '--private-to-local'
47 # '--reduce-load-size'
48 # '--scalar-replacement=100'
49 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
58 # #define _int_1 _GLF_uniform_int_values[0]
59 # #define _int_0 _GLF_uniform_int_values[1]
61 # precision highp float;
62 # precision highp int;
64 # // Contents of _GLF_uniform_int_values: [1, 0]
65 # layout(set = 0, binding = 0) uniform buf0
67 # int _GLF_uniform_int_values[2];
70 # const int _GLF_global_loop_bound = 10;
71 # int _GLF_global_loop_count = 0;
73 # layout(location = 0) out vec4 _GLF_color;
75 # int arr0[10] = int[10](1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
81 # int arr1[10] = int[10](_int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1);
83 # // Iterates ten times.
84 # while(b >= _int_0 && _GLF_global_loop_count < _GLF_global_loop_bound)
86 # _GLF_global_loop_count++;
88 # // Reads zero as an index and then decrements b to -1. Reads value one, so a stays at one.
91 # // arr0[1] = arr0[0]. No effect.
92 # arr0[_int_1] = arr0[a];
97 # // Increments b to zero and indexes with that. Writes one to arr1[0] but that value already existed.
109 # if(func() == _int_0)
111 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
115 # _GLF_color = vec4(_int_0);
118 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
121 ; Generator: Khronos Glslang Reference Front End; 10
125 %1 = OpExtInstImport "GLSL.std.450"
126 OpMemoryModel Logical GLSL450
127 OpEntryPoint Fragment %4 "main" %104
128 OpExecutionMode %4 OriginUpperLeft
132 OpName %11 "_GLF_global_loop_count"
135 OpMemberName %24 0 "_GLF_uniform_int_values"
138 OpName %104 "_GLF_color"
139 OpDecorate %23 ArrayStride 16
140 OpMemberDecorate %24 0 Offset 0
142 OpDecorate %26 DescriptorSet 0
143 OpDecorate %26 Binding 0
144 OpDecorate %104 Location 0
146 %3 = OpTypeFunction %2
148 %7 = OpTypeFunction %6
149 %10 = OpTypePointer Private %6
150 %11 = OpVariable %10 Private
151 %12 = OpConstant %6 0
153 %14 = OpConstant %13 10
154 %15 = OpTypeArray %6 %14
155 %16 = OpTypePointer Private %15
156 %17 = OpVariable %16 Private
157 %18 = OpConstant %6 1
158 %19 = OpConstantComposite %15 %18 %18 %18 %18 %18 %18 %18 %18 %18 %18
159 %20 = OpTypePointer Function %6
160 %22 = OpConstant %13 2
161 %23 = OpTypeArray %6 %22
162 %24 = OpTypeStruct %23
163 %25 = OpTypePointer Uniform %24
164 %26 = OpVariable %25 Uniform
165 %27 = OpTypePointer Uniform %6
166 %33 = OpTypePointer Function %15
168 %67 = OpConstant %6 10
169 %101 = OpTypeFloat 32
170 %102 = OpTypeVector %101 4
171 %103 = OpTypePointer Output %102
172 %104 = OpVariable %103 Output
173 %4 = OpFunction %2 None %3
175 %125 = OpVariable %33 Function
176 %126 = OpVariable %20 Function
179 %128 = OpAccessChain %27 %26 %12 %12
180 %129 = OpLoad %6 %128
181 %130 = OpAccessChain %27 %26 %12 %18
182 %131 = OpLoad %6 %130
183 %132 = OpCompositeConstruct %15 %129 %129 %129 %129 %129 %129 %129 %129 %129 %129
187 %134 = OpPhi %6 %131 %5 %154 %155
188 %136 = OpSGreaterThanEqual %64 %134 %131
190 %138 = OpSLessThan %64 %137 %67
191 %139 = OpLogicalAnd %64 %136 %138
192 OpLoopMerge %156 %155 None
193 OpBranchConditional %139 %140 %156
196 %142 = OpIAdd %6 %141 %18
198 %143 = OpISub %6 %134 %18
199 %144 = OpAccessChain %20 %125 %134
200 %145 = OpLoad %6 %144
201 %146 = OpAccessChain %10 %17 %145
202 %147 = OpLoad %6 %146
203 %148 = OpAccessChain %10 %17 %129
205 %149 = OpSGreaterThan %64 %145 %131
206 OpSelectionMerge %153 None
207 OpBranchConditional %149 %150 %153
209 %151 = OpIAdd %6 %143 %18
210 %152 = OpAccessChain %20 %125 %151
214 %154 = OpPhi %6 %143 %140 %151 %150
221 %96 = OpAccessChain %27 %26 %12 %18
223 %98 = OpIEqual %64 %95 %97
224 OpSelectionMerge %100 None
225 OpBranchConditional %98 %99 %118
227 %105 = OpAccessChain %27 %26 %12 %12
228 %106 = OpLoad %6 %105
229 %107 = OpConvertSToF %101 %106
230 %110 = OpConvertSToF %101 %97
231 %117 = OpCompositeConstruct %102 %107 %110 %110 %107
235 %121 = OpConvertSToF %101 %97
236 %122 = OpCompositeConstruct %102 %121 %121 %121 %121
242 %8 = OpFunction %6 None %7
244 %34 = OpVariable %33 Function
245 %28 = OpAccessChain %27 %26 %12 %12
247 %31 = OpAccessChain %27 %26 %12 %18
249 %55 = OpCompositeConstruct %15 %29 %29 %29 %29 %29 %29 %29 %29 %29 %29
253 %123 = OpPhi %6 %32 %9 %124 %59
254 OpLoopMerge %58 %59 None
257 %65 = OpSGreaterThanEqual %64 %123 %32
259 %68 = OpSLessThan %64 %66 %67
260 %69 = OpLogicalAnd %64 %65 %68
261 OpBranchConditional %69 %57 %58
264 %71 = OpIAdd %6 %70 %18
266 %73 = OpISub %6 %123 %18
267 %74 = OpAccessChain %20 %34 %123
269 %79 = OpAccessChain %10 %17 %75
271 %81 = OpAccessChain %10 %17 %29
273 %85 = OpSGreaterThan %64 %75 %32
274 OpSelectionMerge %87 None
275 OpBranchConditional %85 %86 %87
277 %89 = OpIAdd %6 %73 %18
278 %91 = OpAccessChain %20 %34 %89
282 %124 = OpPhi %6 %73 %57 %89 %86
291 # uniforms for variant
293 # _GLF_uniform_int_values
294 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
298 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
300 PIPELINE graphics variant_pipeline
301 ATTACH variant_vertex_shader
302 ATTACH variant_fragment_shader
303 FRAMEBUFFER_SIZE 32 32
304 BIND BUFFER variant_framebuffer AS color LOCATION 0
305 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
307 CLEAR_COLOR variant_pipeline 0 0 0 255
309 CLEAR variant_pipeline
310 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
312 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255