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
24# Optimized using spirv-opt with the following arguments:
25# '--eliminate-dead-branches'
26# '--merge-return'
27# '--eliminate-dead-inserts'
28# '--eliminate-local-single-store'
29# '--scalar-replacement=100'
30# '--eliminate-dead-branches'
31# '--merge-blocks'
32# '--scalar-replacement=100'
33# '--eliminate-dead-branches'
34# '--ccp'
35# '--ccp'
36# '--eliminate-dead-branches'
37# '--merge-blocks'
38# '--vector-dce'
39# '--eliminate-dead-branches'
40# '--scalar-replacement=100'
41# '--eliminate-local-single-store'
42# '--combine-access-chains'
43# '--redundancy-elimination'
44# '--ccp'
45# '--eliminate-dead-code-aggressive'
46# '--private-to-local'
47# '--eliminate-local-single-block'
48# '--eliminate-local-multi-store'
49# '--eliminate-local-single-block'
50# '--ccp'
51# spirv-opt commit hash: 96354f5047bf35765af49657304357e00264e5f9
52
53
54
55SHADER vertex variant_vertex_shader PASSTHROUGH
56
57# variant_fragment_shader is derived from the following GLSL:
58# #version 310 es
59# precision highp float;
60# precision highp int;
61#
62# layout(location = 0) out vec4 _GLF_color;
63# layout(set = 0, binding = 0) uniform buf0
64# {
65#     int zero;
66# };
67#
68# vec4 returnRed()
69# {
70#     do
71#     {
72#         // Always false.
73#         if(zero == 1)
74#         {
75#             return vec4(1, 0, 0, 1);
76#         }
77#     }
78#     while(false);
79#     return vec4(1, 0, 0, 1);
80# }
81#
82# void main()
83# {
84#     do
85#     {
86#         _GLF_color = returnRed();
87#     }
88#     while(false);
89# }
90SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
91; SPIR-V
92; Version: 1.0
93; Generator: Khronos Glslang Reference Front End; 8
94; Bound: 63
95; Schema: 0
96               OpCapability Shader
97          %1 = OpExtInstImport "GLSL.std.450"
98               OpMemoryModel Logical GLSL450
99               OpEntryPoint Fragment %4 "main" %40
100               OpExecutionMode %4 OriginUpperLeft
101               OpSource ESSL 310
102               OpName %4 "main"
103               OpName %9 "returnRed("
104               OpName %16 "buf0"
105               OpMemberName %16 0 "zero"
106               OpName %18 ""
107               OpName %40 "_GLF_color"
108               OpMemberDecorate %16 0 Offset 0
109               OpDecorate %16 Block
110               OpDecorate %18 DescriptorSet 0
111               OpDecorate %18 Binding 0
112               OpDecorate %40 Location 0
113          %2 = OpTypeVoid
114          %3 = OpTypeFunction %2
115          %6 = OpTypeFloat 32
116          %7 = OpTypeVector %6 4
117          %8 = OpTypeFunction %7
118         %15 = OpTypeInt 32 1
119         %16 = OpTypeStruct %15
120         %17 = OpTypePointer Uniform %16
121         %18 = OpVariable %17 Uniform
122         %19 = OpConstant %15 0
123         %20 = OpTypePointer Uniform %15
124         %23 = OpConstant %15 1
125         %24 = OpTypeBool
126         %28 = OpConstant %6 1
127         %29 = OpConstant %6 0
128         %30 = OpConstantComposite %7 %28 %29 %29 %28
129         %32 = OpConstantFalse %24
130         %39 = OpTypePointer Output %7
131         %40 = OpVariable %39 Output
132         %43 = OpTypePointer Function %7
133         %49 = OpTypePointer Function %24
134         %51 = OpConstantTrue %24
135         %61 = OpUndef %7
136         %62 = OpUndef %24
137          %4 = OpFunction %2 None %3
138          %5 = OpLabel
139               OpBranch %35
140         %35 = OpLabel
141         %41 = OpFunctionCall %7 %9
142               OpStore %40 %41
143               OpLoopMerge %37 %35 None
144               OpBranchConditional %32 %35 %37
145         %37 = OpLabel
146               OpReturn
147               OpFunctionEnd
148          %9 = OpFunction %7 None %8
149         %10 = OpLabel
150         %50 = OpVariable %49 Function %32
151         %44 = OpVariable %43 Function
152               OpBranch %46
153         %46 = OpLabel
154         %56 = OpPhi %24 %32 %10 %62 %48
155               OpLoopMerge %42 %48 None
156               OpBranch %11
157         %11 = OpLabel
158               OpLoopMerge %13 %14 None
159               OpBranch %12
160         %12 = OpLabel
161         %21 = OpAccessChain %20 %18 %19
162         %22 = OpLoad %15 %21
163         %25 = OpIEqual %24 %22 %23
164               OpSelectionMerge %27 None
165               OpBranchConditional %25 %26 %27
166         %26 = OpLabel
167               OpStore %50 %51
168               OpStore %44 %30
169               OpBranch %13
170         %27 = OpLabel
171               OpBranch %14
172         %14 = OpLabel
173               OpBranchConditional %32 %11 %13
174         %13 = OpLabel
175         %58 = OpPhi %7 %30 %26 %61 %14
176         %54 = OpPhi %24 %51 %26 %32 %14
177               OpSelectionMerge %52 None
178               OpBranchConditional %54 %42 %52
179         %52 = OpLabel
180               OpStore %50 %51
181               OpStore %44 %30
182               OpBranch %42
183         %48 = OpLabel
184               OpBranch %46
185         %42 = OpLabel
186         %57 = OpPhi %7 %58 %13 %30 %52
187               OpReturnValue %57
188               OpFunctionEnd
189END
190
191# uniforms for variant
192
193# zero
194BUFFER variant_zero DATA_TYPE int32 DATA
195 0
196END
197
198BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
199
200PIPELINE graphics variant_pipeline
201  ATTACH variant_vertex_shader
202  ATTACH variant_fragment_shader
203  FRAMEBUFFER_SIZE 256 256
204  BIND BUFFER variant_framebuffer AS color LOCATION 0
205  BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0
206END
207CLEAR_COLOR variant_pipeline 0 0 0 255
208
209CLEAR variant_pipeline
210RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
211
212EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
213