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 the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific NIR code paths
21
22# The test passes because the shader always writes red.
23
24# Optimized using spirv-opt with the following arguments:
25# '--eliminate-local-single-block'
26# '--eliminate-local-single-store'
27# '--eliminate-local-multi-store'
28# '--eliminate-dead-branches'
29# '--scalar-replacement=100'
30# '--eliminate-local-multi-store'
31# '--inline-entry-points-exhaustive'
32# '--copy-propagate-arrays'
33# '--inline-entry-points-exhaustive'
34# '--eliminate-dead-code-aggressive'
35# '--redundancy-elimination'
36# '--vector-dce'
37# '--eliminate-dead-branches'
38# '--merge-blocks'
39# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
40
41
42
43SHADER vertex variant_vertex_shader PASSTHROUGH
44
45# variant_fragment_shader is derived from the following GLSL:
46# #version 320 es
47# #define _int_0 _GLF_uniform_int_values[0]
48# #define _int_1 _GLF_uniform_int_values[1]
49# #define _int_12 _GLF_uniform_int_values[2]
50# #define _int_5 _GLF_uniform_int_values[3]
51#
52# precision highp int;
53# precision highp float;
54#
55# // Contents of _GLF_uniform_int_values: [0, 1, 12, 5]
56# layout(set = 0, binding = 0) uniform buf0
57# {
58#     int _GLF_uniform_int_values[4];
59# };
60# layout(location = 0) out vec4 _GLF_color;
61#
62# const int _GLF_global_loop_bound = 10;
63# int _GLF_global_loop_count = 0;
64#
65# void func()
66# {
67#     int a = _int_1;
68#
69#     for(int i = _int_0; i < _int_5; i ++)
70#     {
71#         _GLF_global_loop_count ++;
72#     }
73#
74#     if(a < _int_1)
75#     {
76#         return;
77#     }
78# }
79#
80# void main()
81# {
82#     // _GLF_global_loop_count = 0, 1, 6, 7, 12
83#     while(_GLF_global_loop_count < _GLF_global_loop_bound)
84#     {
85#         _GLF_global_loop_count++;
86#         func();
87#     }
88#
89#     while(_GLF_global_loop_count < _GLF_global_loop_bound)
90#     {
91#         // Never executed.
92#         _GLF_global_loop_count ++;
93#     }
94#
95#     // Always true.
96#     if(_GLF_global_loop_count == _int_12)
97#     {
98#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
99#     }
100#     else
101#     {
102#         _GLF_color = vec4(_int_0);
103#     }
104# }
105SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
106; SPIR-V
107; Version: 1.0
108; Generator: Khronos Glslang Reference Front End; 10
109; Bound: 99
110; Schema: 0
111               OpCapability Shader
112          %1 = OpExtInstImport "GLSL.std.450"
113               OpMemoryModel Logical GLSL450
114               OpEntryPoint Fragment %4 "main" %79
115               OpExecutionMode %4 OriginUpperLeft
116               OpSource ESSL 320
117               OpName %4 "main"
118               OpName %6 "func("
119               OpName %10 "_GLF_global_loop_count"
120               OpName %17 "buf0"
121               OpMemberName %17 0 "_GLF_uniform_int_values"
122               OpName %19 ""
123               OpName %79 "_GLF_color"
124               OpDecorate %16 ArrayStride 16
125               OpMemberDecorate %17 0 Offset 0
126               OpDecorate %17 Block
127               OpDecorate %19 DescriptorSet 0
128               OpDecorate %19 Binding 0
129               OpDecorate %79 Location 0
130          %2 = OpTypeVoid
131          %3 = OpTypeFunction %2
132          %8 = OpTypeInt 32 1
133          %9 = OpTypePointer Private %8
134         %10 = OpVariable %9 Private
135         %11 = OpConstant %8 0
136         %14 = OpTypeInt 32 0
137         %15 = OpConstant %14 4
138         %16 = OpTypeArray %8 %15
139         %17 = OpTypeStruct %16
140         %18 = OpTypePointer Uniform %17
141         %19 = OpVariable %18 Uniform
142         %20 = OpConstant %8 1
143         %21 = OpTypePointer Uniform %8
144         %33 = OpConstant %8 3
145         %36 = OpTypeBool
146         %55 = OpConstant %8 10
147         %70 = OpConstant %8 2
148         %76 = OpTypeFloat 32
149         %77 = OpTypeVector %76 4
150         %78 = OpTypePointer Output %77
151         %79 = OpVariable %78 Output
152          %4 = OpFunction %2 None %3
153          %5 = OpLabel
154               OpStore %10 %11
155               OpBranch %49
156         %49 = OpLabel
157         %54 = OpLoad %8 %10
158         %56 = OpSLessThan %36 %54 %55
159               OpLoopMerge %51 %50 None
160               OpBranchConditional %56 %50 %51
161         %50 = OpLabel
162         %57 = OpLoad %8 %10
163         %58 = OpIAdd %8 %57 %20
164               OpStore %10 %58
165         %59 = OpFunctionCall %2 %6
166               OpBranch %49
167         %51 = OpLabel
168               OpBranch %60
169         %60 = OpLabel
170         %65 = OpLoad %8 %10
171         %66 = OpSLessThan %36 %65 %55
172               OpLoopMerge %62 %61 None
173               OpBranchConditional %66 %61 %62
174         %61 = OpLabel
175         %67 = OpLoad %8 %10
176         %68 = OpIAdd %8 %67 %20
177               OpStore %10 %68
178               OpBranch %60
179         %62 = OpLabel
180         %69 = OpLoad %8 %10
181         %71 = OpAccessChain %21 %19 %11 %70
182         %72 = OpLoad %8 %71
183         %73 = OpIEqual %36 %69 %72
184               OpSelectionMerge %75 None
185               OpBranchConditional %73 %74 %93
186         %74 = OpLabel
187         %80 = OpAccessChain %21 %19 %11 %20
188         %81 = OpLoad %8 %80
189         %82 = OpConvertSToF %76 %81
190         %83 = OpAccessChain %21 %19 %11 %11
191         %84 = OpLoad %8 %83
192         %85 = OpConvertSToF %76 %84
193         %92 = OpCompositeConstruct %77 %82 %85 %85 %82
194               OpStore %79 %92
195               OpBranch %75
196         %93 = OpLabel
197         %94 = OpAccessChain %21 %19 %11 %11
198         %95 = OpLoad %8 %94
199         %96 = OpConvertSToF %76 %95
200         %97 = OpCompositeConstruct %77 %96 %96 %96 %96
201               OpStore %79 %97
202               OpBranch %75
203         %75 = OpLabel
204               OpReturn
205               OpFunctionEnd
206          %6 = OpFunction %2 None %3
207          %7 = OpLabel
208         %22 = OpAccessChain %21 %19 %11 %20
209         %23 = OpLoad %8 %22
210         %25 = OpAccessChain %21 %19 %11 %11
211         %26 = OpLoad %8 %25
212               OpBranch %27
213         %27 = OpLabel
214         %98 = OpPhi %8 %26 %7 %41 %28
215         %34 = OpAccessChain %21 %19 %11 %33
216         %35 = OpLoad %8 %34
217         %37 = OpSLessThan %36 %98 %35
218               OpLoopMerge %29 %28 None
219               OpBranchConditional %37 %28 %29
220         %28 = OpLabel
221         %38 = OpLoad %8 %10
222         %39 = OpIAdd %8 %38 %20
223               OpStore %10 %39
224         %41 = OpIAdd %8 %98 %20
225               OpBranch %27
226         %29 = OpLabel
227         %45 = OpSLessThan %36 %23 %23
228               OpSelectionMerge %47 None
229               OpBranchConditional %45 %46 %47
230         %46 = OpLabel
231               OpReturn
232         %47 = OpLabel
233               OpReturn
234               OpFunctionEnd
235END
236
237# uniforms for variant
238
239# _GLF_uniform_int_values
240BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
241 0 1 12 5
242END
243
244BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
245
246PIPELINE graphics variant_pipeline
247  ATTACH variant_vertex_shader
248  ATTACH variant_fragment_shader
249  FRAMEBUFFER_SIZE 256 256
250  BIND BUFFER variant_framebuffer AS color LOCATION 0
251  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
252END
253CLEAR_COLOR variant_pipeline 0 0 0 255
254
255CLEAR variant_pipeline
256RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
257
258EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
259