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