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 # Optimized using spirv-opt with the following arguments:
25 # '--scalar-replacement=100'
26 # '--eliminate-dead-inserts'
27 # '--eliminate-local-multi-store'
28 # '--convert-local-access-chains'
29 # '--eliminate-dead-branches'
31 # '--eliminate-dead-branches'
32 # '--eliminate-dead-branches'
34 # '--scalar-replacement=100'
35 # '--eliminate-dead-branches'
38 # '--eliminate-local-single-store'
39 # '--scalar-replacement=100'
40 # '--convert-local-access-chains'
42 # '--reduce-load-size'
43 # '--eliminate-dead-branches'
44 # '--eliminate-local-single-block'
45 # '--redundancy-elimination'
46 # '--combine-access-chains'
48 # '--inline-entry-points-exhaustive'
49 # '--scalar-replacement=100'
51 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
55 SHADER vertex variant_vertex_shader PASSTHROUGH
57 # 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]
62 # #define _float_0_5 _GLF_uniform_float_values[1]
64 # precision highp float;
65 # precision highp int;
67 # // Contents of _GLF_uniform_int_values: [1, 0]
68 # layout(set = 0, binding = 0) uniform buf0
70 # int _GLF_uniform_int_values[2];
73 # // Contents of _GLF_uniform_float_values: [1.0, 0.5]
74 # layout(set = 0, binding = 1) uniform buf1
76 # float _GLF_uniform_float_values[2];
79 # // Contents of one: [1.0, 1.0]
80 # layout(set = 0, binding = 2) uniform buf2
85 # layout(location = 0) out vec4 _GLF_color;
89 # float f = _float_1_0;
95 # for (int i = 0; i != clamp(_int_0, int(one.x), 2); i++)
97 # // Always chooses 2.0, thus f becomes 0.5.
98 # f /= one.y > _float_1_0 ? 256.0 : 2.0;
101 # while(_float_1_0 > one.y);
104 # if (f > _float_0_5 - 0.01 && f < _float_0_5 + 0.01)
106 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
110 # _GLF_color = vec4(_int_0);
113 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
116 ; Generator: Khronos Glslang Reference Front End; 10
120 %1 = OpExtInstImport "GLSL.std.450"
121 OpMemoryModel Logical GLSL450
122 OpEntryPoint Fragment %4 "main" %88
123 OpExecutionMode %4 OriginUpperLeft
128 OpMemberName %12 0 "_GLF_uniform_float_values"
132 OpMemberName %33 0 "_GLF_uniform_int_values"
135 OpMemberName %41 0 "one"
137 OpName %88 "_GLF_color"
138 OpDecorate %11 ArrayStride 16
139 OpMemberDecorate %12 0 Offset 0
141 OpDecorate %14 DescriptorSet 0
142 OpDecorate %14 Binding 1
143 OpDecorate %32 ArrayStride 16
144 OpMemberDecorate %33 0 Offset 0
146 OpDecorate %35 DescriptorSet 0
147 OpDecorate %35 Binding 0
148 OpMemberDecorate %41 0 Offset 0
150 OpDecorate %43 DescriptorSet 0
151 OpDecorate %43 Binding 2
152 OpDecorate %88 Location 0
154 %3 = OpTypeFunction %2
156 %7 = OpTypePointer Function %6
158 %10 = OpConstant %9 2
159 %11 = OpTypeArray %6 %10
160 %12 = OpTypeStruct %11
161 %13 = OpTypePointer Uniform %12
162 %14 = OpVariable %13 Uniform
164 %16 = OpConstant %15 0
165 %17 = OpTypePointer Uniform %6
166 %24 = OpTypePointer Function %15
167 %32 = OpTypeArray %15 %10
168 %33 = OpTypeStruct %32
169 %34 = OpTypePointer Uniform %33
170 %35 = OpVariable %34 Uniform
171 %36 = OpConstant %15 1
172 %37 = OpTypePointer Uniform %15
173 %40 = OpTypeVector %6 2
174 %41 = OpTypeStruct %40
175 %42 = OpTypePointer Uniform %41
176 %43 = OpVariable %42 Uniform
177 %44 = OpConstant %9 0
178 %48 = OpConstant %15 2
180 %52 = OpConstant %9 1
181 %58 = OpConstant %6 256
182 %59 = OpConstant %6 2
183 %73 = OpConstant %6 0.00999999978
184 %86 = OpTypeVector %6 4
185 %87 = OpTypePointer Output %86
186 %88 = OpVariable %87 Output
187 %4 = OpFunction %2 None %3
189 %8 = OpVariable %7 Function
190 %25 = OpVariable %24 Function
191 %18 = OpAccessChain %17 %14 %16 %16
196 %109 = OpPhi %6 %19 %5 %108 %23
198 OpLoopMerge %22 %23 None
201 %108 = OpPhi %6 %109 %20 %62 %27
202 %107 = OpPhi %15 %16 %20 %64 %27
203 %38 = OpAccessChain %37 %35 %16 %36
205 %45 = OpAccessChain %17 %43 %16 %44
207 %47 = OpConvertFToS %15 %46
208 %49 = OpExtInst %15 %1 SClamp %39 %47 %48
209 %51 = OpINotEqual %50 %107 %49
210 OpLoopMerge %28 %27 None
211 OpBranchConditional %51 %27 %28
213 %53 = OpAccessChain %17 %43 %16 %52
215 %57 = OpFOrdGreaterThan %50 %54 %19
216 %60 = OpSelect %6 %57 %58 %59
217 %62 = OpFDiv %6 %108 %60
219 %64 = OpIAdd %15 %107 %36
225 %67 = OpAccessChain %17 %43 %16 %52
227 %69 = OpFOrdGreaterThan %50 %19 %68
228 OpBranchConditional %69 %20 %22
230 %71 = OpAccessChain %17 %14 %16 %36
232 %74 = OpFSub %6 %72 %73
233 %75 = OpFOrdGreaterThan %50 %108 %74
234 OpSelectionMerge %77 None
235 OpBranchConditional %75 %76 %77
237 %81 = OpFAdd %6 %72 %73
238 %82 = OpFOrdLessThan %50 %108 %81
241 %83 = OpPhi %50 %75 %22 %82 %76
242 OpSelectionMerge %85 None
243 OpBranchConditional %83 %84 %102
245 %89 = OpAccessChain %37 %35 %16 %16
247 %91 = OpConvertSToF %6 %90
248 %94 = OpConvertSToF %6 %39
249 %101 = OpCompositeConstruct %86 %91 %94 %94 %91
253 %105 = OpConvertSToF %6 %39
254 %106 = OpCompositeConstruct %86 %105 %105 %105 %105
262 # uniforms for variant
265 BUFFER variant_one DATA_TYPE vec2<float> STD140 DATA
268 # _GLF_uniform_float_values
269 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
272 # _GLF_uniform_int_values
273 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
277 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
279 PIPELINE graphics variant_pipeline
280 ATTACH variant_vertex_shader
281 ATTACH variant_fragment_shader
282 FRAMEBUFFER_SIZE 256 256
283 BIND BUFFER variant_framebuffer AS color LOCATION 0
284 BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 2
285 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
286 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
288 CLEAR_COLOR variant_pipeline 0 0 0 255
290 CLEAR variant_pipeline
291 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
293 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255