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:
26 # '--scalar-replacement=100'
27 # '--eliminate-local-multi-store'
28 # '--copy-propagate-arrays'
29 # '--convert-local-access-chains'
30 # '--reduce-load-size'
31 # '--eliminate-dead-inserts'
32 # '--eliminate-dead-inserts'
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]
44 # #define _int_2 _GLF_uniform_int_values[2]
45 # #define _int_4 _GLF_uniform_int_values[3]
46 # #define _float_1_0 _GLF_uniform_float_values[0]
47 # #define _float_0_0 _GLF_uniform_float_values[1]
48 # #define _float_3_0 _GLF_uniform_float_values[2]
50 # precision highp int;
51 # precision highp float;
53 # // Contents of _GLF_uniform_int_values: [1, 0, 2, 4]
54 # layout(set = 0, binding = 0) uniform buf0
56 # int _GLF_uniform_int_values[4];
58 # // Contents of _GLF_uniform_float_values: [1.0, 0.0, 3.0]
59 # layout(set = 0, binding = 1) uniform buf1
61 # float _GLF_uniform_float_values[3];
63 # layout(location = 0) out vec4 _GLF_color;
67 # mat4x3 m43 = mat4x3(_float_0_0);
68 # m43[_int_1][_int_1] = _float_1_0;
69 # float sums[3] = float[3](_float_1_0, _float_1_0, _float_1_0);
71 # // Increases sums[1] by one, picking it from m43[1][1].
72 # for(int i = _int_1; i < _int_4; i++)
74 # sums[_int_1] += m43[i][_int_1];
80 # // Static out of bound access is required
81 # // to hit the coverage point. Still, this
82 # // is never executed.
84 # sums[_int_2] += m43[a][_int_1];
87 # if(sums[_int_0] + sums[_int_1] == _float_3_0)
89 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
93 # _GLF_color = vec4(_int_0);
96 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
99 ; Generator: Khronos Glslang Reference Front End; 10
103 %1 = OpExtInstImport "GLSL.std.450"
104 OpMemoryModel Logical GLSL450
105 OpEntryPoint Fragment %4 "main" %116
106 OpExecutionMode %4 OriginUpperLeft
111 OpMemberName %14 0 "_GLF_uniform_float_values"
114 OpMemberName %32 0 "_GLF_uniform_int_values"
119 OpName %116 "_GLF_color"
120 OpDecorate %13 ArrayStride 16
121 OpMemberDecorate %14 0 Offset 0
123 OpDecorate %16 DescriptorSet 0
124 OpDecorate %16 Binding 1
125 OpDecorate %31 ArrayStride 16
126 OpMemberDecorate %32 0 Offset 0
128 OpDecorate %34 DescriptorSet 0
129 OpDecorate %34 Binding 0
130 OpDecorate %116 Location 0
132 %3 = OpTypeFunction %2
134 %7 = OpTypeVector %6 3
135 %8 = OpTypeMatrix %7 4
136 %9 = OpTypePointer Function %8
138 %12 = OpConstant %11 3
139 %13 = OpTypeArray %6 %12
140 %14 = OpTypeStruct %13
141 %15 = OpTypePointer Uniform %14
142 %16 = OpVariable %15 Uniform
144 %18 = OpConstant %17 0
145 %19 = OpConstant %17 1
146 %20 = OpTypePointer Uniform %6
147 %23 = OpConstant %6 1
148 %24 = OpConstant %6 0
149 %30 = OpConstant %11 4
150 %31 = OpTypeArray %17 %30
151 %32 = OpTypeStruct %31
152 %33 = OpTypePointer Uniform %32
153 %34 = OpVariable %33 Uniform
154 %35 = OpTypePointer Uniform %17
155 %42 = OpTypePointer Function %6
156 %44 = OpTypePointer Function %13
157 %53 = OpTypePointer Function %17
158 %63 = OpConstant %17 3
160 %87 = OpConstant %17 4
161 %88 = OpConstant %17 2
162 %114 = OpTypeVector %6 4
163 %115 = OpTypePointer Output %114
164 %116 = OpVariable %115 Output
165 %136 = OpConstantComposite %7 %24 %24 %24
166 %4 = OpFunction %2 None %3
168 %10 = OpVariable %9 Function
169 %45 = OpVariable %44 Function
170 %54 = OpVariable %53 Function
171 %86 = OpVariable %53 Function
172 %21 = OpAccessChain %20 %16 %18 %19
174 %25 = OpCompositeConstruct %7 %22 %24 %24
175 %26 = OpCompositeConstruct %7 %24 %22 %24
176 %27 = OpCompositeConstruct %7 %24 %24 %22
177 %28 = OpCompositeConstruct %7 %24 %24 %24
178 %29 = OpCompositeConstruct %8 %25 %26 %27 %136
180 %36 = OpAccessChain %35 %34 %18 %18
182 %38 = OpAccessChain %35 %34 %18 %18
184 %40 = OpAccessChain %20 %16 %18 %18
186 %43 = OpAccessChain %42 %10 %37 %39
188 %46 = OpAccessChain %20 %16 %18 %18
190 %48 = OpAccessChain %20 %16 %18 %18
192 %50 = OpAccessChain %20 %16 %18 %18
194 %52 = OpCompositeConstruct %13 %47 %49 %51
196 %55 = OpAccessChain %35 %34 %18 %18
201 %135 = OpPhi %17 %56 %5 %80 %60
202 OpLoopMerge %59 %60 None
205 %64 = OpAccessChain %35 %34 %18 %63
207 %67 = OpSLessThan %66 %135 %65
208 OpBranchConditional %67 %58 %59
210 %68 = OpAccessChain %35 %34 %18 %18
212 %71 = OpAccessChain %35 %34 %18 %18
214 %73 = OpAccessChain %42 %10 %135 %72
216 %75 = OpAccessChain %42 %45 %69
218 %77 = OpFAdd %6 %76 %74
219 %78 = OpAccessChain %42 %45 %69
223 %80 = OpIAdd %17 %135 %19
227 %81 = OpAccessChain %35 %34 %18 %19
229 %83 = OpIEqual %66 %82 %19
230 OpSelectionMerge %85 None
231 OpBranchConditional %83 %84 %85
234 %89 = OpAccessChain %35 %34 %18 %88
236 %92 = OpAccessChain %35 %34 %18 %18
238 %94 = OpAccessChain %42 %10 %87 %93
240 %96 = OpAccessChain %42 %45 %90
242 %98 = OpFAdd %6 %97 %95
243 %99 = OpAccessChain %42 %45 %90
247 %100 = OpAccessChain %35 %34 %18 %19
248 %101 = OpLoad %17 %100
249 %102 = OpAccessChain %42 %45 %101
250 %103 = OpLoad %6 %102
251 %104 = OpAccessChain %35 %34 %18 %18
252 %105 = OpLoad %17 %104
253 %106 = OpAccessChain %42 %45 %105
254 %107 = OpLoad %6 %106
255 %108 = OpFAdd %6 %103 %107
256 %109 = OpAccessChain %20 %16 %18 %88
257 %110 = OpLoad %6 %109
258 %111 = OpFOrdEqual %66 %108 %110
259 OpSelectionMerge %113 None
260 OpBranchConditional %111 %112 %130
262 %117 = OpAccessChain %35 %34 %18 %18
263 %118 = OpLoad %17 %117
264 %119 = OpConvertSToF %6 %118
265 %120 = OpAccessChain %35 %34 %18 %19
266 %121 = OpLoad %17 %120
267 %122 = OpConvertSToF %6 %121
268 %123 = OpAccessChain %35 %34 %18 %19
269 %124 = OpLoad %17 %123
270 %125 = OpConvertSToF %6 %124
271 %126 = OpAccessChain %35 %34 %18 %18
272 %127 = OpLoad %17 %126
273 %128 = OpConvertSToF %6 %127
274 %129 = OpCompositeConstruct %114 %119 %122 %125 %128
278 %131 = OpAccessChain %35 %34 %18 %19
279 %132 = OpLoad %17 %131
280 %133 = OpConvertSToF %6 %132
281 %134 = OpCompositeConstruct %114 %133 %133 %133 %133
289 # uniforms for variant
291 # _GLF_uniform_float_values
292 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
295 # _GLF_uniform_int_values
296 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
300 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
302 PIPELINE graphics variant_pipeline
303 ATTACH variant_vertex_shader
304 ATTACH variant_fragment_shader
305 FRAMEBUFFER_SIZE 256 256
306 BIND BUFFER variant_framebuffer AS color LOCATION 0
307 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
308 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
310 CLEAR_COLOR variant_pipeline 0 0 0 255
312 CLEAR variant_pipeline
313 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
315 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255