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