1#!amber
2
3# Copyright 2022 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 LLVM 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# precision highp float;
30# precision highp int;
31#
32# // Contents of one: 1
33# layout(push_constant) uniform buf_push
34# {
35#     int one;
36# };
37#
38# layout(location = 0) out vec4 _GLF_color;
39#
40# void main()
41# {
42#     int a = 100;
43#
44#     do
45#     {
46#         // Always false.
47#         if(one < 1)
48#         {
49#             break;
50#         }
51#
52#         a--;
53#     }
54#     while(a > 1);
55#
56#     // Always true.
57#     if(a == 1)
58#     {
59#         _GLF_color = vec4(1, 0, 0, 1);
60#     }
61#     else
62#     {
63#         _GLF_color = vec4(0);
64#     }
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; 10
70; Bound: 44
71; Schema: 0
72               OpCapability Shader
73          %1 = OpExtInstImport "GLSL.std.450"
74               OpMemoryModel Logical GLSL450
75               OpEntryPoint Fragment %4 "main" %38
76               OpExecutionMode %4 OriginUpperLeft
77               OpSource ESSL 320
78               OpName %4 "main"
79               OpName %8 "a"
80               OpName %14 "buf_push"
81               OpMemberName %14 0 "one"
82               OpName %16 ""
83               OpName %38 "_GLF_color"
84               OpMemberDecorate %14 0 Offset 0
85               OpDecorate %14 Block
86               OpDecorate %38 Location 0
87          %2 = OpTypeVoid
88          %3 = OpTypeFunction %2
89          %6 = OpTypeInt 32 1
90          %7 = OpTypePointer Function %6
91          %9 = OpConstant %6 100
92         %14 = OpTypeStruct %6
93         %15 = OpTypePointer PushConstant %14
94         %16 = OpVariable %15 PushConstant
95         %17 = OpConstant %6 0
96         %18 = OpTypePointer PushConstant %6
97         %21 = OpConstant %6 1
98         %22 = OpTypeBool
99         %35 = OpTypeFloat 32
100         %36 = OpTypeVector %35 4
101         %37 = OpTypePointer Output %36
102         %38 = OpVariable %37 Output
103         %39 = OpConstant %35 1
104         %40 = OpConstant %35 0
105         %41 = OpConstantComposite %36 %39 %40 %40 %39
106         %43 = OpConstantComposite %36 %40 %40 %40 %40
107          %4 = OpFunction %2 None %3
108          %5 = OpLabel
109          %8 = OpVariable %7 Function
110               OpStore %8 %9
111               OpBranch %10
112         %10 = OpLabel
113               OpLoopMerge %12 %13 None
114               OpBranch %11
115         %11 = OpLabel
116         %19 = OpAccessChain %18 %16 %17
117         %20 = OpLoad %6 %19
118         %23 = OpSLessThan %22 %20 %21
119               OpSelectionMerge %25 None
120               OpBranchConditional %23 %24 %25
121         %24 = OpLabel
122               OpBranch %12
123         %25 = OpLabel
124         %27 = OpLoad %6 %8
125         %28 = OpISub %6 %27 %21
126               OpStore %8 %28
127               OpBranch %13
128         %13 = OpLabel
129         %29 = OpLoad %6 %8
130         %30 = OpSGreaterThan %22 %29 %21
131               OpBranchConditional %30 %10 %12
132         %12 = OpLabel
133         %31 = OpLoad %6 %8
134         %32 = OpIEqual %22 %31 %21
135               OpSelectionMerge %34 None
136               OpBranchConditional %32 %33 %42
137         %33 = OpLabel
138               OpStore %38 %41
139               OpBranch %34
140         %42 = OpLabel
141               OpStore %38 %43
142               OpBranch %34
143         %34 = OpLabel
144               OpReturn
145               OpFunctionEnd
146END
147
148# uniforms for variant
149
150# one
151BUFFER variant_one DATA_TYPE int32 STD140 DATA
152 1
153END
154
155BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
156
157PIPELINE graphics variant_pipeline
158  ATTACH variant_vertex_shader
159  ATTACH variant_fragment_shader
160  FRAMEBUFFER_SIZE 32 32
161  BIND BUFFER variant_framebuffer AS color LOCATION 0
162  BIND BUFFER variant_one AS push_constant
163END
164CLEAR_COLOR variant_pipeline 0 0 0 255
165
166CLEAR variant_pipeline
167RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
168
169EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
170