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