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