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