• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: Covers a specific instruction combine compares and combine select 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 310 es
28# #define _int_2 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _int_1 _GLF_uniform_int_values[2]
31# #define _uint_1 _GLF_uniform_uint_values[0]
32# #define _float_1_0 _GLF_uniform_float_values[0]
33#
34# precision highp float;
35# precision highp int;
36#
37# // Contents of _GLF_uniform_float_values: 1.0
38# layout(set = 0, binding = 0) uniform buf0
39# {
40#     float _GLF_uniform_float_values[1];
41# };
42#
43# // Contents of _GLF_uniform_uint_values: 1
44# layout(set = 0, binding = 1) uniform buf1
45# {
46#     uint _GLF_uniform_uint_values[1];
47# };
48#
49# // Contents of _GLF_uniform_int_values: [2, 0, 1]
50# layout(set = 0, binding = 2) uniform buf2
51# {
52#     int _GLF_uniform_int_values[3];
53# };
54#
55# layout(location = 0) out vec4 _GLF_color;
56#
57# struct S {
58#     int a;
59# };
60#
61# // Always returns 1.
62# int f1()
63# {
64#     S A = S(1);
65#     int i = _int_0;
66#     for (int i = _int_0; i < _int_0 + _int_2; i++)
67#     {
68#         if (A.a == clamp(i, _int_0, 1))
69#         {
70#             return _int_1;
71#         }
72#     }
73#
74#     // The function returns before reaching this.
75#     return _int_2;
76# }
77#
78# // Always returns 1.0.
79# float f2()
80# {
81#     return float(f1());
82# }
83#
84# void main()
85# {
86#     uint a = _uint_1;
87#     uint b = uaddCarry(uint(2 * _int_0), uint(_int_0), a);
88#     if (b == 0u && f2() == _float_1_0)
89#     {
90#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
91#     }
92#     else
93#     {
94#         _GLF_color = vec4(_int_1);
95#     }
96# }
97SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
98; SPIR-V
99; Version: 1.0
100; Generator: Khronos Glslang Reference Front End; 8
101; Bound: 130
102; Schema: 0
103               OpCapability Shader
104          %1 = OpExtInstImport "GLSL.std.450"
105               OpMemoryModel Logical GLSL450
106               OpEntryPoint Fragment %4 "main" %111
107               OpExecutionMode %4 OriginUpperLeft
108               OpSource ESSL 310
109               OpName %4 "main"
110               OpName %8 "f1("
111               OpName %12 "f2("
112               OpName %14 "S"
113               OpMemberName %14 0 "a"
114               OpName %16 "A"
115               OpName %20 "i"
116               OpName %24 "buf2"
117               OpMemberName %24 0 "_GLF_uniform_int_values"
118               OpName %26 ""
119               OpName %31 "i"
120               OpName %71 "a"
121               OpName %74 "buf1"
122               OpMemberName %74 0 "_GLF_uniform_uint_values"
123               OpName %76 ""
124               OpName %80 "b"
125               OpName %88 "ResType"
126               OpName %99 "buf0"
127               OpMemberName %99 0 "_GLF_uniform_float_values"
128               OpName %101 ""
129               OpName %111 "_GLF_color"
130               OpDecorate %23 ArrayStride 16
131               OpMemberDecorate %24 0 Offset 0
132               OpDecorate %24 Block
133               OpDecorate %26 DescriptorSet 0
134               OpDecorate %26 Binding 2
135               OpDecorate %73 ArrayStride 16
136               OpMemberDecorate %74 0 Offset 0
137               OpDecorate %74 Block
138               OpDecorate %76 DescriptorSet 0
139               OpDecorate %76 Binding 1
140               OpDecorate %98 ArrayStride 16
141               OpMemberDecorate %99 0 Offset 0
142               OpDecorate %99 Block
143               OpDecorate %101 DescriptorSet 0
144               OpDecorate %101 Binding 0
145               OpDecorate %111 Location 0
146          %2 = OpTypeVoid
147          %3 = OpTypeFunction %2
148          %6 = OpTypeInt 32 1
149          %7 = OpTypeFunction %6
150         %10 = OpTypeFloat 32
151         %11 = OpTypeFunction %10
152         %14 = OpTypeStruct %6
153         %15 = OpTypePointer Function %14
154         %17 = OpConstant %6 1
155         %18 = OpConstantComposite %14 %17
156         %19 = OpTypePointer Function %6
157         %21 = OpTypeInt 32 0
158         %22 = OpConstant %21 3
159         %23 = OpTypeArray %6 %22
160         %24 = OpTypeStruct %23
161         %25 = OpTypePointer Uniform %24
162         %26 = OpVariable %25 Uniform
163         %27 = OpConstant %6 0
164         %28 = OpTypePointer Uniform %6
165         %45 = OpTypeBool
166         %56 = OpConstant %6 2
167         %70 = OpTypePointer Function %21
168         %72 = OpConstant %21 1
169         %73 = OpTypeArray %21 %72
170         %74 = OpTypeStruct %73
171         %75 = OpTypePointer Uniform %74
172         %76 = OpVariable %75 Uniform
173         %77 = OpTypePointer Uniform %21
174         %88 = OpTypeStruct %21 %21
175         %93 = OpConstant %21 0
176         %98 = OpTypeArray %10 %72
177         %99 = OpTypeStruct %98
178        %100 = OpTypePointer Uniform %99
179        %101 = OpVariable %100 Uniform
180        %102 = OpTypePointer Uniform %10
181        %109 = OpTypeVector %10 4
182        %110 = OpTypePointer Output %109
183        %111 = OpVariable %110 Output
184          %4 = OpFunction %2 None %3
185          %5 = OpLabel
186         %71 = OpVariable %70 Function
187         %80 = OpVariable %70 Function
188         %78 = OpAccessChain %77 %76 %27 %27
189         %79 = OpLoad %21 %78
190               OpStore %71 %79
191         %81 = OpAccessChain %28 %26 %27 %17
192         %82 = OpLoad %6 %81
193         %83 = OpIMul %6 %56 %82
194         %84 = OpBitcast %21 %83
195         %85 = OpAccessChain %28 %26 %27 %17
196         %86 = OpLoad %6 %85
197         %87 = OpBitcast %21 %86
198         %89 = OpIAddCarry %88 %84 %87
199         %90 = OpCompositeExtract %21 %89 1
200               OpStore %71 %90
201         %91 = OpCompositeExtract %21 %89 0
202               OpStore %80 %91
203         %92 = OpLoad %21 %80
204         %94 = OpIEqual %45 %92 %93
205               OpSelectionMerge %96 None
206               OpBranchConditional %94 %95 %96
207         %95 = OpLabel
208         %97 = OpFunctionCall %10 %12
209        %103 = OpAccessChain %102 %101 %27 %27
210        %104 = OpLoad %10 %103
211        %105 = OpFOrdEqual %45 %97 %104
212               OpBranch %96
213         %96 = OpLabel
214        %106 = OpPhi %45 %94 %5 %105 %95
215               OpSelectionMerge %108 None
216               OpBranchConditional %106 %107 %125
217        %107 = OpLabel
218        %112 = OpAccessChain %28 %26 %27 %56
219        %113 = OpLoad %6 %112
220        %114 = OpConvertSToF %10 %113
221        %115 = OpAccessChain %28 %26 %27 %17
222        %116 = OpLoad %6 %115
223        %117 = OpConvertSToF %10 %116
224        %118 = OpAccessChain %28 %26 %27 %17
225        %119 = OpLoad %6 %118
226        %120 = OpConvertSToF %10 %119
227        %121 = OpAccessChain %28 %26 %27 %56
228        %122 = OpLoad %6 %121
229        %123 = OpConvertSToF %10 %122
230        %124 = OpCompositeConstruct %109 %114 %117 %120 %123
231               OpStore %111 %124
232               OpBranch %108
233        %125 = OpLabel
234        %126 = OpAccessChain %28 %26 %27 %56
235        %127 = OpLoad %6 %126
236        %128 = OpConvertSToF %10 %127
237        %129 = OpCompositeConstruct %109 %128 %128 %128 %128
238               OpStore %111 %129
239               OpBranch %108
240        %108 = OpLabel
241               OpReturn
242               OpFunctionEnd
243          %8 = OpFunction %6 None %7
244          %9 = OpLabel
245         %16 = OpVariable %15 Function
246         %20 = OpVariable %19 Function
247         %31 = OpVariable %19 Function
248               OpStore %16 %18
249         %29 = OpAccessChain %28 %26 %27 %17
250         %30 = OpLoad %6 %29
251               OpStore %20 %30
252         %32 = OpAccessChain %28 %26 %27 %17
253         %33 = OpLoad %6 %32
254               OpStore %31 %33
255               OpBranch %34
256         %34 = OpLabel
257               OpLoopMerge %36 %37 None
258               OpBranch %38
259         %38 = OpLabel
260         %39 = OpLoad %6 %31
261         %40 = OpAccessChain %28 %26 %27 %17
262         %41 = OpLoad %6 %40
263         %42 = OpAccessChain %28 %26 %27 %27
264         %43 = OpLoad %6 %42
265         %44 = OpIAdd %6 %41 %43
266         %46 = OpSLessThan %45 %39 %44
267               OpBranchConditional %46 %35 %36
268         %35 = OpLabel
269         %47 = OpAccessChain %19 %16 %27
270         %48 = OpLoad %6 %47
271         %49 = OpLoad %6 %31
272         %50 = OpAccessChain %28 %26 %27 %17
273         %51 = OpLoad %6 %50
274         %52 = OpExtInst %6 %1 SClamp %49 %51 %17
275         %53 = OpIEqual %45 %48 %52
276               OpSelectionMerge %55 None
277               OpBranchConditional %53 %54 %55
278         %54 = OpLabel
279         %57 = OpAccessChain %28 %26 %27 %56
280         %58 = OpLoad %6 %57
281               OpReturnValue %58
282         %55 = OpLabel
283               OpBranch %37
284         %37 = OpLabel
285         %60 = OpLoad %6 %31
286         %61 = OpIAdd %6 %60 %17
287               OpStore %31 %61
288               OpBranch %34
289         %36 = OpLabel
290         %62 = OpAccessChain %28 %26 %27 %27
291         %63 = OpLoad %6 %62
292               OpReturnValue %63
293               OpFunctionEnd
294         %12 = OpFunction %10 None %11
295         %13 = OpLabel
296         %66 = OpFunctionCall %6 %8
297         %67 = OpConvertSToF %10 %66
298               OpReturnValue %67
299               OpFunctionEnd
300END
301
302# uniforms for variant
303
304# _GLF_uniform_int_values
305BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
306 2 0 1
307END
308# _GLF_uniform_uint_values
309BUFFER variant__GLF_uniform_uint_values DATA_TYPE int32[] STD140 DATA
310 1
311END
312# _GLF_uniform_float_values
313BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
314 1.0
315END
316
317BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
318
319PIPELINE graphics variant_pipeline
320  ATTACH variant_vertex_shader
321  ATTACH variant_fragment_shader
322  FRAMEBUFFER_SIZE 256 256
323  BIND BUFFER variant_framebuffer AS color LOCATION 0
324  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 2
325  BIND BUFFER variant__GLF_uniform_uint_values AS uniform DESCRIPTOR_SET 0 BINDING 1
326  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
327END
328CLEAR_COLOR variant_pipeline 0 0 0 255
329
330CLEAR variant_pipeline
331RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
332
333EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
334