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