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'
29 # '--combine-access-chains'
30 # '--redundancy-elimination'
31 # '--eliminate-dead-branches'
32 # '--eliminate-dead-branches'
34 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
38 SHADER vertex variant_vertex_shader PASSTHROUGH
40 # variant_fragment_shader is derived from the following GLSL:
42 # #define _int_1 _GLF_uniform_int_values[0]
43 # #define _int_0 _GLF_uniform_int_values[1]
45 # precision highp float;
46 # precision highp int;
48 # // Contents of _GLF_uniform_int_values: [1, 0]
49 # layout(set = 0, binding = 0) uniform buf0
51 # int _GLF_uniform_int_values[2];
54 # const int _GLF_global_loop_bound = 10;
55 # int _GLF_global_loop_count = 0;
57 # layout(location = 0) out vec4 _GLF_color;
65 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
67 # _GLF_global_loop_count++;
69 # // Iterated nine times. 2 * a has no effect.
70 # for( i = _int_1; _GLF_global_loop_count < _GLF_global_loop_bound; 2 * a)
72 # _GLF_global_loop_count++;
86 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
90 # _GLF_color = vec4(_int_0);
93 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
96 ; Generator: Khronos Glslang Reference Front End; 10
100 %1 = OpExtInstImport "GLSL.std.450"
101 OpMemoryModel Logical GLSL450
102 OpEntryPoint Fragment %4 "main" %61
103 OpExecutionMode %4 OriginUpperLeft
107 OpName %11 "_GLF_global_loop_count"
111 OpMemberName %31 0 "_GLF_uniform_int_values"
113 OpName %61 "_GLF_color"
114 OpDecorate %30 ArrayStride 16
115 OpMemberDecorate %31 0 Offset 0
117 OpDecorate %33 DescriptorSet 0
118 OpDecorate %33 Binding 0
119 OpDecorate %61 Location 0
121 %3 = OpTypeFunction %2
123 %7 = OpTypeFunction %6
124 %10 = OpTypePointer Private %6
125 %11 = OpVariable %10 Private
126 %12 = OpConstant %6 0
127 %13 = OpTypePointer Function %6
128 %15 = OpConstant %6 1
129 %23 = OpConstant %6 10
132 %29 = OpConstant %28 2
133 %30 = OpTypeArray %6 %29
134 %31 = OpTypeStruct %30
135 %32 = OpTypePointer Uniform %31
136 %33 = OpVariable %32 Uniform
137 %34 = OpTypePointer Uniform %6
138 %48 = OpConstant %6 2
140 %59 = OpTypeVector %58 4
141 %60 = OpTypePointer Output %59
142 %61 = OpVariable %60 Output
143 %4 = OpFunction %2 None %3
146 %54 = OpFunctionCall %6 %8
147 %55 = OpIEqual %24 %54 %23
148 OpSelectionMerge %57 None
149 OpBranchConditional %55 %56 %75
151 %62 = OpAccessChain %34 %33 %12 %12
153 %64 = OpConvertSToF %58 %63
154 %65 = OpAccessChain %34 %33 %12 %15
156 %67 = OpConvertSToF %58 %66
157 %74 = OpCompositeConstruct %59 %64 %67 %67 %64
161 %76 = OpAccessChain %34 %33 %12 %15
163 %78 = OpConvertSToF %58 %77
164 %79 = OpCompositeConstruct %59 %78 %78 %78 %78
170 %8 = OpFunction %6 None %7
172 %14 = OpVariable %13 Function
173 %16 = OpVariable %13 Function
178 %80 = OpPhi %6 %15 %9 %81 %20
179 %83 = OpPhi %6 %15 %9 %83 %20
181 %25 = OpSLessThan %24 %22 %23
182 OpLoopMerge %19 %20 None
183 OpBranchConditional %25 %18 %19
186 %27 = OpIAdd %6 %26 %15
188 %35 = OpAccessChain %34 %33 %12 %12
193 %81 = OpPhi %6 %36 %18 %47 %38
195 %43 = OpSLessThan %24 %42 %23
196 OpLoopMerge %39 %38 None
197 OpBranchConditional %43 %38 %39
200 %45 = OpIAdd %6 %44 %15
202 %47 = OpIAdd %6 %81 %15
204 %50 = OpIMul %6 %48 %83
215 # uniforms for variant
217 # _GLF_uniform_int_values
218 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
222 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
224 PIPELINE graphics variant_pipeline
225 ATTACH variant_vertex_shader
226 ATTACH variant_fragment_shader
227 FRAMEBUFFER_SIZE 32 32
228 BIND BUFFER variant_framebuffer AS color LOCATION 0
229 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
231 CLEAR_COLOR variant_pipeline 0 0 0 255
233 CLEAR variant_pipeline
234 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
236 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255