1#!amber
2
3# Copyright 2021 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17
18# A test for a coverage-gap found by the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific NIR code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28#
29# #define _int_1 _GLF_uniform_int_values[0]
30# #define _int_0 _GLF_uniform_int_values[1]
31# #define _int_2 _GLF_uniform_int_values[2]
32# #define _int_100 _GLF_uniform_int_values[3]
33# #define _float_1_0 _GLF_uniform_float_values[0]
34# #define _float_0_0 _GLF_uniform_float_values[1]
35#
36# precision highp int;
37# precision highp float;
38#
39# // Contents of _GLF_uniform_int_values: [1, 0, 2, 100]
40# layout(set = 0, binding = 0) uniform buf0
41# {
42#     int _GLF_uniform_int_values[4];
43# };
44# // Contents of _GLF_uniform_float_values: [1.0, 0.0]
45# layout(set = 0, binding = 1) uniform buf1
46# {
47#     float _GLF_uniform_float_values[2];
48# };
49# layout(location = 0) out vec4 _GLF_color;
50#
51# void main()
52# {
53#     mat2x3 m23 = mat2x3(_float_0_0);
54#
55#     // Iterates once because of the break.
56#     for (int i = 1; i < _int_100; i++)
57#     {
58#         m23[_int_1][_int_2] += _float_1_0;
59#
60#         if (gl_FragCoord.y < _float_1_0)
61#         {
62#         }
63#
64#         // Always true.
65#         if (!(true && (gl_FragCoord.x < 0.0)))
66#         {
67#             break;
68#         }
69#     }
70#
71#     // Always true.
72#     if(m23 == mat2x3(_int_0, _int_0, _int_0, _int_0, _int_0, _int_1))
73#     {
74#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
75#     }
76#     else
77#     {
78#         _GLF_color = vec4(_int_0);
79#     }
80# }
81SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
82; SPIR-V
83; Version: 1.0
84; Generator: Khronos Glslang Reference Front End; 10
85; Bound: 139
86; Schema: 0
87               OpCapability Shader
88          %1 = OpExtInstImport "GLSL.std.450"
89               OpMemoryModel Logical GLSL450
90               OpEntryPoint Fragment %4 "main" %61 %120
91               OpExecutionMode %4 OriginUpperLeft
92               OpSource ESSL 320
93               OpName %4 "main"
94               OpName %10 "m23"
95               OpName %14 "buf1"
96               OpMemberName %14 0 "_GLF_uniform_float_values"
97               OpName %16 ""
98               OpName %29 "i"
99               OpName %38 "buf0"
100               OpMemberName %38 0 "_GLF_uniform_int_values"
101               OpName %40 ""
102               OpName %61 "gl_FragCoord"
103               OpName %120 "_GLF_color"
104               OpDecorate %13 ArrayStride 16
105               OpMemberDecorate %14 0 Offset 0
106               OpDecorate %14 Block
107               OpDecorate %16 DescriptorSet 0
108               OpDecorate %16 Binding 1
109               OpDecorate %37 ArrayStride 16
110               OpMemberDecorate %38 0 Offset 0
111               OpDecorate %38 Block
112               OpDecorate %40 DescriptorSet 0
113               OpDecorate %40 Binding 0
114               OpDecorate %61 BuiltIn FragCoord
115               OpDecorate %120 Location 0
116          %2 = OpTypeVoid
117          %3 = OpTypeFunction %2
118          %6 = OpTypeFloat 32
119          %7 = OpTypeVector %6 3
120          %8 = OpTypeMatrix %7 2
121          %9 = OpTypePointer Function %8
122         %11 = OpTypeInt 32 0
123         %12 = OpConstant %11 2
124         %13 = OpTypeArray %6 %12
125         %14 = OpTypeStruct %13
126         %15 = OpTypePointer Uniform %14
127         %16 = OpVariable %15 Uniform
128         %17 = OpTypeInt 32 1
129         %18 = OpConstant %17 0
130         %19 = OpConstant %17 1
131         %20 = OpTypePointer Uniform %6
132         %23 = OpConstant %6 1
133         %24 = OpConstant %6 0
134         %28 = OpTypePointer Function %17
135         %36 = OpConstant %11 4
136         %37 = OpTypeArray %17 %36
137         %38 = OpTypeStruct %37
138         %39 = OpTypePointer Uniform %38
139         %40 = OpVariable %39 Uniform
140         %41 = OpConstant %17 3
141         %42 = OpTypePointer Uniform %17
142         %45 = OpTypeBool
143         %49 = OpConstant %17 2
144         %54 = OpTypePointer Function %6
145         %59 = OpTypeVector %6 4
146         %60 = OpTypePointer Input %59
147         %61 = OpVariable %60 Input
148         %62 = OpConstant %11 1
149         %63 = OpTypePointer Input %6
150         %71 = OpConstantTrue %45
151         %74 = OpConstant %11 0
152        %109 = OpTypeVector %45 3
153        %119 = OpTypePointer Output %59
154        %120 = OpVariable %119 Output
155          %4 = OpFunction %2 None %3
156          %5 = OpLabel
157         %10 = OpVariable %9 Function
158         %29 = OpVariable %28 Function
159         %21 = OpAccessChain %20 %16 %18 %19
160         %22 = OpLoad %6 %21
161         %25 = OpCompositeConstruct %7 %22 %24 %24
162         %26 = OpCompositeConstruct %7 %24 %22 %24
163         %27 = OpCompositeConstruct %8 %25 %26
164               OpStore %10 %27
165               OpStore %29 %19
166               OpBranch %30
167         %30 = OpLabel
168               OpLoopMerge %32 %33 None
169               OpBranch %34
170         %34 = OpLabel
171         %35 = OpLoad %17 %29
172         %43 = OpAccessChain %42 %40 %18 %41
173         %44 = OpLoad %17 %43
174         %46 = OpSLessThan %45 %35 %44
175               OpBranchConditional %46 %31 %32
176         %31 = OpLabel
177         %47 = OpAccessChain %42 %40 %18 %18
178         %48 = OpLoad %17 %47
179         %50 = OpAccessChain %42 %40 %18 %49
180         %51 = OpLoad %17 %50
181         %52 = OpAccessChain %20 %16 %18 %18
182         %53 = OpLoad %6 %52
183         %55 = OpAccessChain %54 %10 %48 %51
184         %56 = OpLoad %6 %55
185         %57 = OpFAdd %6 %56 %53
186         %58 = OpAccessChain %54 %10 %48 %51
187               OpStore %58 %57
188         %64 = OpAccessChain %63 %61 %62
189         %65 = OpLoad %6 %64
190         %66 = OpAccessChain %20 %16 %18 %18
191         %67 = OpLoad %6 %66
192         %68 = OpFOrdLessThan %45 %65 %67
193               OpSelectionMerge %70 None
194               OpBranchConditional %68 %69 %70
195         %69 = OpLabel
196               OpBranch %70
197         %70 = OpLabel
198               OpSelectionMerge %73 None
199               OpBranchConditional %71 %72 %73
200         %72 = OpLabel
201         %75 = OpAccessChain %63 %61 %74
202         %76 = OpLoad %6 %75
203         %77 = OpFOrdLessThan %45 %76 %24
204               OpBranch %73
205         %73 = OpLabel
206         %78 = OpPhi %45 %71 %70 %77 %72
207         %79 = OpLogicalNot %45 %78
208               OpSelectionMerge %81 None
209               OpBranchConditional %79 %80 %81
210         %80 = OpLabel
211               OpBranch %32
212         %81 = OpLabel
213               OpBranch %33
214         %33 = OpLabel
215         %83 = OpLoad %17 %29
216         %84 = OpIAdd %17 %83 %19
217               OpStore %29 %84
218               OpBranch %30
219         %32 = OpLabel
220         %85 = OpLoad %8 %10
221         %86 = OpAccessChain %42 %40 %18 %19
222         %87 = OpLoad %17 %86
223         %88 = OpConvertSToF %6 %87
224         %89 = OpAccessChain %42 %40 %18 %19
225         %90 = OpLoad %17 %89
226         %91 = OpConvertSToF %6 %90
227         %92 = OpAccessChain %42 %40 %18 %19
228         %93 = OpLoad %17 %92
229         %94 = OpConvertSToF %6 %93
230         %95 = OpAccessChain %42 %40 %18 %19
231         %96 = OpLoad %17 %95
232         %97 = OpConvertSToF %6 %96
233         %98 = OpAccessChain %42 %40 %18 %19
234         %99 = OpLoad %17 %98
235        %100 = OpConvertSToF %6 %99
236        %101 = OpAccessChain %42 %40 %18 %18
237        %102 = OpLoad %17 %101
238        %103 = OpConvertSToF %6 %102
239        %104 = OpCompositeConstruct %7 %88 %91 %94
240        %105 = OpCompositeConstruct %7 %97 %100 %103
241        %106 = OpCompositeConstruct %8 %104 %105
242        %107 = OpCompositeExtract %7 %85 0
243        %108 = OpCompositeExtract %7 %106 0
244        %110 = OpFOrdEqual %109 %107 %108
245        %111 = OpAll %45 %110
246        %112 = OpCompositeExtract %7 %85 1
247        %113 = OpCompositeExtract %7 %106 1
248        %114 = OpFOrdEqual %109 %112 %113
249        %115 = OpAll %45 %114
250        %116 = OpLogicalAnd %45 %111 %115
251               OpSelectionMerge %118 None
252               OpBranchConditional %116 %117 %134
253        %117 = OpLabel
254        %121 = OpAccessChain %42 %40 %18 %18
255        %122 = OpLoad %17 %121
256        %123 = OpConvertSToF %6 %122
257        %124 = OpAccessChain %42 %40 %18 %19
258        %125 = OpLoad %17 %124
259        %126 = OpConvertSToF %6 %125
260        %127 = OpAccessChain %42 %40 %18 %19
261        %128 = OpLoad %17 %127
262        %129 = OpConvertSToF %6 %128
263        %130 = OpAccessChain %42 %40 %18 %18
264        %131 = OpLoad %17 %130
265        %132 = OpConvertSToF %6 %131
266        %133 = OpCompositeConstruct %59 %123 %126 %129 %132
267               OpStore %120 %133
268               OpBranch %118
269        %134 = OpLabel
270        %135 = OpAccessChain %42 %40 %18 %19
271        %136 = OpLoad %17 %135
272        %137 = OpConvertSToF %6 %136
273        %138 = OpCompositeConstruct %59 %137 %137 %137 %137
274               OpStore %120 %138
275               OpBranch %118
276        %118 = OpLabel
277               OpReturn
278               OpFunctionEnd
279END
280
281# uniforms for variant
282
283# _GLF_uniform_float_values
284BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
285 1.0 0.0
286END
287# _GLF_uniform_int_values
288BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
289 1 0 2 100
290END
291
292BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
293
294PIPELINE graphics variant_pipeline
295  ATTACH variant_vertex_shader
296  ATTACH variant_fragment_shader
297  FRAMEBUFFER_SIZE 256 256
298  BIND BUFFER variant_framebuffer AS color LOCATION 0
299  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
300  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
301END
302CLEAR_COLOR variant_pipeline 0 0 0 255
303
304CLEAR variant_pipeline
305RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
306
307EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
308