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 inlining optimization 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#
29# precision highp float;
30# precision highp int;
31#
32# layout(location = 0) out vec4 _GLF_color;
33#
34# float func()
35# {
36#     for (int i = 0; i < 10; ++i)
37#     {
38#         if (i > 5)
39#             ++i;
40#
41#         if (i > 8)
42#             return 0.0;
43#     }
44#
45#     return 1.0;
46# }
47#
48# void main()
49# {
50#     if (false)
51#     {
52#         _GLF_color = vec4(func());
53#     }
54#     else
55#     {
56#         _GLF_color = vec4(1, 0, 0, 1);
57#     }
58# }
59SHADER fragment variant_fragment_shader SPIRV-ASM
60; SPIR-V
61; Version: 1.0
62; Generator: Khronos Glslang Reference Front End; 8
63; Bound: 53
64; Schema: 0
65               OpCapability Shader
66          %1 = OpExtInstImport "GLSL.std.450"
67               OpMemoryModel Logical GLSL450
68               OpEntryPoint Fragment %4 "main" %48
69               OpExecutionMode %4 OriginUpperLeft
70               OpSource ESSL 310
71               OpName %4 "main"
72               OpName %8 "func("
73               OpName %12 "i"
74               OpName %48 "_GLF_color"
75               OpDecorate %48 Location 0
76          %2 = OpTypeVoid
77          %3 = OpTypeFunction %2
78          %6 = OpTypeFloat 32
79          %7 = OpTypeFunction %6
80         %10 = OpTypeInt 32 1
81         %11 = OpTypePointer Function %10
82         %13 = OpConstant %10 0
83         %20 = OpConstant %10 10
84         %21 = OpTypeBool
85         %24 = OpConstant %10 5
86         %29 = OpConstant %10 1
87         %32 = OpConstant %10 8
88         %36 = OpConstant %6 0
89         %40 = OpConstant %6 1
90         %43 = OpConstantFalse %21
91         %46 = OpTypeVector %6 4
92         %47 = OpTypePointer Output %46
93         %48 = OpVariable %47 Output
94         %52 = OpConstantComposite %46 %40 %36 %36 %40
95          %4 = OpFunction %2 None %3
96          %5 = OpLabel
97               OpSelectionMerge %45 None
98               OpBranchConditional %43 %44 %51
99         %44 = OpLabel
100         %49 = OpFunctionCall %6 %8
101         %50 = OpCompositeConstruct %46 %49 %49 %49 %49
102               OpStore %48 %50
103               OpBranch %45
104         %51 = OpLabel
105               OpStore %48 %52
106               OpBranch %45
107         %45 = OpLabel
108               OpReturn
109               OpFunctionEnd
110          %8 = OpFunction %6 None %7
111          %9 = OpLabel
112         %12 = OpVariable %11 Function
113               OpStore %12 %13
114               OpBranch %14
115         %14 = OpLabel
116               OpLoopMerge %16 %17 None
117               OpBranch %18
118         %18 = OpLabel
119         %19 = OpLoad %10 %12
120         %22 = OpSLessThan %21 %19 %20
121               OpBranchConditional %22 %15 %16
122         %15 = OpLabel
123         %23 = OpLoad %10 %12
124         %25 = OpSGreaterThan %21 %23 %24
125               OpSelectionMerge %27 None
126               OpBranchConditional %25 %26 %27
127         %26 = OpLabel
128         %28 = OpLoad %10 %12
129         %30 = OpIAdd %10 %28 %29
130               OpStore %12 %30
131               OpBranch %27
132         %27 = OpLabel
133         %31 = OpLoad %10 %12
134         %33 = OpSGreaterThan %21 %31 %32
135               OpSelectionMerge %35 None
136               OpBranchConditional %33 %34 %35
137         %34 = OpLabel
138               OpReturnValue %36
139         %35 = OpLabel
140               OpBranch %17
141         %17 = OpLabel
142         %38 = OpLoad %10 %12
143         %39 = OpIAdd %10 %38 %29
144               OpStore %12 %39
145               OpBranch %14
146         %16 = OpLabel
147               OpReturnValue %40
148               OpFunctionEnd
149END
150
151
152BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
153
154PIPELINE graphics variant_pipeline
155  ATTACH variant_vertex_shader
156  ATTACH variant_fragment_shader
157  FRAMEBUFFER_SIZE 256 256
158  BIND BUFFER variant_framebuffer AS color LOCATION 0
159END
160CLEAR_COLOR variant_pipeline 0 0 0 255
161
162CLEAR variant_pipeline
163RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
164
165EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
166