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 specific value tracking and simplification 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# precision highp float;
29# precision highp int;
30#
31# layout(location = 0) out vec4 _GLF_color;
32# layout(set = 0, binding = 0) uniform buf0
33# {
34#     int one;
35# };
36#
37# void main()
38# {
39#     int a[3];
40#     a[0] = 1;
41#     a[1] = 2;
42#     a[2] = 3;
43#
44#     int b = 0;
45#     int c = a[one];
46#
47#     // Always true.
48#     if(c > 1)
49#     {
50#         // This will be overwritten later.
51#         _GLF_color = vec4(0, 1, 1, 0);
52#         ++b;
53#     }
54#
55#     // Increments a[2] to 4.
56#     a[clamp(++b, 0, 2)]++;
57#
58#     if (a[2] == 4)
59#         _GLF_color = vec4(1, 0, 0, 1);
60#     else
61#         _GLF_color = vec4(0);
62# }
63SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
64; SPIR-V
65; Version: 1.0
66; Generator: Khronos Glslang Reference Front End; 8
67; Bound: 59
68; Schema: 0
69               OpCapability Shader
70          %1 = OpExtInstImport "GLSL.std.450"
71               OpMemoryModel Logical GLSL450
72               OpEntryPoint Fragment %4 "main" %38
73               OpExecutionMode %4 OriginUpperLeft
74               OpSource ESSL 310
75               OpName %4 "main"
76               OpName %11 "a"
77               OpName %20 "b"
78               OpName %21 "c"
79               OpName %22 "buf0"
80               OpMemberName %22 0 "one"
81               OpName %24 ""
82               OpName %38 "_GLF_color"
83               OpMemberDecorate %22 0 Offset 0
84               OpDecorate %22 Block
85               OpDecorate %24 DescriptorSet 0
86               OpDecorate %24 Binding 0
87               OpDecorate %38 Location 0
88          %2 = OpTypeVoid
89          %3 = OpTypeFunction %2
90          %6 = OpTypeInt 32 1
91          %7 = OpTypeInt 32 0
92          %8 = OpConstant %7 3
93          %9 = OpTypeArray %6 %8
94         %10 = OpTypePointer Function %9
95         %12 = OpConstant %6 0
96         %13 = OpConstant %6 1
97         %14 = OpTypePointer Function %6
98         %16 = OpConstant %6 2
99         %18 = OpConstant %6 3
100         %22 = OpTypeStruct %6
101         %23 = OpTypePointer Uniform %22
102         %24 = OpVariable %23 Uniform
103         %25 = OpTypePointer Uniform %6
104         %31 = OpTypeBool
105         %35 = OpTypeFloat 32
106         %36 = OpTypeVector %35 4
107         %37 = OpTypePointer Output %36
108         %38 = OpVariable %37 Output
109         %39 = OpConstant %35 0
110         %40 = OpConstant %35 1
111         %41 = OpConstantComposite %36 %39 %40 %40 %39
112         %52 = OpConstant %6 4
113         %56 = OpConstantComposite %36 %40 %39 %39 %40
114         %58 = OpConstantComposite %36 %39 %39 %39 %39
115          %4 = OpFunction %2 None %3
116          %5 = OpLabel
117         %11 = OpVariable %10 Function
118         %20 = OpVariable %14 Function
119         %21 = OpVariable %14 Function
120         %15 = OpAccessChain %14 %11 %12
121               OpStore %15 %13
122         %17 = OpAccessChain %14 %11 %13
123               OpStore %17 %16
124         %19 = OpAccessChain %14 %11 %16
125               OpStore %19 %18
126               OpStore %20 %12
127         %26 = OpAccessChain %25 %24 %12
128         %27 = OpLoad %6 %26
129         %28 = OpAccessChain %14 %11 %27
130         %29 = OpLoad %6 %28
131               OpStore %21 %29
132         %30 = OpLoad %6 %21
133         %32 = OpSGreaterThan %31 %30 %13
134               OpSelectionMerge %34 None
135               OpBranchConditional %32 %33 %34
136         %33 = OpLabel
137               OpStore %38 %41
138         %42 = OpLoad %6 %20
139         %43 = OpIAdd %6 %42 %13
140               OpStore %20 %43
141               OpBranch %34
142         %34 = OpLabel
143         %44 = OpLoad %6 %20
144         %45 = OpIAdd %6 %44 %13
145               OpStore %20 %45
146         %46 = OpExtInst %6 %1 SClamp %45 %12 %16
147         %47 = OpAccessChain %14 %11 %46
148         %48 = OpLoad %6 %47
149         %49 = OpIAdd %6 %48 %13
150               OpStore %47 %49
151         %50 = OpAccessChain %14 %11 %16
152         %51 = OpLoad %6 %50
153         %53 = OpIEqual %31 %51 %52
154               OpSelectionMerge %55 None
155               OpBranchConditional %53 %54 %57
156         %54 = OpLabel
157               OpStore %38 %56
158               OpBranch %55
159         %57 = OpLabel
160               OpStore %38 %58
161               OpBranch %55
162         %55 = OpLabel
163               OpReturn
164               OpFunctionEnd
165END
166
167# uniforms for variant
168
169# one
170BUFFER variant_one DATA_TYPE int32 DATA
171 1
172END
173
174BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
175
176PIPELINE graphics variant_pipeline
177  ATTACH variant_vertex_shader
178  ATTACH variant_fragment_shader
179  FRAMEBUFFER_SIZE 256 256
180  BIND BUFFER variant_framebuffer AS color LOCATION 0
181  BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0
182END
183CLEAR_COLOR variant_pipeline 0 0 0 255
184
185CLEAR variant_pipeline
186RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
187
188EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
189