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