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