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 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
29 # #define _int_0 _GLF_uniform_int_values[0]
30 # #define _int_1 _GLF_uniform_int_values[1]
31 # #define _float_0_0 _GLF_uniform_float_values[0]
33 # precision highp float;
34 # precision highp int;
36 # // Contents of _GLF_uniform_float_values: 0.0
37 # layout(set = 0, binding = 0) uniform buf0
39 # float _GLF_uniform_float_values[1];
42 # // Contents of _GLF_uniform_int_values: [0, 1]
43 # layout(set = 0, binding = 1) uniform buf1
45 # int _GLF_uniform_int_values[2];
48 # // Contents of injectionSwitch: [0.0, 1.0]
49 # layout(push_constant) uniform buf_push
51 # highp vec2 injectionSwitch;
54 # layout(location = 0) out vec4 _GLF_color;
56 # // Returns 0 or 1 as long as x >= 0.
69 # int a = int(gl_FragCoord.y);
75 # // Calls func with an argument of one or a positive integer based on gl_FragCoord. The return value is 0 or 1 which both index the red color.
76 # _GLF_color = vec4[4](vec4(_int_1, _int_0, _int_0, _int_1), vec4(_int_1, _int_0, _int_0, _int_1), vec4(_int_0), vec4(_int_0))[(injectionSwitch.y < _float_0_0) ? _int_1 : func(a)];
78 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
81 ; Generator: Khronos Glslang Reference Front End; 10
85 %1 = OpExtInstImport "GLSL.std.450"
86 OpMemoryModel Logical GLSL450
87 OpEntryPoint Fragment %4 "main" %31 %42
88 OpExecutionMode %4 OriginUpperLeft
94 OpName %31 "gl_FragCoord"
95 OpName %42 "_GLF_color"
97 OpMemberName %45 0 "_GLF_uniform_int_values"
100 OpMemberName %88 0 "injectionSwitch"
103 OpMemberName %95 0 "_GLF_uniform_float_values"
106 OpName %113 "indexable"
107 OpDecorate %31 BuiltIn FragCoord
108 OpDecorate %42 Location 0
109 OpDecorate %44 ArrayStride 16
110 OpMemberDecorate %45 0 Offset 0
112 OpDecorate %47 DescriptorSet 0
113 OpDecorate %47 Binding 1
114 OpMemberDecorate %88 0 Offset 0
116 OpDecorate %94 ArrayStride 16
117 OpMemberDecorate %95 0 Offset 0
119 OpDecorate %97 DescriptorSet 0
120 OpDecorate %97 Binding 0
122 %3 = OpTypeFunction %2
124 %7 = OpTypePointer Function %6
125 %8 = OpTypeFunction %6 %7
126 %18 = OpConstant %6 1
128 %21 = OpConstant %6 2
130 %29 = OpTypeVector %28 4
131 %30 = OpTypePointer Input %29
132 %31 = OpVariable %30 Input
134 %33 = OpConstant %32 1
135 %34 = OpTypePointer Input %28
136 %38 = OpConstantTrue %19
137 %41 = OpTypePointer Output %29
138 %42 = OpVariable %41 Output
139 %43 = OpConstant %32 2
140 %44 = OpTypeArray %6 %43
141 %45 = OpTypeStruct %44
142 %46 = OpTypePointer Uniform %45
143 %47 = OpVariable %46 Uniform
144 %48 = OpConstant %6 0
145 %49 = OpTypePointer Uniform %6
146 %84 = OpConstant %32 4
147 %85 = OpTypeArray %29 %84
148 %87 = OpTypeVector %28 2
149 %88 = OpTypeStruct %87
150 %89 = OpTypePointer PushConstant %88
151 %90 = OpVariable %89 PushConstant
152 %91 = OpTypePointer PushConstant %28
153 %94 = OpTypeArray %28 %33
154 %95 = OpTypeStruct %94
155 %96 = OpTypePointer Uniform %95
156 %97 = OpVariable %96 Uniform
157 %98 = OpTypePointer Uniform %28
158 %112 = OpTypePointer Function %85
159 %114 = OpTypePointer Function %29
160 %4 = OpFunction %2 None %3
162 %27 = OpVariable %7 Function
163 %102 = OpVariable %7 Function
164 %108 = OpVariable %7 Function
165 %113 = OpVariable %112 Function
166 %35 = OpAccessChain %34 %31 %33
168 %37 = OpConvertFToS %6 %36
170 OpSelectionMerge %40 None
171 OpBranchConditional %38 %39 %40
175 %50 = OpAccessChain %49 %47 %48 %18
177 %52 = OpConvertSToF %28 %51
178 %53 = OpAccessChain %49 %47 %48 %48
180 %55 = OpConvertSToF %28 %54
181 %56 = OpAccessChain %49 %47 %48 %48
183 %58 = OpConvertSToF %28 %57
184 %59 = OpAccessChain %49 %47 %48 %18
186 %61 = OpConvertSToF %28 %60
187 %62 = OpCompositeConstruct %29 %52 %55 %58 %61
188 %63 = OpAccessChain %49 %47 %48 %18
190 %65 = OpConvertSToF %28 %64
191 %66 = OpAccessChain %49 %47 %48 %48
193 %68 = OpConvertSToF %28 %67
194 %69 = OpAccessChain %49 %47 %48 %48
196 %71 = OpConvertSToF %28 %70
197 %72 = OpAccessChain %49 %47 %48 %18
199 %74 = OpConvertSToF %28 %73
200 %75 = OpCompositeConstruct %29 %65 %68 %71 %74
201 %76 = OpAccessChain %49 %47 %48 %48
203 %78 = OpConvertSToF %28 %77
204 %79 = OpCompositeConstruct %29 %78 %78 %78 %78
205 %80 = OpAccessChain %49 %47 %48 %48
207 %82 = OpConvertSToF %28 %81
208 %83 = OpCompositeConstruct %29 %82 %82 %82 %82
209 %86 = OpCompositeConstruct %85 %62 %75 %79 %83
210 %92 = OpAccessChain %91 %90 %48 %33
212 %99 = OpAccessChain %98 %97 %48 %48
213 %100 = OpLoad %28 %99
214 %101 = OpFOrdLessThan %19 %93 %100
215 OpSelectionMerge %104 None
216 OpBranchConditional %101 %103 %107
218 %105 = OpAccessChain %49 %47 %48 %18
219 %106 = OpLoad %6 %105
225 %110 = OpFunctionCall %6 %10 %108
229 %111 = OpLoad %6 %102
231 %115 = OpAccessChain %114 %113 %111
232 %116 = OpLoad %29 %115
236 %10 = OpFunction %6 None %8
237 %9 = OpFunctionParameter %7
241 OpLoopMerge %14 %15 None
245 %20 = OpSGreaterThan %19 %17 %18
246 OpBranchConditional %20 %13 %14
249 %23 = OpSDiv %6 %22 %21
260 # uniforms for variant
263 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
266 # _GLF_uniform_int_values
267 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
270 # _GLF_uniform_float_values
271 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
275 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
277 PIPELINE graphics variant_pipeline
278 ATTACH variant_vertex_shader
279 ATTACH variant_fragment_shader
280 FRAMEBUFFER_SIZE 32 32
281 BIND BUFFER variant_framebuffer AS color LOCATION 0
282 BIND BUFFER variant_injectionSwitch AS push_constant
283 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
284 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
286 CLEAR_COLOR variant_pipeline 0 0 0 255
288 CLEAR variant_pipeline
289 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
291 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255