1#!amber
2
3# Copyright 2020 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 a specific selection dag code path
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 310 es
28# #define _int_3 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _int_1 _GLF_uniform_int_values[2]
31# #define _float_10_0 _GLF_uniform_float_values[0]
32# #define _float_1_0 _GLF_uniform_float_values[1]
33# #define _float_2_0 _GLF_uniform_float_values[2]
34# #define _float_3_0 _GLF_uniform_float_values[3]
35# #define _float_4_0 _GLF_uniform_float_values[4]
36#
37# precision highp int;
38# precision highp float;
39#
40# // Contents of _GLF_uniform_float_values: [10.0, 1.0, 2.0, 3.0, 4.0]
41# layout(set = 0, binding = 0) uniform buf0
42# {
43#     float _GLF_uniform_float_values[5];
44# };
45#
46# // Contents of _GLF_uniform_int_values: [3, 0, 1]
47# layout(set = 0, binding = 1) uniform buf1
48# {
49#     int _GLF_uniform_int_values[3];
50# };
51#
52# layout(location = 0) out vec4 _GLF_color;
53#
54# void main()
55# {
56#     mat2 M1 = mat2(_float_1_0, _float_2_0, _float_3_0, _float_4_0);
57#     float a = _float_1_0;
58#
59#     for (int c = _int_0; c < _int_3; c++)
60#     {
61#         // At each iteration, clamp returns 0.
62#         a += M1[_int_1][clamp(~c, 0, 1)];
63#     }
64#
65#     if (a == _float_10_0)
66#     {
67#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
68#     }
69#     else
70#     {
71#         _GLF_color = vec4(_int_1);
72#     }
73# }
74SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
75; SPIR-V
76; Version: 1.0
77; Generator: Khronos Glslang Reference Front End; 10
78; Bound: 99
79; Schema: 0
80               OpCapability Shader
81          %1 = OpExtInstImport "GLSL.std.450"
82               OpMemoryModel Logical GLSL450
83               OpEntryPoint Fragment %4 "main" %80
84               OpExecutionMode %4 OriginUpperLeft
85               OpSource ESSL 310
86               OpName %4 "main"
87               OpName %10 "M1"
88               OpName %14 "buf0"
89               OpMemberName %14 0 "_GLF_uniform_float_values"
90               OpName %16 ""
91               OpName %38 "a"
92               OpName %42 "c"
93               OpName %45 "buf1"
94               OpMemberName %45 0 "_GLF_uniform_int_values"
95               OpName %47 ""
96               OpName %80 "_GLF_color"
97               OpDecorate %13 ArrayStride 16
98               OpMemberDecorate %14 0 Offset 0
99               OpDecorate %14 Block
100               OpDecorate %16 DescriptorSet 0
101               OpDecorate %16 Binding 0
102               OpDecorate %44 ArrayStride 16
103               OpMemberDecorate %45 0 Offset 0
104               OpDecorate %45 Block
105               OpDecorate %47 DescriptorSet 0
106               OpDecorate %47 Binding 1
107               OpDecorate %80 Location 0
108          %2 = OpTypeVoid
109          %3 = OpTypeFunction %2
110          %6 = OpTypeFloat 32
111          %7 = OpTypeVector %6 2
112          %8 = OpTypeMatrix %7 2
113          %9 = OpTypePointer Function %8
114         %11 = OpTypeInt 32 0
115         %12 = OpConstant %11 5
116         %13 = OpTypeArray %6 %12
117         %14 = OpTypeStruct %13
118         %15 = OpTypePointer Uniform %14
119         %16 = OpVariable %15 Uniform
120         %17 = OpTypeInt 32 1
121         %18 = OpConstant %17 0
122         %19 = OpConstant %17 1
123         %20 = OpTypePointer Uniform %6
124         %23 = OpConstant %17 2
125         %26 = OpConstant %17 3
126         %29 = OpConstant %17 4
127         %32 = OpConstant %6 1
128         %33 = OpConstant %6 0
129         %37 = OpTypePointer Function %6
130         %41 = OpTypePointer Function %17
131         %43 = OpConstant %11 3
132         %44 = OpTypeArray %17 %43
133         %45 = OpTypeStruct %44
134         %46 = OpTypePointer Uniform %45
135         %47 = OpVariable %46 Uniform
136         %48 = OpTypePointer Uniform %17
137         %59 = OpTypeBool
138         %78 = OpTypeVector %6 4
139         %79 = OpTypePointer Output %78
140         %80 = OpVariable %79 Output
141          %4 = OpFunction %2 None %3
142          %5 = OpLabel
143         %10 = OpVariable %9 Function
144         %38 = OpVariable %37 Function
145         %42 = OpVariable %41 Function
146         %21 = OpAccessChain %20 %16 %18 %19
147         %22 = OpLoad %6 %21
148         %24 = OpAccessChain %20 %16 %18 %23
149         %25 = OpLoad %6 %24
150         %27 = OpAccessChain %20 %16 %18 %26
151         %28 = OpLoad %6 %27
152         %30 = OpAccessChain %20 %16 %18 %29
153         %31 = OpLoad %6 %30
154         %34 = OpCompositeConstruct %7 %22 %25
155         %35 = OpCompositeConstruct %7 %28 %31
156         %36 = OpCompositeConstruct %8 %34 %35
157               OpStore %10 %36
158         %39 = OpAccessChain %20 %16 %18 %19
159         %40 = OpLoad %6 %39
160               OpStore %38 %40
161         %49 = OpAccessChain %48 %47 %18 %19
162         %50 = OpLoad %17 %49
163               OpStore %42 %50
164               OpBranch %51
165         %51 = OpLabel
166               OpLoopMerge %53 %54 None
167               OpBranch %55
168         %55 = OpLabel
169         %56 = OpLoad %17 %42
170         %57 = OpAccessChain %48 %47 %18 %18
171         %58 = OpLoad %17 %57
172         %60 = OpSLessThan %59 %56 %58
173               OpBranchConditional %60 %52 %53
174         %52 = OpLabel
175         %61 = OpAccessChain %48 %47 %18 %23
176         %62 = OpLoad %17 %61
177         %63 = OpLoad %17 %42
178         %64 = OpNot %17 %63
179         %65 = OpExtInst %17 %1 SClamp %64 %18 %19
180         %66 = OpAccessChain %37 %10 %62 %65
181         %67 = OpLoad %6 %66
182         %68 = OpLoad %6 %38
183         %69 = OpFAdd %6 %68 %67
184               OpStore %38 %69
185               OpBranch %54
186         %54 = OpLabel
187         %70 = OpLoad %17 %42
188         %71 = OpIAdd %17 %70 %19
189               OpStore %42 %71
190               OpBranch %51
191         %53 = OpLabel
192         %72 = OpLoad %6 %38
193         %73 = OpAccessChain %20 %16 %18 %18
194         %74 = OpLoad %6 %73
195         %75 = OpFOrdEqual %59 %72 %74
196               OpSelectionMerge %77 None
197               OpBranchConditional %75 %76 %94
198         %76 = OpLabel
199         %81 = OpAccessChain %48 %47 %18 %23
200         %82 = OpLoad %17 %81
201         %83 = OpConvertSToF %6 %82
202         %84 = OpAccessChain %48 %47 %18 %19
203         %85 = OpLoad %17 %84
204         %86 = OpConvertSToF %6 %85
205         %87 = OpAccessChain %48 %47 %18 %19
206         %88 = OpLoad %17 %87
207         %89 = OpConvertSToF %6 %88
208         %90 = OpAccessChain %48 %47 %18 %23
209         %91 = OpLoad %17 %90
210         %92 = OpConvertSToF %6 %91
211         %93 = OpCompositeConstruct %78 %83 %86 %89 %92
212               OpStore %80 %93
213               OpBranch %77
214         %94 = OpLabel
215         %95 = OpAccessChain %48 %47 %18 %23
216         %96 = OpLoad %17 %95
217         %97 = OpConvertSToF %6 %96
218         %98 = OpCompositeConstruct %78 %97 %97 %97 %97
219               OpStore %80 %98
220               OpBranch %77
221         %77 = OpLabel
222               OpReturn
223               OpFunctionEnd
224END
225
226# uniforms for variant
227
228# _GLF_uniform_int_values
229BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
230 3 0 1
231END
232# _GLF_uniform_float_values
233BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
234 10.0 1.0 2.0 3.0 4.0
235END
236
237BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
238
239PIPELINE graphics variant_pipeline
240  ATTACH variant_vertex_shader
241  ATTACH variant_fragment_shader
242  FRAMEBUFFER_SIZE 16 16
243  BIND BUFFER variant_framebuffer AS color LOCATION 0
244  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
245  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
246END
247CLEAR_COLOR variant_pipeline 0 0 0 255
248
249CLEAR variant_pipeline
250RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
251
252EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255
253