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 GraphicsFuzz.
19
20# Short description: A fragment shader that covers a specific live interval code path.
21
22# The test passes because 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# precision highp float;
29# precision highp int;
30#
31# layout(location = 0) out vec4 _GLF_color;
32#
33# vec3 func()
34# {
35#     vec2 v = vec2(1);
36#     int i = 0;
37#     for(int k = 0; k < 2; k++)
38#     {
39#         if(v.y + 1.0 > 4.0) // Always false.
40#             break;
41#
42#         v.y = 1.0;
43#         i++;
44#     }
45#
46#     if(i < 10) // Always true.
47#         return vec3(1, 0, 0);
48#     else
49#         return vec3(0, 0, 1);
50# }
51#
52# void main()
53# {
54#     vec3 data[2];
55#
56#     // Writes data[0] = (1, 0, 0).
57#     for(int j = 0; j < 1; j++)
58#         data[j] = func();
59#
60#     // Writes data[1] = (1, 0, 0).
61#     for(int j = 0; j < 1; j++)
62#         data[4*j + 1] = func();
63#
64#     _GLF_color = vec4(data[0], 1);
65# }
66SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
67; SPIR-V
68; Version: 1.0
69; Generator: Khronos Glslang Reference Front End; 8
70; Bound: 102
71; Schema: 0
72               OpCapability Shader
73          %1 = OpExtInstImport "GLSL.std.450"
74               OpMemoryModel Logical GLSL450
75               OpEntryPoint Fragment %4 "main" %95
76               OpExecutionMode %4 OriginUpperLeft
77               OpSource ESSL 310
78               OpName %4 "main"
79               OpName %9 "func("
80               OpName %13 "v"
81               OpName %18 "i"
82               OpName %20 "k"
83               OpName %59 "j"
84               OpName %70 "data"
85               OpName %77 "j"
86               OpName %95 "_GLF_color"
87               OpDecorate %95 Location 0
88          %2 = OpTypeVoid
89          %3 = OpTypeFunction %2
90          %6 = OpTypeFloat 32
91          %7 = OpTypeVector %6 3
92          %8 = OpTypeFunction %7
93         %11 = OpTypeVector %6 2
94         %12 = OpTypePointer Function %11
95         %14 = OpConstant %6 1
96         %15 = OpConstantComposite %11 %14 %14
97         %16 = OpTypeInt 32 1
98         %17 = OpTypePointer Function %16
99         %19 = OpConstant %16 0
100         %27 = OpConstant %16 2
101         %28 = OpTypeBool
102         %30 = OpTypeInt 32 0
103         %31 = OpConstant %30 1
104         %32 = OpTypePointer Function %6
105         %36 = OpConstant %6 4
106         %43 = OpConstant %16 1
107         %48 = OpConstant %16 10
108         %52 = OpConstant %6 0
109         %53 = OpConstantComposite %7 %14 %52 %52
110         %56 = OpConstantComposite %7 %52 %52 %14
111         %67 = OpConstant %30 2
112         %68 = OpTypeArray %7 %67
113         %69 = OpTypePointer Function %68
114         %73 = OpTypePointer Function %7
115         %85 = OpConstant %16 4
116         %93 = OpTypeVector %6 4
117         %94 = OpTypePointer Output %93
118         %95 = OpVariable %94 Output
119          %4 = OpFunction %2 None %3
120          %5 = OpLabel
121         %59 = OpVariable %17 Function
122         %70 = OpVariable %69 Function
123         %77 = OpVariable %17 Function
124               OpStore %59 %19
125               OpBranch %60
126         %60 = OpLabel
127               OpLoopMerge %62 %63 None
128               OpBranch %64
129         %64 = OpLabel
130         %65 = OpLoad %16 %59
131         %66 = OpSLessThan %28 %65 %43
132               OpBranchConditional %66 %61 %62
133         %61 = OpLabel
134         %71 = OpLoad %16 %59
135         %72 = OpFunctionCall %7 %9
136         %74 = OpAccessChain %73 %70 %71
137               OpStore %74 %72
138               OpBranch %63
139         %63 = OpLabel
140         %75 = OpLoad %16 %59
141         %76 = OpIAdd %16 %75 %43
142               OpStore %59 %76
143               OpBranch %60
144         %62 = OpLabel
145               OpStore %77 %19
146               OpBranch %78
147         %78 = OpLabel
148               OpLoopMerge %80 %81 None
149               OpBranch %82
150         %82 = OpLabel
151         %83 = OpLoad %16 %77
152         %84 = OpSLessThan %28 %83 %43
153               OpBranchConditional %84 %79 %80
154         %79 = OpLabel
155         %86 = OpLoad %16 %77
156         %87 = OpIMul %16 %85 %86
157         %88 = OpIAdd %16 %87 %43
158         %89 = OpFunctionCall %7 %9
159         %90 = OpAccessChain %73 %70 %88
160               OpStore %90 %89
161               OpBranch %81
162         %81 = OpLabel
163         %91 = OpLoad %16 %77
164         %92 = OpIAdd %16 %91 %43
165               OpStore %77 %92
166               OpBranch %78
167         %80 = OpLabel
168         %96 = OpAccessChain %73 %70 %19
169         %97 = OpLoad %7 %96
170         %98 = OpCompositeExtract %6 %97 0
171         %99 = OpCompositeExtract %6 %97 1
172        %100 = OpCompositeExtract %6 %97 2
173        %101 = OpCompositeConstruct %93 %98 %99 %100 %14
174               OpStore %95 %101
175               OpReturn
176               OpFunctionEnd
177          %9 = OpFunction %7 None %8
178         %10 = OpLabel
179         %13 = OpVariable %12 Function
180         %18 = OpVariable %17 Function
181         %20 = OpVariable %17 Function
182               OpStore %13 %15
183               OpStore %18 %19
184               OpStore %20 %19
185               OpBranch %21
186         %21 = OpLabel
187               OpLoopMerge %23 %24 None
188               OpBranch %25
189         %25 = OpLabel
190         %26 = OpLoad %16 %20
191         %29 = OpSLessThan %28 %26 %27
192               OpBranchConditional %29 %22 %23
193         %22 = OpLabel
194         %33 = OpAccessChain %32 %13 %31
195         %34 = OpLoad %6 %33
196         %35 = OpFAdd %6 %34 %14
197         %37 = OpFOrdGreaterThan %28 %35 %36
198               OpSelectionMerge %39 None
199               OpBranchConditional %37 %38 %39
200         %38 = OpLabel
201               OpBranch %23
202         %39 = OpLabel
203         %41 = OpAccessChain %32 %13 %31
204               OpStore %41 %14
205         %42 = OpLoad %16 %18
206         %44 = OpIAdd %16 %42 %43
207               OpStore %18 %44
208               OpBranch %24
209         %24 = OpLabel
210         %45 = OpLoad %16 %20
211         %46 = OpIAdd %16 %45 %43
212               OpStore %20 %46
213               OpBranch %21
214         %23 = OpLabel
215         %47 = OpLoad %16 %18
216         %49 = OpSLessThan %28 %47 %48
217               OpSelectionMerge %51 None
218               OpBranchConditional %49 %50 %55
219         %50 = OpLabel
220               OpReturnValue %53
221         %55 = OpLabel
222               OpReturnValue %56
223         %51 = OpLabel
224               OpUnreachable
225               OpFunctionEnd
226END
227
228
229BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
230
231PIPELINE graphics variant_pipeline
232  ATTACH variant_vertex_shader
233  ATTACH variant_fragment_shader
234  FRAMEBUFFER_SIZE 256 256
235  BIND BUFFER variant_framebuffer AS color LOCATION 0
236END
237CLEAR_COLOR variant_pipeline 0 0 0 255
238
239CLEAR variant_pipeline
240RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
241
242EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
243