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:
27 # '--convert-local-access-chains'
28 # '--eliminate-dead-branches'
30 # '--eliminate-dead-branches'
32 # '--private-to-local'
33 # '--eliminate-dead-branches'
34 # '--eliminate-dead-branches'
36 # '--eliminate-local-multi-store'
37 # '--eliminate-dead-inserts'
38 # '--simplify-instructions'
39 # '--redundancy-elimination'
40 # '--simplify-instructions'
41 # '--copy-propagate-arrays'
42 # '--eliminate-local-single-block'
43 # '--convert-local-access-chains'
44 # '--eliminate-local-single-store'
45 # '--eliminate-dead-code-aggressive'
46 # '--eliminate-local-single-store'
47 # '--reduce-load-size'
48 # '--eliminate-dead-branches'
49 # '--simplify-instructions'
50 # '--eliminate-dead-branches'
52 # '--inline-entry-points-exhaustive'
53 # '--eliminate-dead-branches'
55 # '--eliminate-dead-inserts'
56 # '--eliminate-dead-branches'
57 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
61 SHADER vertex variant_vertex_shader PASSTHROUGH
63 # variant_fragment_shader is derived from the following GLSL:
66 # #define _int_1 _GLF_uniform_int_values[0]
67 # #define _int_0 _GLF_uniform_int_values[1]
68 # #define _int_5 _GLF_uniform_int_values[2]
69 # #define _int_3 _GLF_uniform_int_values[3]
70 # #define _float_0_0 _GLF_uniform_float_values[0]
72 # precision highp float;
73 # precision highp int;
75 # // Contents of _GLF_uniform_float_values: 0.0
76 # layout(set = 0, binding = 0) uniform buf0
78 # float _GLF_uniform_float_values[1];
81 # // Contents of _GLF_uniform_int_values: [1, 0, 5, 3]
82 # layout(set = 0, binding = 1) uniform buf1
84 # int _GLF_uniform_int_values[4];
87 # layout(location = 0) out vec4 _GLF_color;
91 # ivec4 v = ivec4(_int_5);
93 # // Iterates three times.
94 # for(int k = 1; k < 4; k++)
96 # for(int b = 4; b >= k; b--)
99 # if(gl_FragCoord.x < 0.0)
106 # if(gl_FragCoord.x < 0.0)
111 # v[_int_1] = _int_1;
114 # // At this point v is (5, 1, 5, 5).
116 # for(int i = _int_1; i >= 0; i--)
118 # for(int j = _int_3; j >= i + _int_1; j--)
120 # // This is iterated with (i, j) pairs of (1, 3), (1, 2), (0, 3), (0, 2), (0, 1).
126 # if(v == ivec4(_int_5, _int_0, _int_3, _int_3))
128 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
132 # _GLF_color = vec4(_int_0);
135 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
138 ; Generator: Khronos Glslang Reference Front End; 10
142 %1 = OpExtInstImport "GLSL.std.450"
143 OpMemoryModel Logical GLSL450
144 OpEntryPoint Fragment %4 "main" %46 %120
145 OpExecutionMode %4 OriginUpperLeft
150 OpMemberName %13 0 "_GLF_uniform_int_values"
152 OpName %46 "gl_FragCoord"
153 OpName %120 "_GLF_color"
154 OpDecorate %12 ArrayStride 16
155 OpMemberDecorate %13 0 Offset 0
157 OpDecorate %15 DescriptorSet 0
158 OpDecorate %15 Binding 1
159 OpDecorate %46 BuiltIn FragCoord
160 OpDecorate %120 Location 0
162 %3 = OpTypeFunction %2
164 %7 = OpTypeVector %6 4
165 %8 = OpTypePointer Function %7
167 %11 = OpConstant %10 4
168 %12 = OpTypeArray %6 %11
169 %13 = OpTypeStruct %12
170 %14 = OpTypePointer Uniform %13
171 %15 = OpVariable %14 Uniform
172 %16 = OpConstant %6 0
173 %17 = OpConstant %6 2
174 %18 = OpTypePointer Uniform %6
175 %22 = OpTypePointer Function %6
176 %24 = OpConstant %6 1
177 %31 = OpConstant %6 4
180 %44 = OpTypeVector %43 4
181 %45 = OpTypePointer Input %44
182 %46 = OpVariable %45 Input
183 %47 = OpConstant %10 0
184 %48 = OpTypePointer Input %43
185 %51 = OpConstant %43 0
186 %82 = OpConstant %6 3
187 %114 = OpTypeVector %32 4
188 %119 = OpTypePointer Output %44
189 %120 = OpVariable %119 Output
190 %152 = OpConstantFalse %32
191 %153 = OpTypePointer Function %32
192 %155 = OpConstantTrue %32
193 %4 = OpFunction %2 None %3
195 %154 = OpVariable %153 Function %152
196 %9 = OpVariable %8 Function
197 OpSelectionMerge %150 None
200 %19 = OpAccessChain %18 %15 %16 %17
202 %21 = OpCompositeConstruct %7 %20 %20 %20 %20
206 %144 = OpPhi %6 %24 %151 %70 %28
207 %33 = OpSLessThan %32 %144 %31
208 OpLoopMerge %27 %28 None
209 OpBranchConditional %33 %26 %27
213 %148 = OpPhi %6 %31 %26 %57 %38
214 %42 = OpSGreaterThanEqual %32 %148 %144
215 OpLoopMerge %37 %38 None
216 OpBranchConditional %42 %36 %37
218 %49 = OpAccessChain %48 %46 %47
220 %52 = OpFOrdLessThan %32 %50 %51
221 OpSelectionMerge %54 None
222 OpBranchConditional %52 %53 %54
229 %57 = OpISub %6 %148 %24
232 %157 = OpLoad %32 %154
233 OpSelectionMerge %156 None
234 OpBranchConditional %157 %27 %156
236 %58 = OpAccessChain %48 %46 %47
238 %60 = OpFOrdLessThan %32 %59 %51
239 OpSelectionMerge %62 None
240 OpBranchConditional %60 %61 %62
245 %64 = OpAccessChain %18 %15 %16 %16
247 %68 = OpAccessChain %22 %9 %65
251 %70 = OpIAdd %6 %144 %24
254 %159 = OpLoad %32 %154
255 OpSelectionMerge %158 None
256 OpBranchConditional %159 %150 %158
258 %72 = OpAccessChain %18 %15 %16 %16
262 %145 = OpPhi %6 %73 %158 %103 %77
263 %80 = OpSGreaterThanEqual %32 %145 %16
264 OpLoopMerge %76 %77 None
265 OpBranchConditional %80 %75 %76
267 %83 = OpAccessChain %18 %15 %16 %82
271 %146 = OpPhi %6 %84 %75 %101 %86
272 %94 = OpIAdd %6 %145 %73
273 %95 = OpSGreaterThanEqual %32 %146 %94
274 OpLoopMerge %87 %86 None
275 OpBranchConditional %95 %86 %87
277 %97 = OpAccessChain %22 %9 %146
279 %99 = OpISub %6 %98 %24
281 %101 = OpISub %6 %146 %24
286 %103 = OpISub %6 %145 %24
290 %107 = OpAccessChain %18 %15 %16 %24
291 %108 = OpLoad %6 %107
292 %109 = OpAccessChain %18 %15 %16 %82
293 %110 = OpLoad %6 %109
294 %113 = OpCompositeConstruct %7 %20 %108 %110 %110
295 %115 = OpIEqual %114 %104 %113
296 %116 = OpAll %32 %115
297 OpSelectionMerge %118 None
298 OpBranchConditional %116 %117 %134
300 %123 = OpConvertSToF %43 %73
301 %126 = OpConvertSToF %43 %108
302 %133 = OpCompositeConstruct %44 %123 %126 %126 %123
306 %137 = OpConvertSToF %43 %108
307 %138 = OpCompositeConstruct %44 %137 %137 %137 %137
318 # uniforms for variant
320 # _GLF_uniform_int_values
321 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
324 # _GLF_uniform_float_values
325 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
329 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
331 PIPELINE graphics variant_pipeline
332 ATTACH variant_vertex_shader
333 ATTACH variant_fragment_shader
334 FRAMEBUFFER_SIZE 32 32
335 BIND BUFFER variant_framebuffer AS color LOCATION 0
336 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
337 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
339 CLEAR_COLOR variant_pipeline 0 0 0 255
341 CLEAR variant_pipeline
342 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
344 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255