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# #define _int_1 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30#
31# precision highp int;
32# precision highp float;
33#
34# // Contents of _GLF_uniform_int_values: [1, 0]
35# layout(set = 0, binding = 0) uniform buf0
36# {
37#     int _GLF_uniform_int_values[2];
38# };
39#
40# layout(location = 0) out vec4 _GLF_color;
41#
42# void main()
43# {
44#     // After this a has either all or none of the bits as one.
45#     int a = (int(gl_FragCoord.y) & 1) != 0 ? 0 : ~ 0;
46#
47#     // Bitwise AND with a negation is always zero.
48#     if((a & (~a)) == _int_0)
49#     {
50#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
51#     }
52#     else
53#     {
54#         _GLF_color = vec4(_int_0);
55#     }
56# }
57SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
58; SPIR-V
59; Version: 1.0
60; Generator: Khronos Glslang Reference Front End; 10
61; Bound: 61
62; Schema: 0
63               OpCapability Shader
64          %1 = OpExtInstImport "GLSL.std.450"
65               OpMemoryModel Logical GLSL450
66               OpEntryPoint Fragment %4 "main" %12 %42
67               OpExecutionMode %4 OriginUpperLeft
68               OpSource ESSL 320
69               OpName %4 "main"
70               OpName %8 "a"
71               OpName %12 "gl_FragCoord"
72               OpName %32 "buf0"
73               OpMemberName %32 0 "_GLF_uniform_int_values"
74               OpName %34 ""
75               OpName %42 "_GLF_color"
76               OpDecorate %12 BuiltIn FragCoord
77               OpDecorate %31 ArrayStride 16
78               OpMemberDecorate %32 0 Offset 0
79               OpDecorate %32 Block
80               OpDecorate %34 DescriptorSet 0
81               OpDecorate %34 Binding 0
82               OpDecorate %42 Location 0
83          %2 = OpTypeVoid
84          %3 = OpTypeFunction %2
85          %6 = OpTypeInt 32 1
86          %7 = OpTypePointer Function %6
87          %9 = OpTypeFloat 32
88         %10 = OpTypeVector %9 4
89         %11 = OpTypePointer Input %10
90         %12 = OpVariable %11 Input
91         %13 = OpTypeInt 32 0
92         %14 = OpConstant %13 1
93         %15 = OpTypePointer Input %9
94         %19 = OpConstant %6 1
95         %21 = OpConstant %6 0
96         %22 = OpTypeBool
97         %24 = OpConstant %6 -1
98         %30 = OpConstant %13 2
99         %31 = OpTypeArray %6 %30
100         %32 = OpTypeStruct %31
101         %33 = OpTypePointer Uniform %32
102         %34 = OpVariable %33 Uniform
103         %35 = OpTypePointer Uniform %6
104         %41 = OpTypePointer Output %10
105         %42 = OpVariable %41 Output
106          %4 = OpFunction %2 None %3
107          %5 = OpLabel
108          %8 = OpVariable %7 Function
109         %16 = OpAccessChain %15 %12 %14
110         %17 = OpLoad %9 %16
111         %18 = OpConvertFToS %6 %17
112         %20 = OpBitwiseAnd %6 %18 %19
113         %23 = OpINotEqual %22 %20 %21
114         %25 = OpSelect %6 %23 %21 %24
115               OpStore %8 %25
116         %26 = OpLoad %6 %8
117         %27 = OpLoad %6 %8
118         %28 = OpNot %6 %27
119         %29 = OpBitwiseAnd %6 %26 %28
120         %36 = OpAccessChain %35 %34 %21 %19
121         %37 = OpLoad %6 %36
122         %38 = OpIEqual %22 %29 %37
123               OpSelectionMerge %40 None
124               OpBranchConditional %38 %39 %56
125         %39 = OpLabel
126         %43 = OpAccessChain %35 %34 %21 %21
127         %44 = OpLoad %6 %43
128         %45 = OpConvertSToF %9 %44
129         %46 = OpAccessChain %35 %34 %21 %19
130         %47 = OpLoad %6 %46
131         %48 = OpConvertSToF %9 %47
132         %49 = OpAccessChain %35 %34 %21 %19
133         %50 = OpLoad %6 %49
134         %51 = OpConvertSToF %9 %50
135         %52 = OpAccessChain %35 %34 %21 %21
136         %53 = OpLoad %6 %52
137         %54 = OpConvertSToF %9 %53
138         %55 = OpCompositeConstruct %10 %45 %48 %51 %54
139               OpStore %42 %55
140               OpBranch %40
141         %56 = OpLabel
142         %57 = OpAccessChain %35 %34 %21 %19
143         %58 = OpLoad %6 %57
144         %59 = OpConvertSToF %9 %58
145         %60 = OpCompositeConstruct %10 %59 %59 %59 %59
146               OpStore %42 %60
147               OpBranch %40
148         %40 = OpLabel
149               OpReturn
150               OpFunctionEnd
151END
152
153# uniforms for variant
154
155# _GLF_uniform_int_values
156BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
157 1 0
158END
159
160BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
161
162PIPELINE graphics variant_pipeline
163  ATTACH variant_vertex_shader
164  ATTACH variant_fragment_shader
165  FRAMEBUFFER_SIZE 256 256
166  BIND BUFFER variant_framebuffer AS color LOCATION 0
167  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
168END
169CLEAR_COLOR variant_pipeline 0 0 0 255
170
171CLEAR variant_pipeline
172RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
173
174EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
175